source: src/main/java/agents/anac/y2018/fullagent/OpponentModel_lgsmi.java@ 341

Last change on this file since 341 was 341, checked in by Katsuhide Fujita, 5 years ago

Katsuhide Fujita added ANAC2018 agents.

File size: 7.9 KB
Line 
1
2package agents.anac.y2018.fullagent;
3
4import java.util.HashMap;
5import java.util.HashSet;
6import java.util.Map;
7import java.util.Map.Entry;
8import java.util.Set;
9
10
11import com.sun.xml.internal.bind.api.impl.NameConverter;
12import flanagan.math.Matrix;
13
14import negotiator.Bid;
15import negotiator.bidding.BidDetails;
16import negotiator.boaframework.BOAparameter;
17import negotiator.boaframework.NegotiationSession;
18import negotiator.boaframework.OpponentModel;
19import negotiator.issue.Issue;
20import negotiator.issue.IssueDiscrete;
21import negotiator.issue.Objective;
22import negotiator.issue.ValueDiscrete;
23
24
25import negotiator.persistent.DefaultStandardInfo;
26import negotiator.persistent.StandardInfo;
27
28import negotiator.utility.AdditiveUtilitySpace;
29import negotiator.utility.Evaluator;
30import negotiator.utility.EvaluatorDiscrete;
31
32/**
33 * BOA framework implementation of the HardHeaded Frequecy Model. My main
34 * contribution to this model is that I fixed a bug in the mainbranch which
35 * resulted in an equal preference of each bid in the ANAC 2011 competition.
36 * Effectively, the corrupt model resulted in the offering of a random bid in
37 * the ANAC 2011.
38 *
39 * Default: learning coef l = 0.2; learnValueAddition v = 1.0
40 *
41 * Adapted by Mark Hendrikx to be compatible with the BOA framework.
42 *
43 * Tim Baarslag, Koen Hindriks, Mark Hendrikx, Alex Dirkzwager and Catholijn M.
44 * Jonker. Decoupling Negotiating Agents to Explore the Space of Negotiation
45 * Strategies
46 *
47 *
48 */
49public class OpponentModel_lgsmi extends OpponentModel {
50
51
52 // the learning coefficient is the weight that is added each turn to the
53 // issue weights
54 // which changed. It's a trade-off between concession speed and accuracy.
55
56 /*********** can be reduced over time for giving less importance to later bids *******/
57 private double learnCoef;
58 // value which is added to a value if it is found. Determines how fast
59 // the value weights converge.
60 /*********************** can be reduced over time for giving less importance to later bids *********************/
61 private int learnValueAddition;
62
63 private int amountOfIssues;
64
65 /**
66 * Initializes the utility space of the opponent such that all value issue
67 * weights are equal.
68 */
69 @Override
70 public void init(NegotiationSession negotiationSession, Map<String, Double> parameters) {
71 super.init(negotiationSession, parameters);
72 this.negotiationSession = negotiationSession;
73 if (parameters != null && parameters.get("l") != null) {
74 learnCoef = parameters.get("l");
75 } else {
76 learnCoef = 0.2;
77 }
78 learnValueAddition = 1;
79 initializeModel();
80 }
81
82 private void initializeModel() {
83 opponentUtilitySpace = new AdditiveUtilitySpace(negotiationSession.getDomain());
84 amountOfIssues = opponentUtilitySpace.getDomain().getIssues().size();
85 double commonWeight = 1D / (double) amountOfIssues;
86
87 // initialize the weights
88 for (Entry<Objective, Evaluator> e : opponentUtilitySpace.getEvaluators()) {
89 // set the issue weights
90 opponentUtilitySpace.unlock(e.getKey());
91 e.getValue().setWeight(commonWeight);
92 try {
93 // set all value weights to one (they are normalized when
94 // calculating the utility)
95 for (ValueDiscrete vd : ((IssueDiscrete) e.getKey()).getValues())
96 ((EvaluatorDiscrete) e.getValue()).setEvaluation(vd, 1);
97 } catch (Exception ex) {
98 ex.printStackTrace();
99 }
100 }
101 }
102
103 /**
104 * Determines the difference between bids. For each issue, it is determined
105 * if the value changed. If this is the case, a 1 is stored in a hashmap for
106 * that issue, else a 0.
107 *
108 * @param first
109 * bid of the opponent
110 * @param second
111 * bid
112 * @return
113 */
114 private HashMap<Integer, Integer> determineDifference(BidDetails first, BidDetails second) {
115
116 HashMap<Integer, Integer> diff = new HashMap<Integer, Integer>();
117 try {
118 for (Issue i : opponentUtilitySpace.getDomain().getIssues()) {
119 diff.put(i.getNumber(), (((ValueDiscrete) first.getBid().getValue(i.getNumber()))
120 .equals((ValueDiscrete) second.getBid().getValue(i.getNumber()))) ? 0 : 1);
121 }
122 } catch (Exception ex) {
123 ex.printStackTrace();
124 }
125
126 return diff;
127 }
128
129 /**
130 * Updates the opponent model given a bid.
131 */
132 @Override
133 public void updateModel(Bid opponentBid, double time) {
134 if (negotiationSession.getOpponentBidHistory().size() < 2) {
135 return;
136 }
137 int numberOfUnchanged = 0;
138 BidDetails oppBid = negotiationSession.getOpponentBidHistory().getHistory()
139 .get(negotiationSession.getOpponentBidHistory().size() - 1);
140 BidDetails prevOppBid = negotiationSession.getOpponentBidHistory().getHistory()
141 .get(negotiationSession.getOpponentBidHistory().size() - 2);
142 HashMap<Integer, Integer> lastDiffSet = determineDifference(prevOppBid, oppBid);
143
144 // count the number of changes in value
145 for (Integer i : lastDiffSet.keySet()) {
146 if (lastDiffSet.get(i) == 0)
147 numberOfUnchanged++;
148 }
149
150 // This is the value to be added to weights of unchanged issues before
151 // normalization.
152 // Also the value that is taken as the minimum possible weight,
153 // (therefore defining the maximum possible also).
154
155 // the proportion given to last bid
156 double goldenValue = learnCoef / (double) amountOfIssues;
157 // The total sum of weights before normalization.
158 double totalSum = 1D + goldenValue * (double) numberOfUnchanged;
159 // The maximum possible weight
160 double maximumWeight = 1D - ((double) amountOfIssues) * goldenValue / totalSum;
161
162 // re-weighing issues while making sure that the sum remains 1
163 for (Integer i : lastDiffSet.keySet()) {
164
165 //if issue's value unchanged and the weight of the issue is smaller then maximumWeight
166 if (lastDiffSet.get(i) == 0 && opponentUtilitySpace.getWeight(i) < maximumWeight)
167 //if the new weight is legal, set the weight for this issue
168 opponentUtilitySpace.setWeight(opponentUtilitySpace.getDomain().getObjectives().get(i),
169 (opponentUtilitySpace.getWeight(i) + goldenValue) / totalSum);
170 else
171 // the assumption is that values that have been changed are values that the
172 // opponent is willing to compromise on them, so we reduce their weight
173 opponentUtilitySpace.setWeight(opponentUtilitySpace.getDomain().getObjectives().get(i),
174 opponentUtilitySpace.getWeight(i) / totalSum);
175 }
176
177 // Then for each issue's value that has been offered last time, a constant
178
179 // value is added to its corresponding ValueDiscrete.
180 try {
181 for (Entry<Objective, Evaluator> e : opponentUtilitySpace.getEvaluators()) {
182 // cast issue to discrete and retrieve value. Next, add constant
183 // learnValueAddition to the current preference of the value to
184
185 // make it more important
186
187 ((EvaluatorDiscrete) e.getValue()).setEvaluation(
188 oppBid.getBid().getValue(((IssueDiscrete) e.getKey()).getNumber()),
189 (learnValueAddition + ((EvaluatorDiscrete) e.getValue()).getEvaluationNotNormalized(
190 ((ValueDiscrete) oppBid.getBid().getValue(((IssueDiscrete) e.getKey()).getNumber())))));
191 }
192 } catch (Exception ex) {
193 ex.printStackTrace();
194 }
195 }
196
197 @Override
198 public double getBidEvaluation(Bid bid) {
199 double result = 0;
200 try {
201 result = opponentUtilitySpace.getUtility(bid);
202 } catch (Exception e) {
203 e.printStackTrace();
204 }
205 return result;
206 }
207
208 @Override
209 public String getName() {
210
211 return "OpponentModel_lgsmi";
212
213 }
214
215 @Override
216 public Set<BOAparameter> getParameterSpec() {
217 Set<BOAparameter> set = new HashSet<BOAparameter>();
218 set.add(new BOAparameter("l", 0.2,
219 "The learning coefficient determines how quickly the issue weights are learned"));
220 return set;
221 }
222
223
224 public Map<String, Double> getParameters() {
225 Map<String, Double> map = new HashMap<String, Double>();
226 //The learning coefficient determines how quickly the issue weights are learned
227 map.put("l", 0.2);
228 return map;
229 }
230
231}
Note: See TracBrowser for help on using the repository browser.