1 | package agents.anac.y2010.Southampton.similarity;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 |
|
---|
5 | import agents.anac.y2010.Southampton.SouthamptonAgent;
|
---|
6 | import agents.anac.y2010.Southampton.utils.OpponentModel;
|
---|
7 | import agents.anac.y2010.Southampton.utils.Pair;
|
---|
8 | import genius.core.Bid;
|
---|
9 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
10 |
|
---|
11 | public abstract class SimilarityAgent extends SouthamptonAgent {
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * The best bids (in terms of our utility) that we have seen from the
|
---|
15 | * opponent.
|
---|
16 | */
|
---|
17 | protected ArrayList<Pair<Double, Double>> bestOpponentBidUtilityHistory;
|
---|
18 | /**
|
---|
19 | * The best bid (in terms of our utility) that we have seen from the
|
---|
20 | * opponent.
|
---|
21 | */
|
---|
22 | private Bid bestOpponentBid;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * The utility (to us) of the best bid (in terms of our utility) that we
|
---|
26 | * have seen from the opponent.
|
---|
27 | */
|
---|
28 | private double bestOpponentUtility;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * The utility (to us) of the first bid made by the opponent.
|
---|
32 | */
|
---|
33 | protected double utility0 = 0;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * The expected utility (to us) of the final bid made by the opponent.
|
---|
37 | */
|
---|
38 | protected final double utility1 = 0.95;
|
---|
39 |
|
---|
40 | public SimilarityAgent() {
|
---|
41 | super();
|
---|
42 | bestOpponentBidUtilityHistory = new ArrayList<Pair<Double, Double>>();
|
---|
43 | // CONCESSIONFACTOR = 0.01;
|
---|
44 | }
|
---|
45 |
|
---|
46 | public void init() {
|
---|
47 | super.init();
|
---|
48 | prepareOpponentModel();
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public String getVersion() {
|
---|
53 | return "1.0";
|
---|
54 | }
|
---|
55 |
|
---|
56 | protected Bid proposeInitialBid() {
|
---|
57 | Bid bid = null;
|
---|
58 |
|
---|
59 | try {
|
---|
60 | bid = bidSpace.getMaxUtilityBid();
|
---|
61 | } catch (Exception e) {
|
---|
62 | e.printStackTrace();
|
---|
63 | }
|
---|
64 | return bid;
|
---|
65 | }
|
---|
66 |
|
---|
67 | protected Bid proposeNextBid(Bid opponentBid) {
|
---|
68 | try {
|
---|
69 | performUpdating(opponentBid);
|
---|
70 | } catch (Exception e) {
|
---|
71 | e.printStackTrace();
|
---|
72 | }
|
---|
73 |
|
---|
74 | double myUtility = 0, opponentUtility = 0, targetUtility;
|
---|
75 | // Both parties have made an initial bid. Compute associated utilities
|
---|
76 | // from my point of view.
|
---|
77 | try {
|
---|
78 | myUtility = utilitySpace.getUtility(myLastBid);
|
---|
79 | opponentUtility = utilitySpace.getUtility(opponentBid);
|
---|
80 | if (opponentPreviousBid == null)
|
---|
81 | utility0 = opponentUtility;
|
---|
82 | } catch (Exception e) {
|
---|
83 | e.printStackTrace();
|
---|
84 | }
|
---|
85 | targetUtility = getTargetUtility(myUtility, opponentUtility);
|
---|
86 | Bid nextBid = getTradeOffExhaustive(targetUtility, opponentBid, 1000);
|
---|
87 | return nextBid;
|
---|
88 | }
|
---|
89 |
|
---|
90 | protected abstract double getTargetUtility(double myUtility,
|
---|
91 | double opponentUtility);
|
---|
92 |
|
---|
93 | /*
|
---|
94 | * (non-Javadoc)
|
---|
95 | *
|
---|
96 | * @see agents.southampton.SouthamptonAgent#getRandomBidInRange(double,
|
---|
97 | * double)
|
---|
98 | */
|
---|
99 | @Override
|
---|
100 | protected Bid getRandomBidInRange(double lowerBound, double upperBound)
|
---|
101 | throws Exception {
|
---|
102 | throw new Exception(
|
---|
103 | "Method 'getRandomBidInRange' is not implemented in this agent.");
|
---|
104 | }
|
---|
105 |
|
---|
106 | private Bid getTradeOffExhaustive(double ourUtility, Bid opponentBid,
|
---|
107 | int count) {
|
---|
108 | // Project a point onto the bidspace...
|
---|
109 | bestOpponentBid = getBestBid(opponentBid);
|
---|
110 |
|
---|
111 | if (bestOpponentUtility * acceptMultiplier >= ourUtility) {
|
---|
112 | return bestOpponentBid;
|
---|
113 | }
|
---|
114 |
|
---|
115 | ArrayList<Bid> bids = bidSpace.Project(
|
---|
116 | bidSpace.getPoint(bestOpponentBid), ourUtility, count,
|
---|
117 | (AdditiveUtilitySpace) this.utilitySpace, this.opponentModel);
|
---|
118 | if (bids.size() == 0) {
|
---|
119 | return getTradeOffExhaustive(ourUtility, opponentBid, count + 10000);
|
---|
120 | }
|
---|
121 | double maxOpponentUtility = 0;
|
---|
122 | Bid bestBid = null;
|
---|
123 |
|
---|
124 | for (Bid bid : bids) {
|
---|
125 | try {
|
---|
126 | double opponentUtility = opponentModel
|
---|
127 | .getNormalizedUtility(bid);
|
---|
128 | if (opponentUtility > maxOpponentUtility) {
|
---|
129 | maxOpponentUtility = opponentUtility;
|
---|
130 | bestBid = bid;
|
---|
131 | }
|
---|
132 | } catch (Exception e) {
|
---|
133 | e.printStackTrace();
|
---|
134 | }
|
---|
135 | }
|
---|
136 |
|
---|
137 | return bestBid;
|
---|
138 | }
|
---|
139 |
|
---|
140 | private Bid getBestBid(Bid opponentBid) {
|
---|
141 | double utility;
|
---|
142 | try {
|
---|
143 | utility = utilitySpace.getUtility(opponentBid);
|
---|
144 | if (utility >= bestOpponentUtility) {
|
---|
145 | bestOpponentUtility = utility;
|
---|
146 | bestOpponentBid = opponentBid;
|
---|
147 | }
|
---|
148 | storeDataPoint(bestOpponentUtility);
|
---|
149 | } catch (Exception e) {
|
---|
150 | e.printStackTrace();
|
---|
151 | }
|
---|
152 | return bestOpponentBid;
|
---|
153 | }
|
---|
154 |
|
---|
155 | private void storeDataPoint(double utility) {
|
---|
156 | double time = timeline.getTime();
|
---|
157 | // bestOpponentBidUtilityHistory.add(new Pair<Double,
|
---|
158 | // Double>(-Math.log(1 - ((utility - utility0) / (utility1 -
|
---|
159 | // utility0))), time));
|
---|
160 | bestOpponentBidUtilityHistory.add(new Pair<Double, Double>(utility,
|
---|
161 | time));
|
---|
162 | }
|
---|
163 |
|
---|
164 | private void performUpdating(Bid opponentBid) throws Exception {
|
---|
165 | double currentTime = timeline.getTime() * timeline.getTotalTime()
|
---|
166 | * 1000;
|
---|
167 | double totalTime = timeline.getTotalTime() * 1000;
|
---|
168 | opponentModel.updateBeliefs(opponentBid, Math.round(currentTime),
|
---|
169 | totalTime);
|
---|
170 | }
|
---|
171 |
|
---|
172 | private void prepareOpponentModel() {
|
---|
173 | opponentModel = new OpponentModel((AdditiveUtilitySpace) utilitySpace);
|
---|
174 | }
|
---|
175 | }
|
---|