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