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