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