source: src/main/java/agents/anac/y2011/ValueModelAgent/ValueModeler.java@ 117

Last change on this file since 117 was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 4.5 KB
Line 
1package agents.anac.y2011.ValueModelAgent;
2
3import genius.core.Bid;
4import genius.core.issue.Value;
5import genius.core.utility.AdditiveUtilitySpace;
6
7public class ValueModeler {
8 public boolean initialized=false;
9 AdditiveUtilitySpace utilitySpace;
10 IssuesDecreases[] issues;
11 //initializing the opponenent model with the opponentFirstBid,
12 //which is assumed to be the best bid possible
13 public void initialize(AdditiveUtilitySpace space,Bid firstBid) throws Exception{
14 initialized=true;
15 utilitySpace = space;
16 int issueCount = utilitySpace.getDomain().getIssues().size();
17 issues = new IssuesDecreases[issueCount];
18 for(int i =0; i<issueCount;i++) {
19 Value value = firstBid.getValue(utilitySpace.getIssue(i).getNumber());
20 issues[i] = new IssuesDecreases(utilitySpace);
21 issues[i].initilize(utilitySpace.getDomain().getIssues().get(i), value, issueCount);
22 }
23 }
24 private void normalize(){
25
26 for(int i=0;i<issues.length;i++){
27 //issues[i].normalize(issues[i].weight()/sumWeight);
28 //OK so it dosn't really sum up to 1...
29 issues[i].normalize(issues[i].weight());
30 }
31
32
33 }
34 //this function gets a reliability measurement of a value and determines
35 //how much units of deviation should this reliability level move
36 //for each movement of 100% reliability
37 private double reliabilityToDevUnits(double reliability){
38 if(reliability>1/2){
39 return (1/(reliability*reliability))/issues.length;
40 }
41 if(reliability>1/4){
42 return (2/reliability)/issues.length;
43 }
44 if(reliability>0){
45 return (4/Math.sqrt(reliability))/issues.length;
46 }
47 //this case shouldn't be reached
48 return 1000;
49 }
50 //the bid utility for the player is assumed to be 1-expectedDecrease
51 public void assumeBidWorth(Bid bid,double expectedDecrease,double stdDev) throws Exception{
52 ValueDecrease[] values = new ValueDecrease[issues.length];
53 double maxReliableDecrease=0;
54 for(int i=0;i<issues.length;i++){
55 Value value = bid.getValue(utilitySpace.getIssue(i).getNumber());
56 values[i] = issues[i].getExpectedDecrease(value);
57 }
58 //double deviationUnit=stdDev;
59 double deviationUnit=0;
60 for(int i=0;i<issues.length;i++){
61 deviationUnit +=
62 reliabilityToDevUnits(values[i].getReliabilty())
63 *values[i].getDeviance();
64 if(maxReliableDecrease<values[i].getDecrease() && values[i].getReliabilty()>0.8){
65 maxReliableDecrease=values[i].getDecrease();
66 }
67 }
68 ValueDecrease origEvaluation=utilityLoss(bid);
69 double unitsToMove = (expectedDecrease-origEvaluation.getDecrease())/deviationUnit;
70 for(int i=0;i<issues.length;i++){
71 double newVal = values[i].getDecrease()+
72 reliabilityToDevUnits(values[i].getReliabilty())
73 *values[i].getDeviance()
74 *unitsToMove;
75 if(values[i].getMaxReliabilty()>0.7 || maxReliableDecrease<newVal){
76 if(newVal>0){
77 values[i].updateWithNewValue(newVal, origEvaluation.getReliabilty());
78 }
79 else values[i].updateWithNewValue(0, origEvaluation.getReliabilty());
80 }
81 //assumes that new unreliable values costs more than previously seen values.
82 //if our opponent selected a bid that costs 10%,
83 //that is split between values that costs 4%,6%.
84 //than if 4%->6% we will think that 6%->4%.
85 //worst this sway also influences the estimate
86 //of our opponent's concession, so we may think he
87 //Consented to 7% and 6%->1%.
88 //both issues require this failsafe...
89 //else values[i].updateWithNewValue(maxReliableDecrease, origEvaluation.getReliabilty());
90 else values[i].updateWithNewValue(newVal, origEvaluation.getReliabilty());
91
92 }
93 normalize();
94
95 }
96 public ValueDecrease utilityLoss(Bid bid) throws Exception{
97 ValueDecrease[] values = new ValueDecrease[issues.length];
98 for(int i=0;i<issues.length;i++){
99 Value value = bid.getValue(utilitySpace.getIssue(i).getNumber());
100 values[i] = issues[i].getExpectedDecrease(value);
101 }
102 double stdDev = 0;
103 for(int i=0;i<issues.length;i++){
104 stdDev += values[i].getDeviance();
105 }
106 double decrease=0;
107 for(int i=0;i<issues.length;i++){
108 decrease += values[i].getDecrease();
109 }
110 //the sum square of 1/reliability
111 double sumSQ=0;
112 for(int i=0;i<issues.length;i++){
113 double rel = values[i].getReliabilty();
114 rel = rel>0?rel:0.01;
115 sumSQ += (1/rel)*(1/rel);
116 }
117 //added postBG
118 sumSQ/=issues.length;
119 double rel = Math.sqrt(1/sumSQ);
120 return new ValueDecrease(decrease,rel,stdDev);
121 }
122
123 public IssuesDecreases getIssue(int index){
124 if(index<issues.length && index>=0){
125 return issues[index];
126 }
127 return issues[0];
128
129 }
130
131}
Note: See TracBrowser for help on using the repository browser.