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