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