1 | package agents.anac.y2014.DoNA;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Collections;
|
---|
5 | import java.util.HashMap;
|
---|
6 | import java.util.List;
|
---|
7 | import java.util.Random;
|
---|
8 |
|
---|
9 | import genius.core.Agent;
|
---|
10 | import genius.core.Bid;
|
---|
11 | import genius.core.actions.Accept;
|
---|
12 | import genius.core.actions.Action;
|
---|
13 | import genius.core.actions.DefaultAction;
|
---|
14 | import genius.core.actions.EndNegotiation;
|
---|
15 | import genius.core.actions.Offer;
|
---|
16 | import genius.core.issue.Issue;
|
---|
17 | import genius.core.issue.IssueDiscrete;
|
---|
18 | import genius.core.issue.IssueInteger;
|
---|
19 | import genius.core.issue.IssueReal;
|
---|
20 | import genius.core.issue.Value;
|
---|
21 | import genius.core.issue.ValueInteger;
|
---|
22 | import genius.core.issue.ValueReal;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * @author Eden Erez
|
---|
26 | * @since 2014-03-21
|
---|
27 | */
|
---|
28 | public class DoNA extends Agent {
|
---|
29 |
|
---|
30 | boolean isPrinting = false;
|
---|
31 | ClearDefaultStrategy defaultStrategy;
|
---|
32 | private Bid firstBidOfOpponent, lastBidOfOpponent;
|
---|
33 | private Bid maxUtilityBid;
|
---|
34 | private Bid minUtilityBid;
|
---|
35 | private double maxUtility;
|
---|
36 | private double minUtility;
|
---|
37 | private double UtilityRange;
|
---|
38 | private OpponentBidHistory opponentBidHistory;
|
---|
39 | private double averageResponseTime;
|
---|
40 | private double stiaResponseTime;
|
---|
41 | int numOfRounds;
|
---|
42 | boolean NotFirstTime;
|
---|
43 |
|
---|
44 | private double theTimeIAmReadyToInvestInNegotiation;
|
---|
45 | private double theMotivationIHaveToInvestInNegotiation;
|
---|
46 |
|
---|
47 | private int countBid;
|
---|
48 | private double MyOfferedUtility;
|
---|
49 | boolean IConcedeLast;
|
---|
50 | boolean IsPrintForDebug;
|
---|
51 | int numberOfStepsDoneByOpponent;
|
---|
52 |
|
---|
53 | private Action actionOfPartner = null;
|
---|
54 | private double stia = 0;
|
---|
55 | HashMap<Double, Bid> hashBids;
|
---|
56 | ArrayList<Double> arrSamples;
|
---|
57 |
|
---|
58 | HashMap<Double, Bid> otherHashBids;
|
---|
59 | ArrayList<Double> otherArrSamples;
|
---|
60 |
|
---|
61 | HashMap<Double, Bid> alternativeHashBids;
|
---|
62 | ArrayList<Double> alternativeArrSamples;
|
---|
63 |
|
---|
64 | double[] timeArr;
|
---|
65 | int currentTimeIndex = 0;
|
---|
66 |
|
---|
67 | boolean highReservation;// = (utilitySpace.getReservationValue() >=
|
---|
68 | // 0.8);//(minUtility+0.75*UtilityRange));
|
---|
69 | boolean midReservation;// = (utilitySpace.getReservationValue() < 0.8 &&
|
---|
70 | // utilitySpace.getReservationValue() >
|
---|
71 | // 0.2);//(minUtility+0.75*UtilityRange) &&
|
---|
72 | // utilitySpace.getReservationValue() >=
|
---|
73 | // (minUtility+0.375*UtilityRange));
|
---|
74 | boolean lowReservation;// = (utilitySpace.getReservationValue() <=
|
---|
75 | // 0.2);//(minUtility+0.375*UtilityRange));
|
---|
76 |
|
---|
77 | boolean highDiscount;// = (utilitySpace.getDiscountFactor() >= 0.8);
|
---|
78 | boolean midDiscount;// = (utilitySpace.getDiscountFactor() < 0.8 &&
|
---|
79 | // utilitySpace.getDiscountFactor() > 0.2);
|
---|
80 | boolean lowDiscount;// = (utilitySpace.getDiscountFactor() <= 0.2);
|
---|
81 | double R, D;
|
---|
82 | double UtilityFactor;
|
---|
83 | double EndFactor;
|
---|
84 | double TimeFactor;
|
---|
85 |
|
---|
86 | int numOfSamplesForAvgTime;
|
---|
87 | double sumUtil = 0;
|
---|
88 | int numOfUtil = 0;
|
---|
89 | Action lastAction;
|
---|
90 | double dblMinUtil = 0.0;
|
---|
91 | double myMinUtil = 1;
|
---|
92 | boolean flagStopExplor;
|
---|
93 | int countOffer;
|
---|
94 | long DomainSize;
|
---|
95 |
|
---|
96 | @Override
|
---|
97 | public void init() {
|
---|
98 |
|
---|
99 | DomainSize = utilitySpace.getDomain().getNumberOfPossibleBids();
|
---|
100 |
|
---|
101 | if (DomainSize > 1 && DomainSize < 1000000) {
|
---|
102 | defaultStrategy = new ClearDefaultStrategy();
|
---|
103 | defaultStrategy.utilitySpace = utilitySpace;
|
---|
104 | defaultStrategy.timeline = timeline;
|
---|
105 |
|
---|
106 | defaultStrategy.init(getAgentID());
|
---|
107 | return;
|
---|
108 | }
|
---|
109 |
|
---|
110 | highReservation = (utilitySpace.getReservationValue() >= 0.8);// (minUtility+0.75*UtilityRange));
|
---|
111 | midReservation = (utilitySpace.getReservationValue() < 0.8
|
---|
112 | && utilitySpace.getReservationValue() > 0.2);// (minUtility+0.75*UtilityRange)
|
---|
113 | // &&
|
---|
114 | // utilitySpace.getReservationValue()
|
---|
115 | // >=
|
---|
116 | // (minUtility+0.375*UtilityRange));
|
---|
117 | lowReservation = (utilitySpace.getReservationValue() <= 0.2);// (minUtility+0.375*UtilityRange));
|
---|
118 |
|
---|
119 | highDiscount = (utilitySpace.getDiscountFactor() >= 0.8);
|
---|
120 | midDiscount = (utilitySpace.getDiscountFactor() < 0.8
|
---|
121 | && utilitySpace.getDiscountFactor() > 0.2);
|
---|
122 | lowDiscount = (utilitySpace.getDiscountFactor() <= 0.2);
|
---|
123 | R = utilitySpace.getReservationValue();
|
---|
124 | D = utilitySpace.getDiscountFactor();
|
---|
125 |
|
---|
126 | int numOfSamples = 100000;
|
---|
127 | numOfSamplesForAvgTime = 12;
|
---|
128 |
|
---|
129 | if ((highReservation) || (midReservation && lowDiscount)) {
|
---|
130 | return;
|
---|
131 | }
|
---|
132 |
|
---|
133 | try {
|
---|
134 | if (utilitySpace.getReservationValue() > 0
|
---|
135 | && utilitySpace.getReservationValue() < 1
|
---|
136 | && utilitySpace.getDiscountFactor() < 1)
|
---|
137 | theTimeIAmReadyToInvestInNegotiation = Math
|
---|
138 | .sqrt(Math.sqrt(1 - utilitySpace.getReservationValue())
|
---|
139 | * Math.sqrt(utilitySpace.getDiscountFactor()));
|
---|
140 | /*
|
---|
141 | * (1-utilitySpace.getReservationValue())
|
---|
142 | *
|
---|
143 | * Math.pow(utilitySpace.getDiscountFactor(),2)
|
---|
144 | *
|
---|
145 | * 2;
|
---|
146 | */
|
---|
147 | else
|
---|
148 | theTimeIAmReadyToInvestInNegotiation = 1.0;
|
---|
149 |
|
---|
150 | numOfRounds = 0;
|
---|
151 | firstBidOfOpponent = lastBidOfOpponent = null;
|
---|
152 | opponentBidHistory = new OpponentBidHistory();
|
---|
153 | opponentBidHistory
|
---|
154 | .initializeDataStructures(utilitySpace.getDomain());
|
---|
155 | NotFirstTime = false;
|
---|
156 | countBid = 0;
|
---|
157 | MyOfferedUtility = 2;
|
---|
158 | IConcedeLast = false;
|
---|
159 | IsPrintForDebug = false;
|
---|
160 |
|
---|
161 | } catch (Exception e) {
|
---|
162 | System.out.println("initialization error" + e.getMessage());
|
---|
163 | }
|
---|
164 |
|
---|
165 | numOfUtil = 0;
|
---|
166 | sumUtil = 0;
|
---|
167 | arrSamples = new ArrayList<Double>();
|
---|
168 | hashBids = new HashMap<Double, Bid>();
|
---|
169 | otherHashBids = new HashMap<Double, Bid>();
|
---|
170 | otherArrSamples = new ArrayList<Double>();
|
---|
171 | alternativeHashBids = new HashMap<Double, Bid>();
|
---|
172 | alternativeArrSamples = new ArrayList<Double>();
|
---|
173 |
|
---|
174 | for (int i = 0; i < numOfSamples; i++) {
|
---|
175 | lastAction = chooseRandomBidAction(0);
|
---|
176 | Bid myBid = ((Offer) lastAction).getBid();
|
---|
177 | // myBid = getBestNigberBid(myBid,0);
|
---|
178 | double myOfferedUtil = getUtility(myBid);
|
---|
179 | numOfUtil++;
|
---|
180 | // System.out.println("numOfUtil: " + numOfUtil);
|
---|
181 | sumUtil += myOfferedUtil;
|
---|
182 | hashBids.put(myOfferedUtil, myBid);
|
---|
183 | arrSamples.add(myOfferedUtil);
|
---|
184 | }
|
---|
185 | double avg = sumUtil / numOfUtil;
|
---|
186 | if (isPrinting)
|
---|
187 | System.out.println("m=" + (avg));
|
---|
188 |
|
---|
189 | double sumAll = 0;
|
---|
190 | for (Double double1 : arrSamples) {
|
---|
191 | sumAll += Math.pow(double1 - avg, 2);
|
---|
192 | }
|
---|
193 | stia = Math.pow(sumAll / numOfSamples, 0.5);
|
---|
194 | if (isPrinting)
|
---|
195 | System.out.println("S=" + stia);
|
---|
196 | dblMinUtil = 2.4 * stia + avg * 1.2;
|
---|
197 |
|
---|
198 | opponentBidHistory = new OpponentBidHistory();
|
---|
199 | opponentBidHistory.initializeDataStructures(utilitySpace.getDomain());
|
---|
200 |
|
---|
201 | Collections.sort(arrSamples);
|
---|
202 |
|
---|
203 | maxUtilityBid = hashBids.get(arrSamples.get(arrSamples.size() - 10));
|
---|
204 | maxUtility = getUtility(maxUtilityBid);
|
---|
205 |
|
---|
206 | if (dblMinUtil > maxUtility)
|
---|
207 | dblMinUtil = maxUtility;
|
---|
208 |
|
---|
209 | minUtilityBid = hashBids.get(arrSamples.get(arrSamples.size() - 100));
|
---|
210 | minUtility = getUtility(minUtilityBid);
|
---|
211 |
|
---|
212 | if (dblMinUtil < minUtility)
|
---|
213 | dblMinUtil = minUtility;
|
---|
214 |
|
---|
215 | maxUtilityBid = hashBids.get(arrSamples.get(arrSamples.size() - 1));
|
---|
216 | minUtilityBid = hashBids.get(arrSamples.get(0));
|
---|
217 | myMinUtil = 1;
|
---|
218 | try {
|
---|
219 | maxUtility = utilitySpace.getUtility(maxUtilityBid);
|
---|
220 | minUtility = utilitySpace.getUtility(minUtilityBid);
|
---|
221 | myMinUtil = maxUtility;
|
---|
222 |
|
---|
223 | } catch (Exception e) {
|
---|
224 | // TODO Auto-generated catch block
|
---|
225 | e.printStackTrace();
|
---|
226 | }
|
---|
227 |
|
---|
228 | lastAction = new Offer(getAgentID(), maxUtilityBid);
|
---|
229 | countOffer = arrSamples.size() - 1;
|
---|
230 |
|
---|
231 | timeArr = new double[numOfSamplesForAvgTime];
|
---|
232 | int currentTimeIndex = 0;
|
---|
233 |
|
---|
234 | theMotivationIHaveToInvestInNegotiation = dblMinUtil
|
---|
235 | - utilitySpace.getReservationValue();
|
---|
236 | UtilityFactor = (1 - (D - 0.2) * 5 / 3) * 0.1 + 0.05;
|
---|
237 | EndFactor = (1 - R * 5 / 4) / (1 / (dblMinUtil - R));
|
---|
238 | TimeFactor = 1 / (((D - 0.2) / 0.6) * (1 - EndFactor) + EndFactor);
|
---|
239 | flagStopExplor = false;
|
---|
240 | }
|
---|
241 |
|
---|
242 | @Override
|
---|
243 | public void ReceiveMessage(Action opponentAction) {
|
---|
244 |
|
---|
245 | if (DomainSize > 1 && DomainSize < 1000000) {
|
---|
246 | defaultStrategy.ReceiveMessage(opponentAction);
|
---|
247 | return;
|
---|
248 | }
|
---|
249 |
|
---|
250 | actionOfPartner = opponentAction;
|
---|
251 | if (opponentAction instanceof Offer) {
|
---|
252 | lastBidOfOpponent = ((Offer) opponentAction).getBid();
|
---|
253 | if (firstBidOfOpponent == null)
|
---|
254 | firstBidOfOpponent = lastBidOfOpponent;
|
---|
255 |
|
---|
256 | double remainingTime = timeline.getTime();
|
---|
257 | double weight = remainingTime * 100;
|
---|
258 | opponentBidHistory.updateOpponentModel(lastBidOfOpponent, weight,
|
---|
259 | utilitySpace);
|
---|
260 |
|
---|
261 | numOfRounds++;
|
---|
262 |
|
---|
263 | double dbltime = timeline.getTime();
|
---|
264 | timeArr[currentTimeIndex] = dbltime;
|
---|
265 | currentTimeIndex++;
|
---|
266 | if (currentTimeIndex == numOfSamplesForAvgTime) {
|
---|
267 | currentTimeIndex = 0;
|
---|
268 | averageResponseTime = (timeArr[numOfSamplesForAvgTime - 1]
|
---|
269 | - timeArr[0]) / (numOfSamplesForAvgTime - 1);
|
---|
270 | double sumAll = 0;
|
---|
271 | for (int i = 1; i < numOfSamplesForAvgTime; i++) {
|
---|
272 | sumAll += Math.pow(
|
---|
273 | timeArr[i] - timeArr[i - 1] - averageResponseTime,
|
---|
274 | 2);
|
---|
275 | }
|
---|
276 | stiaResponseTime = Math
|
---|
277 | .pow(sumAll / (numOfSamplesForAvgTime - 1), 0.5);
|
---|
278 |
|
---|
279 | NotFirstTime = true;
|
---|
280 | // averageResponseTime = timeline.getTime() / numOfRounds;
|
---|
281 | }
|
---|
282 |
|
---|
283 | numberOfStepsDoneByOpponent = opponentBidHistory
|
---|
284 | .getNumberOfDistinctBids();
|
---|
285 | }
|
---|
286 |
|
---|
287 | }
|
---|
288 |
|
---|
289 | int countRRR = 0;
|
---|
290 |
|
---|
291 | @Override
|
---|
292 | public Action chooseAction() {
|
---|
293 |
|
---|
294 | // if(NotFirstTime==false)
|
---|
295 | // return cleanEndNegotiation();
|
---|
296 |
|
---|
297 | if (DomainSize > 1 && DomainSize < 1000000) {
|
---|
298 | return defaultStrategy.chooseAction();
|
---|
299 | }
|
---|
300 |
|
---|
301 | if (highReservation || (midReservation && lowDiscount)
|
---|
302 | || theMotivationIHaveToInvestInNegotiation <= 0.1) {
|
---|
303 | return cleanEndNegotiation();
|
---|
304 | }
|
---|
305 |
|
---|
306 | double lastBidOfOpponentUtil = 0;
|
---|
307 | try {
|
---|
308 | lastBidOfOpponentUtil = lastBidOfOpponent == null ? 0
|
---|
309 | : utilitySpace.getUtility(lastBidOfOpponent);
|
---|
310 | } catch (Exception e1) {
|
---|
311 | // TODO Auto-generated catch block
|
---|
312 | e1.printStackTrace();
|
---|
313 | }
|
---|
314 |
|
---|
315 | if ((lastBidOfOpponentUtil > dblMinUtil
|
---|
316 | || lastBidOfOpponentUtil > myMinUtil)
|
---|
317 | && lastBidOfOpponentUtil > R) {
|
---|
318 | if (isPrinting)
|
---|
319 | System.out.println("Accept1 Util: " + lastBidOfOpponentUtil);
|
---|
320 | if (R > utilitySpace.getUtilityWithDiscount(lastBidOfOpponent,
|
---|
321 | timeline.getTime()))
|
---|
322 | return cleanEndNegotiation();
|
---|
323 | return new Accept(getAgentID(), lastBidOfOpponent);
|
---|
324 | }
|
---|
325 |
|
---|
326 | double currentTime = timeline.getTime();
|
---|
327 |
|
---|
328 | // check BEST neighbor with highest utility
|
---|
329 | if (actionOfPartner != null) {
|
---|
330 | Bid Nbid = getBestNigberBid(
|
---|
331 | DefaultAction.getBidFromAction(actionOfPartner), 0);
|
---|
332 | double dblNbid = getUtility(Nbid);
|
---|
333 | if (dblNbid > dblMinUtil && currentTime < 0.9) {
|
---|
334 | alternativeHashBids.put(dblNbid, Nbid);
|
---|
335 | alternativeArrSamples.add(dblNbid);
|
---|
336 | Collections.sort(alternativeArrSamples);
|
---|
337 | }
|
---|
338 | }
|
---|
339 |
|
---|
340 | if (isPrinting)
|
---|
341 | System.out.println("111111111111111111111");
|
---|
342 | if (highDiscount) {
|
---|
343 | if (NotFirstTime == false) {
|
---|
344 | Bid curBid = hashBids.get(arrSamples.get(countOffer));
|
---|
345 | lastAction = cleanOffer(curBid, lastBidOfOpponentUtil);
|
---|
346 | return lastAction;
|
---|
347 | }
|
---|
348 |
|
---|
349 | double utilOfBid = 0;
|
---|
350 | double utilOflastBidOfOpponent = 0;
|
---|
351 | double utilOfBestBidOfOppenent = 0;
|
---|
352 |
|
---|
353 | try {
|
---|
354 | utilOfBid = utilitySpace.getUtility(lastBidOfOpponent);
|
---|
355 | utilOflastBidOfOpponent = utilOfBid;
|
---|
356 | utilOfBestBidOfOppenent = utilitySpace.getUtility(
|
---|
357 | this.opponentBidHistory.getBestBidInHistory());
|
---|
358 | } catch (Exception e) {
|
---|
359 | System.out.println(
|
---|
360 | "Exception in ChooseAction1:" + e.getMessage());
|
---|
361 |
|
---|
362 | lastAction = cleanOffer(
|
---|
363 | hashBids.get(arrSamples.get(countOffer)),
|
---|
364 | lastBidOfOpponentUtil); // best
|
---|
365 | // guess
|
---|
366 | // if
|
---|
367 | // things
|
---|
368 | // go
|
---|
369 | // wrong.
|
---|
370 |
|
---|
371 | }
|
---|
372 |
|
---|
373 | int FactorOfAverageResponseTime = 1;
|
---|
374 | Bid bid;
|
---|
375 | if (currentTime >= 1 - FactorOfAverageResponseTime
|
---|
376 | * (averageResponseTime + 2 * stiaResponseTime)) { // last
|
---|
377 | // last
|
---|
378 | // moment
|
---|
379 | if (utilitySpace.getReservationValue() > utilOfBid) {
|
---|
380 | if (isPrinting)
|
---|
381 | System.out.println("Enddddddddddddd 1111111111111");
|
---|
382 | return cleanEndNegotiation();
|
---|
383 | } else {
|
---|
384 | if (isPrinting)
|
---|
385 | System.out.println("Accept2 Util: " + utilOfBid);
|
---|
386 | if (R > utilitySpace.getUtilityWithDiscount(
|
---|
387 | lastBidOfOpponent, timeline.getTime()))
|
---|
388 | return cleanEndNegotiation();
|
---|
389 | return new Accept(getAgentID(), lastBidOfOpponent);
|
---|
390 | }
|
---|
391 | } else if (currentTime >= 1 - Math.pow(2, 1)
|
---|
392 | * FactorOfAverageResponseTime * averageResponseTime) { // one
|
---|
393 | // before
|
---|
394 | // last
|
---|
395 | // moment
|
---|
396 | if (isPrinting)
|
---|
397 | System.out.println(
|
---|
398 | "averageResponseTime: " + averageResponseTime);
|
---|
399 | if (isPrinting)
|
---|
400 | System.out.println("Math.pow(2,1): " + Math.pow(2, 1));
|
---|
401 | if (isPrinting)
|
---|
402 | System.out.println("currentTime: " + currentTime + " / "
|
---|
403 | + (1 - Math.pow(2, 1) * FactorOfAverageResponseTime
|
---|
404 | * averageResponseTime));
|
---|
405 | if (utilitySpace.getReservationValue() > utilOfBestBidOfOppenent
|
---|
406 | && utilitySpace
|
---|
407 | .getReservationValue() > utilOflastBidOfOpponent) {
|
---|
408 | if (isPrinting)
|
---|
409 | System.out.println("Enddddddddddddd 2222222222222");
|
---|
410 |
|
---|
411 | return cleanEndNegotiation();
|
---|
412 | } else if (utilOflastBidOfOpponent >= utilOfBestBidOfOppenent) {
|
---|
413 | if (isPrinting)
|
---|
414 | System.out.println(
|
---|
415 | "Accept3 Util: " + utilOflastBidOfOpponent);
|
---|
416 | if (R > utilitySpace.getUtilityWithDiscount(
|
---|
417 | lastBidOfOpponent, timeline.getTime()))
|
---|
418 | return cleanEndNegotiation();
|
---|
419 |
|
---|
420 | return new Accept(getAgentID(), lastBidOfOpponent);
|
---|
421 | } else {
|
---|
422 | double dblutility = getUtility(
|
---|
423 | this.opponentBidHistory.getBestBidInHistory());
|
---|
424 | if (isPrinting)
|
---|
425 | System.out.println("Offer best history: " + dblutility);
|
---|
426 | return new Offer(getAgentID(),
|
---|
427 | this.opponentBidHistory.getBestBidInHistory());
|
---|
428 | }
|
---|
429 | }
|
---|
430 | if (isPrinting)
|
---|
431 | System.out.println("222222222222222222222");
|
---|
432 |
|
---|
433 | return FastLastMomentStrategyWithoutEndNegotiation(
|
---|
434 | dblMinUtil + 0.25 * stia, dblMinUtil, currentTime);
|
---|
435 | }
|
---|
436 | if (lowDiscount) {
|
---|
437 | return FastStrategy();
|
---|
438 | }
|
---|
439 |
|
---|
440 | if (NotFirstTime == false) {
|
---|
441 | Bid curBid = hashBids.get(arrSamples.get(countOffer));
|
---|
442 | lastAction = cleanOffer(curBid, lastBidOfOpponentUtil);
|
---|
443 | return lastAction;
|
---|
444 | }
|
---|
445 |
|
---|
446 | // System.out.println("TimeFactor: " + TimeFactor);
|
---|
447 | currentTime = timeline.getTime() * TimeFactor;
|
---|
448 |
|
---|
449 | double utilOfBid = 0;
|
---|
450 | double utilOflastBidOfOpponent = 0;
|
---|
451 | double utilOfBestBidOfOppenent = 0;
|
---|
452 |
|
---|
453 | try {
|
---|
454 | utilOfBid = utilitySpace.getUtility(lastBidOfOpponent);
|
---|
455 | utilOflastBidOfOpponent = utilOfBid;
|
---|
456 | utilOfBestBidOfOppenent = utilitySpace
|
---|
457 | .getUtility(this.opponentBidHistory.getBestBidInHistory());
|
---|
458 | } catch (Exception e) {
|
---|
459 | System.out.println("Exception in ChooseAction2:" + e.getMessage());
|
---|
460 | lastAction = cleanEndNegotiation(); // best guess if things go
|
---|
461 | // wrong.
|
---|
462 | }
|
---|
463 |
|
---|
464 | int FactorOfAverageResponseTime = 1;
|
---|
465 | Bid bid;
|
---|
466 | if (currentTime >= 1 - FactorOfAverageResponseTime
|
---|
467 | * (averageResponseTime + 2 * stiaResponseTime)) { // last
|
---|
468 | // last
|
---|
469 | // moment
|
---|
470 | if (utilitySpace.getReservationValue() > utilOfBid) {
|
---|
471 | if (isPrinting)
|
---|
472 | System.out.println("Enddddddddddddd 3333333333333");
|
---|
473 |
|
---|
474 | return cleanEndNegotiation();
|
---|
475 | } else {
|
---|
476 | if (isPrinting)
|
---|
477 | System.out.println("Accept4 Util: " + utilOfBid);
|
---|
478 | if (R > utilitySpace.getUtilityWithDiscount(lastBidOfOpponent,
|
---|
479 | timeline.getTime()))
|
---|
480 | return cleanEndNegotiation();
|
---|
481 |
|
---|
482 | return new Accept(getAgentID(), lastBidOfOpponent);
|
---|
483 | }
|
---|
484 | } else if (currentTime >= 1 - Math.pow(2, 1)
|
---|
485 | * FactorOfAverageResponseTime * averageResponseTime) { // one
|
---|
486 | // before
|
---|
487 | // last
|
---|
488 | // moment
|
---|
489 | if (utilitySpace.getReservationValue() > utilOfBestBidOfOppenent
|
---|
490 | && utilitySpace
|
---|
491 | .getReservationValue() > utilOflastBidOfOpponent) {
|
---|
492 | if (isPrinting)
|
---|
493 | System.out.println("Enddddddddddddd 444444444444");
|
---|
494 |
|
---|
495 | return cleanEndNegotiation();
|
---|
496 | } else if (utilOflastBidOfOpponent >= utilOfBestBidOfOppenent) {
|
---|
497 | if (isPrinting)
|
---|
498 | System.out.println(
|
---|
499 | "Accept5 Util: " + utilOflastBidOfOpponent);
|
---|
500 | if (R > utilitySpace.getUtilityWithDiscount(lastBidOfOpponent,
|
---|
501 | timeline.getTime()))
|
---|
502 | return cleanEndNegotiation();
|
---|
503 |
|
---|
504 | return new Accept(getAgentID(), lastBidOfOpponent);
|
---|
505 | } else
|
---|
506 | return new Offer(getAgentID(),
|
---|
507 | this.opponentBidHistory.getBestBidInHistory());
|
---|
508 | }
|
---|
509 |
|
---|
510 | return FastLastMomentStrategyWithoutEndNegotiation(
|
---|
511 | dblMinUtil - UtilityFactor + 0.25 * stia,
|
---|
512 | dblMinUtil - UtilityFactor, currentTime);
|
---|
513 |
|
---|
514 | }
|
---|
515 |
|
---|
516 | /**
|
---|
517 | * If the utility of the given bid is better than the reservation value -
|
---|
518 | * offer it. Otherwise - return EndNegotiation.
|
---|
519 | *
|
---|
520 | * @throws Exception
|
---|
521 | */
|
---|
522 | private Action EndNegotiationOrAcceptOrNewOfferr(Bid myOfferedBid)
|
---|
523 | throws Exception {
|
---|
524 | double lastBidOfOpponentUtility = (lastBidOfOpponent == null ? 0
|
---|
525 | : utilitySpace.getUtility(lastBidOfOpponent));
|
---|
526 |
|
---|
527 | double MyOfferedUtility = utilitySpace.getUtility(myOfferedBid);
|
---|
528 |
|
---|
529 | Bid bestOpponentBid = this.opponentBidHistory.getBestBidInHistory();
|
---|
530 |
|
---|
531 | double bestOpponentBidUtility = (bestOpponentBid == null)
|
---|
532 | ? utilitySpace.getUtility(this.minUtilityBid)
|
---|
533 | : utilitySpace.getUtility(bestOpponentBid);
|
---|
534 |
|
---|
535 | double endNegotiationUtility = utilitySpace.getReservationValue();
|
---|
536 |
|
---|
537 | // 1st priority - EndNegotiation is the best choice
|
---|
538 | if (endNegotiationUtility >= MyOfferedUtility
|
---|
539 | && endNegotiationUtility >= bestOpponentBidUtility
|
---|
540 | && endNegotiationUtility >= lastBidOfOpponentUtility) {
|
---|
541 | if (isPrinting)
|
---|
542 | System.out.println("Enddddddddddddd 5555555555555555");
|
---|
543 |
|
---|
544 | return cleanEndNegotiation();
|
---|
545 | }
|
---|
546 |
|
---|
547 | // 2nd priority - Accept (lastBidOfOpponentUtil) is the best choice
|
---|
548 | else if (lastBidOfOpponentUtility >= bestOpponentBidUtility
|
---|
549 | && lastBidOfOpponentUtility >= MyOfferedUtility
|
---|
550 | && lastBidOfOpponentUtility >= endNegotiationUtility) {
|
---|
551 | if (isPrinting)
|
---|
552 | System.out.println("Accept6 Util: " + lastBidOfOpponentUtility);
|
---|
553 | if (R > utilitySpace.getUtilityWithDiscount(lastBidOfOpponent,
|
---|
554 | timeline.getTime()))
|
---|
555 | return cleanEndNegotiation();
|
---|
556 |
|
---|
557 | return new Accept(getAgentID(), lastBidOfOpponent);
|
---|
558 | }
|
---|
559 |
|
---|
560 | // 3rd priority - bestOpponentBidUtility is the best choice
|
---|
561 | else if (bestOpponentBidUtility >= lastBidOfOpponentUtility
|
---|
562 | && bestOpponentBidUtility >= MyOfferedUtility
|
---|
563 | && bestOpponentBidUtility >= endNegotiationUtility) {
|
---|
564 | if (isPrinting)
|
---|
565 | System.out.println(
|
---|
566 | "new Offer(this.opponentBidHistory.getBestBidInHistory())");
|
---|
567 | return new Offer(getAgentID(),
|
---|
568 | this.opponentBidHistory.getBestBidInHistory());
|
---|
569 | }
|
---|
570 |
|
---|
571 | // 4th priority - myOfferedBid
|
---|
572 | else {
|
---|
573 | if (isPrinting)
|
---|
574 | System.out.println("else");
|
---|
575 | lastAction = cleanOffer(myOfferedBid, lastBidOfOpponentUtility);
|
---|
576 | MyOfferedUtility = utilitySpace
|
---|
577 | .getUtility(DefaultAction.getBidFromAction(lastAction));
|
---|
578 | if (isPrinting)
|
---|
579 | System.out.println(
|
---|
580 | "else MyOfferedUtility 333: " + MyOfferedUtility);
|
---|
581 | return lastAction;
|
---|
582 | }
|
---|
583 | }
|
---|
584 |
|
---|
585 | /**
|
---|
586 | * This strategy tries to achieve an agreement as fast as possible.
|
---|
587 | */
|
---|
588 | public Action FastStrategy() {
|
---|
589 | Bid curBid = hashBids.get(arrSamples.get(countOffer--));
|
---|
590 | lastAction = new Offer(getAgentID(), curBid);
|
---|
591 | try {
|
---|
592 | return EndNegotiationOrAcceptOrNewOfferr(curBid);
|
---|
593 | } catch (Exception e) {
|
---|
594 | System.out.println("Exception in ChooseAction3:" + e.getMessage());
|
---|
595 | return cleanEndNegotiation();
|
---|
596 | }
|
---|
597 | }
|
---|
598 |
|
---|
599 | @Override
|
---|
600 | public String getName() {
|
---|
601 | return "DoNA";
|
---|
602 | }
|
---|
603 |
|
---|
604 | private Bid getRandomBid(double minUtil) throws Exception {
|
---|
605 | HashMap<Integer, Value> values = new HashMap<Integer, Value>(); // pairs
|
---|
606 | // <issuenumber,chosen
|
---|
607 | // value
|
---|
608 | // string>
|
---|
609 | List<Issue> issues = utilitySpace.getDomain().getIssues();
|
---|
610 | Random randomnr = new Random();
|
---|
611 |
|
---|
612 | double tmpMinUtil = 0, currentUtil = 0;
|
---|
613 | // create a random bid with utility>MINIMUM_BID_UTIL.
|
---|
614 | // note that this may never succeed if you set MINIMUM too high!!!
|
---|
615 | // in that case we will search for a bid till the time is up (3 minutes)
|
---|
616 | // but this is just a simple agent.
|
---|
617 | Bid bid = null;
|
---|
618 | int countTimes = 0;
|
---|
619 | do {
|
---|
620 | countTimes++;
|
---|
621 | tmpMinUtil = UpdateMinUtil(minUtil);
|
---|
622 | for (Issue lIssue : issues) {
|
---|
623 | switch (lIssue.getType()) {
|
---|
624 | case DISCRETE:
|
---|
625 | IssueDiscrete lIssueDiscrete = (IssueDiscrete) lIssue;
|
---|
626 | int optionIndex = randomnr
|
---|
627 | .nextInt(lIssueDiscrete.getNumberOfValues());
|
---|
628 | values.put(lIssue.getNumber(),
|
---|
629 | lIssueDiscrete.getValue(optionIndex));
|
---|
630 | break;
|
---|
631 | case REAL:
|
---|
632 | IssueReal lIssueReal = (IssueReal) lIssue;
|
---|
633 | int optionInd = randomnr.nextInt(
|
---|
634 | lIssueReal.getNumberOfDiscretizationSteps() - 1);
|
---|
635 | values.put(lIssueReal.getNumber(), new ValueReal(lIssueReal
|
---|
636 | .getLowerBound()
|
---|
637 | + (lIssueReal.getUpperBound()
|
---|
638 | - lIssueReal.getLowerBound()) * (optionInd)
|
---|
639 | / (lIssueReal
|
---|
640 | .getNumberOfDiscretizationSteps())));
|
---|
641 | break;
|
---|
642 | case INTEGER:
|
---|
643 | IssueInteger lIssueInteger = (IssueInteger) lIssue;
|
---|
644 | int optionIndex2 = lIssueInteger.getLowerBound()
|
---|
645 | + randomnr.nextInt(lIssueInteger.getUpperBound()
|
---|
646 | - lIssueInteger.getLowerBound());
|
---|
647 | values.put(lIssueInteger.getNumber(),
|
---|
648 | new ValueInteger(optionIndex2));
|
---|
649 | break;
|
---|
650 | default:
|
---|
651 | throw new Exception("issue type " + lIssue.getType()
|
---|
652 | + " not supported by SimpleAgent2");
|
---|
653 | }
|
---|
654 | }
|
---|
655 | bid = new Bid(utilitySpace.getDomain(), values);
|
---|
656 | // System.out.println("sumUtil/numOfUtil: " + (sumUtil/numOfUtil));
|
---|
657 | currentUtil = getUtility(bid);
|
---|
658 | // System.out.println("currentUtil: " + currentUtil + " / " +
|
---|
659 | // tmpMinUtil);
|
---|
660 | if (currentUtil >= dblMinUtil) {
|
---|
661 | otherHashBids.put(currentUtil, bid);
|
---|
662 | otherArrSamples.add(currentUtil);
|
---|
663 | }
|
---|
664 | if (countTimes >= 150000)
|
---|
665 | flagStopExplor = true;
|
---|
666 | } while (currentUtil < tmpMinUtil && otherArrSamples.size() < 500
|
---|
667 | && (flagStopExplor == false));
|
---|
668 |
|
---|
669 | if (otherArrSamples.size() > 0) {
|
---|
670 | Collections.sort(otherArrSamples);
|
---|
671 | double tmpUtil = otherArrSamples.get(otherArrSamples.size() - 1);
|
---|
672 | bid = otherHashBids.get(tmpUtil);
|
---|
673 | otherArrSamples.remove(tmpUtil);
|
---|
674 | otherHashBids.remove(tmpUtil);
|
---|
675 | } else {
|
---|
676 | if (currentUtil < tmpMinUtil) {
|
---|
677 | bid = hashBids.get(arrSamples.get(arrSamples.size() - 1));
|
---|
678 | }
|
---|
679 | }
|
---|
680 | return bid;
|
---|
681 | }
|
---|
682 |
|
---|
683 | private double UpdateMinUtil(double minUtil) {
|
---|
684 | double k = 0.01;
|
---|
685 | double time = timeline.getTime();
|
---|
686 | return minUtil - (time / k) * 0.01 * stia * 0.5;
|
---|
687 | }
|
---|
688 |
|
---|
689 | private Action chooseRandomBidAction(double minUtil) {
|
---|
690 | double lastBidOfOpponentUtil = lastBidOfOpponent == null ? 0
|
---|
691 | : getUtility(lastBidOfOpponent);
|
---|
692 | Bid nextBid = null;
|
---|
693 | try {
|
---|
694 | nextBid = getRandomBid(minUtil);
|
---|
695 | } catch (Exception e) {
|
---|
696 | System.out.println("Problem with received bid:" + e.getMessage()
|
---|
697 | + ". cancelling bidding");
|
---|
698 | }
|
---|
699 | if (nextBid == null)
|
---|
700 | return cleanOffer(
|
---|
701 | hashBids.get(arrSamples.get(arrSamples.size() - 1)),
|
---|
702 | lastBidOfOpponentUtil);
|
---|
703 | if (lastBidOfOpponent == null)
|
---|
704 | return new Offer(getAgentID(), nextBid);
|
---|
705 | else {
|
---|
706 | if (isPrinting)
|
---|
707 | System.out
|
---|
708 | .println("chooseRandomBidAction-lastBidOfOpponentUtil: "
|
---|
709 | + lastBidOfOpponentUtil);
|
---|
710 | return cleanOffer(nextBid, lastBidOfOpponentUtil);
|
---|
711 | }
|
---|
712 | }
|
---|
713 |
|
---|
714 | private Bid getBestNigberBid(Bid currentBid, int deep) {
|
---|
715 | HashMap<Integer, Value> tmpvalues;
|
---|
716 | List<Issue> issues = utilitySpace.getDomain().getIssues();
|
---|
717 |
|
---|
718 | double secondMaxUtil = 0;
|
---|
719 | double maxUtil = 0;
|
---|
720 | Bid secondBestBid = null;
|
---|
721 | Bid bestBid = null;
|
---|
722 | Bid newBid;
|
---|
723 | double newUtil;
|
---|
724 | int numOfValues;
|
---|
725 | for (Issue lIssue : issues) {
|
---|
726 | switch (lIssue.getType()) {
|
---|
727 | case DISCRETE:
|
---|
728 | IssueDiscrete lIssueDiscrete = (IssueDiscrete) lIssue;
|
---|
729 | numOfValues = lIssueDiscrete.getNumberOfValues();
|
---|
730 | for (int optionIndex = 0; optionIndex < numOfValues; optionIndex++) {
|
---|
731 |
|
---|
732 | newBid = currentBid;
|
---|
733 | newBid = newBid.putValue(lIssue.getNumber(),
|
---|
734 | lIssueDiscrete.getValue(optionIndex));
|
---|
735 | if (deep > 0) {
|
---|
736 | newBid = getBestNigberBid(newBid, deep - 1);
|
---|
737 | }
|
---|
738 | newUtil = getUtility(newBid);
|
---|
739 | if (newUtil >= maxUtil) {
|
---|
740 | secondMaxUtil = maxUtil;
|
---|
741 | maxUtil = newUtil;
|
---|
742 | secondBestBid = bestBid;
|
---|
743 | bestBid = newBid;
|
---|
744 | } else if (newUtil >= secondMaxUtil) {
|
---|
745 | secondMaxUtil = newUtil;
|
---|
746 | secondBestBid = newBid;
|
---|
747 | }
|
---|
748 | }
|
---|
749 | break;
|
---|
750 | case REAL:
|
---|
751 | IssueReal lIssueReal = (IssueReal) lIssue;
|
---|
752 | numOfValues = lIssueReal.getNumberOfDiscretizationSteps() - 1;
|
---|
753 | for (int optionInd = 0; optionInd < numOfValues; optionInd++) {
|
---|
754 | newBid = currentBid;
|
---|
755 | newBid = newBid.putValue(lIssue.getNumber(), new ValueReal(
|
---|
756 | lIssueReal.getLowerBound() + (lIssueReal
|
---|
757 | .getUpperBound()
|
---|
758 | - lIssueReal.getLowerBound()) * (optionInd)
|
---|
759 | / (lIssueReal
|
---|
760 | .getNumberOfDiscretizationSteps())));
|
---|
761 | if (deep > 0) {
|
---|
762 | newBid = getBestNigberBid(newBid, deep - 1);
|
---|
763 | }
|
---|
764 | newUtil = getUtility(newBid);
|
---|
765 | if (newUtil >= maxUtil) {
|
---|
766 | secondMaxUtil = maxUtil;
|
---|
767 | maxUtil = newUtil;
|
---|
768 | secondBestBid = bestBid;
|
---|
769 | bestBid = newBid;
|
---|
770 | } else if (newUtil >= secondMaxUtil) {
|
---|
771 | secondMaxUtil = newUtil;
|
---|
772 | secondBestBid = newBid;
|
---|
773 | }
|
---|
774 | }
|
---|
775 | break;
|
---|
776 | case INTEGER:
|
---|
777 | IssueInteger lIssueInteger = (IssueInteger) lIssue;
|
---|
778 |
|
---|
779 | numOfValues = lIssueInteger.getUpperBound()
|
---|
780 | - lIssueInteger.getLowerBound();
|
---|
781 | for (int optionIndex2 = lIssueInteger
|
---|
782 | .getLowerBound(); optionIndex2 < numOfValues; optionIndex2++) {
|
---|
783 | newBid = currentBid;
|
---|
784 | newBid = newBid.putValue(lIssue.getNumber(),
|
---|
785 | new ValueInteger(optionIndex2));
|
---|
786 | if (deep > 0) {
|
---|
787 | newBid = getBestNigberBid(newBid, deep - 1);
|
---|
788 | }
|
---|
789 | newUtil = getUtility(newBid);
|
---|
790 | if (newUtil >= maxUtil) {
|
---|
791 | secondMaxUtil = maxUtil;
|
---|
792 | maxUtil = newUtil;
|
---|
793 | secondBestBid = bestBid;
|
---|
794 | bestBid = newBid;
|
---|
795 | } else if (newUtil >= secondMaxUtil) {
|
---|
796 | secondMaxUtil = newUtil;
|
---|
797 | secondBestBid = newBid;
|
---|
798 | }
|
---|
799 | }
|
---|
800 | break;
|
---|
801 |
|
---|
802 | }
|
---|
803 | }
|
---|
804 | if (bestBid.equals(currentBid))
|
---|
805 | return secondBestBid;
|
---|
806 | else
|
---|
807 | return bestBid;
|
---|
808 | }
|
---|
809 |
|
---|
810 | public Action FastStrategyWithoutEndNegotiation(double VirtulReservation) {
|
---|
811 | if (myMinUtil > VirtulReservation)
|
---|
812 | myMinUtil = VirtulReservation;
|
---|
813 |
|
---|
814 | try {
|
---|
815 | double lastBidOfOpponentUtil = lastBidOfOpponent == null ? 0
|
---|
816 | : utilitySpace.getUtility(lastBidOfOpponent);
|
---|
817 | Bid curBid = hashBids.get(arrSamples.get(countOffer));
|
---|
818 | lastAction = cleanOffer(curBid, lastBidOfOpponentUtil);
|
---|
819 |
|
---|
820 | double bestOpponentBidUtility = utilitySpace
|
---|
821 | .getUtility(this.opponentBidHistory.getBestBidInHistory());
|
---|
822 | // lastBidOfOpponentUtil is the best choice
|
---|
823 | if ((lastBidOfOpponentUtil > MyOfferedUtility
|
---|
824 | || lastBidOfOpponentUtil >= VirtulReservation)
|
---|
825 | && lastBidOfOpponentUtil > R) {
|
---|
826 | if (isPrinting)
|
---|
827 | System.out
|
---|
828 | .println("Accept7 Util: " + lastBidOfOpponentUtil);
|
---|
829 | if (R > utilitySpace.getUtilityWithDiscount(lastBidOfOpponent,
|
---|
830 | timeline.getTime()))
|
---|
831 | return cleanEndNegotiation();
|
---|
832 |
|
---|
833 | return new Accept(getAgentID(), lastBidOfOpponent);
|
---|
834 | }
|
---|
835 | // bestOpponentBidUtility is the best choice
|
---|
836 | else if (bestOpponentBidUtility > MyOfferedUtility
|
---|
837 | || bestOpponentBidUtility >= VirtulReservation) {
|
---|
838 | if (isPrinting)
|
---|
839 | System.out.println("bestOpponentBidUtility: "
|
---|
840 | + bestOpponentBidUtility + " MyOfferedUtility: "
|
---|
841 | + MyOfferedUtility + " VirtulReservation: "
|
---|
842 | + VirtulReservation);
|
---|
843 | return new Offer(getAgentID(),
|
---|
844 | this.opponentBidHistory.getBestBidInHistory());
|
---|
845 | }
|
---|
846 | // Reservation is the best choice
|
---|
847 | else if (VirtulReservation > MyOfferedUtility) {
|
---|
848 | if (isPrinting)
|
---|
849 | System.out.println("MyOfferedUtility 111: ");
|
---|
850 | double dbltime = timeline.getTime();
|
---|
851 |
|
---|
852 | if (flagStopExplor == false && dbltime < 0.90) {
|
---|
853 | if (isPrinting)
|
---|
854 | System.out.println("flagStopExplor==false");
|
---|
855 | lastAction = chooseRandomBidAction(VirtulReservation);
|
---|
856 | } else {
|
---|
857 |
|
---|
858 | if (otherArrSamples.size() > 0) {
|
---|
859 | if (isPrinting)
|
---|
860 | System.out.println("otherArrSamples.size()>0");
|
---|
861 |
|
---|
862 | Collections.sort(otherArrSamples);
|
---|
863 | double tmpUtil = otherArrSamples
|
---|
864 | .get(otherArrSamples.size() - 1);
|
---|
865 | curBid = otherHashBids.get(tmpUtil);
|
---|
866 | otherArrSamples.remove(tmpUtil);
|
---|
867 | otherHashBids.remove(tmpUtil);
|
---|
868 |
|
---|
869 | if (curBid == null) {
|
---|
870 | if (isPrinting)
|
---|
871 | System.out.println("curBid==null");
|
---|
872 |
|
---|
873 | int tmpDif = arrSamples.size() - countOffer;
|
---|
874 | double randNum = Math.random();
|
---|
875 | if (isPrinting)
|
---|
876 | System.out.println("countOffer: " + countOffer
|
---|
877 | + " tmpDif: " + tmpDif + " randNum: "
|
---|
878 | + randNum);
|
---|
879 | int randIndex = ((int) (randNum * tmpDif))
|
---|
880 | + countOffer;
|
---|
881 | curBid = hashBids.get(arrSamples.get(randIndex));
|
---|
882 | if (isPrinting)
|
---|
883 | System.out.println("randIndex: " + randIndex);
|
---|
884 | if (isPrinting)
|
---|
885 | System.out.println("curBid: " + curBid);
|
---|
886 | }
|
---|
887 | } else {
|
---|
888 | if (isPrinting)
|
---|
889 | System.out.println("otherArrSamples.size()>0 else");
|
---|
890 |
|
---|
891 | int tmpDif = arrSamples.size() - countOffer;
|
---|
892 | double randNum = Math.random();
|
---|
893 | if (isPrinting)
|
---|
894 | System.out.println(
|
---|
895 | "countOffer: " + countOffer + " tmpDif: "
|
---|
896 | + tmpDif + " randNum: " + randNum);
|
---|
897 | int randIndex = ((int) (randNum * tmpDif)) + countOffer;
|
---|
898 | curBid = hashBids.get(arrSamples.get(randIndex));
|
---|
899 | if (isPrinting)
|
---|
900 | System.out.println("randIndex: " + randIndex);
|
---|
901 | if (isPrinting)
|
---|
902 | System.out.println("curBid: " + curBid);
|
---|
903 |
|
---|
904 | }
|
---|
905 | lastAction = cleanOffer(curBid, lastBidOfOpponentUtil);
|
---|
906 | }
|
---|
907 | MyOfferedUtility = utilitySpace
|
---|
908 | .getUtility(DefaultAction.getBidFromAction(lastAction));
|
---|
909 | if (isPrinting)
|
---|
910 | System.out.println(
|
---|
911 | "MyOfferedUtility 111: " + MyOfferedUtility);
|
---|
912 |
|
---|
913 | return lastAction;
|
---|
914 | } else {
|
---|
915 | if (isPrinting)
|
---|
916 | System.out.println("MyOfferedUtility 222: ");
|
---|
917 |
|
---|
918 | countOffer--;
|
---|
919 | lastAction = cleanOffer(curBid, lastBidOfOpponentUtil);
|
---|
920 | MyOfferedUtility = utilitySpace
|
---|
921 | .getUtility(DefaultAction.getBidFromAction(lastAction));
|
---|
922 | if (isPrinting)
|
---|
923 | System.out.println(
|
---|
924 | "MyOfferedUtility 222: " + MyOfferedUtility);
|
---|
925 |
|
---|
926 | return lastAction;
|
---|
927 | }
|
---|
928 | } catch (Exception e) {
|
---|
929 | System.out.println("Exception in ChooseAction4:" + e.getMessage());
|
---|
930 | return FastStrategy();
|
---|
931 | }
|
---|
932 | }
|
---|
933 |
|
---|
934 | public Action FastLastMomentStrategyWithoutEndNegotiation(
|
---|
935 | double StartMinUtil, double MinUtil, double dblMyRoundTime) {
|
---|
936 |
|
---|
937 | int constForNumOfRounds = 100;
|
---|
938 | double Delta = (StartMinUtil - MinUtil) / 11;
|
---|
939 | // double MinUtil = 0.75;
|
---|
940 | // double dblMyRoundTime =
|
---|
941 | // timeline.getTime()/(1.1*(1-utilitySpace.getReservationValue()));
|
---|
942 | // double dblMyRoundTime = timeline.getTime();
|
---|
943 | int FactorOfAverageResponseTime = 1;
|
---|
944 | if (dblMyRoundTime >= 1 - constForNumOfRounds
|
---|
945 | * FactorOfAverageResponseTime * averageResponseTime) { // Other
|
---|
946 | // before-last
|
---|
947 | // moments
|
---|
948 | // -
|
---|
949 | // logarithmic
|
---|
950 | // scale
|
---|
951 | if (isPrinting)
|
---|
952 | System.out.println("dblMyRoundTime 1111");
|
---|
953 | return FastStrategyWithoutEndNegotiation(MinUtil);
|
---|
954 | } else if (dblMyRoundTime >= 1 - constForNumOfRounds
|
---|
955 | * FactorOfAverageResponseTime * averageResponseTime) {
|
---|
956 | if (isPrinting)
|
---|
957 | System.out.println("dblMyRoundTime 2222");
|
---|
958 | return FastStrategyWithoutEndNegotiation(MinUtil + Delta);
|
---|
959 | } else if (dblMyRoundTime >= 1 - constForNumOfRounds
|
---|
960 | * FactorOfAverageResponseTime * averageResponseTime) {
|
---|
961 | if (isPrinting)
|
---|
962 | System.out.println("dblMyRoundTime 33333");
|
---|
963 | return FastStrategyWithoutEndNegotiation(MinUtil + 2 * Delta);
|
---|
964 | } else if (dblMyRoundTime >= 1 - constForNumOfRounds
|
---|
965 | * FactorOfAverageResponseTime * averageResponseTime) {
|
---|
966 | if (isPrinting)
|
---|
967 | System.out.println("dblMyRoundTime 44444");
|
---|
968 | return FastStrategyWithoutEndNegotiation(MinUtil + 3 * Delta);
|
---|
969 | } else if (dblMyRoundTime >= 1 - constForNumOfRounds
|
---|
970 | * FactorOfAverageResponseTime * averageResponseTime) {
|
---|
971 | if (isPrinting)
|
---|
972 | System.out.println("dblMyRoundTime 55555");
|
---|
973 | return FastStrategyWithoutEndNegotiation(MinUtil + 4 * Delta);
|
---|
974 | } else if (dblMyRoundTime >= 1 - constForNumOfRounds
|
---|
975 | * FactorOfAverageResponseTime * averageResponseTime) {
|
---|
976 | if (isPrinting)
|
---|
977 | System.out.println("dblMyRoundTime 6666");
|
---|
978 | return FastStrategyWithoutEndNegotiation(MinUtil + 5 * Delta);
|
---|
979 | } else if (dblMyRoundTime >= 1 - constForNumOfRounds
|
---|
980 | * FactorOfAverageResponseTime * averageResponseTime) {
|
---|
981 | if (isPrinting)
|
---|
982 | System.out.println("dblMyRoundTime 7777");
|
---|
983 | return FastStrategyWithoutEndNegotiation(MinUtil + 6 * Delta);
|
---|
984 | } else if (dblMyRoundTime >= 1 - constForNumOfRounds
|
---|
985 | * FactorOfAverageResponseTime * averageResponseTime) {
|
---|
986 | if (isPrinting)
|
---|
987 | System.out.println("dblMyRoundTime 88888");
|
---|
988 | return FastStrategyWithoutEndNegotiation(MinUtil + 7 * Delta);
|
---|
989 | } else if (dblMyRoundTime >= 1 - constForNumOfRounds
|
---|
990 | * FactorOfAverageResponseTime * averageResponseTime) {
|
---|
991 | if (isPrinting)
|
---|
992 | System.out.println("dblMyRoundTime 9999");
|
---|
993 | return FastStrategyWithoutEndNegotiation(MinUtil + 8 * Delta);
|
---|
994 | } else if (dblMyRoundTime >= 1 - constForNumOfRounds
|
---|
995 | * FactorOfAverageResponseTime * averageResponseTime) {
|
---|
996 | if (isPrinting)
|
---|
997 | System.out.println("dblMyRoundTime 111 000");
|
---|
998 | return FastStrategyWithoutEndNegotiation(MinUtil + 9 * Delta);
|
---|
999 | } else if (dblMyRoundTime >= 1 - constForNumOfRounds
|
---|
1000 | * FactorOfAverageResponseTime * averageResponseTime) {
|
---|
1001 | if (isPrinting)
|
---|
1002 | System.out.println("dblMyRoundTime 111 111");
|
---|
1003 | return FastStrategyWithoutEndNegotiation(MinUtil + 10 * Delta);
|
---|
1004 | } else {
|
---|
1005 | if (isPrinting)
|
---|
1006 | System.out.println("dblMyRoundTime 111 222");
|
---|
1007 | return FastStrategyWithoutEndNegotiation(StartMinUtil);
|
---|
1008 | }
|
---|
1009 | }
|
---|
1010 |
|
---|
1011 | public Action cleanOffer(Bid curBid, double lastBidOfOpponentUtil) {
|
---|
1012 | try {
|
---|
1013 | MyOfferedUtility = utilitySpace.getUtility(curBid);
|
---|
1014 | boolean flagViol = false;
|
---|
1015 | while (MyOfferedUtility <= lastBidOfOpponentUtil) {
|
---|
1016 | flagViol = true;
|
---|
1017 | countOffer--;
|
---|
1018 | if (countOffer == -1) {
|
---|
1019 | System.out.println("countOffer==-1");
|
---|
1020 | break;
|
---|
1021 | }
|
---|
1022 | curBid = hashBids.get(arrSamples.get(countOffer));
|
---|
1023 | lastAction = new Offer(getAgentID(), curBid);
|
---|
1024 | MyOfferedUtility = utilitySpace.getUtility(curBid);
|
---|
1025 | }
|
---|
1026 | if (flagViol) {
|
---|
1027 | int tmpSize = arrSamples.size() - 1 - countOffer;
|
---|
1028 | arrSamples = new ArrayList<Double>();
|
---|
1029 | for (double key : hashBids.keySet()) {
|
---|
1030 | arrSamples.add(key);
|
---|
1031 | }
|
---|
1032 | if (countOffer == -1) {
|
---|
1033 | System.out.println("countOffer==-1");
|
---|
1034 | hashBids.get(arrSamples.get(arrSamples.size() - 1));
|
---|
1035 | }
|
---|
1036 | countOffer = arrSamples.size() - 1 - tmpSize;
|
---|
1037 | Collections.sort(arrSamples);
|
---|
1038 | curBid = hashBids.get(arrSamples.get(countOffer));
|
---|
1039 | lastAction = new Offer(getAgentID(), curBid);
|
---|
1040 | MyOfferedUtility = utilitySpace.getUtility(curBid);
|
---|
1041 | }
|
---|
1042 | if (MyOfferedUtility < dblMinUtil) {
|
---|
1043 | countOffer--;
|
---|
1044 | curBid = hashBids.get(arrSamples.get(countOffer));
|
---|
1045 | lastAction = new Offer(getAgentID(), curBid);
|
---|
1046 | MyOfferedUtility = utilitySpace.getUtility(curBid);
|
---|
1047 | }
|
---|
1048 | if (MyOfferedUtility <= lastBidOfOpponentUtil
|
---|
1049 | || MyOfferedUtility < R) {
|
---|
1050 | if (isPrinting)
|
---|
1051 | System.out.println("Enddddddddddddd 7777777777777777");
|
---|
1052 |
|
---|
1053 | return cleanEndNegotiation();
|
---|
1054 | }
|
---|
1055 | } catch (Exception e) {
|
---|
1056 | // TODO Auto-generated catch block
|
---|
1057 | e.printStackTrace();
|
---|
1058 | System.out.println(e.getMessage());
|
---|
1059 | // System.out.println("nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn");
|
---|
1060 | return bestFromOpponent();
|
---|
1061 |
|
---|
1062 | }
|
---|
1063 |
|
---|
1064 | try {
|
---|
1065 | MyOfferedUtility = utilitySpace.getUtility(curBid);
|
---|
1066 | } catch (Exception e) {
|
---|
1067 | // TODO Auto-generated catch block
|
---|
1068 | e.printStackTrace();
|
---|
1069 | }
|
---|
1070 | return new Offer(getAgentID(), curBid);
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 | private Action cleanEndNegotiation() {
|
---|
1074 | // TODO Auto-generated method stub
|
---|
1075 | java.util.Random generateRandom = new java.util.Random();
|
---|
1076 | int randIndex = generateRandom.nextInt(countOffer - arrSamples.size());
|
---|
1077 | if (randIndex == countOffer)
|
---|
1078 | return new Offer(getAgentID(),
|
---|
1079 | hashBids.get(arrSamples.get(randIndex)));
|
---|
1080 | else
|
---|
1081 | return new EndNegotiation(getAgentID());
|
---|
1082 | }
|
---|
1083 |
|
---|
1084 | private Action bestFromOpponent() {
|
---|
1085 | double dblUtilVal = alternativeArrSamples
|
---|
1086 | .get(alternativeArrSamples.size() - 1);
|
---|
1087 | Bid lastBid = alternativeHashBids.get(dblUtilVal);
|
---|
1088 |
|
---|
1089 | alternativeHashBids.remove(dblUtilVal);
|
---|
1090 | alternativeArrSamples.remove(dblUtilVal);
|
---|
1091 |
|
---|
1092 | if (R > utilitySpace.getUtilityWithDiscount(lastBid,
|
---|
1093 | timeline.getTime()))
|
---|
1094 | return cleanEndNegotiation();
|
---|
1095 | else
|
---|
1096 | return new Offer(getAgentID(), lastBid);
|
---|
1097 | }
|
---|
1098 |
|
---|
1099 | @Override
|
---|
1100 | public String getDescription() {
|
---|
1101 | return "ANAC2014 compatible with non-linear utility spaces";
|
---|
1102 | }
|
---|
1103 | }
|
---|