source: src/main/java/negotiator/boaframework/omstrategy/TheFawkes_OMS.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: 3.4 KB
Line 
1package negotiator.boaframework.omstrategy;
2
3import java.util.ArrayDeque;
4import java.util.Collections;
5import java.util.Comparator;
6import java.util.HashMap;
7import java.util.List;
8import java.util.Map;
9
10import genius.core.bidding.BidDetails;
11import genius.core.boaframework.NegotiationSession;
12import genius.core.boaframework.OMStrategy;
13import genius.core.boaframework.OpponentModel;
14
15/**
16 * Opponent Model Strategy
17 */
18public final class TheFawkes_OMS extends OMStrategy {
19 private ArrayDeque<Double> lastTen;
20 private int secondBestCounter = 1;
21
22 @Override
23 public void init(NegotiationSession nSession, OpponentModel oppModel, Map<String, Double> parameters) {
24 initializeAgent(nSession, oppModel);
25 }
26
27 private void initializeAgent(NegotiationSession negotiationSession, OpponentModel model) {
28 super.init(negotiationSession, model, new HashMap<String, Double>());
29 this.lastTen = new ArrayDeque<Double>(11);
30 }
31
32 @Override
33 public BidDetails getBid(List<BidDetails> list) { // gets as input a List
34 // with bid that have an
35 // utily u', given
36 // formula 14
37 Collections.sort(list, new Comparing(this.model));
38 BidDetails opponentBestBid = list.get(0);
39 boolean allEqual = true;
40
41 for (double bid : this.lastTen) {
42 if (bid != opponentBestBid.getMyUndiscountedUtil()) { // Use our own
43 // undiscounted
44 // util to
45 // check if
46 // we're
47 // effectively
48 // offering
49 // the same
50 // thing
51 allEqual = false;
52 }
53 }
54 if (allEqual) { // Offer the second best bid when we're offering the
55 // same every time... does this work, and if so does it
56 // need expansion?
57 this.secondBestCounter++;
58 if (list.size() > 1) {
59 opponentBestBid = list.get(1);
60 }
61 }
62
63 this.lastTen.addLast(opponentBestBid.getMyUndiscountedUtil());
64 if (this.lastTen.size() > 10) {
65 this.lastTen.removeFirst();
66 }
67
68 return opponentBestBid;
69 }
70
71 public int getSecondBestCount() {
72 return this.secondBestCounter;
73 }
74
75 @Override
76 public boolean canUpdateOM() {
77 return true; // other variants mess up the whole code apparantley?!
78 }
79
80 private final static class Comparing implements Comparator<BidDetails> { // Sort
81 // according
82 // to
83 // what
84 // we
85 // think
86 // are
87 // the
88 // best
89 // bids
90 // for
91 // the
92 // opponent
93 // (best
94 // at
95 // the
96 // head
97 // of
98 // the
99 // list)
100 private final OpponentModel model;
101
102 protected Comparing(OpponentModel model) {
103 this.model = model;
104 }
105
106 @Override
107 public int compare(final BidDetails a, BidDetails b) {
108 double evalA = this.model.getBidEvaluation(a.getBid());
109 double evalB = this.model.getBidEvaluation(b.getBid());
110 if (evalA < evalB) {
111 return 1;
112 } else if (evalA > evalB) {
113 return -1;
114 } else {
115 return 0;
116 }
117 }
118 }
119
120 @Override
121 public String getName() {
122 return "TheFawkes";
123 }
124}
Note: See TracBrowser for help on using the repository browser.