1 | package negotiator.boaframework.sharedagentstate.anac2011;
|
---|
2 |
|
---|
3 | import java.util.HashMap;
|
---|
4 | import java.util.Random;
|
---|
5 |
|
---|
6 | import genius.core.Bid;
|
---|
7 | import genius.core.bidding.BidDetails;
|
---|
8 | import genius.core.boaframework.NegotiationSession;
|
---|
9 | import genius.core.boaframework.SharedAgentState;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * This is the shared code of the acceptance condition and bidding strategy of ANAC 2011 Agent K2.
|
---|
13 | * The code was taken from the ANAC2010 Agent K2 and adapted to work within the BOA framework.
|
---|
14 | *
|
---|
15 | * @author Mark Hendrikx
|
---|
16 | */
|
---|
17 | public class AgentK2SAS extends SharedAgentState{
|
---|
18 |
|
---|
19 | private NegotiationSession negotiationSession;
|
---|
20 | private double sum;
|
---|
21 | private double sum2;
|
---|
22 | private int rounds;
|
---|
23 | private double target;
|
---|
24 | private double bidTarget;
|
---|
25 | private double tremor;
|
---|
26 | private double p;
|
---|
27 | private Random random400;
|
---|
28 | private HashMap<Bid, Double> offeredBidMap;
|
---|
29 | private final boolean TEST_EQUIVALENCE = false;
|
---|
30 |
|
---|
31 | public AgentK2SAS (NegotiationSession negoSession) {
|
---|
32 | negotiationSession = negoSession;
|
---|
33 | NAME = "AgentK2";
|
---|
34 | offeredBidMap = new HashMap<Bid, Double>();
|
---|
35 | sum = 0.0;
|
---|
36 | sum2 = 0.0;
|
---|
37 | rounds = 0;
|
---|
38 | target = 1.0;
|
---|
39 | bidTarget = 1.0;
|
---|
40 | tremor = 2.0;
|
---|
41 |
|
---|
42 | if (TEST_EQUIVALENCE) {
|
---|
43 | random400 = new Random(400);
|
---|
44 | } else {
|
---|
45 | random400 = new Random();
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | public double calculateAcceptProbability() {
|
---|
50 | BidDetails lastOpponentBid = negotiationSession.getOpponentBidHistory().getLastBidDetails();
|
---|
51 | double offeredUtility = lastOpponentBid.getMyUndiscountedUtil();
|
---|
52 | offeredBidMap.put(negotiationSession.getOpponentBidHistory().getLastBidDetails().getBid(), offeredUtility);
|
---|
53 |
|
---|
54 | sum += offeredUtility;
|
---|
55 | sum2 += offeredUtility * offeredUtility;
|
---|
56 | rounds++;
|
---|
57 |
|
---|
58 | double mean = sum / rounds;
|
---|
59 |
|
---|
60 | double variance = (sum2 / rounds) - (mean * mean);
|
---|
61 |
|
---|
62 | double deviation = Math.sqrt(variance * 12);
|
---|
63 | if (Double.isNaN(deviation)) {
|
---|
64 | deviation = 0.0;
|
---|
65 | }
|
---|
66 |
|
---|
67 | //double time = ((new Date()).getTime() - startTime.getTime()) // get passed time in ms
|
---|
68 | // / (1000. * totalTime); // divide by 1000 * totalTime to get normalized time between 0 and 1
|
---|
69 | double time = negotiationSession.getTime();
|
---|
70 | double t = time * time * time;
|
---|
71 |
|
---|
72 | if (offeredUtility > 1.) {
|
---|
73 | offeredUtility = 1;
|
---|
74 | }
|
---|
75 | double estimateMax = mean + ((1 - mean) * deviation);
|
---|
76 |
|
---|
77 | double alpha = 1 + tremor + (10 * mean) - (2 * tremor * mean);
|
---|
78 | double beta = alpha + (random400.nextDouble() * tremor) - (tremor / 2);
|
---|
79 |
|
---|
80 | double preTarget = 1 - (Math.pow(time, alpha) * (1 - estimateMax));
|
---|
81 | double preTarget2 = 1 - (Math.pow(time, beta) * (1 - estimateMax));
|
---|
82 |
|
---|
83 | double ratio = (deviation + 0.1) / (1 - preTarget);
|
---|
84 | if (Double.isNaN(ratio) || ratio > 2.0) {
|
---|
85 | ratio = 2.0;
|
---|
86 | }
|
---|
87 |
|
---|
88 | double ratio2 = (deviation + 0.1) / (1 - preTarget2);
|
---|
89 | if (Double.isNaN(ratio2) || ratio2 > 2.0) {
|
---|
90 | ratio2 = 2.0;
|
---|
91 | }
|
---|
92 |
|
---|
93 | target = ratio * preTarget + 1 - ratio;
|
---|
94 | bidTarget = ratio2 * preTarget2 + 1 - ratio2;
|
---|
95 |
|
---|
96 | double m = t * (-300) + 400;
|
---|
97 | if (target > estimateMax) {
|
---|
98 | double r = target - estimateMax;
|
---|
99 | double f = 1 / (r * r);
|
---|
100 | if (f > m || Double.isNaN(f))
|
---|
101 | f = m;
|
---|
102 | double app = r * f / m;
|
---|
103 | target = target - app;
|
---|
104 | } else {
|
---|
105 | target = estimateMax;
|
---|
106 | }
|
---|
107 |
|
---|
108 | if (bidTarget > estimateMax) {
|
---|
109 | double r = bidTarget - estimateMax;
|
---|
110 | double f = 1 / (r * r);
|
---|
111 | if (f > m || Double.isNaN(f))
|
---|
112 | f = m;
|
---|
113 | double app = r * f / m;
|
---|
114 | bidTarget = bidTarget - app;
|
---|
115 | } else {
|
---|
116 | bidTarget = estimateMax;
|
---|
117 | }
|
---|
118 |
|
---|
119 | // test code for Discount Factor
|
---|
120 | double discount_utility = this.negotiationSession.getUtilitySpace().getUtilityWithDiscount(
|
---|
121 | lastOpponentBid.getBid(), time);
|
---|
122 |
|
---|
123 | double discount_ratio = discount_utility / offeredUtility;
|
---|
124 | if (!Double.isNaN(discount_utility) && !Double.isNaN(discount_ratio)) {
|
---|
125 | target *= discount_ratio;
|
---|
126 | bidTarget *= discount_ratio;
|
---|
127 | }
|
---|
128 |
|
---|
129 | double utilityEvaluation = offeredUtility - estimateMax;
|
---|
130 | double satisfy = offeredUtility - target;
|
---|
131 |
|
---|
132 | p = (Math.pow(time, alpha) / 5) + utilityEvaluation + satisfy;
|
---|
133 | if (p < 0.1) {
|
---|
134 | p = 0.0;
|
---|
135 | }
|
---|
136 | return p;
|
---|
137 | }
|
---|
138 |
|
---|
139 | public double getTarget() {
|
---|
140 | return target;
|
---|
141 | }
|
---|
142 |
|
---|
143 | public double getBidTarget() {
|
---|
144 | return bidTarget;
|
---|
145 | }
|
---|
146 |
|
---|
147 | public void decrementBidTarget(double d) {
|
---|
148 | bidTarget = bidTarget - d;
|
---|
149 | }
|
---|
150 |
|
---|
151 | public int getRounds() {
|
---|
152 | return rounds;
|
---|
153 | }
|
---|
154 |
|
---|
155 | public HashMap<Bid, Double> getOfferedBidMap() {
|
---|
156 | return offeredBidMap;
|
---|
157 | }
|
---|
158 |
|
---|
159 | public double getAcceptProbability() {
|
---|
160 | return p;
|
---|
161 | }
|
---|
162 | } |
---|