source: src/main/java/agents/anac/y2010/Nozomi/Nozomi.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: 34.0 KB
Line 
1package agents.anac.y2010.Nozomi;
2
3import java.util.HashMap;
4import java.util.List;
5import java.util.Random;
6
7import genius.core.Agent;
8import genius.core.Bid;
9import genius.core.SupportedNegotiationSetting;
10import genius.core.actions.Accept;
11import genius.core.actions.Action;
12import genius.core.actions.ActionWithBid;
13import genius.core.actions.Offer;
14import genius.core.issue.ISSUETYPE;
15import genius.core.issue.Issue;
16import genius.core.issue.IssueDiscrete;
17import genius.core.issue.IssueInteger;
18import genius.core.issue.IssueReal;
19import genius.core.issue.Value;
20import genius.core.issue.ValueDiscrete;
21import genius.core.issue.ValueInteger;
22import genius.core.issue.ValueReal;
23import genius.core.utility.AdditiveUtilitySpace;
24import genius.core.utility.Evaluator;
25import genius.core.utility.EvaluatorDiscrete;
26
27/**
28 * ANAC2010 competitor Nozomi.
29 */
30public class Nozomi extends Agent {
31 private Bid maxUtilityBid = null;
32 private double maxUtility = 0.0;
33 private Bid prevBid = null;
34 private Bid restoreBid = null;
35 private double minGap = 0.0;
36 private Action actionOfPartner = null;
37 private Bid prevPartnerBid = null;
38 private Bid maxUtilityPartnerBid = null;
39 private double maxUtilityOfPartnerBid = 0.0;
40 private double maxCompromiseUtility = 1.0;
41 private boolean compromise = false;
42 private boolean updateMaxPartnerUtility = false;
43 private int continuousCompromiseBid = 0;
44 private int continuousPartnerCompromiseBid = 0;
45 private int continuousKeep = 0;
46 private int measureT = 1;
47 private int bidNumber = 0;
48 private double prevAverageUtility = 0.0;
49 private double averageUtility = 0.0;
50 private double averagePartnerUtility = 0.0;
51 private double prevAveragePartnerUtility = 0.0;
52 private static double COMPROMISE_PROBABILITY = 0.70;
53 private static double KEEP_PROBABILITY = 0.15;
54 private final boolean TEST_EQUIVALENCE = false;
55 private Random random100;
56 private Random random200;
57
58 private static enum BidType {
59 COMPROMISE, KEEP, APPROACH, RESTORE, RANDOM
60 };
61
62 /**
63 * init is called when a next session starts with the same opponent.
64 */
65
66 @Override
67 public void init() {
68 try {
69 maxUtilityBid = utilitySpace.getMaxUtilityBid();
70 maxUtility = utilitySpace.getUtility(maxUtilityBid);
71 prevAverageUtility = maxUtility;
72 maxCompromiseUtility = maxUtility * 0.95;
73 restoreBid = maxUtilityBid;
74 minGap = utilitySpace.getDomain().getIssues().size();
75
76 if (TEST_EQUIVALENCE) {
77 random100 = new Random(100);
78 random200 = new Random(200);
79 } else {
80 random100 = new Random();
81 random200 = new Random();
82 }
83 } catch (Exception e) {
84 e.printStackTrace();
85 }
86 }
87
88 @Override
89 public String getVersion() {
90 return "1.0";
91 }
92
93 @Override
94 public String getName() {
95 return "Nozomi";
96 }
97
98 @Override
99 public void ReceiveMessage(Action opponentAction) {
100 actionOfPartner = opponentAction;
101 }
102
103 @Override
104 public Action chooseAction() {
105 Action action = null;
106
107 try {
108 if (actionOfPartner == null) {
109 action = new Offer(getAgentID(), maxUtilityBid);
110 prevBid = maxUtilityBid;
111 } else if (actionOfPartner instanceof Offer) {
112 Bid partnerBid = ((Offer) actionOfPartner).getBid();
113
114 if (isAccept(partnerBid)) {
115 action = new Accept(getAgentID(), partnerBid);
116 } else {
117 action = chooseBidAction(partnerBid);
118 }
119 prevPartnerBid = partnerBid;
120 }
121 } catch (Exception e) {
122 action = new Accept(getAgentID(),
123 ((ActionWithBid) actionOfPartner).getBid());
124 }
125 return action;
126 }
127
128 private Action chooseBidAction(Bid partnerBid) {
129 Action action = null;
130
131 try {
132 if (prevPartnerBid == null) {
133 maxUtilityPartnerBid = partnerBid;
134 maxUtilityOfPartnerBid = utilitySpace.getUtility(partnerBid);
135 action = new Offer(getAgentID(), maxUtilityBid);
136
137 prevBid = maxUtilityBid;
138 } else {
139 bidNumber++;
140 double prevPartnerUtility = utilitySpace
141 .getUtility(prevPartnerBid);
142 double partnerUtility = utilitySpace.getUtility(partnerBid);
143
144 averagePartnerUtility += partnerUtility;
145 if (partnerUtility < prevPartnerUtility) {
146 if (continuousPartnerCompromiseBid < 0)
147 continuousPartnerCompromiseBid = 0;
148 continuousPartnerCompromiseBid++;
149 } else if (partnerUtility > prevPartnerUtility) {
150 if (continuousPartnerCompromiseBid > 0)
151 continuousPartnerCompromiseBid = 0;
152 continuousPartnerCompromiseBid--;
153 } else {
154 continuousPartnerCompromiseBid = 0;
155 }
156
157 double time = timeline.getTime() * 100;
158
159 if (maxUtilityOfPartnerBid > maxCompromiseUtility) {
160 maxCompromiseUtility = maxUtilityOfPartnerBid;
161 }
162
163 if (time > 90 && maxCompromiseUtility
164 - maxUtilityOfPartnerBid < 0.1) {
165 maxCompromiseUtility = (maxCompromiseUtility * 7.0
166 + maxUtilityOfPartnerBid * 3.0) / 10.0;
167 }
168
169 if (maxCompromiseUtility > maxUtility * 0.95) {
170 maxCompromiseUtility = maxUtility * 0.95;
171 }
172
173 Bid nextBid = prevBid;
174 BidType bidType = chooseBidType(partnerBid);
175
176 switch (bidType) {
177 case RESTORE:
178 nextBid = restoreBid;
179 break;
180 case APPROACH:
181 nextBid = getApproachBid(partnerBid);
182
183 if (utilitySpace.getUtility(nextBid) < maxCompromiseUtility
184 || utilitySpace
185 .getUtility(nextBid) > maxCompromiseUtility
186 * 105 / 95) {
187 nextBid = getBetweenBid(nextBid, partnerBid,
188 maxCompromiseUtility,
189 maxCompromiseUtility * 105 / 95);
190 }
191 break;
192 case COMPROMISE:
193 nextBid = getCompromiseBid(partnerBid);
194
195 if (utilitySpace
196 .getUtility(nextBid) < maxCompromiseUtility) {
197 nextBid = getBetweenBid(nextBid, partnerBid,
198 maxCompromiseUtility,
199 maxCompromiseUtility * 105 / 95);
200 }
201
202 if (continuousCompromiseBid < 0)
203 continuousCompromiseBid = 0;
204 continuousCompromiseBid++;
205 break;
206 case KEEP:
207 nextBid = prevBid;
208 continuousCompromiseBid /= 2;
209 break;
210 }
211
212 if (utilitySpace.getUtility(
213 nextBid) <= utilitySpace.getUtility(prevBid) / 2.0) {
214 nextBid = getApproachBid(partnerBid);
215
216 if (utilitySpace.getUtility(nextBid) < maxCompromiseUtility
217 || utilitySpace
218 .getUtility(nextBid) > maxCompromiseUtility
219 * 105 / 95) {
220 nextBid = getBetweenBid(nextBid, partnerBid,
221 maxCompromiseUtility,
222 maxCompromiseUtility * 105 / 95);
223 }
224 }
225
226 if (((utilitySpace.getUtility(nextBid) < maxCompromiseUtility
227 || utilitySpace.getUtility(
228 nextBid) > maxCompromiseUtility * 105 / 95)
229 && continuousKeep < 20)
230 || utilitySpace.getUtility(
231 nextBid) <= utilitySpace.getUtility(prevBid)
232 / 2.0
233 || utilitySpace
234 .getUtility(nextBid) < maxUtilityOfPartnerBid) {
235
236 nextBid = restoreBid;
237 }
238
239 averageUtility += utilitySpace.getUtility(nextBid);
240
241 if (continuousKeep <= 0) {
242 updateRestoreBid(nextBid);
243 }
244
245 if (time > measureT * 3.0) {
246 checkCompromise(time);
247 averageUtility = 0.0;
248 averagePartnerUtility = 0.0;
249 bidNumber = 1;
250 measureT++;
251 }
252
253 if (utilitySpace.getUtility(nextBid) == utilitySpace
254 .getUtility(prevBid)) {
255 continuousKeep++;
256 } else {
257 continuousKeep = 0;
258 }
259
260 if (continuousKeep > 30 && time > 90.0) {
261 maxCompromiseUtility *= 0.99;
262 continuousKeep = 0;
263 }
264
265 prevBid = nextBid;
266 action = new Offer(getAgentID(), nextBid);
267 }
268 } catch (Exception e) {
269 action = new Accept(getAgentID(),
270 ((ActionWithBid) actionOfPartner).getBid());
271 }
272 return action;
273 }
274
275 private void checkCompromise(double time) {
276 averageUtility /= bidNumber;
277 averagePartnerUtility /= bidNumber;
278
279 double diff = prevAverageUtility - averageUtility;
280 double partnerDiff = averagePartnerUtility - prevAveragePartnerUtility;
281
282 if (compromise) {
283 double gap = Math.abs(averageUtility - averagePartnerUtility);
284 if (partnerDiff < diff * 0.90
285 || gap > Math.pow(1.0 - time / 100, 2.0) * 0.90) {
286 double p1 = maxCompromiseUtility, p2 = maxCompromiseUtility;
287 for (int attenuation = 95; attenuation <= 100; attenuation++) {
288 if (maxCompromiseUtility * attenuation
289 / 100 > maxUtilityOfPartnerBid) {
290 p1 = maxCompromiseUtility * attenuation / 100;
291 break;
292 }
293 }
294
295 for (int attenuation = 10; attenuation < 1000; attenuation++) {
296 if (maxCompromiseUtility
297 - gap / attenuation > maxUtilityOfPartnerBid) {
298 p2 = maxCompromiseUtility - gap / attenuation;
299 break;
300 }
301 }
302
303 maxCompromiseUtility = (p1 + p2) / 2;
304
305 prevAverageUtility = averageUtility;
306 compromise = false;
307 }
308 } else {
309 if (partnerDiff > diff * 0.90
310 || (time > 50 && updateMaxPartnerUtility)) {
311 prevAveragePartnerUtility = averagePartnerUtility;
312 compromise = true;
313 }
314 }
315 updateMaxPartnerUtility = false;
316 }
317
318 private BidType chooseBidType(Bid partnerBid) {
319 BidType bidType = null;
320
321 try {
322 double time = timeline.getTime();
323
324 double prevUtility = utilitySpace.getUtility(prevBid);
325 double partnerUtility = utilitySpace.getUtility(partnerBid);
326 double gap = Math.abs(prevUtility - partnerUtility);
327
328 if (gap < 0.05)
329 return BidType.APPROACH;
330
331 gap = Math.abs(prevAverageUtility - prevAverageUtility);
332 if (gap < 0.10 && time > 0.80)
333 return BidType.APPROACH;
334
335 if (random100.nextInt(20) <= 0)
336 return BidType.RESTORE;
337
338 int approachBorder = 5;
339 if (time > 0.9) {
340 approachBorder = (int) Math.round((time * 100) / 10);
341 }
342 if (random100.nextInt(20) <= approachBorder)
343 return BidType.RESTORE;
344
345 if (prevUtility > maxCompromiseUtility * 105 / 95) {
346 return BidType.COMPROMISE;
347 }
348 if (continuousKeep > 20 && time > 0.60
349 && random100.nextDouble() > 0.60)
350 return BidType.APPROACH;
351
352 } catch (Exception e) {
353 bidType = BidType.RESTORE;
354 }
355
356 double rnd = random100.nextDouble();
357 double compromiseProbability = getCompromiseProbability();
358
359 if (rnd < compromiseProbability) {
360 bidType = BidType.COMPROMISE;
361 } else if (rnd < getKeepProbability(compromiseProbability)
362 + compromiseProbability) {
363 bidType = BidType.KEEP;
364 }
365
366 if (bidType == null)
367 bidType = bidType.RESTORE;
368 return bidType;
369 }
370
371 private double getCompromiseProbability() {
372 double compromiseProbabilty = 0.0;
373
374 try {
375 double prevUtility = utilitySpace.getUtility(prevBid);
376 double prevUtilityOfPartnerBid = utilitySpace
377 .getUtility(prevPartnerBid);
378 // Below Values are less and less, more and more compromised.
379 double compromiseDegree = prevUtility / maxUtility;
380
381 double compromisePartnerDegree = 1.0
382 - prevUtilityOfPartnerBid / maxUtility;
383
384 double continuous = ((double) continuousCompromiseBid
385 + (double) Math.abs(continuousPartnerCompromiseBid) + 0.001)
386 / 2.0;
387 double ratioUtilityToMaxUtility = prevUtility / (maxUtility * 0.9);
388
389 compromiseProbabilty = (compromiseDegree + compromisePartnerDegree)
390 / 2.0;
391
392 compromiseProbabilty /= 1.0 + continuous / 8.0;
393 compromiseProbabilty *= ratioUtilityToMaxUtility;
394 } catch (Exception e) {
395 compromiseProbabilty = COMPROMISE_PROBABILITY;
396 }
397
398 return compromiseProbabilty;
399 }
400
401 private double getKeepProbability(double compromiseProbability) {
402 double keepProbability = 1.0 - compromiseProbability;
403
404 try {
405 double time = timeline.getTime();
406 double prevUtility = utilitySpace.getUtility(prevBid);
407 double prevUtilityOfPartnerBid = utilitySpace
408 .getUtility(prevPartnerBid);
409 double ratioUtilityToMaxUtility = prevUtility / (maxUtility * 0.8);
410
411 if (prevUtility > prevUtilityOfPartnerBid) {
412 keepProbability *= (prevUtility - prevUtilityOfPartnerBid)
413 / maxUtility;
414 keepProbability *= time;
415 keepProbability *= 1.0
416 + Math.abs(continuousCompromiseBid) / 4.0;
417 keepProbability *= ratioUtilityToMaxUtility;
418 } else {
419 keepProbability = 0.0;
420 }
421 } catch (Exception e) {
422 keepProbability = KEEP_PROBABILITY;
423 }
424
425 return keepProbability;
426 }
427
428 private Bid getCompromiseBid(Bid partnerBid) {
429 Bid compromiseBid = prevBid;
430 try {
431
432 double compromiseUtility = 0.0;
433 double prevUtility = utilitySpace.getUtility(prevBid);
434 double basicUtility = prevUtility;
435 double gap = Math
436 .abs(prevUtility - utilitySpace.getUtility(partnerBid));
437 HashMap<Integer, Value> values = new HashMap<Integer, Value>();
438 List<Issue> issues = utilitySpace.getDomain().getIssues();
439
440 for (Issue issue : issues) {
441 values.put(issue.getNumber(),
442 prevBid.getValue(issue.getNumber()));
443 }
444
445 Integer changeIssueID = -1;
446 for (Issue compromiseIssue : issues) {
447 Integer compromiseIssueID = compromiseIssue.getNumber();
448
449 if ((!prevPartnerBid.getValue(compromiseIssueID)
450 .equals(partnerBid.getValue(compromiseIssueID))
451 && gap > 0.05 && continuousKeep < 20)
452 || prevBid.getValue(compromiseIssueID)
453 .equals(partnerBid.getValue(compromiseIssueID))
454 || compromiseIssueID == changeIssueID) {
455 continue;
456 }
457
458 HashMap<Integer, Value> candidateValues = new HashMap<Integer, Value>(
459 values);
460 candidateValues.remove(compromiseIssueID);
461 candidateValues.put(compromiseIssueID,
462 getCompromiseValue(compromiseIssue,
463 prevBid.getValue(compromiseIssueID),
464 partnerBid.getValue(compromiseIssueID)));
465 Bid candidateBid = new Bid(utilitySpace.getDomain(),
466 candidateValues);
467 double candidateUtility = utilitySpace.getUtility(candidateBid);
468
469 if (candidateUtility > compromiseUtility
470 && candidateUtility < basicUtility) {
471
472 compromiseUtility = candidateUtility;
473 compromiseBid = candidateBid;
474 changeIssueID = compromiseIssueID;
475 }
476 }
477
478 } catch (Exception e) {
479 e.printStackTrace();
480 compromiseBid = restoreBid; // best guess if things go wrong.
481 }
482 try {
483 } catch (Exception e) {
484 e.printStackTrace();
485 }
486 return compromiseBid;
487 }
488
489 private Value getCompromiseValue(Issue issue, Value val, Value partnerVal) {
490 Value compromiseVal = null;
491 Evaluator eval = ((AdditiveUtilitySpace) utilitySpace)
492 .getEvaluator(issue.getNumber());
493
494 switch (issue.getType()) {
495 case DISCRETE:
496 EvaluatorDiscrete evalDiscrete = (EvaluatorDiscrete) eval;
497 compromiseVal = val;
498 Integer evaluation = evalDiscrete.getValue((ValueDiscrete) val);
499 IssueDiscrete issueDiscrete = (IssueDiscrete) issue;
500 Integer compromiseEvaluation = 0;
501 for (int i = 0; i < issueDiscrete.getNumberOfValues(); i++) {
502 ValueDiscrete candidateVal = issueDiscrete.getValue(i);
503 Integer candidateEvaluation = evalDiscrete
504 .getValue(candidateVal);
505 if (candidateEvaluation >= compromiseEvaluation
506 && candidateEvaluation < evaluation) {
507 compromiseVal = candidateVal;
508 compromiseEvaluation = candidateEvaluation;
509 }
510 }
511 break;
512 case INTEGER:
513 ValueInteger valInt = (ValueInteger) val;
514 int compromiseInt = valInt.getValue();
515 ValueInteger partnerValInt = (ValueInteger) partnerVal;
516 if (compromiseInt > partnerValInt.getValue()) {
517 compromiseInt--;
518 } else {
519 compromiseInt++;
520 }
521 compromiseVal = new ValueInteger(compromiseInt);
522 break;
523 case REAL:
524 ValueReal valReal = (ValueReal) val;
525 double compromiseReal = valReal.getValue();
526 ValueReal partnerValReal = (ValueReal) partnerVal;
527 compromiseReal += new Random().nextDouble()
528 * (partnerValReal.getValue() - compromiseReal) / 10;
529 compromiseVal = new ValueReal(compromiseReal);
530 break;
531 default:
532 compromiseVal = val;
533 break;
534 }
535 return compromiseVal;
536 }
537
538 private Bid getBetweenBid(Bid basicBid, Bid partnerBid, double minUtility,
539 double maxUtility) {
540 Bid betweenBid = basicBid;
541 try {
542 List<Issue> issues = utilitySpace.getDomain().getIssues();
543 HashMap<Integer, Value> values = new HashMap<Integer, Value>();
544
545 for (Issue issue : issues) {
546 values.put(issue.getNumber(),
547 basicBid.getValue(issue.getNumber()));
548 }
549
550 double utility = utilitySpace.getUtility(basicBid);
551 for (int i = 0; i < 1000; i++) {
552 Issue issue = issues.get(random200.nextInt(issues.size()));
553 int issueID = issue.getNumber();
554
555 if (prevBid.getValue(issueID)
556 .equals(partnerBid.getValue(issueID))) {
557 continue;
558 }
559
560 Value value = values.get(issueID);
561 values.remove(issueID);
562 if (utility > maxUtility) {
563 values.put(issueID, getLowerValue(issue, value, values));
564 } else {
565 values.put(issueID, getHigherValue(issue, value, values));
566 }
567
568 Bid candidateBid = new Bid(utilitySpace.getDomain(), values);
569 utility = utilitySpace.getUtility(candidateBid);
570 if (utility > minUtility && utility < maxUtility) {
571 betweenBid = candidateBid;
572 break;
573 }
574 }
575 } catch (Exception e) {
576 betweenBid = restoreBid;
577 }
578 return betweenBid;
579 }
580
581 private Value getHigherValue(Issue issue, Value value,
582 HashMap<Integer, Value> values) {
583 Value higher = null;
584 Evaluator eval = ((AdditiveUtilitySpace) utilitySpace)
585 .getEvaluator(issue.getNumber());
586
587 switch (issue.getType()) {
588 case DISCRETE:
589 EvaluatorDiscrete evalDiscrete = (EvaluatorDiscrete) eval;
590
591 Integer evaluation = evalDiscrete.getValue((ValueDiscrete) value);
592 IssueDiscrete issueDiscrete = (IssueDiscrete) issue;
593 higher = evalDiscrete.getMaxValue();
594 Integer highEvaluation = evalDiscrete
595 .getValue((ValueDiscrete) higher);
596 for (int i = 0; i < issueDiscrete.getNumberOfValues(); i++) {
597 ValueDiscrete candidateVal = issueDiscrete.getValue(i);
598 Integer candidateEvaluation = evalDiscrete
599 .getValue(candidateVal);
600 if (candidateEvaluation < highEvaluation
601 && candidateEvaluation > evaluation) {
602 higher = candidateVal;
603 highEvaluation = candidateEvaluation;
604 }
605 }
606 break;
607 case INTEGER:
608 IssueInteger issueInt = (IssueInteger) issue;
609 ValueInteger valInt = (ValueInteger) value;
610 try {
611 Bid bid = new Bid(utilitySpace.getDomain(), values);
612 values.remove(issueInt.getNumber());
613 values.put(issueInt.getNumber(),
614 new ValueInteger(valInt.getValue() - 1));
615 Bid candidateBid = new Bid(utilitySpace.getDomain(), values);
616 if (utilitySpace.getUtility(candidateBid) > utilitySpace
617 .getUtility(bid)) {
618 higher = new ValueInteger(valInt.getValue() - 1);
619 } else {
620 higher = new ValueInteger(valInt.getValue() + 1);
621 }
622 } catch (Exception e) {
623 higher = valInt;
624 }
625 break;
626 case REAL:
627 IssueReal issueReal = (IssueReal) issue;
628 ValueReal valReal = (ValueReal) value;
629 try {
630 Bid bid = new Bid(utilitySpace.getDomain(), values);
631 values.remove(issueReal.getNumber());
632 values.put(issueReal.getNumber(), new ValueReal(valReal
633 .getValue()
634 - (valReal.getValue() - issueReal.getLowerBound())
635 / 10));
636 Bid candidateBid = new Bid(utilitySpace.getDomain(), values);
637 if (utilitySpace.getUtility(candidateBid) > utilitySpace
638 .getUtility(bid)) {
639 higher = new ValueReal(
640 valReal.getValue()
641 - new Random().nextDouble()
642 * (valReal.getValue()
643 - issueReal.getLowerBound())
644 / 10);
645 } else {
646 higher = new ValueReal(valReal.getValue() + new Random()
647 .nextDouble()
648 * (issueReal.getUpperBound() - valReal.getValue())
649 / 10);
650 }
651 } catch (Exception e) {
652 higher = valReal;
653 }
654 break;
655 default:
656 higher = value;
657 break;
658 }
659
660 return higher;
661 }
662
663 private Value getLowerValue(Issue issue, Value value,
664 HashMap<Integer, Value> values) {
665 Value lower = null;
666 Evaluator eval = ((AdditiveUtilitySpace) utilitySpace)
667 .getEvaluator(issue.getNumber());
668
669 switch (issue.getType()) {
670 case DISCRETE:
671 EvaluatorDiscrete evalDiscrete = (EvaluatorDiscrete) eval;
672
673 Integer evaluation = evalDiscrete.getValue((ValueDiscrete) value);
674 IssueDiscrete issueDiscrete = (IssueDiscrete) issue;
675 lower = evalDiscrete.getMinValue();
676 Integer lowEvaluation = evalDiscrete
677 .getValue((ValueDiscrete) lower);
678 for (int i = 0; i < issueDiscrete.getNumberOfValues(); i++) {
679 ValueDiscrete candidateVal = issueDiscrete.getValue(i);
680 Integer candidateEvaluation = evalDiscrete
681 .getValue(candidateVal);
682 if (candidateEvaluation > lowEvaluation
683 && candidateEvaluation < evaluation) {
684 lower = candidateVal;
685 lowEvaluation = candidateEvaluation;
686 }
687 }
688 break;
689 case INTEGER:
690 IssueInteger issueInt = (IssueInteger) issue;
691 ValueInteger valInt = (ValueInteger) value;
692 try {
693 Bid bid = new Bid(utilitySpace.getDomain(), values);
694 values.remove(issueInt.getNumber());
695 values.put(issueInt.getNumber(),
696 new ValueInteger(valInt.getValue() - 1));
697 Bid candidateBid = new Bid(utilitySpace.getDomain(), values);
698 if (utilitySpace.getUtility(candidateBid) < utilitySpace
699 .getUtility(bid)) {
700 lower = new ValueInteger(valInt.getValue() - 1);
701 } else {
702 lower = new ValueInteger(valInt.getValue() + 1);
703 }
704 } catch (Exception e) {
705 lower = valInt;
706 }
707 break;
708 case REAL:
709 IssueReal issueReal = (IssueReal) issue;
710 ValueReal valReal = (ValueReal) value;
711 try {
712 Bid bid = new Bid(utilitySpace.getDomain(), values);
713 values.remove(issueReal.getNumber());
714 values.put(issueReal.getNumber(), new ValueReal(valReal
715 .getValue()
716 - (valReal.getValue() - issueReal.getLowerBound())
717 / 10));
718 Bid candidateBid = new Bid(utilitySpace.getDomain(), values);
719 if (utilitySpace.getUtility(candidateBid) < utilitySpace
720 .getUtility(bid)) {
721 lower = new ValueReal(
722 valReal.getValue()
723 - new Random().nextDouble()
724 * (valReal.getValue()
725 - issueReal.getLowerBound())
726 / 10);
727 } else {
728 lower = new ValueReal(valReal.getValue() + new Random()
729 .nextDouble()
730 * (issueReal.getUpperBound() - valReal.getValue())
731 / 10);
732 }
733 } catch (Exception e) {
734 lower = valReal;
735 }
736 break;
737 default:
738 lower = value;
739 break;
740 }
741 return lower;
742 }
743
744 private Bid getApproachBid(Bid partnerBid) {
745 Bid approachBid = prevBid;
746 try {
747 HashMap<Integer, Value> values = new HashMap<Integer, Value>();
748 HashMap<Integer, Value> approachValues = new HashMap<Integer, Value>();
749 List<Issue> issues = utilitySpace.getDomain().getIssues();
750
751 for (Issue issue : issues) {
752 values.put(issue.getNumber(),
753 prevBid.getValue(issue.getNumber()));
754 }
755 approachValues = values;
756
757 double candidateUtility = 0.0;
758 for (Issue issue : issues) {
759 int issueID = issue.getNumber();
760
761 if (issue.getType() == ISSUETYPE.REAL) {
762 IssueReal issueReal = (IssueReal) issue;
763 ValueReal valueReal = (ValueReal) prevBid.getValue(issueID);
764 ValueReal partnerValueReal = (ValueReal) partnerBid
765 .getValue(issueID);
766 ValueReal prevPartnerValueReal = (ValueReal) prevPartnerBid
767 .getValue(issueID);
768 double gap = Math.abs(
769 valueReal.getValue() - partnerValueReal.getValue());
770 double gapPartnerValue = Math
771 .abs(partnerValueReal.getValue()
772 - prevPartnerValueReal.getValue());
773 if (gap < (issueReal.getUpperBound()
774 - issueReal.getLowerBound()) / 100
775 || !(gapPartnerValue < (issueReal.getUpperBound()
776 - issueReal.getLowerBound()) / 100)) {
777 continue;
778 }
779 }
780
781 if (prevBid.getValue(issueID)
782 .equals(partnerBid.getValue(issueID))) {
783 continue;
784 }
785
786 HashMap<Integer, Value> candidateValues = new HashMap<Integer, Value>(
787 values);
788
789 candidateValues.remove(issueID);
790 candidateValues.put(issueID,
791 getApproachValue(issue, prevBid.getValue(issueID),
792 partnerBid.getValue(issueID)));
793 Bid candidateBid = new Bid(utilitySpace.getDomain(),
794 candidateValues);
795 if (utilitySpace.getUtility(candidateBid) > candidateUtility) {
796 candidateUtility = utilitySpace.getUtility(candidateBid);
797 approachBid = candidateBid;
798 approachValues = candidateValues;
799 }
800 }
801
802 while (true) {
803 candidateUtility = 0.0;
804 HashMap<Integer, Value> candidateValues = new HashMap<Integer, Value>(
805 approachValues);
806 for (Issue issue : issues) {
807 HashMap<Integer, Value> tempValues = new HashMap<Integer, Value>(
808 approachValues);
809
810 int issueID = issue.getNumber();
811
812 if (issue.getType() == ISSUETYPE.REAL) {
813 IssueReal issueReal = (IssueReal) issue;
814 ValueReal valueReal = (ValueReal) prevBid
815 .getValue(issueID);
816 ValueReal partnerValueReal = (ValueReal) partnerBid
817 .getValue(issueID);
818 double gap = Math.abs(valueReal.getValue()
819 - partnerValueReal.getValue());
820 if (gap < (issueReal.getUpperBound()
821 - issueReal.getLowerBound()) / 100) {
822 continue;
823 }
824 }
825
826 if (prevBid.getValue(issueID)
827 .equals(partnerBid.getValue(issueID))) {
828 continue;
829 }
830
831 tempValues.remove(issueID);
832 tempValues.put(issueID,
833 getApproachValue(issue, prevBid.getValue(issueID),
834 partnerBid.getValue(issueID)));
835
836 Bid tempBid = new Bid(utilitySpace.getDomain(), tempValues);
837 if (utilitySpace.getUtility(tempBid) > candidateUtility) {
838 candidateValues = tempValues;
839 candidateUtility = utilitySpace.getUtility(tempBid);
840 }
841 }
842 if (candidateUtility >= utilitySpace.getUtility(approachBid)
843 && !candidateValues.equals(approachValues)) {
844 Bid candidateBid = new Bid(utilitySpace.getDomain(),
845 candidateValues);
846 approachBid = candidateBid;
847 approachValues = candidateValues;
848 } else {
849 break;
850 }
851 }
852 } catch (Exception e) {
853 approachBid = restoreBid; // best guess if things go wrong.
854 }
855 return approachBid;
856 }
857
858 private Value getApproachValue(Issue issue, Value myVal, Value partnerVal) {
859 Value approachVal = null;
860
861 switch (issue.getType()) {
862 case DISCRETE:
863 IssueDiscrete issueDiscrete = (IssueDiscrete) issue;
864
865 boolean checkMyVal = false;
866 boolean checkPartnerVal = false;
867 for (Value value : issueDiscrete.getValues()) {
868 if (checkMyVal) {
869 approachVal = value;
870 break;
871 }
872
873 if (myVal.equals(value)) {
874 if (checkPartnerVal) {
875 break;
876 } else {
877 checkMyVal = true;
878 }
879 }
880
881 if (partnerVal.equals(value)) {
882 if (checkMyVal) {
883 approachVal = value;
884 break;
885 } else {
886 checkPartnerVal = true;
887 }
888 }
889
890 approachVal = value;
891 }
892 break;
893 case INTEGER:
894 ValueInteger valInt = (ValueInteger) myVal;
895 int approachInt = valInt.getValue();
896 ValueInteger partnerValInt = (ValueInteger) partnerVal;
897 if (approachInt > partnerValInt.getValue()) {
898 approachInt--;
899 } else {
900 approachInt++;
901 }
902 approachVal = new ValueInteger(approachInt);
903 break;
904 case REAL:
905 ValueReal valReal = (ValueReal) myVal;
906 double approachReal = valReal.getValue();
907 ValueReal partnerValReal = (ValueReal) partnerVal;
908 approachReal += new Random().nextDouble()
909 * (partnerValReal.getValue() - approachReal) / 10;
910 approachVal = new ValueReal(approachReal);
911 break;
912 default:
913 approachVal = myVal;
914 break;
915 }
916 return approachVal;
917 }
918
919 private void updateRestoreBid(Bid nextBid) {
920 List<Issue> issues = utilitySpace.getDomain().getIssues();
921
922 try {
923 } catch (Exception e) {
924 e.printStackTrace();
925 }
926 double evalGap = 0.0;
927 for (Issue issue : issues) {
928 int issueID = issue.getNumber();
929 Evaluator eval = ((AdditiveUtilitySpace) utilitySpace)
930 .getEvaluator(issueID);
931
932 try {
933 evalGap += Math.abs(eval.getEvaluation(
934 ((AdditiveUtilitySpace) utilitySpace), nextBid, issueID)
935 - eval.getEvaluation(
936 ((AdditiveUtilitySpace) utilitySpace),
937 maxUtilityPartnerBid, issueID));
938
939 } catch (Exception e) {
940 evalGap += 1.0;
941 }
942 }
943 if (evalGap < minGap) {
944 restoreBid = nextBid;
945 minGap = evalGap;
946 } else if (evalGap == minGap) {
947 try {
948 if (utilitySpace.getUtility(nextBid) > utilitySpace
949 .getUtility(restoreBid)) {
950 restoreBid = nextBid;
951 }
952 } catch (Exception e) {
953 e.printStackTrace();
954 }
955 }
956 }
957
958 private boolean isAccept(Bid partnerBid) {
959 boolean accept = false;
960 try {
961 double prevUtility = utilitySpace.getUtility(prevBid);
962 double offeredUtil = utilitySpace.getUtility(partnerBid);
963 double time = timeline.getTime();
964
965 if (offeredUtil > maxUtilityOfPartnerBid) {
966 maxUtilityPartnerBid = partnerBid;
967 maxUtilityOfPartnerBid = offeredUtil;
968 updateMaxPartnerUtility = true;
969 }
970
971 if (offeredUtil > maxUtility * 0.95 || offeredUtil >= prevUtility) {
972 accept = true;
973 } else {
974 List<Issue> issues = utilitySpace.getDomain().getIssues();
975
976 double evalGap = 0.0;
977 for (Issue issue : issues) {
978
979 int issueID = issue.getNumber();
980
981 switch (issue.getType()) {
982 case REAL:
983 IssueReal issueReal = (IssueReal) issue;
984 ValueReal valueReal = (ValueReal) prevBid
985 .getValue(issueID);
986 ValueReal partnerValueReal = (ValueReal) partnerBid
987 .getValue(issueID);
988 double gap = Math.abs(valueReal.getValue()
989 - partnerValueReal.getValue());
990 if (gap > (issueReal.getUpperBound()
991 - issueReal.getLowerBound()) / 100) {
992 evalGap += 0.5;
993 }
994 break;
995 default:
996 if (!prevBid.getValue(issueID)
997 .equals(partnerBid.getValue(issueID))) {
998 evalGap += 0.5;
999 }
1000 break;
1001 }
1002
1003 Evaluator eval = ((AdditiveUtilitySpace) utilitySpace)
1004 .getEvaluator(issueID);
1005
1006 try {
1007 evalGap += Math.abs(eval.getEvaluation(
1008 ((AdditiveUtilitySpace) utilitySpace), prevBid,
1009 issueID)
1010 - eval.getEvaluation(
1011 ((AdditiveUtilitySpace) utilitySpace),
1012 partnerBid, issueID));
1013 } catch (Exception e) {
1014 evalGap += 1.0;
1015 }
1016
1017 evalGap += 0.5;
1018 }
1019
1020 evalGap /= 2.0 * issues.size();
1021
1022 if (time < 0.50) {
1023 if (prevPartnerBid != null
1024 && offeredUtil > maxCompromiseUtility
1025 && offeredUtil >= maxUtilityOfPartnerBid) {
1026 double acceptCoefficient = -0.1 * time + 1.0;
1027
1028 if (evalGap < 0.30 && offeredUtil > prevUtility
1029 * acceptCoefficient) {
1030 accept = true;
1031 }
1032 }
1033 } else if (time < 0.80) {
1034 if (prevPartnerBid != null
1035 && offeredUtil > maxCompromiseUtility * 0.95
1036 && offeredUtil > maxUtilityOfPartnerBid * 0.95) {
1037 double diffMyBidAndOffered = prevUtility - offeredUtil;
1038
1039 if (diffMyBidAndOffered < 0.0)
1040 diffMyBidAndOffered = 0.0;
1041
1042 double acceptCoefficient = -0.16 * (time - 0.50) + 0.95;
1043
1044 if (evalGap < 0.35 && offeredUtil > prevUtility
1045 * acceptCoefficient) {
1046 accept = true;
1047 }
1048 }
1049 } else {
1050
1051 if (prevPartnerBid != null
1052 && offeredUtil > maxCompromiseUtility * 0.90
1053 && offeredUtil > maxUtilityOfPartnerBid * 0.95) {
1054
1055 double restoreEvalGap = 0.0;
1056 for (Issue issue : issues) {
1057 int issueID = issue.getNumber();
1058
1059 switch (issue.getType()) {
1060 case REAL:
1061 IssueReal issueReal = (IssueReal) issue;
1062 ValueReal valueReal = (ValueReal) restoreBid
1063 .getValue(issueID);
1064 ValueReal partnerValueReal = (ValueReal) partnerBid
1065 .getValue(issueID);
1066 double gap = Math.abs(valueReal.getValue()
1067 - partnerValueReal.getValue());
1068 if (gap > (issueReal.getUpperBound()
1069 - issueReal.getLowerBound()) / 100) {
1070 restoreEvalGap += 0.5;
1071 }
1072 break;
1073 default:
1074 if (!restoreBid.getValue(issueID)
1075 .equals(partnerBid.getValue(issueID))) {
1076 restoreEvalGap += 0.5;
1077 }
1078 break;
1079 }
1080
1081 Evaluator eval = ((AdditiveUtilitySpace) utilitySpace)
1082 .getEvaluator(issueID);
1083
1084 try {
1085 restoreEvalGap += Math.abs(eval.getEvaluation(
1086 ((AdditiveUtilitySpace) utilitySpace),
1087 prevBid, issueID)
1088 - eval.getEvaluation(
1089 ((AdditiveUtilitySpace) utilitySpace),
1090 partnerBid, issueID));
1091 } catch (Exception e) {
1092 restoreEvalGap += 1.0;
1093 }
1094
1095 restoreEvalGap += 0.5;
1096 }
1097
1098 restoreEvalGap /= 2.0 * issues.size();
1099
1100 double threshold = 0.40;
1101
1102 if (time > (0.90)) {
1103 threshold = 0.50;
1104
1105 }
1106 if (restoreEvalGap <= threshold
1107 || evalGap <= threshold) {
1108 accept = true;
1109 }
1110 }
1111 }
1112 }
1113 } catch (Exception e) {
1114 accept = false;
1115 }
1116 return accept;
1117 }
1118
1119 /**
1120 * This function determines the accept probability for an offer. At t=0 it
1121 * will prefer high-utility offers. As t gets closer to 1, it will accept
1122 * lower utility offers with increasing probability. it will never accept
1123 * offers with utility 0.
1124 *
1125 * @param u
1126 * is the utility
1127 * @param t
1128 * is the time as fraction of the total available time (t=0 at
1129 * start, and t=1 at end time)
1130 * @return the probability of an accept at time t
1131 * @throws Exception
1132 * if you use wrong values for u or t.
1133 *
1134 */
1135 double Paccept(double u, double t1) throws Exception {
1136 double t = t1 * t1 * t1; // steeper increase when deadline approaches.
1137 if (u < 0 || u > 1.05)
1138 throw new Exception("utility " + u + " outside [0,1]");
1139 // normalization may be slightly off, therefore we have a broad boundary
1140 // up to 1.05
1141 if (t < 0 || t > 1)
1142 throw new Exception("time " + t + " outside [0,1]");
1143 if (u > 1.)
1144 u = 1;
1145 if (t == 0.5)
1146 return u;
1147 return (u - 2. * u * t
1148 + 2. * (-1. + t + Math.sqrt(sq(-1. + t) + u * (-1. + 2 * t))))
1149 / (-1. + 2 * t);
1150 }
1151
1152 double sq(double x) {
1153 return x * x;
1154 }
1155
1156 @Override
1157 public SupportedNegotiationSetting getSupportedNegotiationSetting() {
1158 return SupportedNegotiationSetting.getLinearUtilitySpaceInstance();
1159 }
1160
1161 @Override
1162 public String getDescription() {
1163 return "ANAC2010";
1164 }
1165
1166}
Note: See TracBrowser for help on using the repository browser.