source: src/test/java/bilateralexamples/boacomponents/BestBid.java@ 209

Last change on this file since 209 was 184, checked in by Tim Baarslag, 6 years ago

Created bilateralexamples

File size: 3.3 KB
Line 
1package bilateralexamples.boacomponents;
2
3import java.util.List;
4
5import java.util.HashSet;
6import java.util.Map;
7import java.util.Random;
8import java.util.Set;
9
10import genius.core.bidding.BidDetails;
11import genius.core.boaframework.BOAparameter;
12import genius.core.boaframework.NegotiationSession;
13import genius.core.boaframework.OMStrategy;
14import genius.core.boaframework.OpponentModel;
15
16/**
17 * This class uses an opponent model to determine the next bid for the opponent,
18 * while taking the opponent's preferences into account. The opponent model is
19 * used to select the best bid.
20 *
21 */
22public class BestBid extends OMStrategy {
23
24 /**
25 * when to stop updating the opponentmodel. Note that this value is not
26 * exactly one as a match sometimes lasts slightly longer.
27 */
28 double updateThreshold = 1.1;
29
30 /**
31 * Initializes the opponent model strategy. If a value for the parameter t
32 * is given, then it is set to this value. Otherwise, the default value is
33 * used.
34 *
35 * @param negotiationSession
36 * state of the negotiation.
37 * @param model
38 * opponent model used in conjunction with this opponent modeling
39 * strategy.
40 * @param parameters
41 * set of parameters for this opponent model strategy.
42 */
43 @Override
44 public void init(NegotiationSession negotiationSession, OpponentModel model, Map<String, Double> parameters) {
45 super.init(negotiationSession, model, parameters);
46 if (parameters.get("t") != null) {
47 updateThreshold = parameters.get("t").doubleValue();
48 } else {
49 System.out.println("OMStrategy assumed t = 1.1");
50 }
51 }
52
53 /**
54 * Returns the best bid for the opponent given a set of similarly preferred
55 * bids.
56 *
57 * @param list
58 * of the bids considered for offering.
59 * @return bid to be offered to opponent.
60 */
61 @Override
62 public BidDetails getBid(List<BidDetails> allBids) {
63
64 // 1. If there is only a single bid, return this bid
65 if (allBids.size() == 1) {
66 return allBids.get(0);
67 }
68 double bestUtil = -1;
69 BidDetails bestBid = allBids.get(0);
70
71 // 2. Check that not all bids are assigned at utility of 0
72 // to ensure that the opponent model works. If the opponent model
73 // does not work, offer a random bid.
74 boolean allWereZero = true;
75 // 3. Determine the best bid
76 for (BidDetails bid : allBids) {
77 double evaluation = model.getBidEvaluation(bid.getBid());
78 if (evaluation > 0.0001) {
79 allWereZero = false;
80 }
81 if (evaluation > bestUtil) {
82 bestBid = bid;
83 bestUtil = evaluation;
84 }
85 }
86 // 4. The opponent model did not work, therefore, offer a random bid.
87 if (allWereZero) {
88 Random r = new Random();
89 return allBids.get(r.nextInt(allBids.size()));
90 }
91 return bestBid;
92 }
93
94 /**
95 * The opponent model may be updated, unless the time is higher than a given
96 * constant.
97 *
98 * @return true if model may be updated.
99 */
100 @Override
101 public boolean canUpdateOM() {
102 return negotiationSession.getTime() < updateThreshold;
103 }
104
105 @Override
106 public Set<BOAparameter> getParameterSpec() {
107 Set<BOAparameter> set = new HashSet<BOAparameter>();
108 set.add(new BOAparameter("t", 1.1, "Time after which the OM should not be updated"));
109 return set;
110 }
111
112 @Override
113 public String getName() {
114 return "BestBid example";
115 }
116}
Note: See TracBrowser for help on using the repository browser.