1 | package negotiator.boaframework.offeringstrategy.anac2010;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Collections;
|
---|
5 | import java.util.Comparator;
|
---|
6 | import java.util.Map;
|
---|
7 |
|
---|
8 | import genius.core.Bid;
|
---|
9 | import genius.core.BidIterator;
|
---|
10 | import genius.core.bidding.BidDetails;
|
---|
11 | import genius.core.boaframework.NegotiationSession;
|
---|
12 | import genius.core.boaframework.NoModel;
|
---|
13 | import genius.core.boaframework.OMStrategy;
|
---|
14 | import genius.core.boaframework.OfferingStrategy;
|
---|
15 | import genius.core.boaframework.OpponentModel;
|
---|
16 | import genius.core.boaframework.SortedOutcomeSpace;
|
---|
17 | import genius.core.utility.AbstractUtilitySpace;
|
---|
18 | import negotiator.boaframework.opponentmodel.DefaultModel;
|
---|
19 | import negotiator.boaframework.opponentmodel.FSEGABayesianModel;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * This is the decoupled Offering Strategy for AgentFSEGA (ANAC2010). The code
|
---|
23 | * was taken from the ANAC2010 AgentFSEGA and adapted to work within the BOA
|
---|
24 | * framework.
|
---|
25 | *
|
---|
26 | * DEFAULT OM: FSEGABayesianModel (model is broken)
|
---|
27 | *
|
---|
28 | * Decoupling Negotiating Agents to Explore the Space of Negotiation Strategies
|
---|
29 | * T. Baarslag, K. Hindriks, M. Hendrikx, A. Dirkzwager, C.M. Jonker
|
---|
30 | *
|
---|
31 | * @author Alex Dirkzwager, Mark Hendrikx
|
---|
32 | */
|
---|
33 | public class AgentFSEGA_Offering extends OfferingStrategy {
|
---|
34 |
|
---|
35 | private static final double MIN_ALLOWED_UTILITY = 0.5;
|
---|
36 | private static final double SIGMA = 0.01;
|
---|
37 | private static final double SIGMA_MAX = 0.5;
|
---|
38 | private final boolean TEST_EQUIVALENCE = false;
|
---|
39 |
|
---|
40 | private double elapsedTimeNorm;
|
---|
41 | private ArrayList<Bid> leftBids;
|
---|
42 | private SortedOutcomeSpace outcomeSpace;
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Empty constructor for the BOA framework.
|
---|
46 | */
|
---|
47 | public AgentFSEGA_Offering() {
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public void init(NegotiationSession negotiationSession, OpponentModel model, OMStrategy oms,
|
---|
52 | Map<String, Double> parameters) throws Exception {
|
---|
53 | if (model instanceof DefaultModel) {
|
---|
54 | model = new FSEGABayesianModel();
|
---|
55 | model.init(negotiationSession, null);
|
---|
56 | oms.setOpponentModel(model);
|
---|
57 | }
|
---|
58 | initializeAgent(negotiationSession, model, oms);
|
---|
59 | }
|
---|
60 |
|
---|
61 | private void initializeAgent(NegotiationSession negoSession, OpponentModel model, OMStrategy oms) {
|
---|
62 | this.negotiationSession = negoSession;
|
---|
63 | this.omStrategy = oms;
|
---|
64 | this.opponentModel = model;
|
---|
65 | if (!(model instanceof NoModel || model instanceof FSEGABayesianModel)) {
|
---|
66 | outcomeSpace = new SortedOutcomeSpace(negoSession.getUtilitySpace());
|
---|
67 | }
|
---|
68 | // initialize left bids
|
---|
69 | BidIterator bIterCount = new BidIterator(negotiationSession.getUtilitySpace().getDomain());
|
---|
70 | // proposedBids = new ArrayList<Bid>();
|
---|
71 |
|
---|
72 | double[] nrBids = { 0, 0, 0, 0, 0 };
|
---|
73 |
|
---|
74 | while (bIterCount.hasNext()) {
|
---|
75 | Bid tmpBid = bIterCount.next();
|
---|
76 | double utility;
|
---|
77 | try {
|
---|
78 | utility = negotiationSession.getUtilitySpace().getUtility(tmpBid);
|
---|
79 | // exclude bids with utility < MIN_ALLOWED_UTILITY
|
---|
80 | if ((utility > 1.0) && (utility > 0.9))
|
---|
81 | nrBids[0]++;
|
---|
82 | else if ((utility <= 0.9) && (utility > 0.8))
|
---|
83 | nrBids[1]++;
|
---|
84 | else if ((utility <= 0.8) && (utility > 0.7))
|
---|
85 | nrBids[2]++;
|
---|
86 | else if ((utility <= 0.7) && (utility > 0.6))
|
---|
87 | nrBids[3]++;
|
---|
88 | else if (utility >= MIN_ALLOWED_UTILITY)
|
---|
89 | nrBids[4]++;
|
---|
90 | } catch (Exception e) {
|
---|
91 | }
|
---|
92 | }
|
---|
93 | try {
|
---|
94 | Thread.sleep(1000);
|
---|
95 | } catch (Exception e) {
|
---|
96 | }
|
---|
97 |
|
---|
98 | //
|
---|
99 | double arrayBidCount = 0;
|
---|
100 | int iMin = 0;
|
---|
101 | do {
|
---|
102 | arrayBidCount = nrBids[iMin];
|
---|
103 | iMin++;
|
---|
104 | } while ((arrayBidCount == 0) && (iMin < 5));
|
---|
105 |
|
---|
106 | // end Test
|
---|
107 |
|
---|
108 | // initialize left bids
|
---|
109 | BidIterator bIter = new BidIterator(negotiationSession.getUtilitySpace().getDomain());
|
---|
110 | // proposedBids = new ArrayList<Bid>();
|
---|
111 | leftBids = new ArrayList<Bid>();
|
---|
112 |
|
---|
113 | while (bIter.hasNext()) {
|
---|
114 | Bid tmpBid = bIter.next();
|
---|
115 | try {
|
---|
116 | // exclude bids with utility < MIN_ALLOWED_UTILITY
|
---|
117 | if (negotiationSession.getUtilitySpace().getUtility(tmpBid) >= 0.9 - 0.1 * iMin)
|
---|
118 | leftBids.add(tmpBid);
|
---|
119 | } catch (Exception e) {
|
---|
120 | e.printStackTrace();
|
---|
121 | }
|
---|
122 | }
|
---|
123 | Collections.sort(leftBids, new ReverseBidComparator(negotiationSession.getUtilitySpace()));
|
---|
124 | }
|
---|
125 |
|
---|
126 | @Override
|
---|
127 | public BidDetails determineOpeningBid() {
|
---|
128 | try {
|
---|
129 | return initialOffer();
|
---|
130 | } catch (Exception e) {
|
---|
131 | e.printStackTrace();
|
---|
132 | }
|
---|
133 | return null;
|
---|
134 | }
|
---|
135 |
|
---|
136 | @Override
|
---|
137 | public BidDetails determineNextBid() {
|
---|
138 | int timeCase; // the curent time interval id for cameleonic behaviour
|
---|
139 |
|
---|
140 | elapsedTimeNorm = negotiationSession.getTime();
|
---|
141 |
|
---|
142 | if (elapsedTimeNorm < 0.85)
|
---|
143 | timeCase = 0;
|
---|
144 | else if (elapsedTimeNorm < 0.95)
|
---|
145 | timeCase = 1;
|
---|
146 | else
|
---|
147 | timeCase = 2;
|
---|
148 |
|
---|
149 | if (negotiationSession.getOwnBidHistory().getLastBidDetails() != null) {
|
---|
150 | try {
|
---|
151 | Bid bid = getNextBid(timeCase);
|
---|
152 | double bidUtil = negotiationSession.getUtilitySpace().getUtility(bid);
|
---|
153 | nextBid = new BidDetails(bid, bidUtil, negotiationSession.getTime());
|
---|
154 | } catch (Exception e) {
|
---|
155 | e.printStackTrace();
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 | if (!(opponentModel instanceof NoModel || opponentModel instanceof FSEGABayesianModel)) {
|
---|
160 | try {
|
---|
161 | nextBid = omStrategy.getBid(outcomeSpace,
|
---|
162 | negotiationSession.getUtilitySpace().getUtility(nextBid.getBid()));
|
---|
163 | } catch (Exception e) {
|
---|
164 | e.printStackTrace();
|
---|
165 | }
|
---|
166 | }
|
---|
167 |
|
---|
168 | return nextBid;
|
---|
169 | }
|
---|
170 |
|
---|
171 | private BidDetails initialOffer() throws Exception {
|
---|
172 | nextBid = negotiationSession.getMaxBidinDomain();
|
---|
173 | return negotiationSession.getMaxBidinDomain();
|
---|
174 | }
|
---|
175 |
|
---|
176 | private Bid getNextBid(int pTimeCase) throws Exception {
|
---|
177 | switch (pTimeCase) {
|
---|
178 | case 0:
|
---|
179 | return getSmartBid(pTimeCase);
|
---|
180 | case 1:
|
---|
181 | return getSmartBid(1);
|
---|
182 | default:
|
---|
183 | return getSmartBid(2);
|
---|
184 | }
|
---|
185 | }
|
---|
186 |
|
---|
187 | private Bid getSmartBid(int pTimeCase) {
|
---|
188 | // log("Nr. candidates: " + leftBids.size());
|
---|
189 |
|
---|
190 | double currentOpponentUtility = 0.0;
|
---|
191 | double lastOpponentUtility = 0.0;
|
---|
192 | ;
|
---|
193 |
|
---|
194 | double myBestUtil; // utility for remained best bid
|
---|
195 | double myNextUtility; // utility for next bid
|
---|
196 | // java.util.Iterator<Bid> lbi = leftBids.iterator();
|
---|
197 |
|
---|
198 | Bid nextBest = null; // best for me and opponent
|
---|
199 | Bid theBest = null; // the best for me, top of the ordered list
|
---|
200 |
|
---|
201 | // get first entry
|
---|
202 | if (leftBids.size() > 0) {
|
---|
203 | theBest = leftBids.get(0);
|
---|
204 | try {
|
---|
205 | } catch (Exception e1) {
|
---|
206 | e1.printStackTrace();
|
---|
207 | }
|
---|
208 |
|
---|
209 | try {
|
---|
210 | myBestUtil = negotiationSession.getUtilitySpace().getUtility(theBest);
|
---|
211 | } catch (Exception e) {
|
---|
212 | myBestUtil = 1;
|
---|
213 | }
|
---|
214 |
|
---|
215 | nextBest = theBest;
|
---|
216 | } else {
|
---|
217 | // log("no other bid remained");
|
---|
218 | return negotiationSession.getOwnBidHistory().getLastBidDetails().getBid();
|
---|
219 | }
|
---|
220 |
|
---|
221 | Bid lNext = null;
|
---|
222 |
|
---|
223 | double minUtilAllowed = Math.max(0.98 * Math.exp(Math.log(0.52) * elapsedTimeNorm), 0.5);
|
---|
224 | double minArrayUtility = 0;
|
---|
225 | try {
|
---|
226 | minArrayUtility = negotiationSession.getUtilitySpace().getUtility(leftBids.get(leftBids.size() - 1));
|
---|
227 | } catch (Exception e) {
|
---|
228 | }
|
---|
229 |
|
---|
230 | // log("Minimum array utility: " + minArrayUtility);
|
---|
231 | // log("Minimum utility allowed: " + minUtilAllowed);
|
---|
232 | // log("Left bids no: " + leftBids.size());
|
---|
233 | // !!! left bids receiveMessage
|
---|
234 | if (((minArrayUtility > minUtilAllowed + SIGMA) || (minArrayUtility > (myBestUtil - SIGMA)))) {
|
---|
235 | BidIterator bIter = new BidIterator(negotiationSession.getUtilitySpace().getDomain());
|
---|
236 |
|
---|
237 | for (Bid tmpBid = bIter.next(); bIter.hasNext(); tmpBid = bIter.next()) {
|
---|
238 | try {
|
---|
239 | double tmpBidUtil = negotiationSession.getUtilitySpace().getUtility(tmpBid);
|
---|
240 | if ((tmpBidUtil > MIN_ALLOWED_UTILITY) && (tmpBidUtil < minArrayUtility)
|
---|
241 | && (tmpBidUtil > Math.min(minUtilAllowed, myBestUtil) - 0.1))
|
---|
242 | leftBids.add(tmpBid);
|
---|
243 | } catch (Exception e) {
|
---|
244 | }
|
---|
245 | }
|
---|
246 | Collections.sort(leftBids, new ReverseBidComparator(negotiationSession.getUtilitySpace()));
|
---|
247 | }
|
---|
248 |
|
---|
249 | // get second entry in last bids
|
---|
250 | if (leftBids.size() > 1) {
|
---|
251 | lNext = leftBids.get(1);
|
---|
252 | } else {
|
---|
253 | // proposedBids.add(nextBest);
|
---|
254 | leftBids.remove(nextBest);
|
---|
255 | return nextBest;
|
---|
256 | }
|
---|
257 |
|
---|
258 | try {
|
---|
259 | myNextUtility = negotiationSession.getUtilitySpace().getUtility(lNext);
|
---|
260 | } catch (Exception e) {
|
---|
261 | myNextUtility = 0;
|
---|
262 | }
|
---|
263 |
|
---|
264 | double lowerAcceptableUtilLimit;
|
---|
265 |
|
---|
266 | // if time case is 2 -> make concession
|
---|
267 | if (pTimeCase == 2) {
|
---|
268 | lowerAcceptableUtilLimit = myBestUtil
|
---|
269 | - (Math.exp(Math.log(SIGMA_MAX) / (0.05 * negotiationSession.getTimeline().getTotalTime())));
|
---|
270 | } else {
|
---|
271 | // minimum allowed utility for me at this time
|
---|
272 | if (pTimeCase == 0)
|
---|
273 | lowerAcceptableUtilLimit = Math.max(myBestUtil - SIGMA, minUtilAllowed);
|
---|
274 | else
|
---|
275 | lowerAcceptableUtilLimit = Math.min(myBestUtil - SIGMA, minUtilAllowed);
|
---|
276 | }
|
---|
277 |
|
---|
278 | // eliminate first bid + next bid
|
---|
279 | java.util.Iterator<Bid> lbi = leftBids.iterator();
|
---|
280 | if (leftBids.size() > 1) {
|
---|
281 | lbi.next(); // first bid
|
---|
282 | lbi.next();
|
---|
283 | } else {
|
---|
284 | return negotiationSession.getOwnBidHistory().getLastBidDetails().getBid();
|
---|
285 | }
|
---|
286 |
|
---|
287 | // get a bid in interval (max_util - SIGMA, max_util]
|
---|
288 | while ((myNextUtility > lowerAcceptableUtilLimit) && (myNextUtility <= minUtilAllowed)) {
|
---|
289 | // check (my next util) < (last opponent bid's utility for me)
|
---|
290 | // in this case, offer previous bid
|
---|
291 | // Cristi Litan 19.03.2010
|
---|
292 | if (pTimeCase == 0) // use behaviour 0
|
---|
293 | {
|
---|
294 | try // catch getUtility exceptions
|
---|
295 | {
|
---|
296 | // do not offer bids with utility smaller than that gived by
|
---|
297 | // opponent in time case 0
|
---|
298 | if (myNextUtility < negotiationSession.getUtilitySpace()
|
---|
299 | .getUtility(negotiationSession.getOpponentBidHistory().getLastBidDetails().getBid())) {
|
---|
300 | nextBest = negotiationSession.getOwnBidHistory().getLastBidDetails().getBid();
|
---|
301 | break;
|
---|
302 | }
|
---|
303 | } catch (Exception e) { /* do nothing - ignore */
|
---|
304 | }
|
---|
305 | }
|
---|
306 |
|
---|
307 | try {
|
---|
308 | // log("opponent util");
|
---|
309 | // TODO: Dan modified because it's not necessary to normalize
|
---|
310 | // these utilities
|
---|
311 | currentOpponentUtility = opponentModel.getBidEvaluation(lNext);
|
---|
312 | } catch (Exception e) {
|
---|
313 | currentOpponentUtility = 0;
|
---|
314 | }
|
---|
315 |
|
---|
316 | // log("exit from cycle");
|
---|
317 |
|
---|
318 | if (currentOpponentUtility > lastOpponentUtility) {
|
---|
319 | lastOpponentUtility = currentOpponentUtility;
|
---|
320 | nextBest = lNext;
|
---|
321 | }
|
---|
322 |
|
---|
323 | if (lbi.hasNext()) {
|
---|
324 | lNext = lbi.next();
|
---|
325 |
|
---|
326 | // get my utility for next possible bid
|
---|
327 | try {
|
---|
328 | myNextUtility = negotiationSession.getUtilitySpace().getUtility(lNext);
|
---|
329 | } catch (Exception e) {
|
---|
330 | myNextUtility = 0;
|
---|
331 | }
|
---|
332 | } else
|
---|
333 | // log("no other in possible bids");
|
---|
334 | break;
|
---|
335 | }
|
---|
336 |
|
---|
337 | try {
|
---|
338 | // test under limit case
|
---|
339 | if (negotiationSession.getUtilitySpace().getUtility(nextBest) <= minUtilAllowed) {
|
---|
340 | // TODO: place here code for under limit case
|
---|
341 | // log(myNextUtility + " < " + minUtilAllowed + " under limit");
|
---|
342 | return negotiationSession.getOwnBidHistory().getLastBidDetails().getBid();
|
---|
343 | }
|
---|
344 | } catch (Exception e) {
|
---|
345 | }
|
---|
346 |
|
---|
347 | // log("iteration count: " + iteration_count);
|
---|
348 |
|
---|
349 | // proposedBids.add(nextBest);
|
---|
350 | leftBids.remove(nextBest);
|
---|
351 |
|
---|
352 | // log("return a bid in interval");
|
---|
353 |
|
---|
354 | return nextBest;
|
---|
355 | }
|
---|
356 |
|
---|
357 | private class ReverseBidComparator implements Comparator<Bid> {
|
---|
358 | private AbstractUtilitySpace usp;
|
---|
359 |
|
---|
360 | public ReverseBidComparator(AbstractUtilitySpace pUsp) {
|
---|
361 | usp = pUsp;
|
---|
362 | }
|
---|
363 |
|
---|
364 | public int compare(Bid b1, Bid b2) {
|
---|
365 | try {
|
---|
366 | double u1 = usp.getUtility(b1);
|
---|
367 | double u2 = usp.getUtility(b2);
|
---|
368 | if (TEST_EQUIVALENCE) {
|
---|
369 | if (u1 == u2) {
|
---|
370 | return String.CASE_INSENSITIVE_ORDER.compare(b1.toString(), b2.toString());
|
---|
371 | }
|
---|
372 | }
|
---|
373 | if (u1 > u2)
|
---|
374 | return -1; // ! is reversed
|
---|
375 | else if (u1 < u2)
|
---|
376 | return 1;
|
---|
377 | else
|
---|
378 | return 0;
|
---|
379 | } catch (Exception e) {
|
---|
380 | return -1;
|
---|
381 | }
|
---|
382 | }
|
---|
383 | }
|
---|
384 |
|
---|
385 | @Override
|
---|
386 | public String getName() {
|
---|
387 | return "2010 - AgentFSEGA";
|
---|
388 | }
|
---|
389 | }
|
---|