source: src/main/java/agents/anac/y2015/AgentNeo/BidOptions.java@ 1

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

Initial import : Genius 9.0.0

File size: 31.4 KB
Line 
1package agents.anac.y2015.AgentNeo;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6import java.util.Random;
7
8import genius.core.Bid;
9import genius.core.Domain;
10import genius.core.issue.Issue;
11import genius.core.issue.IssueDiscrete;
12import genius.core.issue.IssueInteger;
13import genius.core.issue.Value;
14import genius.core.issue.ValueInteger;
15import genius.core.utility.AbstractUtilitySpace;
16
17public class BidOptions {
18
19 private ArrayList<Bid> bidHistoryOpp1;
20 private ArrayList<Bid> bidHistoryOpp2;
21 private ArrayList<Bid> bidHistoryOpp3;
22 private static ArrayList<Bid> bidHistory;
23
24 // private int maximumBidsStored = 100;
25 // private HashMap<Bid, Integer> bidCounter = new HashMap<Bid, Integer>();
26 int opp1_token_counter = 0;
27 int opp2_token_counter = 0;
28 int opp3_token_counter = 0;
29 int temp_token_counter = 0;
30 private Bid bid_maximum;
31 private Bid bid_maximum_from_opponent1;
32 private Bid bid_maximum_from_opponent2;
33 private Bid bid_maximum_from_opponent3;
34 private double bid_maximum_utility_from_opponent1;
35 private double bid_maximum_utility_from_opponent2;
36 private double bid_maximum_utility_from_opponent3;// the bid with maximum
37 // utility proposed by
38 // the opponent so far.
39 private ArrayList<HashMap<Value, Integer>> opponentBidsStatisticsDiscreteOpp1;
40 private ArrayList<ArrayList<Integer>> opponentBidsStatisticsForIntegerOpp1;
41 private ArrayList<HashMap<Value, Integer>> opponentBidsStatisticsDiscreteOpp2;
42 private ArrayList<ArrayList<Integer>> opponentBidsStatisticsForIntegerOpp2;
43 private ArrayList<HashMap<Value, Integer>> opponentBidsStatisticsDiscreteOpp3;
44 private ArrayList<ArrayList<Integer>> opponentBidsStatisticsForIntegerOpp3;
45 HashMap<String, Integer> token_counter = new HashMap<String, Integer>();
46
47 public BidOptions() {
48 this.bidHistoryOpp1 = new ArrayList<Bid>();
49 this.bidHistoryOpp2 = new ArrayList<Bid>();
50 this.bidHistoryOpp3 = new ArrayList<Bid>();
51 BidOptions.bidHistory = new ArrayList<Bid>();
52 opponentBidsStatisticsDiscreteOpp1 = new ArrayList<HashMap<Value, Integer>>();
53 opponentBidsStatisticsForIntegerOpp1 = new ArrayList<ArrayList<Integer>>();
54 opponentBidsStatisticsDiscreteOpp2 = new ArrayList<HashMap<Value, Integer>>();
55 opponentBidsStatisticsForIntegerOpp2 = new ArrayList<ArrayList<Integer>>();
56 opponentBidsStatisticsDiscreteOpp3 = new ArrayList<HashMap<Value, Integer>>();
57 opponentBidsStatisticsForIntegerOpp3 = new ArrayList<ArrayList<Integer>>();
58
59 }
60
61 protected void initializeDataStructures(Domain domain) {
62 try {
63
64 List<Issue> issues = domain.getIssues();
65 System.out.println(issues);
66 for (Issue lIssue : issues) {
67 switch (lIssue.getType()) {
68
69 case DISCRETE:
70
71 IssueDiscrete lIssueDiscrete = (IssueDiscrete) lIssue;
72 HashMap<Value, Integer> discreteIssueValuesMap = new HashMap<Value, Integer>();
73 for (int j = 0; j < lIssueDiscrete.getNumberOfValues(); j++) {
74 Value v = lIssueDiscrete.getValue(j);
75 discreteIssueValuesMap.put(v, 0);
76 System.out.println(discreteIssueValuesMap);
77 }
78
79 opponentBidsStatisticsDiscreteOpp1
80 .add(discreteIssueValuesMap);
81 opponentBidsStatisticsDiscreteOpp2
82 .add(discreteIssueValuesMap);
83 opponentBidsStatisticsDiscreteOpp3
84 .add(discreteIssueValuesMap);
85
86 break;
87
88 case INTEGER:
89 IssueInteger lIssueInteger = (IssueInteger) lIssue;
90 ArrayList<Integer> numOfValueProposals = new ArrayList<Integer>();
91
92 // number of possible value when issue is integer (we should
93 // add 1 in order to include all values)
94 int lNumOfPossibleValuesForThisIssue = lIssueInteger
95 .getUpperBound()
96 - lIssueInteger.getLowerBound()
97 + 1;
98 for (int i = 0; i < lNumOfPossibleValuesForThisIssue; i++) {
99 numOfValueProposals.add(0);
100 }
101 opponentBidsStatisticsForIntegerOpp1
102 .add(numOfValueProposals);
103 opponentBidsStatisticsForIntegerOpp2
104 .add(numOfValueProposals);
105 opponentBidsStatisticsForIntegerOpp3
106 .add(numOfValueProposals);
107
108 break;
109 }
110 }
111 } catch (Exception e) {
112 System.out.println("EXCEPTION in initializeDataStructures");
113 }
114 }
115
116 protected void addBidOpp1(Bid bid, AbstractUtilitySpace utilitySpace) {
117
118 bidHistory.add(bid);
119 if (bidHistoryOpp1.indexOf(bid) == -1) { // list does not contain the
120 // bid
121 bidHistoryOpp1.add(bid);
122
123 }
124 try {
125 if (bidHistoryOpp1.size() == 1) {
126 this.bid_maximum_from_opponent1 = bidHistoryOpp1.get(0);
127 this.bid_maximum_utility_from_opponent1 = utilitySpace
128 .getUtility(this.bid_maximum_from_opponent1);
129
130 } else {
131
132 this.bid_maximum_from_opponent1 = bid;
133 this.bid_maximum_utility_from_opponent1 = utilitySpace
134 .getUtility(bid);
135 }
136 } catch (Exception e) {
137 System.out.println("error in addBid method" + e.getMessage());
138 }
139 }
140
141 protected void addBidOpp2(Bid bid, AbstractUtilitySpace utilitySpace) {
142
143 bidHistory.add(bid);
144 if (bidHistoryOpp2.indexOf(bid) == -1) { // list does not contain the
145 // bid
146 bidHistoryOpp2.add(bid);
147
148 }
149 try {
150 if (bidHistoryOpp2.size() == 1) {
151 this.bid_maximum_from_opponent2 = bidHistoryOpp2.get(0);
152 this.bid_maximum_utility_from_opponent2 = utilitySpace
153 .getUtility(this.bid_maximum_from_opponent2);
154
155 } else {
156
157 this.bid_maximum_from_opponent2 = bid;
158 this.bid_maximum_utility_from_opponent2 = utilitySpace
159 .getUtility(bid);
160
161 }
162 } catch (Exception e) {
163 System.out.println("error in addBid method" + e.getMessage());
164 }
165 }
166
167 protected void addBidOpp3(Bid bid, AbstractUtilitySpace utilitySpace) {
168
169 bidHistory.add(bid);
170 if (bidHistoryOpp3.indexOf(bid) == -1) { // list does not contain the
171 // bid
172 bidHistoryOpp3.add(bid);
173
174 }
175
176 try {
177 if (bidHistoryOpp3.size() == 1) {
178 this.bid_maximum_from_opponent3 = bidHistoryOpp3.get(0);
179 this.bid_maximum_utility_from_opponent3 = utilitySpace
180 .getUtility(this.bid_maximum_from_opponent3);
181
182 } else {
183
184 this.bid_maximum_from_opponent3 = bid;
185 this.bid_maximum_utility_from_opponent3 = utilitySpace
186 .getUtility(bid);
187
188 }
189 } catch (Exception e) {
190 System.out.println("error in addBid method" + e.getMessage());
191 }
192 }
193
194 protected void addOpponentBid(Bid bidToUpdate, Domain domain,
195 AbstractUtilitySpace utilitySpace, Object IDOfOpponent) {
196 String OppID = IDOfOpponent.toString();
197
198 if (OppID.equals("Party 1")) {
199 this.addBidOpp1(bidToUpdate, utilitySpace);
200 this.updateStatisticsOpp1(bidToUpdate, false, domain);
201 }
202 if (OppID.equals("Party 2")) {
203 this.addBidOpp2(bidToUpdate, utilitySpace);
204 this.updateStatisticsOpp2(bidToUpdate, false, domain);
205 }
206 if (OppID.equals("Party 3")) {
207 this.addBidOpp3(bidToUpdate, utilitySpace);
208 this.updateStatisticsOpp3(bidToUpdate, false, domain);
209 }
210 }
211
212 private void updateStatisticsOpp1(Bid bidToUpdate, boolean toRemove,
213 Domain domain) {
214 try {
215 List<Issue> issues = domain.getIssues();
216
217 // counters for each type of the issues
218
219 int discreteIndex = 0;
220 int integerIndex = 0;
221
222 for (Issue lIssue : issues) {
223 int issueNum = lIssue.getNumber();
224 Value v = bidToUpdate.getValue(issueNum); // v is the reference
225 // key
226 switch (lIssue.getType()) {
227 case DISCRETE:
228 if (opponentBidsStatisticsDiscreteOpp1 == null) {
229 System.out
230 .println("opponentBidsStatisticsDiscreteOpp1 is NULL");
231 } else if (opponentBidsStatisticsDiscreteOpp1
232 .get(discreteIndex) != null) {
233 int ValueofCounter = opponentBidsStatisticsDiscreteOpp1
234 .get(discreteIndex).get(v);
235 if (toRemove) {
236 ValueofCounter--;
237 } else {
238 ValueofCounter++;
239 }
240 opponentBidsStatisticsDiscreteOpp1.get(discreteIndex)
241 .put(v, ValueofCounter);
242 }
243 discreteIndex++;
244 break;
245
246 case INTEGER:
247
248 IssueInteger lIssueInteger = (IssueInteger) lIssue;
249 int valueInteger = ((ValueInteger) v).getValue();
250
251 int valueIndex = valueInteger
252 - lIssueInteger.getLowerBound(); // For ex.
253 // LowerBound
254 // index is 0,
255 // and the lower
256 // bound is 2,
257 // the value is
258 // 4, so the
259 // index of 4
260 // would be 2
261 // which is
262 // exactly 4-2
263 int countPerValue = opponentBidsStatisticsForIntegerOpp1
264 .get(integerIndex).get(valueIndex);
265 if (toRemove) {
266 countPerValue--;
267 } else {
268 countPerValue++;
269 }
270 opponentBidsStatisticsForIntegerOpp1.get(integerIndex).set(
271 valueIndex, countPerValue);
272 integerIndex++;
273 break;
274 default:
275 break;
276 }
277 }
278 } catch (Exception e) {
279 System.out.println("Exception in updateStatistics1: "
280 + e.getMessage());
281 }
282 }
283
284 private void updateStatisticsOpp2(Bid bidToUpdate, boolean toRemove,
285 Domain domain) {
286 try {
287 List<Issue> issues = domain.getIssues();
288
289 // counters for each type of the issues
290
291 int discreteIndex = 0;
292 int integerIndex = 0;
293
294 for (Issue lIssue : issues) {
295 int issueNum = lIssue.getNumber();
296 Value v = bidToUpdate.getValue(issueNum); // v is the reference
297 // key
298 switch (lIssue.getType()) {
299 case DISCRETE:
300 if (opponentBidsStatisticsDiscreteOpp2 == null) {
301 System.out
302 .println("opponentBidsStatisticsDiscreteOpp2 is NULL");
303 } else if (opponentBidsStatisticsDiscreteOpp2
304 .get(discreteIndex) != null) {
305 int ValueofCounter = opponentBidsStatisticsDiscreteOpp2
306 .get(discreteIndex).get(v);
307 if (toRemove) {
308 ValueofCounter--;
309 } else {
310 ValueofCounter++;
311 }
312 opponentBidsStatisticsDiscreteOpp2.get(discreteIndex)
313 .put(v, ValueofCounter);
314 }
315 discreteIndex++;
316 break;
317
318 case INTEGER:
319
320 IssueInteger lIssueInteger = (IssueInteger) lIssue;
321 int valueInteger = ((ValueInteger) v).getValue();
322
323 int valueIndex = valueInteger
324 - lIssueInteger.getLowerBound(); // For ex.
325 // LowerBound
326 // index is 0,
327 // and the lower
328 // bound is 2,
329 // the value is
330 // 4, so the
331 // index of 4
332 // would be 2
333 // which is
334 // exactly 4-2
335 int countPerValue = opponentBidsStatisticsForIntegerOpp2
336 .get(integerIndex).get(valueIndex);
337 if (toRemove) {
338 countPerValue--;
339 } else {
340 countPerValue++;
341 }
342 opponentBidsStatisticsForIntegerOpp2.get(integerIndex).set(
343 valueIndex, countPerValue);
344 integerIndex++;
345 break;
346 default:
347 break;
348 }
349 }
350 } catch (Exception e) {
351 System.out.println("Exception in updateStatistics2: "
352 + e.getMessage());
353 }
354 }
355
356 private void updateStatisticsOpp3(Bid bidToUpdate, boolean toRemove,
357 Domain domain) {
358 try {
359 List<Issue> issues = domain.getIssues();
360
361 // counters for each type of the issues
362
363 int discreteIndex = 0;
364 int integerIndex = 0;
365
366 for (Issue lIssue : issues) {
367 int issueNum = lIssue.getNumber();
368 Value v = bidToUpdate.getValue(issueNum); // v is the reference
369 // key
370 switch (lIssue.getType()) {
371 case DISCRETE:
372 if (opponentBidsStatisticsDiscreteOpp3 == null) {
373 System.out
374 .println("opponentBidsStatisticsDiscreteOpp3 is NULL");
375 } else if (opponentBidsStatisticsDiscreteOpp3
376 .get(discreteIndex) != null) {
377 int ValueofCounter = opponentBidsStatisticsDiscreteOpp3
378 .get(discreteIndex).get(v);
379 if (toRemove) {
380 ValueofCounter--;
381 } else {
382 ValueofCounter++;
383 }
384 opponentBidsStatisticsDiscreteOpp3.get(discreteIndex)
385 .put(v, ValueofCounter);
386 }
387 discreteIndex++;
388 break;
389
390 case INTEGER:
391
392 IssueInteger lIssueInteger = (IssueInteger) lIssue;
393 int valueInteger = ((ValueInteger) v).getValue();
394
395 int valueIndex = valueInteger
396 - lIssueInteger.getLowerBound(); // For ex.
397 // LowerBound
398 // index is 0,
399 // and the lower
400 // bound is 2,
401 // the value is
402 // 4, so the
403 // index of 4
404 // would be 2
405 // which is
406 // exactly 4-2
407 int countPerValue = opponentBidsStatisticsForIntegerOpp3
408 .get(integerIndex).get(valueIndex);
409 if (toRemove) {
410 countPerValue--;
411 } else {
412 countPerValue++;
413 }
414 opponentBidsStatisticsForIntegerOpp3.get(integerIndex).set(
415 valueIndex, countPerValue);
416 integerIndex++;
417 break;
418 default:
419 break;
420 }
421 }
422 } catch (Exception e) {
423 System.out.println("Exception in updateStatistics3: "
424 + e.getMessage());
425 }
426 }
427
428 protected Bid getBestBidInHistory() {
429
430 if (token_counter.get("opponent 1") > token_counter.get("opponent 2")
431 && token_counter.get("opponent 1") > token_counter
432 .get("opponent 3")) {
433
434 bid_maximum = this.bid_maximum_from_opponent1;
435
436 } else if (token_counter.get("opponent 2") > token_counter
437 .get("opponent 1")
438 && token_counter.get("opponent 2") > token_counter
439 .get("opponent 3")) {
440
441 bid_maximum = this.bid_maximum_from_opponent2;
442
443 } else if (token_counter.get("opponent 3") > token_counter
444 .get("opponent 2")
445 && token_counter.get("opponent 3") > token_counter
446 .get("opponent 1")) {
447
448 bid_maximum = this.bid_maximum_from_opponent3;
449
450 }
451 // Determine who is the opponent I am siding with
452 return bid_maximum;
453 }
454
455 enum maxType {
456 A, B, C
457 };
458
459 protected int SimilartoOpponent(int value) {
460
461 double a = this.bid_maximum_utility_from_opponent1;
462 double b = this.bid_maximum_utility_from_opponent2;
463 double c = this.bid_maximum_utility_from_opponent3;
464
465 maxType max = maxType.A;
466
467 // System.out.println(a);
468 // System.out.println(b);
469 // System.out.println(c);
470
471 if (b > a && b > c) {
472 max = maxType.B;
473 }
474 if (c > b && c > a) {
475 max = maxType.C;
476 }
477
478 // System.out.println(max);
479
480 if (token_counter.isEmpty()) {
481 token_counter.put("opponent 1", 0);
482 token_counter.put("opponent 2", 0);
483 token_counter.put("opponent 3", 0);
484 }
485
486 System.out.println(token_counter);
487 System.out.println(max);
488 switch (max) {
489
490 case A:
491
492 temp_token_counter = token_counter.get("opponent 1") + 1;
493 token_counter.put("opponent 1", temp_token_counter);
494 break;
495
496 case B:
497
498 temp_token_counter = token_counter.get("opponent 2") + 1;
499 token_counter.put("opponent 2", temp_token_counter);
500 break;
501
502 case C:
503
504 temp_token_counter = token_counter.get("opponent 3") + 1;
505 token_counter.put("opponent 3", temp_token_counter);
506 break;
507 }
508
509 System.out.println(token_counter);
510
511 if (token_counter.get("opponent 1") >= token_counter.get("opponent 2")
512 && token_counter.get("opponent 1") >= token_counter
513 .get("opponent 3")) {
514
515 // System.out.println("A");
516 value = 1;
517 } else if (token_counter.get("opponent 2") >= token_counter
518 .get("opponent 1")
519 && token_counter.get("opponent 2") >= token_counter
520 .get("opponent 3")) {
521 // System.out.println("B");
522 value = 2;
523 } else if (token_counter.get("opponent 3") >= token_counter
524 .get("opponent 2")
525 && token_counter.get("opponent 3") >= token_counter
526 .get("opponent 1")) {
527 // System.out.println("C");
528 value = 3;
529 }
530 // System.out.println(value);
531
532 return value;
533
534 }
535
536 protected Bid ChooseBid1(List<Bid> candidateBids, Domain domain) {
537 int upperSearchLimit = 200;// 100;
538 if (candidateBids.isEmpty()) {
539 System.out.println("test");
540 }
541 int maxIndex = -1;
542 Random ran = new Random();
543 List<Issue> issues = domain.getIssues();
544 int MaximumFreq = 0;
545 int discreteIndex = 0;
546 int integerIndex = 0;
547 try {
548 if (candidateBids.size() < upperSearchLimit) {
549 for (int i = 0; i < candidateBids.size(); i++) {
550 int MaximumCount = 0;
551 discreteIndex = integerIndex = 0;
552 for (int j = 0; j < issues.size(); j++) {
553 Value v = candidateBids.get(i).getValue(
554 issues.get(j).getNumber());
555 switch (issues.get(j).getType()) {
556 case DISCRETE:
557 if (opponentBidsStatisticsDiscreteOpp1 == null) {
558 System.out
559 .println("opponentBidsStatisticsDiscrete is NULL");
560 } else if (opponentBidsStatisticsDiscreteOpp1
561 .get(discreteIndex) != null) {
562 int ValueofCounter = opponentBidsStatisticsDiscreteOpp1
563 .get(discreteIndex).get(v);
564 MaximumCount += ValueofCounter;
565 }
566 discreteIndex++;
567 break;
568
569 case INTEGER:
570 IssueInteger lIssueInteger = (IssueInteger) issues
571 .get(j);
572 int valueInteger = ((ValueInteger) v).getValue();
573 int valueIndex = valueInteger
574 - lIssueInteger.getLowerBound(); // For ex.
575 // LowerBound
576 // index
577 // is 0,
578 // and
579 // the
580 // lower
581 // bound
582 // is 2,
583 // the
584 // value
585 // is 4,
586 // so
587 // the
588 // index
589 // of 4
590 // would
591 // be 2
592 // which
593 // is
594 // exactly
595 // 4-2
596 int ValueofCounter = opponentBidsStatisticsForIntegerOpp1
597 .get(integerIndex).get(valueIndex);
598 MaximumCount += ValueofCounter;
599 integerIndex++;
600 break;
601 }
602 }
603 if (MaximumCount > MaximumFreq) {// choose the bid with the
604 // maximum MaximumCount
605 MaximumFreq = MaximumCount;
606 maxIndex = i;
607 } else if (MaximumCount == MaximumFreq) {// random
608 // exploration
609 if (ran.nextDouble() < 0.5) {
610 MaximumFreq = MaximumCount;
611 maxIndex = i;
612 }
613 }
614 }
615
616 } else {// only evaluate the upperSearchLimit number of bids
617 for (int i = 0; i < upperSearchLimit; i++) {
618 int MaximumCount = 0;
619 int issueIndex = ran.nextInt(candidateBids.size());
620 discreteIndex = integerIndex = 0;
621 for (int j = 0; j < issues.size(); j++) {
622 Value v = candidateBids.get(issueIndex).getValue(
623 issues.get(j).getNumber());
624 switch (issues.get(j).getType()) {
625 case DISCRETE:
626 if (opponentBidsStatisticsDiscreteOpp1 == null) {
627 System.out
628 .println("opponentBidsStatisticsDiscrete is NULL");
629 } else if (opponentBidsStatisticsDiscreteOpp1
630 .get(discreteIndex) != null) {
631 int ValueofCounter = opponentBidsStatisticsDiscreteOpp1
632 .get(discreteIndex).get(v);
633 MaximumCount += ValueofCounter;
634 }
635 discreteIndex++;
636 break;
637
638 case INTEGER:
639 IssueInteger lIssueInteger = (IssueInteger) issues
640 .get(j);
641 int valueInteger = ((ValueInteger) v).getValue();
642 int valueIndex = valueInteger
643 - lIssueInteger.getLowerBound(); // For ex.
644 // LowerBound
645 // index
646 // is 0,
647 // and
648 // the
649 // lower
650 // bound
651 // is 2,
652 // the
653 // value
654 // is 4,
655 // so
656 // the
657 // index
658 // of 4
659 // would
660 // be 2
661 // which
662 // is
663 // exactly
664 // 4-2
665 int ValueofCounter = opponentBidsStatisticsForIntegerOpp1
666 .get(integerIndex).get(valueIndex);
667 MaximumCount += ValueofCounter;
668 integerIndex++;
669 break;
670 }
671 }
672 if (MaximumCount > MaximumFreq) {// choose the bid with the
673 // maximum MaximumCount
674 MaximumFreq = MaximumCount;
675 maxIndex = i;
676 } else if (MaximumCount == MaximumFreq) {// random
677 // exploration
678 if (ran.nextDouble() < 0.5) {
679 MaximumFreq = MaximumCount;
680 maxIndex = i;
681 }
682 }
683 }
684 }
685
686 } catch (Exception e) {
687 System.out.println("Exception in choosing a bid");
688 System.out.println(e.getMessage() + "---" + discreteIndex);
689 }
690 if (maxIndex == -1) {
691 return candidateBids.get(ran.nextInt(candidateBids.size()));
692 } else {
693 // here we adopt the random exploration mechanism
694 if (ran.nextDouble() < 0.95) {
695 return candidateBids.get(maxIndex);
696 } else {
697 return candidateBids.get(ran.nextInt(candidateBids.size()));
698 }
699 }
700 }
701
702 protected Bid ChooseBid2(List<Bid> candidateBids, Domain domain) {
703 int upperSearchLimit = 200;// 100;
704 if (candidateBids.isEmpty()) {
705 System.out.println("test");
706 }
707 int maxIndex = -1;
708 Random ran = new Random();
709 List<Issue> issues = domain.getIssues();
710 int MaximumFreq = 0;
711 int discreteIndex = 0;
712 int integerIndex = 0;
713 try {
714 if (candidateBids.size() < upperSearchLimit) {
715 for (int i = 0; i < candidateBids.size(); i++) {
716 int MaximumCount = 0;
717 discreteIndex = integerIndex = 0;
718 for (int j = 0; j < issues.size(); j++) {
719 Value v = candidateBids.get(i).getValue(
720 issues.get(j).getNumber());
721 switch (issues.get(j).getType()) {
722 case DISCRETE:
723 if (opponentBidsStatisticsDiscreteOpp2 == null) {
724 System.out
725 .println("opponentBidsStatisticsDiscrete is NULL");
726 } else if (opponentBidsStatisticsDiscreteOpp2
727 .get(discreteIndex) != null) {
728 int ValueofCounter = opponentBidsStatisticsDiscreteOpp2
729 .get(discreteIndex).get(v);
730 MaximumCount += ValueofCounter;
731 }
732 discreteIndex++;
733 break;
734
735 case INTEGER:
736 IssueInteger lIssueInteger = (IssueInteger) issues
737 .get(j);
738 int valueInteger = ((ValueInteger) v).getValue();
739 int valueIndex = valueInteger
740 - lIssueInteger.getLowerBound(); // For ex.
741 // LowerBound
742 // index
743 // is 0,
744 // and
745 // the
746 // lower
747 // bound
748 // is 2,
749 // the
750 // value
751 // is 4,
752 // so
753 // the
754 // index
755 // of 4
756 // would
757 // be 2
758 // which
759 // is
760 // exactly
761 // 4-2
762 int ValueofCounter = opponentBidsStatisticsForIntegerOpp2
763 .get(integerIndex).get(valueIndex);
764 MaximumCount += ValueofCounter;
765 integerIndex++;
766 break;
767 }
768 }
769 if (MaximumCount > MaximumFreq) {// choose the bid with the
770 // maximum MaximumCount
771 MaximumFreq = MaximumCount;
772 maxIndex = i;
773 } else if (MaximumCount == MaximumFreq) {// random
774 // exploration
775 if (ran.nextDouble() < 0.5) {
776 MaximumFreq = MaximumCount;
777 maxIndex = i;
778 }
779 }
780 }
781
782 } else {// only evaluate the upperSearchLimit number of bids
783 for (int i = 0; i < upperSearchLimit; i++) {
784 int MaximumCount = 0;
785 int issueIndex = ran.nextInt(candidateBids.size());
786 discreteIndex = integerIndex = 0;
787 for (int j = 0; j < issues.size(); j++) {
788 Value v = candidateBids.get(issueIndex).getValue(
789 issues.get(j).getNumber());
790 switch (issues.get(j).getType()) {
791 case DISCRETE:
792 if (opponentBidsStatisticsDiscreteOpp2 == null) {
793 System.out
794 .println("opponentBidsStatisticsDiscrete is NULL");
795 } else if (opponentBidsStatisticsDiscreteOpp2
796 .get(discreteIndex) != null) {
797 int ValueofCounter = opponentBidsStatisticsDiscreteOpp2
798 .get(discreteIndex).get(v);
799 MaximumCount += ValueofCounter;
800 }
801 discreteIndex++;
802 break;
803
804 case INTEGER:
805 IssueInteger lIssueInteger = (IssueInteger) issues
806 .get(j);
807 int valueInteger = ((ValueInteger) v).getValue();
808 int valueIndex = valueInteger
809 - lIssueInteger.getLowerBound(); // For ex.
810 // LowerBound
811 // index
812 // is 0,
813 // and
814 // the
815 // lower
816 // bound
817 // is 2,
818 // the
819 // value
820 // is 4,
821 // so
822 // the
823 // index
824 // of 4
825 // would
826 // be 2
827 // which
828 // is
829 // exactly
830 // 4-2
831 int ValueofCounter = opponentBidsStatisticsForIntegerOpp2
832 .get(integerIndex).get(valueIndex);
833 MaximumCount += ValueofCounter;
834 integerIndex++;
835 break;
836 }
837 }
838 if (MaximumCount > MaximumFreq) {// choose the bid with the
839 // maximum MaximumCount
840 MaximumFreq = MaximumCount;
841 maxIndex = i;
842 } else if (MaximumCount == MaximumFreq) {// random
843 // exploration
844 if (ran.nextDouble() < 0.5) {
845 MaximumFreq = MaximumCount;
846 maxIndex = i;
847 }
848 }
849 }
850 }
851
852 } catch (Exception e) {
853 System.out.println("Exception in choosing a bid");
854 System.out.println(e.getMessage() + "---" + discreteIndex);
855 }
856 if (maxIndex == -1) {
857 return candidateBids.get(ran.nextInt(candidateBids.size()));
858 } else {
859 // here we adopt the random exploration mechanism
860 if (ran.nextDouble() < 0.95) {
861 return candidateBids.get(maxIndex);
862 } else {
863 return candidateBids.get(ran.nextInt(candidateBids.size()));
864 }
865 }
866 }
867
868 protected Bid ChooseBid3(List<Bid> candidateBids, Domain domain) {
869 int upperSearchLimit = 200;// 100;
870 if (candidateBids.isEmpty()) {
871 System.out.println("test");
872 }
873 int maxIndex = -1;
874 Random ran = new Random();
875 List<Issue> issues = domain.getIssues();
876 int MaximumFreq = 0;
877 int discreteIndex = 0;
878 int integerIndex = 0;
879 try {
880 if (candidateBids.size() < upperSearchLimit) {
881 for (int i = 0; i < candidateBids.size(); i++) {
882 int MaximumCount = 0;
883 discreteIndex = integerIndex = 0;
884 for (int j = 0; j < issues.size(); j++) {
885 Value v = candidateBids.get(i).getValue(
886 issues.get(j).getNumber());
887 switch (issues.get(j).getType()) {
888 case DISCRETE:
889 if (opponentBidsStatisticsDiscreteOpp3 == null) {
890 System.out
891 .println("opponentBidsStatisticsDiscrete is NULL");
892 } else if (opponentBidsStatisticsDiscreteOpp3
893 .get(discreteIndex) != null) {
894 int ValueofCounter = opponentBidsStatisticsDiscreteOpp3
895 .get(discreteIndex).get(v);
896 MaximumCount += ValueofCounter;
897 }
898 discreteIndex++;
899 break;
900
901 case INTEGER:
902 IssueInteger lIssueInteger = (IssueInteger) issues
903 .get(j);
904 int valueInteger = ((ValueInteger) v).getValue();
905 int valueIndex = valueInteger
906 - lIssueInteger.getLowerBound(); // For ex.
907 // LowerBound
908 // index
909 // is 0,
910 // and
911 // the
912 // lower
913 // bound
914 // is 2,
915 // the
916 // value
917 // is 4,
918 // so
919 // the
920 // index
921 // of 4
922 // would
923 // be 2
924 // which
925 // is
926 // exactly
927 // 4-2
928 int ValueofCounter = opponentBidsStatisticsForIntegerOpp3
929 .get(integerIndex).get(valueIndex);
930 MaximumCount += ValueofCounter;
931 integerIndex++;
932 break;
933 }
934 }
935 if (MaximumCount > MaximumFreq) {// choose the bid with the
936 // maximum MaximumCount
937 MaximumFreq = MaximumCount;
938 maxIndex = i;
939 } else if (MaximumCount == MaximumFreq) {// random
940 // exploration
941 if (ran.nextDouble() < 0.5) {
942 MaximumFreq = MaximumCount;
943 maxIndex = i;
944 }
945 }
946 }
947
948 } else {// only evaluate the upperSearchLimit number of bids
949 for (int i = 0; i < upperSearchLimit; i++) {
950 int MaximumCount = 0;
951 int issueIndex = ran.nextInt(candidateBids.size());
952 discreteIndex = integerIndex = 0;
953 for (int j = 0; j < issues.size(); j++) {
954 Value v = candidateBids.get(issueIndex).getValue(
955 issues.get(j).getNumber());
956 switch (issues.get(j).getType()) {
957 case DISCRETE:
958 if (opponentBidsStatisticsDiscreteOpp3 == null) {
959 System.out
960 .println("opponentBidsStatisticsDiscrete is NULL");
961 } else if (opponentBidsStatisticsDiscreteOpp3
962 .get(discreteIndex) != null) {
963 int ValueofCounter = opponentBidsStatisticsDiscreteOpp3
964 .get(discreteIndex).get(v);
965 MaximumCount += ValueofCounter;
966 }
967 discreteIndex++;
968 break;
969
970 case INTEGER:
971 IssueInteger lIssueInteger = (IssueInteger) issues
972 .get(j);
973 int valueInteger = ((ValueInteger) v).getValue();
974 int valueIndex = valueInteger
975 - lIssueInteger.getLowerBound(); // For ex.
976 // LowerBound
977 // index
978 // is 0,
979 // and
980 // the
981 // lower
982 // bound
983 // is 2,
984 // the
985 // value
986 // is 4,
987 // so
988 // the
989 // index
990 // of 4
991 // would
992 // be 2
993 // which
994 // is
995 // exactly
996 // 4-2
997 int ValueofCounter = opponentBidsStatisticsForIntegerOpp3
998 .get(integerIndex).get(valueIndex);
999 MaximumCount += ValueofCounter;
1000 integerIndex++;
1001 break;
1002 }
1003 }
1004 if (MaximumCount > MaximumFreq) {// choose the bid with the
1005 // maximum MaximumCount
1006 MaximumFreq = MaximumCount;
1007 maxIndex = i;
1008 } else if (MaximumCount == MaximumFreq) {// random
1009 // exploration
1010 if (ran.nextDouble() < 0.5) {
1011 MaximumFreq = MaximumCount;
1012 maxIndex = i;
1013 }
1014 }
1015 }
1016 }
1017
1018 } catch (Exception e) {
1019 System.out.println("Exception in choosing a bid");
1020 System.out.println(e.getMessage() + "---" + discreteIndex);
1021 }
1022 if (maxIndex == -1) {
1023 return candidateBids.get(ran.nextInt(candidateBids.size()));
1024 } else {
1025 // here we adopt the random exploration mechanism
1026 if (ran.nextDouble() < 0.95) {
1027 return candidateBids.get(maxIndex);
1028 } else {
1029 return candidateBids.get(ran.nextInt(candidateBids.size()));
1030 }
1031 }
1032 }
1033
1034 protected static Bid getLastBid() {
1035 if (bidHistory.size() >= 1) {
1036 return bidHistory.get(bidHistory.size() - 1);
1037 } else {
1038 return null;
1039 }
1040 }
1041}
Note: See TracBrowser for help on using the repository browser.