source: src/main/java/agents/anac/y2015/AresParty/AresParty.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 29.8 KB
RevLine 
[127]1package agents.anac.y2015.AresParty;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6import java.util.Random;
7
8import genius.core.AgentID;
9import genius.core.Bid;
10import genius.core.BidIterator;
11import genius.core.actions.Accept;
12import genius.core.actions.Action;
13import genius.core.actions.ActionWithBid;
14import genius.core.actions.EndNegotiation;
15import genius.core.actions.Offer;
16import genius.core.issue.Issue;
17import genius.core.issue.IssueDiscrete;
18import genius.core.issue.IssueInteger;
19import genius.core.issue.IssueReal;
20import genius.core.issue.Value;
21import genius.core.issue.ValueInteger;
22import genius.core.issue.ValueReal;
23import genius.core.parties.AbstractNegotiationParty;
24import genius.core.parties.NegotiationInfo;
25import genius.core.utility.AdditiveUtilitySpace;
26
27/**
28 *
29 * @author S.Chen & J.Hao
30 */
31public class AresParty extends AbstractNegotiationParty {
32
33 private double totalTime;
34 private Action ActionOfOpponent = null;
35 private Object party = null;
36 private Object myparty = null;
37 private double maximumOfBid;
38 private OwnBidHistory ownBidHistory;
39 private OpponentBidHistory opponentBidHistory;
40 private double minimumUtilityThreshold;
41 private double utilitythreshold;
42 private double MaximumUtility;
43 private double timeLeftBefore;
44 private double timeLeftAfter;
45 private double maximumTimeOfOpponent;
46 private double maximumTimeOfOwn;
47 private double discountingFactor;
48 private double concedeToDiscountingFactor;
49 private double concedeToDiscountingFactor_original;
50 private double minConcedeToDiscountingFactor;
51 private ArrayList<ArrayList<Bid>> bidsBetweenUtility;
52 private boolean concedeToOpponent;
53 private boolean toughAgent; // if we propose a bid that was proposed by the
54 // opponnet, then it should be accepted.
55 private double alpha1;// the larger alpha is, the more tough the agent is.
56 private Bid bid_maximum_utility;// the bid with the maximum utility over the
57 // utility space.
58 private double reservationValue;
59 private Random random;
60 private Bid maxBid = null;
61
62 private int NoOfParty = -1;
63
64 @Override
65 public void init(NegotiationInfo info) {
66 super.init(info);
67 myparty = getPartyId();
68
69 try {
70 random = new Random();
71 maximumOfBid = this.utilitySpace.getDomain()
72 .getNumberOfPossibleBids();
73 ownBidHistory = new OwnBidHistory();
74 opponentBidHistory = new OpponentBidHistory();
75 bidsBetweenUtility = new ArrayList<ArrayList<Bid>>();
76 this.bid_maximum_utility = utilitySpace.getMaxUtilityBid();
77 this.utilitythreshold = utilitySpace
78 .getUtility(bid_maximum_utility); // initial
79 // utility
80 // threshold
81 this.MaximumUtility = this.utilitythreshold;
82 this.timeLeftAfter = 0;
83 this.timeLeftBefore = 0;
84 this.totalTime = timeline.getTotalTime();
85 this.maximumTimeOfOpponent = 0;
86 this.maximumTimeOfOwn = 0;
87 this.minConcedeToDiscountingFactor = 0.08;// 0.1;
88 this.discountingFactor = 1;
89 if (utilitySpace.getDiscountFactor() <= 1D
90 && utilitySpace.getDiscountFactor() > 0D) {
91 this.discountingFactor = utilitySpace.getDiscountFactor();
92 }
93 this.chooseUtilityThreshold();
94 this.calculateBidsBetweenUtility();
95 this.chooseConcedeToDiscountingDegree();
96 this.opponentBidHistory
97 .initializeDataStructures(utilitySpace.getDomain());
98 this.timeLeftAfter = timeline.getCurrentTime();
99 this.concedeToOpponent = false;
100 this.toughAgent = false;
101 this.alpha1 = 2;
102 this.reservationValue = 0;
103 if (utilitySpace.getReservationValue() > 0) {
104 this.reservationValue = utilitySpace.getReservationValue();
105 }
106
107 maxBid = utilitySpace.getMaxUtilityBid();
108 } catch (Exception e) {
109 System.out.println("initialization error" + e.getMessage());
110 }
111 }
112
113 @Override
114 public void receiveMessage(AgentID sender, Action opponentAction) {
115 super.receiveMessage(sender, opponentAction);
116
117 this.ActionOfOpponent = opponentAction;
118 this.party = sender;
119
120 if (NoOfParty == -1) {
121 NoOfParty = getNumberOfParties();
122 } else {
123
124 if (ActionOfOpponent instanceof Offer) {
125 // Bid partnerBid = ((Offer) ActionOfOpponent).getBid();
126 // double offeredUtilFromOpponent = getUtility(partnerBid);
127
128 this.opponentBidHistory.updateOpponentModel(
129 ((Offer) ActionOfOpponent).getBid(),
130 utilitySpace.getDomain(),
131 (AdditiveUtilitySpace) this.utilitySpace);
132
133 } else if (ActionOfOpponent instanceof Accept) {
134 // receive an accept from an opponent over an offer, which may
135 // not be ours.
136
137 /*
138 * this.opponentBidHistory.updateOpponentModel(
139 * ownBidHistory.getLastBid(), utilitySpace.getDomain(),
140 * this.utilitySpace);
141 */
142
143 } else {
144 //
145 System.out.println("unexpected action");
146 }
147
148 }
149
150 }
151
152 @Override
153 public Action chooseAction(List<Class<? extends Action>> validActions) {
154 Action action = null;
155 try {
156 // System.out.println("i propose " + debug + " bid at time " +
157 // timeline.getTime());
158 this.timeLeftBefore = timeline.getCurrentTime();
159 Bid bid = null;
160 // we propose first and propose the bid with maximum utility
161 if (!validActions.contains(Accept.class)) {
162 bid = this.bid_maximum_utility;
163 action = new Offer(getPartyId(), bid);
164 } else if (ActionOfOpponent instanceof Offer) {// the opponent
165 // propose first and
166 // we response
167 // secondly
168 // update opponent model first
169 this.opponentBidHistory.updateOpponentModel(
170 ((Offer) ActionOfOpponent).getBid(),
171 utilitySpace.getDomain(),
172 (AdditiveUtilitySpace) this.utilitySpace);
173 this.updateConcedeDegree();
174 // update the estimation
175 if (ownBidHistory.numOfBidsProposed() == 0) {
176 // bid = utilitySpace.getMaxUtilityBid();
177 bid = this.bid_maximum_utility;
178
179 action = new Offer(getPartyId(), bid);
180 } else {// other conditions
181 if (estimateRoundLeft(true) > 10) {// still have some rounds
182 // left to further
183 // negotiate (the major
184 // negotiation period)
185 bid = BidToOffer();
186 Boolean IsAccept = AcceptOpponentOffer(
187 ((Offer) ActionOfOpponent).getBid(), bid);
188 Boolean IsTerminate = TerminateCurrentNegotiation(bid);
189 if (IsAccept && !IsTerminate) {
190 action = new Accept(getPartyId(), getOppBid());
191 } else if (IsTerminate && !IsAccept) {
192 // action = new EndNegotiation();
193 action = new Offer(getPartyId(), maxBid);
194 } else if (IsAccept && IsTerminate) {
195 if (this.utilitySpace
196 .getUtility(((Offer) ActionOfOpponent)
197 .getBid()) > this.reservationValue) {
198 action = new Accept(getPartyId(), getOppBid());
199 } else {
200 // action = new EndNegotiation();
201 action = new Offer(getPartyId(), maxBid);
202 }
203 } else {
204 // we expect that the negotiation is over once we
205 // select a bid from the opponent's history.
206 if (this.concedeToOpponent == true) {
207 // bid =
208 // opponentBidHistory.chooseBestFromHistory(this.utilitySpace);
209 bid = opponentBidHistory.getBestBidInHistory();
210
211 action = new Offer(getPartyId(), bid);
212 this.toughAgent = true;
213 this.concedeToOpponent = false;
214 } else {
215 action = new Offer(getPartyId(), bid);
216 this.toughAgent = false;
217 }
218 }
219 } else {// this is the last chance and we concede by
220 // providing the opponent the best offer he ever
221 // proposed to us
222 // in this case, it corresponds to an opponent whose
223 // decision time is short
224 if (timeline.getTime() > 0.9985
225 && estimateRoundLeft(true) < 5) {
226 // bid =
227 // opponentBidHistory.chooseBestFromHistory(this.utilitySpace);
228 bid = opponentBidHistory.getBestBidInHistory();
229
230 // this is specially designed to avoid that we got
231 // very low utility by searching between an
232 // acceptable range (when the domain is small)
233 if (this.utilitySpace.getUtility(bid) < 0.85) {
234 List<Bid> candidateBids = this
235 .getBidsBetweenUtility(
236 this.MaximumUtility - 0.15,
237 this.MaximumUtility - 0.02);
238 // if the candidate bids do not exsit and also
239 // the deadline is approaching in next round, we
240 // concede.
241 // if (candidateBids.size() == 1 &&
242 // timeline.getTime()>0.9998) {
243 // we have no chance to make a new proposal
244 // before the deadline
245 if (this.estimateRoundLeft(true) < 2) {
246 bid = opponentBidHistory
247 .getBestBidInHistory();
248 } else {
249 bid = opponentBidHistory.ChooseBid(
250 candidateBids,
251 this.utilitySpace.getDomain());
252 }
253 if (bid == null) {
254 bid = opponentBidHistory
255 .getBestBidInHistory();
256 }
257 }
258 Boolean IsAccept = AcceptOpponentOffer(
259 ((Offer) ActionOfOpponent).getBid(), bid);
260 Boolean IsTerminate = TerminateCurrentNegotiation(
261 bid);
262 if (IsAccept && !IsTerminate) {
263 action = new Accept(getPartyId(), getOppBid());
264 } else if (IsTerminate && !IsAccept) {
265 // action = new EndNegotiation();
266 action = new Offer(getPartyId(), maxBid);
267 } else if (IsTerminate && IsAccept) {
268 if (this.utilitySpace
269 .getUtility(((Offer) ActionOfOpponent)
270 .getBid()) > this.reservationValue) {
271 action = new Accept(getPartyId(),
272 getOppBid());
273 } else {
274 // action = new EndNegotiation();
275 action = new Offer(getPartyId(), maxBid);
276 }
277 } else {
278 if (this.toughAgent == true) {
279 action = new Accept(getPartyId(),
280 getOppBid());
281 } else {
282 action = new Offer(getPartyId(), bid);
283 }
284 }
285 // in this case, it corresponds to the situation
286 // that we encounter an opponent who needs more
287 // computation to make decision each round
288 } else {// we still have some time to negotiate,
289 // and be tough by sticking with the lowest one in
290 // previous offer history.
291 // we also have to make the decisin fast to avoid
292 // reaching the deadline before the decision is made
293 // bid = ownBidHistory.GetMinBidInHistory();//reduce
294 // the computational cost
295 bid = BidToOffer();
296
297 // System.out.println("test----------------------------------------------------------"
298 // + timeline.getTime());
299 Boolean IsAccept = AcceptOpponentOffer(
300 ((Offer) ActionOfOpponent).getBid(), bid);
301 Boolean IsTerminate = TerminateCurrentNegotiation(
302 bid);
303 if (IsAccept && !IsTerminate) {
304 action = new Accept(getPartyId(), getOppBid());
305 } else if (IsTerminate && !IsAccept) {
306 // action = new EndNegotiation();
307 action = new Offer(getPartyId(), maxBid);
308 } else if (IsAccept && IsTerminate) {
309 if (this.utilitySpace
310 .getUtility(((Offer) ActionOfOpponent)
311 .getBid()) > this.reservationValue) {
312 action = new Accept(getPartyId(),
313 getOppBid());
314 } else {
315 // action = new EndNegotiation();
316 action = new Offer(getPartyId(), maxBid);
317 }
318 } else {
319 action = new Offer(getPartyId(), bid);
320 // System.out.println("we have to be tough now"
321 // + bid.toString() + " with utility of " +
322 // utilitySpace.getUtility(bid));
323 }
324 }
325 }
326 }
327 } else if (ActionOfOpponent instanceof Accept) {
328
329 try {
330 if (this.utilitythreshold <= ((1 - this.discountingFactor)
331 * 0.1 + 1.05)
332 * this.utilitySpace.getUtility(
333 opponentBidHistory.getLastOppBid())) {
334 System.out.println(
335 "accept an offer after seeing an acceptance action with a not bad result"
336 + ActionOfOpponent.getAgent());
337 action = new Accept(getPartyId(), getOppBid());
338 }
339 } catch (Exception e) {
340
341 }
342
343 bid = BidToOffer();
344
345 Boolean IsAccept = AcceptOpponentOffer(
346 ((Offer) ActionOfOpponent).getBid(), bid);
347 Boolean IsTerminate = TerminateCurrentNegotiation(bid);
348 if (IsAccept && !IsTerminate) {
349 action = new Accept(getPartyId(), getOppBid());
350 } else if (IsTerminate && !IsAccept) {
351 // action = new EndNegotiation();
352 action = new Offer(getPartyId(), maxBid);
353 } else if (IsAccept && IsTerminate) {
354 if (this.utilitySpace.getUtility(((Offer) ActionOfOpponent)
355 .getBid()) > this.reservationValue) {
356 action = new Accept(getPartyId(), getOppBid());
357 } else {
358 // action = new EndNegotiation();
359 action = new Offer(getPartyId(), maxBid);
360 }
361 } else {
362 action = new Offer(getPartyId(), bid);
363 // System.out.println("we have to be tough now"
364 // + bid.toString() + " with utility of " +
365 // utilitySpace.getUtility(bid));
366 }
367 }
368 // System.out.println("i propose " + debug + " bid at time " +
369 // timeline.getTime());
370
371 if (bid != null)
372 this.ownBidHistory.addBid(bid,
373 (AdditiveUtilitySpace) utilitySpace);
374
375 this.timeLeftAfter = timeline.getCurrentTime();
376 this.estimateRoundLeft(false);// update the estimation
377 } catch (Exception e) {
378 System.out.println("Exception in ChooseAction:" + e.getMessage());
379 System.out.println(estimateRoundLeft(false));
380 // action = new Accept(getAgentID()); // accept if anything goes
381 // wrong.
382 // action = new EndNegotiation(); // terminate if anything
383 action = new Offer(getPartyId(), maxBid); // goes wrong.
384 }
385
386 if (this.discountingFactor <= 0.5 && this.reservationValue >= 0.4
387 && timeline.getTime() > 0.1)
388 action = new EndNegotiation(getPartyId());
389
390 if (timeline.getCurrentTime() > timeline.getTotalTime() * 1.1) {
391 System.out.println("exception in negotiation time for Ares!"
392 + timeline.getCurrentTime() + ","
393 + timeline.getTotalTime());
394 action = new EndNegotiation(getPartyId());
395 }
396
397 if (action == null)
398 action = new Offer(getPartyId(), maxBid);
399
400 return action;
401 }
402
403 /**
404 * @return bid in the last opponent action.
405 * @throws ClassCastException
406 * if last opponent action did not contain a bid.
407 */
408 private Bid getOppBid() {
409 return ((ActionWithBid) ActionOfOpponent).getBid();
410 }
411
412 /*
413 * principle: randomization over those candidate bids to let the opponent
414 * have a better model of my utility profile return the bid to be offered in
415 * the next round
416 */
417 private Bid BidToOffer() {
418 Bid bidReturned = null;
419 double decreasingAmount_1 = 0.05;
420 double decreasingAmount_2 = 0.25;
421 try {
422
423 double maximumOfBid = this.MaximumUtility;// utilitySpace.getUtility(utilitySpace.getMaxUtilityBid());
424 double minimumOfBid;
425 // used when the domain is very large.
426 // make concession when the domin is large
427 if (this.discountingFactor == 1 && this.maximumOfBid > 3000) {
428 minimumOfBid = this.MaximumUtility - decreasingAmount_1;
429 // make further concession when the deadline is approaching and
430 // the domain is large
431 if (this.discountingFactor > 1 - decreasingAmount_2
432 && this.maximumOfBid > 10000
433 && timeline.getTime() >= 0.98) {
434 minimumOfBid = this.MaximumUtility - decreasingAmount_2;
435 }
436 if (this.utilitythreshold > minimumOfBid) {
437 this.utilitythreshold = minimumOfBid;
438 }
439 } /*
440 * else if (this.discountingFactor > 1 - decreasingAmount_3 &&
441 * this.maximumOfBid >= 100000 && this.maximumOfBid < 300000) {
442 * minimumOfBid = this.MaximumUtility - decreasingAmount_3; }
443 * else if (this.discountingFactor > 1 - decreasingAmount_4 &&
444 * this.maximumOfBid >= 300000) { minimumOfBid =
445 * this.MaximumUtility - decreasingAmount_4; }
446 */else {// the general case
447 if (timeline.getTime() <= this.concedeToDiscountingFactor) {
448 double minThreshold = (maximumOfBid
449 * this.discountingFactor)
450 / Math.pow(this.discountingFactor,
451 this.concedeToDiscountingFactor);
452 this.utilitythreshold = maximumOfBid
453 - (maximumOfBid - minThreshold) * Math.pow(
454 (timeline.getTime()
455 / this.concedeToDiscountingFactor),
456 alpha1);
457 } else {
458 this.utilitythreshold = (maximumOfBid
459 * this.discountingFactor)
460 / Math.pow(this.discountingFactor,
461 timeline.getTime());
462 }
463 minimumOfBid = this.utilitythreshold;
464 }
465
466 /*
467 * if(minimumOfBid < 0.9 && this.guessOpponentType == false){
468 * if(this.opponentBidHistory.getSize() <= 2){ this.opponentType =
469 * 1;//tough opponent alpha1 = 2; } else{ this.opponentType = 0;
470 * alpha1 = 4; } this.guessOpponentType = true;//we only guess the
471 * opponent type once here System.out.println("we guess the opponent
472 * type is "+this.opponentType); }
473 */
474
475 // choose from the opponent bid history first to reduce calculation
476 // time
477 Bid bestBidOfferedByOpponent = opponentBidHistory
478 .getBestBidInHistory();
479 if (utilitySpace.getUtility(
480 bestBidOfferedByOpponent) >= this.utilitythreshold
481 || utilitySpace.getUtility(
482 bestBidOfferedByOpponent) >= minimumOfBid) {
483 return bestBidOfferedByOpponent;
484 }
485 List<Bid> candidateBids = this.getBidsBetweenUtility(minimumOfBid,
486 maximumOfBid);
487
488 bidReturned = opponentBidHistory.ChooseBid(candidateBids,
489 this.utilitySpace.getDomain());
490 if (bidReturned == null) {
491 bidReturned = this.utilitySpace.getMaxUtilityBid();
492 }
493 } catch (Exception e) {
494 System.out
495 .println(e.getMessage() + "exception in method BidToOffer");
496 }
497 // System.out.println("the current threshold is " +
498 // this.utilitythreshold + " with the value of alpha1 is " + alpha1);
499 return bidReturned;
500 }
501
502 /*
503 * decide whether to accept the current offer or not
504 */
505 private boolean AcceptOpponentOffer(Bid opponentBid, Bid ownBid) {
506 double currentUtility = 0;
507 double nextRoundUtility = 0;
508 double maximumUtility = 0;
509 this.concedeToOpponent = false;
510 try {
511 currentUtility = this.utilitySpace.getUtility(opponentBid);
512 maximumUtility = this.MaximumUtility;// utilitySpace.getUtility(utilitySpace.getMaxUtilityBid());
513 } catch (Exception e) {
514 System.out.println(e.getMessage()
515 + "Exception in method AcceptOpponentOffer part 1");
516 }
517 try {
518 nextRoundUtility = this.utilitySpace.getUtility(ownBid);
519 } catch (Exception e) {
520 System.out.println(e.getMessage()
521 + "Exception in method AcceptOpponentOffer part 2");
522 }
523 // System.out.println(this.utilitythreshold +"at time "+
524 // timeline.getTime());
525 if (currentUtility >= this.utilitythreshold
526 || currentUtility >= nextRoundUtility) {
527 return true;
528 } else {
529 // if the current utility with discount is larger than the predicted
530 // maximum utility with discount
531 // then accept it.
532 double predictMaximumUtility = maximumUtility
533 * this.discountingFactor;
534 // double currentMaximumUtility =
535 // this.utilitySpace.getUtilityWithDiscount(opponentBidHistory.chooseBestFromHistory(utilitySpace),
536 // timeline);
537 double currentMaximumUtility = this.utilitySpace
538 .getUtilityWithDiscount(
539 opponentBidHistory.getBestBidInHistory(), timeline);
540 if (currentMaximumUtility > predictMaximumUtility
541 && timeline.getTime() > this.concedeToDiscountingFactor) {
542 try {
543 // if the current offer is approximately as good as the best
544 // one in the history, then accept it.
545 if (utilitySpace
546 .getUtility(opponentBid) >= utilitySpace.getUtility(
547 opponentBidHistory.getBestBidInHistory())
548 - 0.01) {
549 return true;
550 } else {
551 this.concedeToOpponent = true;
552 return false;
553 }
554 } catch (Exception e) {
555 System.out
556 .println("exception in Method AcceptOpponentOffer");
557 return true;
558 }
559 // retrieve the opponent's biding history and utilize it
560 } else if (currentMaximumUtility > this.utilitythreshold
561 * Math.pow(this.discountingFactor, timeline.getTime())) {
562 try {
563 // if the current offer is approximately as good as the best
564 // one in the history, then accept it.
565 if (utilitySpace
566 .getUtility(opponentBid) >= utilitySpace.getUtility(
567 opponentBidHistory.getBestBidInHistory())
568 - 0.01) {
569 return true;
570 } else {
571 System.out.println(
572 "test" + utilitySpace.getUtility(opponentBid)
573 + this.utilitythreshold);
574 this.concedeToOpponent = true;
575 return false;
576 }
577 } catch (Exception e) {
578 System.out
579 .println("exception in Method AcceptOpponentOffer");
580 return true;
581 }
582 } else {
583 return false;
584 }
585 }
586 }
587
588 /*
589 * decide whether or not to terminate now
590 */
591 private boolean TerminateCurrentNegotiation(Bid ownBid) {
592 double currentUtility = 0;
593 double nextRoundUtility = 0;
594 double maximumUtility = 0;
595 this.concedeToOpponent = false;
596 try {
597 currentUtility = this.reservationValue;
598 nextRoundUtility = this.utilitySpace.getUtility(ownBid);
599 maximumUtility = this.MaximumUtility;
600 } catch (Exception e) {
601 System.out.println(e.getMessage()
602 + "Exception in method TerminateCurrentNegotiation part 1");
603 }
604
605 if (currentUtility >= this.utilitythreshold
606 || currentUtility >= nextRoundUtility) {
607 return true;
608 } else {
609 // if the current reseravation utility with discount is larger than
610 // the predicted maximum utility with discount
611 // then terminate the negotiation.
612 double predictMaximumUtility = maximumUtility
613 * this.discountingFactor;
614 double currentMaximumUtility = this.utilitySpace
615 .getReservationValueWithDiscount(timeline);
616 // System.out.println("the current reserved value is "+
617 // this.reservationValue+" after discounting is
618 // "+currentMaximumUtility);
619 if (currentMaximumUtility > predictMaximumUtility
620 && timeline.getTime() > this.concedeToDiscountingFactor) {
621 return true;
622 } else {
623 return false;
624 }
625 }
626 }
627
628 /*
629 * estimate the number of rounds left before reaching the deadline @param
630 * opponent @return
631 */
632
633 private int estimateRoundLeft(boolean opponent) {
634 double round;
635 if (opponent == true) {
636 if (this.timeLeftBefore
637 - this.timeLeftAfter > this.maximumTimeOfOpponent) {
638 this.maximumTimeOfOpponent = this.timeLeftBefore
639 - this.timeLeftAfter;
640 }
641 } else {
642 if (this.timeLeftAfter
643 - this.timeLeftBefore > this.maximumTimeOfOwn) {
644 this.maximumTimeOfOwn = this.timeLeftAfter
645 - this.timeLeftBefore;
646 }
647 }
648 if (this.maximumTimeOfOpponent + this.maximumTimeOfOwn == 0) {
649 System.out.println("divided by zero exception");
650 }
651 round = (this.totalTime - timeline.getCurrentTime())
652 / (this.maximumTimeOfOpponent + this.maximumTimeOfOwn);
653 // System.out.println("current time is " + timeline.getElapsedSeconds()
654 // + "---" + round + "----" + this.maximumTimeOfOpponent);
655 return ((int) (round));
656 }
657
658 /*
659 * pre-processing to save the computational time each round
660 */
661 private void calculateBidsBetweenUtility() {
662 BidIterator myBidIterator = new BidIterator(
663 this.utilitySpace.getDomain());
664
665 try {
666 // double maximumUtility =
667 // utilitySpace.getUtility(utilitySpace.getMaxUtilityBid());
668 double maximumUtility = this.MaximumUtility;
669 double minUtility = this.minimumUtilityThreshold;
670 int maximumRounds = (int) ((maximumUtility - minUtility) / 0.01);
671 // initalization for each arraylist storing the bids between each
672 // range
673 for (int i = 0; i < maximumRounds; i++) {
674 ArrayList<Bid> BidList = new ArrayList<Bid>();
675 // BidList.add(this.bid_maximum_utility);
676 this.bidsBetweenUtility.add(BidList);
677 }
678 this.bidsBetweenUtility.get(maximumRounds - 1)
679 .add(this.bid_maximum_utility);
680 // note that here we may need to use some trick to reduce the
681 // computation cost (to be checked later);
682 // add those bids in each range into the corresponding arraylist
683 int limits = 0;
684 if (this.maximumOfBid < 20000) {
685 while (myBidIterator.hasNext()) {
686 Bid b = myBidIterator.next();
687 for (int i = 0; i < maximumRounds; i++) {
688 if (utilitySpace.getUtility(b) <= (i + 1) * 0.01
689 + minUtility
690 && utilitySpace.getUtility(b) >= i * 0.01
691 + minUtility) {
692 this.bidsBetweenUtility.get(i).add(b);
693 break;
694 }
695 }
696 // limits++;
697 }
698 } else {
699 while (limits <= 20000) {
700 Bid b = this.RandomSearchBid();
701 for (int i = 0; i < maximumRounds; i++) {
702 if (utilitySpace.getUtility(b) <= (i + 1) * 0.01
703 + minUtility
704 && utilitySpace.getUtility(b) >= i * 0.01
705 + minUtility) {
706 this.bidsBetweenUtility.get(i).add(b);
707 break;
708 }
709 }
710 limits++;
711 }
712 }
713 } catch (Exception e) {
714 System.out.println("Exception in calculateBidsBetweenUtility()");
715 e.printStackTrace();
716 }
717 }
718
719 private Bid RandomSearchBid() throws Exception {
720 HashMap<Integer, Value> values = new HashMap<Integer, Value>();
721 List<Issue> issues = utilitySpace.getDomain().getIssues();
722 Bid bid = null;
723
724 for (Issue lIssue : issues) {
725 switch (lIssue.getType()) {
726 case DISCRETE:
727 IssueDiscrete lIssueDiscrete = (IssueDiscrete) lIssue;
728 int optionIndex = random
729 .nextInt(lIssueDiscrete.getNumberOfValues());
730
731 values.put(lIssue.getNumber(),
732 lIssueDiscrete.getValue(optionIndex));
733 break;
734 case REAL:
735 IssueReal lIssueReal = (IssueReal) lIssue;
736 int optionInd = random.nextInt(
737 lIssueReal.getNumberOfDiscretizationSteps() - 1);
738 values.put(lIssueReal.getNumber(),
739 new ValueReal(lIssueReal.getLowerBound() + (lIssueReal
740 .getUpperBound() - lIssueReal.getLowerBound())
741 * (optionInd) / (lIssueReal
742 .getNumberOfDiscretizationSteps())));
743 break;
744 case INTEGER:
745 IssueInteger lIssueInteger = (IssueInteger) lIssue;
746 int optionIndex2 = lIssueInteger.getLowerBound()
747 + random.nextInt(lIssueInteger.getUpperBound()
748 - lIssueInteger.getLowerBound());
749 values.put(lIssueInteger.getNumber(),
750 new ValueInteger(optionIndex2));
751 break;
752 default:
753 throw new Exception(
754 "issue type " + lIssue.getType() + " not supported");
755 }
756 }
757 bid = new Bid(utilitySpace.getDomain(), values);
758 return bid;
759 }
760
761 /*
762 * Get all the bids within a given utility range.
763 */
764 private List<Bid> getBidsBetweenUtility(double lowerBound,
765 double upperBound) {
766 List<Bid> bidsInRange = new ArrayList<Bid>();
767 try {
768 int range = (int) ((upperBound - this.minimumUtilityThreshold)
769 / 0.01);
770 int initial = (int) ((lowerBound - this.minimumUtilityThreshold)
771 / 0.01);
772 // System.out.println(range+"---"+initial);
773 for (int i = initial; i < range; i++) {
774 bidsInRange.addAll(this.bidsBetweenUtility.get(i));
775 }
776 if (bidsInRange.isEmpty()) {
777 bidsInRange.add(this.bid_maximum_utility);
778 }
779 } catch (Exception e) {
780 System.out.println("Exception in getBidsBetweenUtility");
781 e.printStackTrace();
782 }
783 return bidsInRange;
784 }
785
786 /*
787 * determine the lowest bound of our utility threshold based on the
788 * discounting factor we think that the minimum utility threshold should not
789 * be related with the discounting degree.
790 */
791 private void chooseUtilityThreshold() {
792 double discountingFactor = this.discountingFactor;
793 if (discountingFactor >= 0.9) {
794 this.minimumUtilityThreshold = 0;// this.MaximumUtility - 0.09;
795 } else {
796 // this.minimumUtilityThreshold = 0.85;
797 this.minimumUtilityThreshold = 0;// this.MaximumUtility - 0.09;
798 }
799 }
800
801 /*
802 * determine concede-to-time degree based on the discounting factor.
803 */
804
805 private void chooseConcedeToDiscountingDegree() {
806 double alpha = 0;
807 double beta = 1.5;// 1.3;//this value controls the rate at which the
808 // agent concedes to the discouting factor.
809 // the larger beta is, the more the agent makes concesions.
810 // if (utilitySpace.getDomain().getNumberOfPossibleBids() > 100) {
811 /*
812 * if (this.maximumOfBid > 100) { beta = 2;//1.3; } else { beta = 1.5; }
813 */
814 // the vaule of beta depends on the discounting factor (trade-off
815 // between concede-to-time degree and discouting factor)
816 if (this.discountingFactor > 0.9) {
817 beta = 1.9;
818 } else if (this.discountingFactor > 0.75) {
819 beta = 1.85;
820 } else if (this.discountingFactor > 0.5) {
821 beta = 1.45;
822 } else {
823 beta = 1.15;
824 }
825 alpha = Math.pow(this.discountingFactor, beta);
826 this.concedeToDiscountingFactor = this.minConcedeToDiscountingFactor
827 + (1 - this.minConcedeToDiscountingFactor) * alpha;
828 this.concedeToDiscountingFactor_original = this.concedeToDiscountingFactor;
829 System.out.println("concedeToDiscountingFactor is "
830 + this.concedeToDiscountingFactor + "current time is "
831 + timeline.getTime());
832 }
833
834 /*
835 * update the concede-to-time degree based on the predicted toughness degree
836 * of the opponent
837 */
838
839 private void updateConcedeDegree() {
840 double gama = 10;
841 double weight = 0.1;
842 double opponnetToughnessDegree = this.opponentBidHistory
843 .getConcessionDegree();
844 // this.concedeToDiscountingFactor =
845 // this.concedeToDiscountingFactor_original * (1 +
846 // opponnetToughnessDegree);
847 this.concedeToDiscountingFactor = this.concedeToDiscountingFactor_original
848 + weight * (1 - this.concedeToDiscountingFactor_original)
849 * Math.pow(opponnetToughnessDegree, gama);
850 if (this.concedeToDiscountingFactor >= 1) {
851 this.concedeToDiscountingFactor = 1;
852 }
853 // System.out.println("concedeToDiscountingFactor is " +
854 // this.concedeToDiscountingFactor + "current time is " +
855 // timeline.getTime() + "original concedetodiscoutingfactor is " +
856 // this.concedeToDiscountingFactor_original);
857 }
858
859 @Override
860 public String getDescription() {
861 return "ANAC2015";
862 }
863
864}
Note: See TracBrowser for help on using the repository browser.