source: src/main/java/agents/anac/y2010/Southampton/utils/OpponentModel.java

Last change on this file was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 21.5 KB
Line 
1package agents.anac.y2010.Southampton.utils;
2
3import java.util.ArrayList;
4import agents.anac.y2010.Southampton.utils.concession.TimeConcessionFunction;
5import genius.core.Bid;
6import genius.core.issue.IssueDiscrete;
7import genius.core.issue.IssueInteger;
8import genius.core.issue.IssueReal;
9import genius.core.issue.ValueDiscrete;
10import genius.core.utility.AdditiveUtilitySpace;
11import genius.core.utility.EVALFUNCTYPE;
12import genius.core.utility.Evaluator;
13import genius.core.utility.EvaluatorDiscrete;
14import genius.core.utility.EvaluatorInteger;
15import genius.core.utility.EvaluatorReal;
16
17/**
18 * @author Colin Williams
19 *
20 */
21public class OpponentModel extends agents.bayesianopponentmodel.OpponentModel{
22
23 private AdditiveUtilitySpace utilitySpace;
24
25 private ArrayList<Bid> biddingHistory;
26 private ArrayList<ArrayList<EvaluatorHypothesis>> evaluatorHypotheses;
27 private ArrayList<ArrayList<WeightHypothesis>> weightHypotheses;
28 private double previousBidUtility;
29 private Double maxUtility;
30 private Double minUtility;
31 private double[] expectedWeights;
32 private double SIGMA = 0.25;
33 private final int totalTriangularFunctions = 4;
34 private TimeConcessionFunction opponentConcessionFunction;
35
36 /**
37 * Default constructor.
38 * @param utilitySpace The utility space of the agent.
39 * @param agent The agent (used only for logging purposes).
40 */
41 public OpponentModel(AdditiveUtilitySpace utilitySpace) {
42 opponentConcessionFunction = new TimeConcessionFunction(TimeConcessionFunction.Beta.LINEAR, TimeConcessionFunction.BREAKOFF);
43 this.utilitySpace = utilitySpace;
44
45 previousBidUtility = 1;
46
47 biddingHistory = new ArrayList<Bid>();
48 weightHypotheses = new ArrayList<ArrayList<WeightHypothesis>>();
49 evaluatorHypotheses = new ArrayList<ArrayList<EvaluatorHypothesis>>();
50 expectedWeights = new double[utilitySpace.getDomain().getIssues().size()];
51
52 initWeightHypotheses();
53
54 initEvaluatorHypotheses();
55 }
56
57 /**
58 * Initialise the weight hypotheses.
59 */
60 private void initWeightHypotheses() {
61 int weightHypothesesNumber = 11;
62 for (int i = 0; i < utilitySpace.getDomain().getIssues().size(); ++i) {
63 ArrayList<WeightHypothesis> weightHypothesis = new ArrayList<WeightHypothesis>();
64 for (int j = 0; j < weightHypothesesNumber; ++j) {
65 WeightHypothesis weight = new WeightHypothesis();
66 weight.setProbability((1.0 - (((double) j + 1.0) / weightHypothesesNumber)) * (1.0 - (((double) j + 1.0) / weightHypothesesNumber))
67 * (1.0 - (((double) j + 1.0D) / weightHypothesesNumber)));
68 weight.setWeight((double) j / (weightHypothesesNumber - 1));
69 weightHypothesis.add(weight);
70 }
71
72 // Normalization
73 double n = 0.0D;
74 for (int j = 0; j < weightHypothesesNumber; ++j) {
75 n += weightHypothesis.get(j).getProbability();
76 }
77 for (int j = 0; j < weightHypothesesNumber; ++j) {
78 weightHypothesis.get(j).setProbability(weightHypothesis.get(j).getProbability() / n);
79 }
80
81 weightHypotheses.add(weightHypothesis);
82 }
83 }
84
85 /**
86 * Initialise the evaluator hypotheses.
87 */
88 private void initEvaluatorHypotheses() {
89 evaluatorHypotheses = new ArrayList<ArrayList<EvaluatorHypothesis>>();
90 for (int i = 0; i < utilitySpace.getNrOfEvaluators(); ++i) {
91 ArrayList<EvaluatorHypothesis> lEvalHyps;
92 EvaluatorReal lHypEvalReal;
93 EvaluatorInteger lHypEvalInteger;
94 EvaluatorHypothesis lEvaluatorHypothesis;
95 switch (utilitySpace.getEvaluator(utilitySpace.getIssue(i).getNumber()).getType()) {
96
97 case REAL:
98 {
99 lEvalHyps = new ArrayList<EvaluatorHypothesis>();
100 evaluatorHypotheses.add(lEvalHyps);
101
102 IssueReal lIssue = (IssueReal) utilitySpace.getIssue(i);
103
104 /* Uphill */
105 lHypEvalReal = new EvaluatorReal();
106 lHypEvalReal.setUpperBound(lIssue.getUpperBound());
107 lHypEvalReal.setLowerBound(lIssue.getLowerBound());
108 lHypEvalReal.setType(EVALFUNCTYPE.LINEAR);
109 lHypEvalReal.addParam(1, 1.0 / (lHypEvalReal.getUpperBound() - lHypEvalReal.getLowerBound()));
110 lHypEvalReal.addParam(0, -lHypEvalReal.getLowerBound() / (lHypEvalReal.getUpperBound() - lHypEvalReal.getLowerBound()));
111 lEvaluatorHypothesis = new EvaluatorHypothesis(lHypEvalReal);
112 lEvaluatorHypothesis.setDesc("uphill");
113 lEvalHyps.add(lEvaluatorHypothesis);
114
115 /* Triangular */
116 for (int k = 1; k <= totalTriangularFunctions; ++k) {
117 lHypEvalReal = new EvaluatorReal();
118 lHypEvalReal.setUpperBound(lIssue.getUpperBound());
119 lHypEvalReal.setLowerBound(lIssue.getLowerBound());
120 lHypEvalReal.setType(EVALFUNCTYPE.TRIANGULAR);
121 lHypEvalReal.addParam(0, lHypEvalReal.getLowerBound());
122 lHypEvalReal.addParam(1, lHypEvalReal.getUpperBound());
123 double lMaxPoint = lHypEvalReal.getLowerBound() + (double) k * (lHypEvalReal.getUpperBound() - lHypEvalReal.getLowerBound())
124 / (totalTriangularFunctions + 1);
125 lHypEvalReal.addParam(2, lMaxPoint);
126 lEvaluatorHypothesis = new EvaluatorHypothesis(lHypEvalReal);
127 lEvalHyps.add(lEvaluatorHypothesis);
128 lEvaluatorHypothesis.setDesc("triangular " + String.format("%1.2f", lMaxPoint));
129 }
130
131 /* Downhill */
132 lHypEvalReal = new EvaluatorReal();
133 lHypEvalReal.setUpperBound(lIssue.getUpperBound());
134 lHypEvalReal.setLowerBound(lIssue.getLowerBound());
135 lHypEvalReal.setType(EVALFUNCTYPE.LINEAR);
136 lHypEvalReal.addParam(1, -1.0 / (lHypEvalReal.getUpperBound() - lHypEvalReal.getLowerBound()));
137 lHypEvalReal.addParam(0, 1.0 + lHypEvalReal.getLowerBound() / (lHypEvalReal.getUpperBound() - lHypEvalReal.getLowerBound()));
138 lEvaluatorHypothesis = new EvaluatorHypothesis(lHypEvalReal);
139 lEvaluatorHypothesis.setDesc("downhill");
140 lEvalHyps.add(lEvaluatorHypothesis);
141
142 for (int k = 0; k < lEvalHyps.size(); ++k) {
143 lEvalHyps.get(k).setProbability(1.0 / lEvalHyps.size());
144 }
145
146 break;
147 }
148 case INTEGER:
149 {
150 lEvalHyps = new ArrayList<EvaluatorHypothesis>();
151 evaluatorHypotheses.add(lEvalHyps);
152
153 IssueInteger lIssue = (IssueInteger) utilitySpace.getIssue(i);
154
155 /* Uphill */
156 lHypEvalInteger = new EvaluatorInteger();
157 lHypEvalInteger.setUpperBound(lIssue.getUpperBound());
158 lHypEvalInteger.setLowerBound(lIssue.getLowerBound());
159 lHypEvalInteger.setOffset(-lHypEvalInteger.getLowerBound() / (lHypEvalInteger.getUpperBound() - lHypEvalInteger.getLowerBound()));
160 lHypEvalInteger.setSlope(1.0 / (lHypEvalInteger.getUpperBound() - lHypEvalInteger.getLowerBound()));
161 lEvaluatorHypothesis = new EvaluatorHypothesis(lHypEvalInteger);
162 lEvaluatorHypothesis.setDesc("uphill");
163 lEvalHyps.add(lEvaluatorHypothesis);
164
165 /* Downhill */
166 lHypEvalInteger = new EvaluatorInteger();
167 lHypEvalInteger.setUpperBound(lIssue.getUpperBound());
168 lHypEvalInteger.setLowerBound(lIssue.getLowerBound());
169 lHypEvalInteger.setOffset(1.0 + lHypEvalInteger.getLowerBound() / (lHypEvalInteger.getUpperBound() - lHypEvalInteger.getLowerBound()));
170 lHypEvalInteger.setSlope(-1.0 / (lHypEvalInteger.getUpperBound() - lHypEvalInteger.getLowerBound()));
171 lEvaluatorHypothesis = new EvaluatorHypothesis(lHypEvalInteger);
172 lEvaluatorHypothesis.setDesc("downhill");
173 lEvalHyps.add(lEvaluatorHypothesis);
174
175 for (int k = 0; k < lEvalHyps.size(); ++k) {
176 lEvalHyps.get(k).setProbability(1.0 / lEvalHyps.size());
177 }
178
179 break;
180 }
181 case DISCRETE:
182 {
183 lEvalHyps = new ArrayList<EvaluatorHypothesis>();
184 evaluatorHypotheses.add(lEvalHyps);
185
186 IssueDiscrete lDiscIssue = (IssueDiscrete) utilitySpace.getIssue(i);
187
188 /* Uphill */
189 EvaluatorDiscrete lDiscreteEval = new EvaluatorDiscrete();
190 for (int j = 0; j < lDiscIssue.getNumberOfValues(); ++j)
191 lDiscreteEval.addEvaluation(lDiscIssue.getValue(j), Integer.valueOf(1000 * j + 1));
192 lEvaluatorHypothesis = new EvaluatorHypothesis(lDiscreteEval);
193 lEvaluatorHypothesis.setDesc("uphill");
194 lEvalHyps.add(lEvaluatorHypothesis);
195
196 /* Triangular */
197 if (lDiscIssue.getNumberOfValues() > 2) {
198 for (int k = 1; k < lDiscIssue.getNumberOfValues() - 1; ++k) {
199 lDiscreteEval = new EvaluatorDiscrete();
200 for (int j = 0; j < lDiscIssue.getNumberOfValues(); ++j) {
201 if (j < k) {
202 lDiscreteEval.addEvaluation(lDiscIssue.getValue(j), 1000 * j / k);
203 } else
204 lDiscreteEval.addEvaluation(lDiscIssue.getValue(j), 1000 * (lDiscIssue.getNumberOfValues() - j - 1
205 / (lDiscIssue.getNumberOfValues() - k - 1) + 1));
206 }
207 lEvaluatorHypothesis = new EvaluatorHypothesis(lDiscreteEval);
208 lEvalHyps.add(lEvaluatorHypothesis);
209 lEvaluatorHypothesis.setDesc("triangular " + String.valueOf(k));
210 }
211 }
212
213 /* Downhill */
214 lDiscreteEval = new EvaluatorDiscrete();
215 for (int j = 0; j < lDiscIssue.getNumberOfValues(); ++j)
216 lDiscreteEval.addEvaluation(lDiscIssue.getValue(j), Integer.valueOf(1000 * (lDiscIssue.getNumberOfValues() - j - 1) + 1));
217 lEvaluatorHypothesis = new EvaluatorHypothesis(lDiscreteEval);
218 lEvaluatorHypothesis.setDesc("downhill");
219 lEvalHyps.add(lEvaluatorHypothesis);
220
221 for (int k = 0; k < lEvalHyps.size(); ++k) {
222 lEvalHyps.get(k).setProbability(1.0 / lEvalHyps.size());
223 }
224
225 break;
226 }
227 }
228 }
229
230 for (int i = 0; i < expectedWeights.length; ++i)
231 expectedWeights[i] = getExpectedWeight(i);
232
233 normalize(expectedWeights);
234 }
235
236 /**
237 * Get the normalised utility of a bid.
238 * @param bid The bid to get the normalised utility of.
239 * @return the normalised utility of a bid.
240 * @throws Exception
241 */
242 public double getNormalizedUtility(Bid bid) throws Exception {
243 return getNormalizedUtility(bid, false);
244 }
245
246 /**
247 * Get the normalised utility of a bid.
248 * @param bid The bid to get the normalised utility of.
249 * @param debug Whether or not to output debugging information
250 * @return the normalised utility of a bid.
251 * @throws Exception
252 */
253 public double getNormalizedUtility(Bid bid, boolean debug) throws Exception {
254 double u = getExpectedUtility(bid);
255 if (minUtility == null || maxUtility == null)
256 findMinMaxUtility();
257 return (u - minUtility) / (maxUtility - minUtility);
258 }
259
260 /**
261 * Get the expected utility of a bid.
262 * @param bid The bid to get the expected utility of.
263 * @return the expected utility of the bid.
264 * @throws Exception
265 */
266 public double getExpectedUtility(Bid bid) throws Exception {
267 double u = 0;
268 for (int i = 0; i < utilitySpace.getDomain().getIssues().size(); i++) {
269 u += expectedWeights[i] * getExpectedEvaluationValue(bid, i);
270 }
271 return u;
272 }
273
274 /**
275 * Update the beliefs about the opponent, based on an observation.
276 * @param opponentBid The opponent's bid that was observed.
277 * @throws Exception
278 */
279 public void updateBeliefs(Bid opponentBid, long currentTime, double totalTime) throws Exception {
280 if (biddingHistory.contains(opponentBid))
281 return;
282 biddingHistory.add(opponentBid);
283
284 if (biddingHistory.size() > 1) {
285 updateWeights();
286 }
287 updateEvaluationFunctions();
288
289 previousBidUtility = opponentConcessionFunction.getConcession(1, currentTime, totalTime);
290 for (int i = 0; i < expectedWeights.length; ++i)
291 expectedWeights[i] = getExpectedWeight(i);
292
293 normalize(expectedWeights);
294
295 findMinMaxUtility();
296 }
297
298 /**
299 * Normalise the values in an array so that they sum to 1.
300 * @param array The array to normalise;
301 */
302 private void normalize(double[] array) {
303 double n = 0;
304 for (int i = 0; i < array.length; ++i) {
305 n += array[i];
306 }
307 if(n == 0)
308 {
309 for (int i = 0; i < array.length; ++i) {
310 array[i] = 1.0/array.length;
311 }
312 return;
313 }
314
315 for (int i = 0; i < array.length; ++i) {
316 array[i] = array[i] / n;
317 }
318 }
319
320 /**
321 * Find the minimum and maximum utilities of the bids in the utility space.
322 * @throws Exception
323 */
324 protected void findMinMaxUtility() throws Exception {
325 maxUtility = getExtremeUtility(Extreme.MAX);
326 minUtility = getExtremeUtility(Extreme.MIN);
327 }
328
329 public enum Extreme { MIN, MAX }
330
331 private double getExtremeUtility(Extreme extreme) {
332 double u = 0;
333 for (int i = 0; i < utilitySpace.getDomain().getIssues().size(); i++) {
334 u += expectedWeights[i] * getExtremeEvaluationValue(i, extreme);
335 }
336 return u;
337 }
338
339 private double getExtremeEvaluationValue(int number, Extreme extreme) {
340 double expectedEval = 0;
341 for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(number)) {
342 expectedEval += evaluatorHypothesis.getProbability()
343 * getExtremeEvaluation(evaluatorHypothesis.getEvaluator(), extreme);
344 }
345 return expectedEval;
346 }
347
348 public double getExtremeEvaluation(Evaluator evaluator, Extreme extreme) {
349 double extremeEval = initExtreme(extreme);
350 switch(evaluator.getType())
351 {
352 case DISCRETE:
353 EvaluatorDiscrete discreteEvaluator = (EvaluatorDiscrete)evaluator;
354 for(ValueDiscrete value : discreteEvaluator.getValues())
355 {
356 try {
357 switch(extreme)
358 {
359 case MAX:
360 extremeEval = Math.max(extremeEval, discreteEvaluator.getEvaluation(value));
361 break;
362 case MIN:
363 extremeEval = Math.min(extremeEval, discreteEvaluator.getEvaluation(value));
364 break;
365 }
366 } catch (Exception e) {
367 e.printStackTrace();
368 }
369 }
370 break;
371 case INTEGER:
372 EvaluatorInteger integerEvaluator = (EvaluatorInteger)evaluator;
373 switch(extreme)
374 {
375 case MAX:
376 extremeEval = Math.max(integerEvaluator.getEvaluation(integerEvaluator.getUpperBound()), integerEvaluator.getEvaluation(integerEvaluator.getLowerBound()));
377 //if(integerEvaluator.getFuncType() == EVALFUNCTYPE.TRIANGULAR)
378 //{
379 // extremeEval = Math.max(extremeEval, integerEvaluator.getEvaluation(integerEvaluator.getTopParam()));
380 //}
381 break;
382 case MIN:
383 extremeEval = Math.min(integerEvaluator.getEvaluation(integerEvaluator.getUpperBound()), integerEvaluator.getEvaluation(integerEvaluator.getLowerBound()));
384 //if(integerEvaluator.getFuncType() == EVALFUNCTYPE.TRIANGULAR)
385 //{
386 // extremeEval = Math.min(extremeEval, integerEvaluator.getEvaluation(integerEvaluator.getTopParam()));
387 //}
388 break;
389 }
390 break;
391 case REAL:
392 EvaluatorReal realEvaluator = (EvaluatorReal)evaluator;
393 switch(extreme)
394 {
395 case MAX:
396 extremeEval = Math.max(realEvaluator.getEvaluation(realEvaluator.getUpperBound()), realEvaluator.getEvaluation(realEvaluator.getLowerBound()));
397 if(realEvaluator.getFuncType() == EVALFUNCTYPE.TRIANGULAR)
398 {
399 extremeEval = Math.max(extremeEval, realEvaluator.getEvaluation(realEvaluator.getTopParam()));
400 }
401 break;
402 case MIN:
403 extremeEval = Math.min(realEvaluator.getEvaluation(realEvaluator.getUpperBound()), realEvaluator.getEvaluation(realEvaluator.getLowerBound()));
404 if(realEvaluator.getFuncType() == EVALFUNCTYPE.TRIANGULAR)
405 {
406 extremeEval = Math.min(extremeEval, realEvaluator.getEvaluation(realEvaluator.getTopParam()));
407 }
408 break;
409 }
410 break;
411 }
412 return extremeEval;
413 }
414
415 private double initExtreme(Extreme extreme) {
416 switch(extreme)
417 {
418 case MAX:
419 return Double.MIN_VALUE;
420 case MIN:
421 return Double.MAX_VALUE;
422 }
423 return 0;
424 }
425
426 /**
427 * Update the evaluation functions.
428 * @throws Exception
429 */
430 private void updateEvaluationFunctions() throws Exception {
431 maxUtility = null;
432 minUtility = null;
433
434 Bid bid = biddingHistory.get(biddingHistory.size() - 1);
435 ArrayList<ArrayList<EvaluatorHypothesis>> evaluatorHypotheses = new ArrayList<ArrayList<EvaluatorHypothesis>>();
436
437 for (int i = 0; i < this.evaluatorHypotheses.size(); ++i) {
438 ArrayList<EvaluatorHypothesis> tmp = new ArrayList<EvaluatorHypothesis>();
439 for (int j = 0; j < this.evaluatorHypotheses.get(i).size(); ++j) {
440 EvaluatorHypothesis evaluatorHypothesis = new EvaluatorHypothesis(this.evaluatorHypotheses.get(i).get(j).getEvaluator());
441 evaluatorHypothesis.setDesc(this.evaluatorHypotheses.get(i).get(j).getDesc());
442 evaluatorHypothesis.setProbability(this.evaluatorHypotheses.get(i).get(j).getProbability());
443 tmp.add(evaluatorHypothesis);
444 }
445 evaluatorHypotheses.add(tmp);
446 }
447
448 for (int i = 0; i < this.utilitySpace.getDomain().getIssues().size(); i++) {
449 double n = 0.0D;
450 double utility = 0.0D;
451 for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(i)) {
452 utility = getPartialUtility(bid, i) +
453 getExpectedWeight(i) * evaluatorHypothesis.getEvaluator().getEvaluation(utilitySpace, bid, utilitySpace.getIssue(i).getNumber());
454 n += evaluatorHypothesis.getProbability() * conditionalDistribution(utility, previousBidUtility);
455 }
456
457 for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(i)) {
458 utility = getPartialUtility(bid, i) +
459 getExpectedWeight(i) * evaluatorHypothesis.getEvaluator().getEvaluation(utilitySpace, bid, utilitySpace.getIssue(i).getNumber());
460 evaluatorHypothesis.setProbability(evaluatorHypothesis.getProbability() * conditionalDistribution(utility, previousBidUtility) / n);
461 }
462 }
463
464 this.evaluatorHypotheses = evaluatorHypotheses;
465 }
466
467 /**
468 * Update the weights.
469 * @throws Exception
470 */
471 private void updateWeights() throws Exception {
472 maxUtility = null;
473 minUtility = null;
474
475 Bid bid = biddingHistory.get(biddingHistory.size() - 1);
476 ArrayList<ArrayList<WeightHypothesis>> weightHypotheses = new ArrayList<ArrayList<WeightHypothesis>>();
477
478 for (int i = 0; i < this.weightHypotheses.size(); ++i) {
479 ArrayList<WeightHypothesis> tmp = new ArrayList<WeightHypothesis>();
480 for (int j = 0; j < this.weightHypotheses.get(i).size(); ++j) {
481 WeightHypothesis weightHypothesis = new WeightHypothesis();
482 weightHypothesis.setWeight(this.weightHypotheses.get(i).get(j).getWeight());
483 weightHypothesis.setProbability(this.weightHypotheses.get(i).get(j).getProbability());
484 tmp.add(weightHypothesis);
485 }
486 weightHypotheses.add(tmp);
487 }
488
489 for (int i = 0; i < this.utilitySpace.getDomain().getIssues().size(); i++) {
490 double n = 0.0D;
491 double utility = 0.0D;
492 for (WeightHypothesis weightHypothesis : weightHypotheses.get(i)) {
493 utility = getPartialUtility(bid, i) +
494 weightHypothesis.getWeight() * getExpectedEvaluationValue(bid, i);
495 n += weightHypothesis.getProbability() * conditionalDistribution(utility, previousBidUtility);
496 }
497
498 for (WeightHypothesis weightHypothesis : weightHypotheses.get(i)) {
499 utility = getPartialUtility(bid, i) +
500 weightHypothesis.getWeight() * getExpectedEvaluationValue(bid, i);
501 weightHypothesis.setProbability(weightHypothesis.getProbability() * conditionalDistribution(utility, previousBidUtility) / n);
502 }
503 }
504
505 this.weightHypotheses = weightHypotheses;
506
507 }
508
509 /**
510 * The conditional distribution function.
511 * @param utility The utility.
512 * @param previousBidUtility The utility of the previous bid.
513 * @return
514 */
515 private double conditionalDistribution(double utility, double previousBidUtility) {
516 double x = (previousBidUtility - utility) / previousBidUtility;
517 return (1.0 / (SIGMA * Math.sqrt(2 * Math.PI))) * Math.exp(-(x * x) / (2 * SIGMA * SIGMA));
518 }
519
520 /**
521 * Get the expected evaluation value of a bid for a particular issue.
522 * @param bid The bid to get the expected evaluation value of.
523 * @param number The number of the issue to get the expected evaluation value of.
524 * @return the expected evaluation value of a bid for a particular issue.
525 * @throws Exception
526 */
527 private double getExpectedEvaluationValue(Bid bid, int number) throws Exception {
528 double expectedEval = 0;
529 for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(number)) {
530 expectedEval += evaluatorHypothesis.getProbability()
531 * evaluatorHypothesis.getEvaluator().getEvaluation(utilitySpace, bid, utilitySpace.getIssue(number).getNumber());
532 }
533 return expectedEval;
534 }
535
536 /**
537 * Get the partial utility of a bid, excluding a specific issue.
538 * @param bid The bid to get the partial utility of.
539 * @param number The number of the issue to exclude.
540 * @return the partial utility of a bid, excluding a specific issue.
541 * @throws Exception
542 */
543 private double getPartialUtility(Bid bid, int number) throws Exception {
544 double u = 0;
545 for (int i = 0; i < utilitySpace.getDomain().getIssues().size(); i++) {
546 if (number == i) {
547 continue;
548 }
549 double w = 0;
550 for (WeightHypothesis weightHypothesis : weightHypotheses.get(i))
551 w += weightHypothesis.getProbability() * weightHypothesis.getWeight();
552 u += w * getExpectedEvaluationValue(bid, i);
553 }
554 return u;
555 }
556
557 /**
558 * Get the expected weight of a particular issue.
559 * @param number The issue number.
560 * @return the expected weight of a particular issue.
561 */
562 public double getExpectedWeight(int number) {
563 double expectedWeight = 0;
564 for (WeightHypothesis weightHypothesis : weightHypotheses.get(number)) {
565 expectedWeight += weightHypothesis.getProbability() * weightHypothesis.getWeight();
566 }
567 return expectedWeight;
568 }
569
570 /**
571 * Print the best hypothesis.
572 */
573 public void printBestHypothesis() {
574 double[] bestWeights = new double[utilitySpace.getDomain().getIssues().size()];
575 EvaluatorHypothesis[] bestEvaluatorHypotheses = new EvaluatorHypothesis[utilitySpace.getDomain().getIssues().size()];
576 for (int i = 0; i < this.utilitySpace.getDomain().getIssues().size(); i++) {
577 for (WeightHypothesis weightHypothesis : weightHypotheses.get(i)) {
578 bestWeights[i] += weightHypothesis.getWeight() * weightHypothesis.getProbability();
579 }
580
581 bestEvaluatorHypotheses[i] = getBestHypothesis(i);
582 }
583
584 normalize(bestWeights);
585 }
586
587
588 public EvaluatorHypothesis getBestHypothesis(int issue) {
589 double maxEvaluatorProbability = -1;
590 EvaluatorHypothesis bestEvaluatorHypothesis = null;
591 for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(issue)) {
592 if (evaluatorHypothesis.getProbability() > maxEvaluatorProbability) {
593 maxEvaluatorProbability = evaluatorHypothesis.getProbability();
594 bestEvaluatorHypothesis = evaluatorHypothesis;
595 }
596 }
597 return bestEvaluatorHypothesis;
598 }
599
600 /**
601 * Get the first bid.
602 * @return the first bid.
603 */
604 public Bid getFirstBid() {
605 return biddingHistory.get(0);
606 }
607
608 public Hypothesis getHypothesis(int index) {
609 return this.evaluatorHypotheses.get(index).get(index);
610 }
611}
Note: See TracBrowser for help on using the repository browser.