1 | package negotiator.boaframework.opponentmodel;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.HashSet;
|
---|
5 | import java.util.Map;
|
---|
6 | import java.util.Set;
|
---|
7 |
|
---|
8 | import agents.bayesianopponentmodel.EvaluatorHypothesis;
|
---|
9 | import agents.bayesianopponentmodel.Hypothesis;
|
---|
10 | import genius.core.Bid;
|
---|
11 | import genius.core.Domain;
|
---|
12 | import genius.core.boaframework.BOAparameter;
|
---|
13 | import genius.core.boaframework.NegotiationSession;
|
---|
14 | import genius.core.boaframework.OpponentModel;
|
---|
15 | import genius.core.issue.Issue;
|
---|
16 | import genius.core.issue.IssueDiscrete;
|
---|
17 | import genius.core.issue.IssueInteger;
|
---|
18 | import genius.core.issue.IssueReal;
|
---|
19 | import genius.core.issue.ValueDiscrete;
|
---|
20 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
21 | import genius.core.utility.EVALFUNCTYPE;
|
---|
22 | import genius.core.utility.Evaluator;
|
---|
23 | import genius.core.utility.EvaluatorDiscrete;
|
---|
24 | import genius.core.utility.EvaluatorInteger;
|
---|
25 | import genius.core.utility.EvaluatorReal;
|
---|
26 | import negotiator.boaframework.opponentmodel.iamhaggler.TimeConcessionFunction;
|
---|
27 | import negotiator.boaframework.opponentmodel.iamhaggler.WeightHypothesis;
|
---|
28 | import negotiator.boaframework.opponentmodel.tools.UtilitySpaceAdapter;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * IAMhagglerModel by Colin Williams, adapted for the BOA framework.
|
---|
32 | *
|
---|
33 | * Tim Baarslag, Koen Hindriks, Mark Hendrikx, Alex Dirkzwager and Catholijn M.
|
---|
34 | * Jonker. Decoupling Negotiating Agents to Explore the Space of Negotiation
|
---|
35 | * Strategies
|
---|
36 | *
|
---|
37 | * @author Colin Williams, Mark Hendrikx
|
---|
38 | */
|
---|
39 | public class IAMhagglerBayesianModel extends OpponentModel {
|
---|
40 | private ArrayList<Bid> biddingHistory;
|
---|
41 | private ArrayList<ArrayList<EvaluatorHypothesis>> evaluatorHypotheses;
|
---|
42 | private ArrayList<ArrayList<WeightHypothesis>> weightHypotheses;
|
---|
43 | private double previousBidUtility;
|
---|
44 | private Double maxUtility;
|
---|
45 | private Double minUtility;
|
---|
46 | private double[] expectedWeights;
|
---|
47 | private double SIGMA = 0.25;
|
---|
48 | private final int totalTriangularFunctions = 4;
|
---|
49 | private TimeConcessionFunction opponentConcessionFunction;
|
---|
50 | private Domain domain;
|
---|
51 | private AdditiveUtilitySpace utilitySpace;
|
---|
52 | private boolean useAll = false;
|
---|
53 | private int startingBidIssue = 0;
|
---|
54 |
|
---|
55 | // ADD PARAM TO USE ALL BIDS (default false)
|
---|
56 | // ADD TO SET BETA (default 1.0) b
|
---|
57 | // For IAH TNR true and 0.3
|
---|
58 |
|
---|
59 | @Override
|
---|
60 | public void init(NegotiationSession negotiationSession, Map<String, Double> parameters) {
|
---|
61 | this.negotiationSession = negotiationSession;
|
---|
62 | double beta = 1.0;
|
---|
63 | if (parameters != null && parameters.containsKey("b")) {
|
---|
64 | beta = parameters.get("b");
|
---|
65 | }
|
---|
66 | if (parameters != null && parameters.containsKey("u") && parameters.get("u") > 0.0) {
|
---|
67 | useAll = true;
|
---|
68 | }
|
---|
69 | opponentConcessionFunction = new TimeConcessionFunction(beta, TimeConcessionFunction.BREAKOFF);
|
---|
70 | previousBidUtility = 1;
|
---|
71 | weightHypotheses = new ArrayList<ArrayList<WeightHypothesis>>();
|
---|
72 | evaluatorHypotheses = new ArrayList<ArrayList<EvaluatorHypothesis>>();
|
---|
73 | this.domain = negotiationSession.getUtilitySpace().getDomain();
|
---|
74 | this.utilitySpace = (AdditiveUtilitySpace) negotiationSession.getUtilitySpace();
|
---|
75 | expectedWeights = new double[domain.getIssues().size()];
|
---|
76 | biddingHistory = new ArrayList<Bid>();
|
---|
77 |
|
---|
78 | while (!testIndexOfFirstIssue(negotiationSession.getUtilitySpace().getDomain().getRandomBid(null),
|
---|
79 | startingBidIssue)) {
|
---|
80 | startingBidIssue++;
|
---|
81 | }
|
---|
82 |
|
---|
83 | initWeightHypotheses();
|
---|
84 | initEvaluatorHypotheses();
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Just an auxiliary function to calculate the index where issues start on a
|
---|
89 | * bid because we found out that it depends on the domain.
|
---|
90 | *
|
---|
91 | * @return true when the received index is the proper index
|
---|
92 | */
|
---|
93 | private boolean testIndexOfFirstIssue(Bid bid, int i) {
|
---|
94 | try {
|
---|
95 | @SuppressWarnings("unused")
|
---|
96 | ValueDiscrete valueOfIssue = (ValueDiscrete) bid.getValue(i);
|
---|
97 | } catch (Exception e) {
|
---|
98 | return false;
|
---|
99 | }
|
---|
100 | return true;
|
---|
101 | }
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * Initialise the weight hypotheses.
|
---|
105 | */
|
---|
106 | private void initWeightHypotheses() {
|
---|
107 | int weightHypothesesNumber = 11;
|
---|
108 | for (int i = 0; i < domain.getIssues().size(); ++i) {
|
---|
109 | ArrayList<WeightHypothesis> weightHypothesis = new ArrayList<WeightHypothesis>();
|
---|
110 | for (int j = 0; j < weightHypothesesNumber; ++j) {
|
---|
111 | WeightHypothesis weight = new WeightHypothesis();
|
---|
112 | weight.setProbability((1.0 - (((double) j + 1.0) / weightHypothesesNumber))
|
---|
113 | * (1.0 - (((double) j + 1.0) / weightHypothesesNumber))
|
---|
114 | * (1.0 - (((double) j + 1.0D) / weightHypothesesNumber)));
|
---|
115 | weight.setWeight((double) j / (weightHypothesesNumber - 1));
|
---|
116 | weightHypothesis.add(weight);
|
---|
117 | }
|
---|
118 |
|
---|
119 | // Normalization
|
---|
120 | double n = 0.0D;
|
---|
121 | for (int j = 0; j < weightHypothesesNumber; ++j) {
|
---|
122 | n += weightHypothesis.get(j).getProbability();
|
---|
123 | }
|
---|
124 | for (int j = 0; j < weightHypothesesNumber; ++j) {
|
---|
125 | weightHypothesis.get(j).setProbability(weightHypothesis.get(j).getProbability() / n);
|
---|
126 | }
|
---|
127 |
|
---|
128 | weightHypotheses.add(weightHypothesis);
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Initialize the evaluator hypotheses.
|
---|
134 | */
|
---|
135 | private void initEvaluatorHypotheses() {
|
---|
136 | evaluatorHypotheses = new ArrayList<ArrayList<EvaluatorHypothesis>>();
|
---|
137 | for (int i = 0; i < utilitySpace.getNrOfEvaluators(); ++i) {
|
---|
138 | ArrayList<EvaluatorHypothesis> lEvalHyps;
|
---|
139 | EvaluatorReal lHypEvalReal;
|
---|
140 | EvaluatorInteger lHypEvalInteger;
|
---|
141 | EvaluatorHypothesis lEvaluatorHypothesis;
|
---|
142 | switch (utilitySpace.getEvaluator(utilitySpace.getIssue(i).getNumber()).getType()) {
|
---|
143 |
|
---|
144 | case REAL: {
|
---|
145 | lEvalHyps = new ArrayList<EvaluatorHypothesis>();
|
---|
146 | evaluatorHypotheses.add(lEvalHyps);
|
---|
147 |
|
---|
148 | IssueReal lIssue = (IssueReal) utilitySpace.getIssue(i);
|
---|
149 |
|
---|
150 | /* Uphill */
|
---|
151 | lHypEvalReal = new EvaluatorReal();
|
---|
152 | lHypEvalReal.setUpperBound(lIssue.getUpperBound());
|
---|
153 | lHypEvalReal.setLowerBound(lIssue.getLowerBound());
|
---|
154 | lHypEvalReal.setType(EVALFUNCTYPE.LINEAR);
|
---|
155 | lHypEvalReal.addParam(1, 1.0 / (lHypEvalReal.getUpperBound() - lHypEvalReal.getLowerBound()));
|
---|
156 | lHypEvalReal.addParam(0,
|
---|
157 | -lHypEvalReal.getLowerBound() / (lHypEvalReal.getUpperBound() - lHypEvalReal.getLowerBound()));
|
---|
158 | lEvaluatorHypothesis = new EvaluatorHypothesis(lHypEvalReal);
|
---|
159 | lEvaluatorHypothesis.setDesc("uphill");
|
---|
160 | lEvalHyps.add(lEvaluatorHypothesis);
|
---|
161 |
|
---|
162 | /* Triangular */
|
---|
163 | for (int k = 1; k <= totalTriangularFunctions; ++k) {
|
---|
164 | lHypEvalReal = new EvaluatorReal();
|
---|
165 | lHypEvalReal.setUpperBound(lIssue.getUpperBound());
|
---|
166 | lHypEvalReal.setLowerBound(lIssue.getLowerBound());
|
---|
167 | lHypEvalReal.setType(EVALFUNCTYPE.TRIANGULAR);
|
---|
168 | lHypEvalReal.addParam(0, lHypEvalReal.getLowerBound());
|
---|
169 | lHypEvalReal.addParam(1, lHypEvalReal.getUpperBound());
|
---|
170 | double lMaxPoint = lHypEvalReal.getLowerBound()
|
---|
171 | + (double) k * (lHypEvalReal.getUpperBound() - lHypEvalReal.getLowerBound())
|
---|
172 | / (totalTriangularFunctions + 1);
|
---|
173 | lHypEvalReal.addParam(2, lMaxPoint);
|
---|
174 | lEvaluatorHypothesis = new EvaluatorHypothesis(lHypEvalReal);
|
---|
175 | lEvalHyps.add(lEvaluatorHypothesis);
|
---|
176 | lEvaluatorHypothesis.setDesc("triangular " + String.format("%1.2f", lMaxPoint));
|
---|
177 | }
|
---|
178 |
|
---|
179 | /* Downhill */
|
---|
180 | lHypEvalReal = new EvaluatorReal();
|
---|
181 | lHypEvalReal.setUpperBound(lIssue.getUpperBound());
|
---|
182 | lHypEvalReal.setLowerBound(lIssue.getLowerBound());
|
---|
183 | lHypEvalReal.setType(EVALFUNCTYPE.LINEAR);
|
---|
184 | lHypEvalReal.addParam(1, -1.0 / (lHypEvalReal.getUpperBound() - lHypEvalReal.getLowerBound()));
|
---|
185 | lHypEvalReal.addParam(0, 1.0
|
---|
186 | + lHypEvalReal.getLowerBound() / (lHypEvalReal.getUpperBound() - lHypEvalReal.getLowerBound()));
|
---|
187 | lEvaluatorHypothesis = new EvaluatorHypothesis(lHypEvalReal);
|
---|
188 | lEvaluatorHypothesis.setDesc("downhill");
|
---|
189 | lEvalHyps.add(lEvaluatorHypothesis);
|
---|
190 |
|
---|
191 | for (int k = 0; k < lEvalHyps.size(); ++k) {
|
---|
192 | lEvalHyps.get(k).setProbability(1.0 / lEvalHyps.size());
|
---|
193 | }
|
---|
194 |
|
---|
195 | break;
|
---|
196 | }
|
---|
197 | case INTEGER: {
|
---|
198 | lEvalHyps = new ArrayList<EvaluatorHypothesis>();
|
---|
199 | evaluatorHypotheses.add(lEvalHyps);
|
---|
200 |
|
---|
201 | IssueInteger lIssue = (IssueInteger) utilitySpace.getIssue(i);
|
---|
202 |
|
---|
203 | /* Uphill */
|
---|
204 | lHypEvalInteger = new EvaluatorInteger();
|
---|
205 | lHypEvalInteger.setUpperBound(lIssue.getUpperBound());
|
---|
206 | lHypEvalInteger.setLowerBound(lIssue.getLowerBound());
|
---|
207 | lHypEvalInteger.setOffset(-lHypEvalInteger.getLowerBound()
|
---|
208 | / (lHypEvalInteger.getUpperBound() - lHypEvalInteger.getLowerBound()));
|
---|
209 | lHypEvalInteger.setSlope(1.0 / (lHypEvalInteger.getUpperBound() - lHypEvalInteger.getLowerBound()));
|
---|
210 | lEvaluatorHypothesis = new EvaluatorHypothesis(lHypEvalInteger);
|
---|
211 | lEvaluatorHypothesis.setDesc("uphill");
|
---|
212 | lEvalHyps.add(lEvaluatorHypothesis);
|
---|
213 |
|
---|
214 | /* Downhill */
|
---|
215 | lHypEvalInteger = new EvaluatorInteger();
|
---|
216 | lHypEvalInteger.setUpperBound(lIssue.getUpperBound());
|
---|
217 | lHypEvalInteger.setLowerBound(lIssue.getLowerBound());
|
---|
218 | lHypEvalInteger.setOffset(1.0 + lHypEvalInteger.getLowerBound()
|
---|
219 | / (lHypEvalInteger.getUpperBound() - lHypEvalInteger.getLowerBound()));
|
---|
220 | lHypEvalInteger.setSlope(-1.0 / (lHypEvalInteger.getUpperBound() - lHypEvalInteger.getLowerBound()));
|
---|
221 | lEvaluatorHypothesis = new EvaluatorHypothesis(lHypEvalInteger);
|
---|
222 | lEvaluatorHypothesis.setDesc("downhill");
|
---|
223 | lEvalHyps.add(lEvaluatorHypothesis);
|
---|
224 |
|
---|
225 | for (int k = 0; k < lEvalHyps.size(); ++k) {
|
---|
226 | lEvalHyps.get(k).setProbability(1.0 / lEvalHyps.size());
|
---|
227 | }
|
---|
228 |
|
---|
229 | break;
|
---|
230 | }
|
---|
231 | case DISCRETE: {
|
---|
232 | lEvalHyps = new ArrayList<EvaluatorHypothesis>();
|
---|
233 | evaluatorHypotheses.add(lEvalHyps);
|
---|
234 |
|
---|
235 | IssueDiscrete lDiscIssue = (IssueDiscrete) utilitySpace.getIssue(i);
|
---|
236 |
|
---|
237 | /* Uphill */
|
---|
238 | EvaluatorDiscrete lDiscreteEval = new EvaluatorDiscrete();
|
---|
239 | for (int j = 0; j < lDiscIssue.getNumberOfValues(); ++j)
|
---|
240 | lDiscreteEval.addEvaluation(lDiscIssue.getValue(j), Integer.valueOf(1000 * j + 1));
|
---|
241 | lEvaluatorHypothesis = new EvaluatorHypothesis(lDiscreteEval);
|
---|
242 | lEvaluatorHypothesis.setDesc("uphill");
|
---|
243 | lEvalHyps.add(lEvaluatorHypothesis);
|
---|
244 |
|
---|
245 | /* Triangular */
|
---|
246 | if (lDiscIssue.getNumberOfValues() > 2) {
|
---|
247 | for (int k = 1; k < lDiscIssue.getNumberOfValues() - 1; ++k) {
|
---|
248 | lDiscreteEval = new EvaluatorDiscrete();
|
---|
249 | for (int j = 0; j < lDiscIssue.getNumberOfValues(); ++j) {
|
---|
250 | if (j < k) {
|
---|
251 | lDiscreteEval.addEvaluation(lDiscIssue.getValue(j), 1000 * j / k);
|
---|
252 | } else
|
---|
253 | lDiscreteEval.addEvaluation(lDiscIssue.getValue(j),
|
---|
254 | 1000 * (lDiscIssue.getNumberOfValues() - j
|
---|
255 | - 1 / (lDiscIssue.getNumberOfValues() - k - 1) + 1));
|
---|
256 | }
|
---|
257 | lEvaluatorHypothesis = new EvaluatorHypothesis(lDiscreteEval);
|
---|
258 | lEvalHyps.add(lEvaluatorHypothesis);
|
---|
259 | lEvaluatorHypothesis.setDesc("triangular " + String.valueOf(k));
|
---|
260 | }
|
---|
261 | }
|
---|
262 |
|
---|
263 | /* Downhill */
|
---|
264 | lDiscreteEval = new EvaluatorDiscrete();
|
---|
265 | for (int j = 0; j < lDiscIssue.getNumberOfValues(); ++j)
|
---|
266 | lDiscreteEval.addEvaluation(lDiscIssue.getValue(j),
|
---|
267 | Integer.valueOf(1000 * (lDiscIssue.getNumberOfValues() - j - 1) + 1));
|
---|
268 | lEvaluatorHypothesis = new EvaluatorHypothesis(lDiscreteEval);
|
---|
269 | lEvaluatorHypothesis.setDesc("downhill");
|
---|
270 | lEvalHyps.add(lEvaluatorHypothesis);
|
---|
271 |
|
---|
272 | for (int k = 0; k < lEvalHyps.size(); ++k) {
|
---|
273 | lEvalHyps.get(k).setProbability(1.0 / lEvalHyps.size());
|
---|
274 | }
|
---|
275 |
|
---|
276 | break;
|
---|
277 | }
|
---|
278 | }
|
---|
279 | }
|
---|
280 |
|
---|
281 | for (int i = 0; i < expectedWeights.length; ++i)
|
---|
282 | expectedWeights[i] = getExpectedWeight(i);
|
---|
283 |
|
---|
284 | normalize(expectedWeights);
|
---|
285 | }
|
---|
286 |
|
---|
287 | @Override
|
---|
288 | public double getBidEvaluation(Bid bid) {
|
---|
289 | try {
|
---|
290 | return getNormalizedUtility(bid);
|
---|
291 | } catch (Exception e) {
|
---|
292 | e.printStackTrace();
|
---|
293 | }
|
---|
294 | return 0;
|
---|
295 | }
|
---|
296 |
|
---|
297 | /**
|
---|
298 | * Get the normalised utility of a bid.
|
---|
299 | *
|
---|
300 | * @param bid
|
---|
301 | * The bid to get the normalised utility of.
|
---|
302 | * @return the normalised utility of a bid.
|
---|
303 | * @throws Exception
|
---|
304 | */
|
---|
305 | public double getNormalizedUtility(Bid bid) throws Exception {
|
---|
306 | return getNormalizedUtility(bid, false);
|
---|
307 | }
|
---|
308 |
|
---|
309 | /**
|
---|
310 | * Get the normalised utility of a bid.
|
---|
311 | *
|
---|
312 | * @param bid
|
---|
313 | * The bid to get the normalised utility of.
|
---|
314 | * @param debug
|
---|
315 | * Whether or not to output debugging information
|
---|
316 | * @return the normalised utility of a bid.
|
---|
317 | * @throws Exception
|
---|
318 | */
|
---|
319 | public double getNormalizedUtility(Bid bid, boolean debug) throws Exception {
|
---|
320 | double u = getExpectedUtility(bid);
|
---|
321 | if (minUtility == null || maxUtility == null)
|
---|
322 | findMinMaxUtility();
|
---|
323 | if (Double.isNaN(u)) {
|
---|
324 | return 0.0;
|
---|
325 | }
|
---|
326 | return (u - minUtility) / (maxUtility - minUtility);
|
---|
327 | }
|
---|
328 |
|
---|
329 | /**
|
---|
330 | * Get the expected utility of a bid.
|
---|
331 | *
|
---|
332 | * @param bid
|
---|
333 | * The bid to get the expected utility of.
|
---|
334 | * @return the expected utility of the bid.
|
---|
335 | * @throws Exception
|
---|
336 | */
|
---|
337 | public double getExpectedUtility(Bid bid) throws Exception {
|
---|
338 | double u = 0;
|
---|
339 | for (int i = 0; i < domain.getIssues().size(); i++) {
|
---|
340 | u += expectedWeights[i] * getExpectedEvaluationValue(bid, i);
|
---|
341 | }
|
---|
342 | return u;
|
---|
343 | }
|
---|
344 |
|
---|
345 | /**
|
---|
346 | * Update the beliefs about the opponent, based on an observation.
|
---|
347 | *
|
---|
348 | * @param opponentBid
|
---|
349 | * The opponent's bid that was observed.
|
---|
350 | * @throws Exception
|
---|
351 | */
|
---|
352 | public void updateModel(Bid opponentBid, double time) {
|
---|
353 | if (!useAll) {
|
---|
354 | if (biddingHistory.contains(opponentBid))
|
---|
355 | return;
|
---|
356 | }
|
---|
357 | biddingHistory.add(opponentBid);
|
---|
358 |
|
---|
359 | if (biddingHistory.size() > 1) {
|
---|
360 | try {
|
---|
361 | updateWeights();
|
---|
362 | } catch (Exception e) {
|
---|
363 | e.printStackTrace();
|
---|
364 | }
|
---|
365 | }
|
---|
366 | try {
|
---|
367 | updateEvaluationFunctions();
|
---|
368 | } catch (Exception e) {
|
---|
369 | e.printStackTrace();
|
---|
370 | }
|
---|
371 | previousBidUtility = opponentConcessionFunction.getConcession(1, time, 1.0);
|
---|
372 |
|
---|
373 | for (int i = 0; i < expectedWeights.length; ++i)
|
---|
374 | expectedWeights[i] = getExpectedWeight(i);
|
---|
375 |
|
---|
376 | normalize(expectedWeights);
|
---|
377 |
|
---|
378 | try {
|
---|
379 | findMinMaxUtility();
|
---|
380 | } catch (Exception e) {
|
---|
381 | e.printStackTrace();
|
---|
382 | }
|
---|
383 |
|
---|
384 | }
|
---|
385 |
|
---|
386 | /**
|
---|
387 | * Normalise the values in an array so that they sum to 1.
|
---|
388 | *
|
---|
389 | * @param array
|
---|
390 | * The array to normalise;
|
---|
391 | */
|
---|
392 | private void normalize(double[] array) {
|
---|
393 | double n = 0;
|
---|
394 | for (int i = 0; i < array.length; ++i) {
|
---|
395 | n += array[i];
|
---|
396 | }
|
---|
397 | if (n == 0) {
|
---|
398 | for (int i = 0; i < array.length; ++i) {
|
---|
399 | array[i] = 1.0 / array.length;
|
---|
400 | }
|
---|
401 | return;
|
---|
402 | }
|
---|
403 |
|
---|
404 | for (int i = 0; i < array.length; ++i) {
|
---|
405 | array[i] = array[i] / n;
|
---|
406 | }
|
---|
407 | }
|
---|
408 |
|
---|
409 | /**
|
---|
410 | * Find the minimum and maximum utilities of the bids in the utility space.
|
---|
411 | *
|
---|
412 | * @throws Exception
|
---|
413 | */
|
---|
414 | protected void findMinMaxUtility() throws Exception {
|
---|
415 | maxUtility = getExtremeUtility(Extreme.MAX);
|
---|
416 | minUtility = getExtremeUtility(Extreme.MIN);
|
---|
417 | }
|
---|
418 |
|
---|
419 | public double getWeight(Issue issue) {
|
---|
420 | return getExpectedWeight(issue.getNumber() - startingBidIssue);
|
---|
421 | }
|
---|
422 |
|
---|
423 | public enum Extreme {
|
---|
424 | MIN, MAX
|
---|
425 | }
|
---|
426 |
|
---|
427 | private double getExtremeUtility(Extreme extreme) {
|
---|
428 | double u = 0;
|
---|
429 | for (int i = 0; i < domain.getIssues().size(); i++) {
|
---|
430 | u += expectedWeights[i] * getExtremeEvaluationValue(i, extreme);
|
---|
431 | }
|
---|
432 | return u;
|
---|
433 | }
|
---|
434 |
|
---|
435 | private double getExtremeEvaluationValue(int number, Extreme extreme) {
|
---|
436 | double expectedEval = 0;
|
---|
437 | for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(number)) {
|
---|
438 | expectedEval += evaluatorHypothesis.getProbability()
|
---|
439 | * getExtremeEvaluation(evaluatorHypothesis.getEvaluator(), extreme);
|
---|
440 | }
|
---|
441 | return expectedEval;
|
---|
442 | }
|
---|
443 |
|
---|
444 | public double getExtremeEvaluation(Evaluator evaluator, Extreme extreme) {
|
---|
445 | double extremeEval = initExtreme(extreme);
|
---|
446 | switch (evaluator.getType()) {
|
---|
447 | case DISCRETE:
|
---|
448 | EvaluatorDiscrete discreteEvaluator = (EvaluatorDiscrete) evaluator;
|
---|
449 | for (ValueDiscrete value : discreteEvaluator.getValues()) {
|
---|
450 | try {
|
---|
451 | switch (extreme) {
|
---|
452 | case MAX:
|
---|
453 | extremeEval = Math.max(extremeEval, discreteEvaluator.getEvaluation(value));
|
---|
454 | break;
|
---|
455 | case MIN:
|
---|
456 | extremeEval = Math.min(extremeEval, discreteEvaluator.getEvaluation(value));
|
---|
457 | break;
|
---|
458 | }
|
---|
459 | } catch (Exception e) {
|
---|
460 | e.printStackTrace();
|
---|
461 | }
|
---|
462 | }
|
---|
463 | break;
|
---|
464 | case INTEGER:
|
---|
465 | EvaluatorInteger integerEvaluator = (EvaluatorInteger) evaluator;
|
---|
466 | switch (extreme) {
|
---|
467 | case MAX:
|
---|
468 | extremeEval = Math.max(integerEvaluator.getEvaluation(integerEvaluator.getUpperBound()),
|
---|
469 | integerEvaluator.getEvaluation(integerEvaluator.getLowerBound()));
|
---|
470 | break;
|
---|
471 | case MIN:
|
---|
472 | extremeEval = Math.min(integerEvaluator.getEvaluation(integerEvaluator.getUpperBound()),
|
---|
473 | integerEvaluator.getEvaluation(integerEvaluator.getLowerBound()));
|
---|
474 | break;
|
---|
475 | }
|
---|
476 | break;
|
---|
477 | case REAL:
|
---|
478 | EvaluatorReal realEvaluator = (EvaluatorReal) evaluator;
|
---|
479 | switch (extreme) {
|
---|
480 | case MAX:
|
---|
481 | extremeEval = Math.max(realEvaluator.getEvaluation(realEvaluator.getUpperBound()),
|
---|
482 | realEvaluator.getEvaluation(realEvaluator.getLowerBound()));
|
---|
483 | if (realEvaluator.getFuncType() == EVALFUNCTYPE.TRIANGULAR) {
|
---|
484 | extremeEval = Math.max(extremeEval, realEvaluator.getEvaluation(realEvaluator.getTopParam()));
|
---|
485 | }
|
---|
486 | break;
|
---|
487 | case MIN:
|
---|
488 | extremeEval = Math.min(realEvaluator.getEvaluation(realEvaluator.getUpperBound()),
|
---|
489 | realEvaluator.getEvaluation(realEvaluator.getLowerBound()));
|
---|
490 | if (realEvaluator.getFuncType() == EVALFUNCTYPE.TRIANGULAR) {
|
---|
491 | extremeEval = Math.min(extremeEval, realEvaluator.getEvaluation(realEvaluator.getTopParam()));
|
---|
492 | }
|
---|
493 | break;
|
---|
494 | }
|
---|
495 | break;
|
---|
496 | }
|
---|
497 | return extremeEval;
|
---|
498 | }
|
---|
499 |
|
---|
500 | private double initExtreme(Extreme extreme) {
|
---|
501 | switch (extreme) {
|
---|
502 | case MAX:
|
---|
503 | return Double.MIN_VALUE;
|
---|
504 | case MIN:
|
---|
505 | return Double.MAX_VALUE;
|
---|
506 | }
|
---|
507 | return 0;
|
---|
508 | }
|
---|
509 |
|
---|
510 | /**
|
---|
511 | * Update the evaluation functions.
|
---|
512 | *
|
---|
513 | * @throws Exception
|
---|
514 | */
|
---|
515 | private void updateEvaluationFunctions() throws Exception {
|
---|
516 | maxUtility = null;
|
---|
517 | minUtility = null;
|
---|
518 |
|
---|
519 | Bid bid = biddingHistory.get(biddingHistory.size() - 1);
|
---|
520 | ArrayList<ArrayList<EvaluatorHypothesis>> evaluatorHypotheses = new ArrayList<ArrayList<EvaluatorHypothesis>>();
|
---|
521 |
|
---|
522 | for (int i = 0; i < this.evaluatorHypotheses.size(); ++i) {
|
---|
523 | ArrayList<EvaluatorHypothesis> tmp = new ArrayList<EvaluatorHypothesis>();
|
---|
524 | for (int j = 0; j < this.evaluatorHypotheses.get(i).size(); ++j) {
|
---|
525 | EvaluatorHypothesis evaluatorHypothesis = new EvaluatorHypothesis(
|
---|
526 | this.evaluatorHypotheses.get(i).get(j).getEvaluator());
|
---|
527 | evaluatorHypothesis.setDesc(this.evaluatorHypotheses.get(i).get(j).getDesc());
|
---|
528 | evaluatorHypothesis.setProbability(this.evaluatorHypotheses.get(i).get(j).getProbability());
|
---|
529 | tmp.add(evaluatorHypothesis);
|
---|
530 | }
|
---|
531 | evaluatorHypotheses.add(tmp);
|
---|
532 | }
|
---|
533 |
|
---|
534 | for (int i = 0; i < this.domain.getIssues().size(); i++) {
|
---|
535 | double n = 0.0D;
|
---|
536 | double utility = 0.0D;
|
---|
537 | for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(i)) {
|
---|
538 | utility = getPartialUtility(bid, i) + getExpectedWeight(i) * evaluatorHypothesis.getEvaluator()
|
---|
539 | .getEvaluation(utilitySpace, bid, utilitySpace.getIssue(i).getNumber());
|
---|
540 | n += evaluatorHypothesis.getProbability() * conditionalDistribution(utility, previousBidUtility);
|
---|
541 | }
|
---|
542 |
|
---|
543 | for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(i)) {
|
---|
544 | utility = getPartialUtility(bid, i) + getExpectedWeight(i) * evaluatorHypothesis.getEvaluator()
|
---|
545 | .getEvaluation(utilitySpace, bid, utilitySpace.getIssue(i).getNumber());
|
---|
546 | evaluatorHypothesis.setProbability(evaluatorHypothesis.getProbability()
|
---|
547 | * conditionalDistribution(utility, previousBidUtility) / n);
|
---|
548 | }
|
---|
549 | }
|
---|
550 |
|
---|
551 | this.evaluatorHypotheses = evaluatorHypotheses;
|
---|
552 | }
|
---|
553 |
|
---|
554 | /**
|
---|
555 | * Update the weights.
|
---|
556 | *
|
---|
557 | * @throws Exception
|
---|
558 | */
|
---|
559 | private void updateWeights() throws Exception {
|
---|
560 | maxUtility = null;
|
---|
561 | minUtility = null;
|
---|
562 |
|
---|
563 | Bid bid = biddingHistory.get(biddingHistory.size() - 1);
|
---|
564 | ArrayList<ArrayList<WeightHypothesis>> weightHypotheses = new ArrayList<ArrayList<WeightHypothesis>>();
|
---|
565 |
|
---|
566 | for (int i = 0; i < this.weightHypotheses.size(); ++i) {
|
---|
567 | ArrayList<WeightHypothesis> tmp = new ArrayList<WeightHypothesis>();
|
---|
568 | for (int j = 0; j < this.weightHypotheses.get(i).size(); ++j) {
|
---|
569 | WeightHypothesis weightHypothesis = new WeightHypothesis();
|
---|
570 | weightHypothesis.setWeight(this.weightHypotheses.get(i).get(j).getWeight());
|
---|
571 | weightHypothesis.setProbability(this.weightHypotheses.get(i).get(j).getProbability());
|
---|
572 | tmp.add(weightHypothesis);
|
---|
573 | }
|
---|
574 | weightHypotheses.add(tmp);
|
---|
575 | }
|
---|
576 |
|
---|
577 | for (int i = 0; i < domain.getIssues().size(); i++) {
|
---|
578 | double n = 0.0D;
|
---|
579 | double utility = 0.0D;
|
---|
580 | for (WeightHypothesis weightHypothesis : weightHypotheses.get(i)) {
|
---|
581 | utility = getPartialUtility(bid, i) + weightHypothesis.getWeight() * getExpectedEvaluationValue(bid, i);
|
---|
582 | n += weightHypothesis.getProbability() * conditionalDistribution(utility, previousBidUtility);
|
---|
583 | }
|
---|
584 |
|
---|
585 | for (WeightHypothesis weightHypothesis : weightHypotheses.get(i)) {
|
---|
586 | utility = getPartialUtility(bid, i) + weightHypothesis.getWeight() * getExpectedEvaluationValue(bid, i);
|
---|
587 | weightHypothesis.setProbability(
|
---|
588 | weightHypothesis.getProbability() * conditionalDistribution(utility, previousBidUtility) / n);
|
---|
589 | }
|
---|
590 | }
|
---|
591 |
|
---|
592 | this.weightHypotheses = weightHypotheses;
|
---|
593 |
|
---|
594 | }
|
---|
595 |
|
---|
596 | /**
|
---|
597 | * The conditional distribution function.
|
---|
598 | *
|
---|
599 | * @param utility
|
---|
600 | * The utility.
|
---|
601 | * @param previousBidUtility
|
---|
602 | * The utility of the previous bid.
|
---|
603 | * @return
|
---|
604 | */
|
---|
605 | private double conditionalDistribution(double utility, double previousBidUtility) {
|
---|
606 | double x = (previousBidUtility - utility) / previousBidUtility;
|
---|
607 | return (1.0 / (SIGMA * Math.sqrt(2 * Math.PI))) * Math.exp(-(x * x) / (2 * SIGMA * SIGMA));
|
---|
608 | }
|
---|
609 |
|
---|
610 | /**
|
---|
611 | * Get the expected evaluation value of a bid for a particular issue.
|
---|
612 | *
|
---|
613 | * @param bid
|
---|
614 | * The bid to get the expected evaluation value of.
|
---|
615 | * @param number
|
---|
616 | * The number of the issue to get the expected evaluation value
|
---|
617 | * of.
|
---|
618 | * @return the expected evaluation value of a bid for a particular issue.
|
---|
619 | * @throws Exception
|
---|
620 | */
|
---|
621 | private double getExpectedEvaluationValue(Bid bid, int number) throws Exception {
|
---|
622 | double expectedEval = 0;
|
---|
623 | for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(number)) {
|
---|
624 | expectedEval += evaluatorHypothesis.getProbability() * evaluatorHypothesis.getEvaluator()
|
---|
625 | .getEvaluation(utilitySpace, bid, utilitySpace.getIssue(number).getNumber());
|
---|
626 | }
|
---|
627 | return expectedEval;
|
---|
628 | }
|
---|
629 |
|
---|
630 | /**
|
---|
631 | * Get the partial utility of a bid, excluding a specific issue.
|
---|
632 | *
|
---|
633 | * @param bid
|
---|
634 | * The bid to get the partial utility of.
|
---|
635 | * @param number
|
---|
636 | * The number of the issue to exclude.
|
---|
637 | * @return the partial utility of a bid, excluding a specific issue.
|
---|
638 | * @throws Exception
|
---|
639 | */
|
---|
640 | private double getPartialUtility(Bid bid, int number) throws Exception {
|
---|
641 | double u = 0;
|
---|
642 | for (int i = 0; i < domain.getIssues().size(); i++) {
|
---|
643 | if (number == i) {
|
---|
644 | continue;
|
---|
645 | }
|
---|
646 | double w = 0;
|
---|
647 |
|
---|
648 | for (WeightHypothesis weightHypothesis : weightHypotheses.get(i))
|
---|
649 | w += weightHypothesis.getProbability() * weightHypothesis.getWeight();
|
---|
650 | u += w * getExpectedEvaluationValue(bid, i);
|
---|
651 | }
|
---|
652 | return u;
|
---|
653 | }
|
---|
654 |
|
---|
655 | /**
|
---|
656 | * Get the expected weight of a particular issue.
|
---|
657 | *
|
---|
658 | * @param number
|
---|
659 | * The issue number.
|
---|
660 | * @return the expected weight of a particular issue.
|
---|
661 | */
|
---|
662 | public double getExpectedWeight(int number) {
|
---|
663 | double expectedWeight = 0;
|
---|
664 | for (WeightHypothesis weightHypothesis : weightHypotheses.get(number)) {
|
---|
665 | expectedWeight += weightHypothesis.getProbability() * weightHypothesis.getWeight();
|
---|
666 | }
|
---|
667 | return expectedWeight;
|
---|
668 | }
|
---|
669 |
|
---|
670 | public EvaluatorHypothesis getBestHypothesis(int issue) {
|
---|
671 | double maxEvaluatorProbability = -1;
|
---|
672 | EvaluatorHypothesis bestEvaluatorHypothesis = null;
|
---|
673 | for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(issue)) {
|
---|
674 | if (evaluatorHypothesis.getProbability() > maxEvaluatorProbability) {
|
---|
675 | maxEvaluatorProbability = evaluatorHypothesis.getProbability();
|
---|
676 | bestEvaluatorHypothesis = evaluatorHypothesis;
|
---|
677 | }
|
---|
678 | }
|
---|
679 | return bestEvaluatorHypothesis;
|
---|
680 | }
|
---|
681 |
|
---|
682 | public Hypothesis getHypothesis(int index) {
|
---|
683 | return this.evaluatorHypotheses.get(index).get(index);
|
---|
684 | }
|
---|
685 |
|
---|
686 | @Override
|
---|
687 | public AdditiveUtilitySpace getOpponentUtilitySpace() {
|
---|
688 | return new UtilitySpaceAdapter(this, domain);
|
---|
689 | }
|
---|
690 |
|
---|
691 | public String getName() {
|
---|
692 | return "IAMhaggler Bayesian Model";
|
---|
693 | }
|
---|
694 |
|
---|
695 | public void cleanUp() {
|
---|
696 | super.cleanUp();
|
---|
697 | biddingHistory = null;
|
---|
698 | evaluatorHypotheses = null;
|
---|
699 | weightHypotheses = null;
|
---|
700 | expectedWeights = null;
|
---|
701 | opponentConcessionFunction = null;
|
---|
702 | domain = null;
|
---|
703 | utilitySpace = null;
|
---|
704 | }
|
---|
705 |
|
---|
706 | @Override
|
---|
707 | public Set<BOAparameter> getParameterSpec() {
|
---|
708 | Set<BOAparameter> set = new HashSet<BOAparameter>();
|
---|
709 | set.add(new BOAparameter("u", 0.0, "Use all bids (instead of only unique) if u > 0.0"));
|
---|
710 | set.add(new BOAparameter("b", 1.0, "Concession speed e of assumed opponent TDT function"));
|
---|
711 | return set;
|
---|
712 | }
|
---|
713 | }
|
---|