[200] | 1 | package agents.anac.y2019.podagent;
|
---|
| 2 |
|
---|
| 3 | import java.util.*;
|
---|
| 4 | import java.util.Map.Entry;
|
---|
| 5 |
|
---|
| 6 | import genius.core.Bid;
|
---|
| 7 | import genius.core.BidHistory;
|
---|
| 8 | import genius.core.bidding.BidDetails;
|
---|
| 9 | import genius.core.boaframework.BOAparameter;
|
---|
| 10 | import genius.core.boaframework.NegotiationSession;
|
---|
| 11 | import genius.core.boaframework.OpponentModel;
|
---|
| 12 | import genius.core.issue.IssueDiscrete;
|
---|
| 13 | import genius.core.issue.Objective;
|
---|
| 14 | import genius.core.issue.ValueDiscrete;
|
---|
| 15 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
| 16 | import genius.core.utility.Evaluator;
|
---|
| 17 | import genius.core.utility.EvaluatorDiscrete;
|
---|
| 18 |
|
---|
| 19 | public class Group1_OM extends OpponentModel {
|
---|
| 20 |
|
---|
| 21 | boolean hardHeadedUntilNow = false;
|
---|
| 22 | private int amountOfIssues;
|
---|
| 23 | private double lastStepBidsAverage = 0.0;
|
---|
| 24 |
|
---|
| 25 | @Override
|
---|
| 26 | public void init(NegotiationSession negotiationSession, Map<String, Double> parameters) {
|
---|
| 27 | this.negotiationSession = negotiationSession;
|
---|
| 28 | opponentUtilitySpace = (AdditiveUtilitySpace) negotiationSession
|
---|
| 29 | .getUtilitySpace().copy();
|
---|
| 30 | amountOfIssues = opponentUtilitySpace.getDomain().getIssues().size();
|
---|
| 31 |
|
---|
| 32 | initializeModel();
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | /**
|
---|
| 36 | * Model update function altered from the HardHeaded frequency model.
|
---|
| 37 | *
|
---|
| 38 | * Instead of incrementing issue weights after two of the same successive values in a bid,
|
---|
| 39 | * the range of frequencies per issue is calculated, normalized and used as weight instead
|
---|
| 40 | *
|
---|
| 41 | *
|
---|
| 42 | * @param opponentBid
|
---|
| 43 | * @param time
|
---|
| 44 | */
|
---|
| 45 | @Override
|
---|
| 46 | public void updateModel(Bid opponentBid, double time) {
|
---|
| 47 | if (negotiationSession.getOpponentBidHistory().size() < 1) {
|
---|
| 48 | return;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | BidDetails oppBid = negotiationSession.getOpponentBidHistory().getHistory().get(negotiationSession.getOpponentBidHistory().size() - 1);
|
---|
| 52 |
|
---|
| 53 | // Like HardHeaded, add a constant value of 1 to each value from the bid
|
---|
| 54 | try {
|
---|
| 55 | for (Entry<Objective, Evaluator> e : opponentUtilitySpace.getEvaluators()) {
|
---|
| 56 | EvaluatorDiscrete value = (EvaluatorDiscrete) e.getValue();
|
---|
| 57 | IssueDiscrete issue = ((IssueDiscrete) e.getKey());
|
---|
| 58 |
|
---|
| 59 | ValueDiscrete issuevalue = (ValueDiscrete) oppBid.getBid().getValue(issue.getNumber());
|
---|
| 60 | Integer eval = value.getEvaluationNotNormalized(issuevalue);
|
---|
| 61 | value.setEvaluation(issuevalue, (1 + eval));
|
---|
| 62 | }
|
---|
| 63 | } catch (Exception ex) {
|
---|
| 64 | ex.printStackTrace();
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | // Calculate the difference between the highest value and the lowest value for each issue
|
---|
| 68 | double totalDist = 0;
|
---|
| 69 | Map<IssueDiscrete,Integer> distances = new HashMap<IssueDiscrete,Integer>();
|
---|
| 70 | for (Entry<Objective, Evaluator> e : opponentUtilitySpace.getEvaluators()) {
|
---|
| 71 | try {
|
---|
| 72 | EvaluatorDiscrete value = (EvaluatorDiscrete) e.getValue();
|
---|
| 73 | IssueDiscrete issue = ((IssueDiscrete) e.getKey());
|
---|
| 74 | Integer max = 0;
|
---|
| 75 | Integer min = Integer.MAX_VALUE;
|
---|
| 76 | for (ValueDiscrete vd : ((IssueDiscrete) e.getKey()).getValues()) {
|
---|
| 77 | Integer eval = value.getEvaluationNotNormalized(vd);
|
---|
| 78 | min = eval < min ? eval : min;
|
---|
| 79 | max = eval > max ? eval : max;
|
---|
| 80 | }
|
---|
| 81 | Integer dist = max - min;
|
---|
| 82 | totalDist += max - min;
|
---|
| 83 | distances.put(issue, dist);
|
---|
| 84 | } catch (Exception ex) {
|
---|
| 85 | ex.printStackTrace();
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | // Update weights
|
---|
| 90 | for (Entry<Objective, Evaluator> e : opponentUtilitySpace.getEvaluators()) {
|
---|
| 91 | try {
|
---|
| 92 | EvaluatorDiscrete value = (EvaluatorDiscrete) e.getValue();
|
---|
| 93 | IssueDiscrete issue = ((IssueDiscrete) e.getKey());
|
---|
| 94 | double dist = (double) distances.get(issue);
|
---|
| 95 | // normalize the distance value and update the issue weight
|
---|
| 96 | double newWeight = ((double) dist) / totalDist;
|
---|
| 97 | opponentUtilitySpace.setWeight(issue, newWeight);
|
---|
| 98 | } catch (Exception ex) {
|
---|
| 99 | ex.printStackTrace();
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | @Override
|
---|
| 105 | public double getBidEvaluation(Bid bid) {
|
---|
| 106 | double result = 0;
|
---|
| 107 | try {
|
---|
| 108 | result = opponentUtilitySpace.getUtility(bid);
|
---|
| 109 | } catch (Exception e) {
|
---|
| 110 | e.printStackTrace();
|
---|
| 111 | }
|
---|
| 112 | return result;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | @Override
|
---|
| 116 | public String getName() {
|
---|
| 117 | return "Group1_OM";
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | @Override
|
---|
| 121 | public Set<BOAparameter> getParameterSpec() {
|
---|
| 122 | Set<BOAparameter> set = new HashSet<BOAparameter>();
|
---|
| 123 | set.add(new BOAparameter("l", 0.2,
|
---|
| 124 | "The learning coefficient determines how quickly the issue weights are learned"));
|
---|
| 125 | return set;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | /**
|
---|
| 129 | * Init to flat weight and flat evaluation distribution
|
---|
| 130 | */
|
---|
| 131 | private void initializeModel() {
|
---|
| 132 | double commonWeight = 1D / amountOfIssues;
|
---|
| 133 |
|
---|
| 134 | for (Entry<Objective, Evaluator> e : opponentUtilitySpace
|
---|
| 135 | .getEvaluators()) {
|
---|
| 136 |
|
---|
| 137 | opponentUtilitySpace.unlock(e.getKey());
|
---|
| 138 | e.getValue().setWeight(commonWeight);
|
---|
| 139 | try {
|
---|
| 140 | // set all value weights to one (they are normalized when
|
---|
| 141 | // calculating the utility)
|
---|
| 142 | for (ValueDiscrete vd : ((IssueDiscrete) e.getKey())
|
---|
| 143 | .getValues())
|
---|
| 144 | ((EvaluatorDiscrete) e.getValue()).setEvaluation(vd, 1);
|
---|
| 145 | } catch (Exception ex) {
|
---|
| 146 | ex.printStackTrace();
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | //Should only be called when concede() is called
|
---|
| 153 | public double getOpponentSentiment(double lastSteptime) {
|
---|
| 154 | //Not sure why this happens sometimes :/
|
---|
| 155 | if(negotiationSession == null)
|
---|
| 156 | return 0.5;
|
---|
| 157 |
|
---|
| 158 | //For the first step, use the first bid ever
|
---|
| 159 | if(lastStepBidsAverage == 0 && negotiationSession.getOpponentBidHistory().size() != 0) {
|
---|
| 160 | lastStepBidsAverage = getBidEvaluation(negotiationSession.getOpponentBidHistory().getLastBidDetails().getBid());
|
---|
| 161 | return 0.5;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | double newLastBidsAverage = negotiationSession.getOpponentBidHistory()
|
---|
| 165 | .filterBetweenTime(lastSteptime, this.negotiationSession.getTime()).getHistory().stream().mapToDouble(a -> getBidEvaluation(a.getBid())).average().orElse(0.0);
|
---|
| 166 |
|
---|
| 167 | double opponentSentiment = (newLastBidsAverage - lastStepBidsAverage);
|
---|
| 168 | //Update last step average
|
---|
| 169 | lastStepBidsAverage = newLastBidsAverage;
|
---|
| 170 | if(opponentSentiment < 0) {
|
---|
| 171 | return opponentSentiment - 0.5;
|
---|
| 172 | }else if(opponentSentiment > 0) {
|
---|
| 173 | return opponentSentiment + 0.5;
|
---|
| 174 | }else {
|
---|
| 175 | return 0;
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | /**
|
---|
| 180 | * Counts the amount of different bids offered by the opponent to determine whether he is following a hard headed strategy
|
---|
| 181 | * @return hard headed status of the opponent
|
---|
| 182 | */
|
---|
| 183 | public boolean isHardHeaded() {
|
---|
| 184 | BidHistory hist = negotiationSession.getOpponentBidHistory();
|
---|
| 185 | int diffBids = 0;
|
---|
| 186 | ArrayList seenBids = new ArrayList<Bid>();
|
---|
| 187 | for(BidDetails b : hist.getHistory()) {
|
---|
| 188 | Bid bid = b.getBid();
|
---|
| 189 | if(!seenBids.contains(bid)) {
|
---|
| 190 | seenBids.add(bid);
|
---|
| 191 | diffBids++;
|
---|
| 192 | }
|
---|
| 193 | }
|
---|
| 194 | if(diffBids > 3) {
|
---|
| 195 | return false;
|
---|
| 196 | }
|
---|
| 197 | return true;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | }
|
---|