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