source: src/main/java/negotiator/boaframework/offeringstrategy/anac2010/IAMhaggler2010/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: 23.0 KB
Line 
1package negotiator.boaframework.offeringstrategy.anac2010.IAMhaggler2010;
2
3import java.util.ArrayList;
4
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
256 if (minUtility == null || maxUtility == null)
257 findMinMaxUtility();
258 return (u - minUtility) / (maxUtility - minUtility);
259 }
260
261 /**
262 * Get the expected utility of a bid.
263 * @param bid The bid to get the expected utility of.
264 * @return the expected utility of the bid.
265 * @throws Exception
266 */
267 public double getExpectedUtility(Bid bid) throws Exception {
268 double u = 0;
269 for (int i = 0; i < utilitySpace.getDomain().getIssues().size(); i++) {
270 u += expectedWeights[i] * getExpectedEvaluationValue(bid, i);
271 }
272 return u;
273 }
274
275 /**
276 * Update the beliefs about the opponent, based on an observation.
277 * @param opponentBid The opponent's bid that was observed.
278 * @throws Exception
279 */
280 public void updateBeliefs(Bid opponentBid, long currentTime, double totalTime) throws Exception {
281 if (biddingHistory.contains(opponentBid))
282 return;
283 biddingHistory.add(opponentBid);
284
285 if (biddingHistory.size() > 1) {
286 updateWeights();
287 }
288 updateEvaluationFunctions();
289
290 previousBidUtility = opponentConcessionFunction.getConcession(1, currentTime, totalTime);
291
292 for (int i = 0; i < expectedWeights.length; ++i)
293 expectedWeights[i] = getExpectedWeight(i);
294
295 normalize(expectedWeights);
296
297 findMinMaxUtility();
298 }
299
300 /**
301 * Normalise the values in an array so that they sum to 1.
302 * @param array The array to normalise;
303 */
304 private void normalize(double[] array) {
305 double n = 0;
306 for (int i = 0; i < array.length; ++i) {
307 n += array[i];
308 }
309 if(n == 0)
310 {
311 for (int i = 0; i < array.length; ++i) {
312 array[i] = 1.0/array.length;
313 }
314 return;
315 }
316
317 for (int i = 0; i < array.length; ++i) {
318 array[i] = array[i] / n;
319 }
320 }
321
322 /**
323 * Find the minimum and maximum utilities of the bids in the utility space.
324 * @throws Exception
325 */
326 protected void findMinMaxUtility() throws Exception {
327 maxUtility = getExtremeUtility(Extreme.MAX);
328 minUtility = getExtremeUtility(Extreme.MIN);
329 }
330
331 public enum Extreme { MIN, MAX }
332
333 private double getExtremeUtility(Extreme extreme) {
334 double u = 0;
335 for (int i = 0; i < utilitySpace.getDomain().getIssues().size(); i++) {
336 u += expectedWeights[i] * getExtremeEvaluationValue(i, extreme);
337 }
338 return u;
339 }
340
341 private double getExtremeEvaluationValue(int number, Extreme extreme) {
342 double expectedEval = 0;
343 for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(number)) {
344 expectedEval += evaluatorHypothesis.getProbability()
345 * getExtremeEvaluation(evaluatorHypothesis.getEvaluator(), extreme);
346 }
347 return expectedEval;
348 }
349
350 public double getExtremeEvaluation(Evaluator evaluator, Extreme extreme) {
351 double extremeEval = initExtreme(extreme);
352 switch(evaluator.getType())
353 {
354 case DISCRETE:
355 EvaluatorDiscrete discreteEvaluator = (EvaluatorDiscrete)evaluator;
356 for(ValueDiscrete value : discreteEvaluator.getValues())
357 {
358 try {
359 switch(extreme)
360 {
361 case MAX:
362 extremeEval = Math.max(extremeEval, discreteEvaluator.getEvaluation(value));
363 break;
364 case MIN:
365 extremeEval = Math.min(extremeEval, discreteEvaluator.getEvaluation(value));
366 break;
367 }
368 } catch (Exception e) {
369 e.printStackTrace();
370 }
371 }
372 break;
373 case INTEGER:
374 EvaluatorInteger integerEvaluator = (EvaluatorInteger)evaluator;
375 switch(extreme)
376 {
377 case MAX:
378 extremeEval = Math.max(integerEvaluator.getEvaluation(integerEvaluator.getUpperBound()), integerEvaluator.getEvaluation(integerEvaluator.getLowerBound()));
379 //if(integerEvaluator.getFuncType() == EVALFUNCTYPE.TRIANGULAR)
380 //{
381 // extremeEval = Math.max(extremeEval, integerEvaluator.getEvaluation(integerEvaluator.getTopParam()));
382 //}
383 break;
384 case MIN:
385 extremeEval = Math.min(integerEvaluator.getEvaluation(integerEvaluator.getUpperBound()), integerEvaluator.getEvaluation(integerEvaluator.getLowerBound()));
386 //if(integerEvaluator.getFuncType() == EVALFUNCTYPE.TRIANGULAR)
387 //{
388 // extremeEval = Math.min(extremeEval, integerEvaluator.getEvaluation(integerEvaluator.getTopParam()));
389 //}
390 break;
391 }
392 break;
393 case REAL:
394 EvaluatorReal realEvaluator = (EvaluatorReal)evaluator;
395 switch(extreme)
396 {
397 case MAX:
398 extremeEval = Math.max(realEvaluator.getEvaluation(realEvaluator.getUpperBound()), realEvaluator.getEvaluation(realEvaluator.getLowerBound()));
399 if(realEvaluator.getFuncType() == EVALFUNCTYPE.TRIANGULAR)
400 {
401 extremeEval = Math.max(extremeEval, realEvaluator.getEvaluation(realEvaluator.getTopParam()));
402 }
403 break;
404 case MIN:
405 extremeEval = Math.min(realEvaluator.getEvaluation(realEvaluator.getUpperBound()), realEvaluator.getEvaluation(realEvaluator.getLowerBound()));
406 if(realEvaluator.getFuncType() == EVALFUNCTYPE.TRIANGULAR)
407 {
408 extremeEval = Math.min(extremeEval, realEvaluator.getEvaluation(realEvaluator.getTopParam()));
409 }
410 break;
411 }
412 break;
413 }
414 return extremeEval;
415 }
416
417 private double initExtreme(Extreme extreme) {
418 switch(extreme)
419 {
420 case MAX:
421 return Double.MIN_VALUE;
422 case MIN:
423 return Double.MAX_VALUE;
424 }
425 return 0;
426 }
427
428 /**
429 * Update the evaluation functions.
430 * @throws Exception
431 */
432 private void updateEvaluationFunctions() throws Exception {
433 maxUtility = null;
434 minUtility = null;
435
436 Bid bid = biddingHistory.get(biddingHistory.size() - 1);
437 ArrayList<ArrayList<EvaluatorHypothesis>> evaluatorHypotheses = new ArrayList<ArrayList<EvaluatorHypothesis>>();
438
439 for (int i = 0; i < this.evaluatorHypotheses.size(); ++i) {
440 ArrayList<EvaluatorHypothesis> tmp = new ArrayList<EvaluatorHypothesis>();
441 for (int j = 0; j < this.evaluatorHypotheses.get(i).size(); ++j) {
442 EvaluatorHypothesis evaluatorHypothesis = new EvaluatorHypothesis(this.evaluatorHypotheses.get(i).get(j).getEvaluator());
443 evaluatorHypothesis.setDesc(this.evaluatorHypotheses.get(i).get(j).getDesc());
444 evaluatorHypothesis.setProbability(this.evaluatorHypotheses.get(i).get(j).getProbability());
445 tmp.add(evaluatorHypothesis);
446 }
447 evaluatorHypotheses.add(tmp);
448 }
449
450 for (int i = 0; i < this.utilitySpace.getDomain().getIssues().size(); i++) {
451 double n = 0.0D;
452 double utility = 0.0D;
453 for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(i)) {
454 utility = getPartialUtility(bid, i) +
455 getExpectedWeight(i) * evaluatorHypothesis.getEvaluator().getEvaluation(utilitySpace, bid, utilitySpace.getIssue(i).getNumber());
456 n += evaluatorHypothesis.getProbability() * conditionalDistribution(utility, previousBidUtility);
457 }
458
459 for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(i)) {
460 utility = getPartialUtility(bid, i) +
461 getExpectedWeight(i) * evaluatorHypothesis.getEvaluator().getEvaluation(utilitySpace, bid, utilitySpace.getIssue(i).getNumber());
462 evaluatorHypothesis.setProbability(evaluatorHypothesis.getProbability() * conditionalDistribution(utility, previousBidUtility) / n);
463 }
464 }
465
466 this.evaluatorHypotheses = evaluatorHypotheses;
467 }
468
469 /**
470 * Update the weights.
471 * @throws Exception
472 */
473 private void updateWeights() throws Exception {
474 maxUtility = null;
475 minUtility = null;
476
477 Bid bid = biddingHistory.get(biddingHistory.size() - 1);
478 ArrayList<ArrayList<WeightHypothesis>> weightHypotheses = new ArrayList<ArrayList<WeightHypothesis>>();
479
480 for (int i = 0; i < this.weightHypotheses.size(); ++i) {
481 ArrayList<WeightHypothesis> tmp = new ArrayList<WeightHypothesis>();
482 for (int j = 0; j < this.weightHypotheses.get(i).size(); ++j) {
483 WeightHypothesis weightHypothesis = new WeightHypothesis();
484 weightHypothesis.setWeight(this.weightHypotheses.get(i).get(j).getWeight());
485 weightHypothesis.setProbability(this.weightHypotheses.get(i).get(j).getProbability());
486 tmp.add(weightHypothesis);
487 }
488 weightHypotheses.add(tmp);
489 }
490
491 for (int i = 0; i < this.utilitySpace.getDomain().getIssues().size(); i++) {
492 double n = 0.0D;
493 double utility = 0.0D;
494 for (WeightHypothesis weightHypothesis : weightHypotheses.get(i)) {
495 utility = getPartialUtility(bid, i) +
496 weightHypothesis.getWeight() * getExpectedEvaluationValue(bid, i);
497 n += weightHypothesis.getProbability() * conditionalDistribution(utility, previousBidUtility);
498 }
499
500 for (WeightHypothesis weightHypothesis : weightHypotheses.get(i)) {
501 utility = getPartialUtility(bid, i) +
502 weightHypothesis.getWeight() * getExpectedEvaluationValue(bid, i);
503 weightHypothesis.setProbability(weightHypothesis.getProbability() * conditionalDistribution(utility, previousBidUtility) / n);
504 }
505 }
506
507 this.weightHypotheses = weightHypotheses;
508
509 }
510
511 /**
512 * The conditional distribution function.
513 * @param utility The utility.
514 * @param previousBidUtility The utility of the previous bid.
515 * @return
516 */
517 private double conditionalDistribution(double utility, double previousBidUtility) {
518 double x = (previousBidUtility - utility) / previousBidUtility;
519 return (1.0 / (SIGMA * Math.sqrt(2 * Math.PI))) * Math.exp(-(x * x) / (2 * SIGMA * SIGMA));
520 }
521
522 /**
523 * Get the expected evaluation value of a bid for a particular issue.
524 * @param bid The bid to get the expected evaluation value of.
525 * @param number The number of the issue to get the expected evaluation value of.
526 * @return the expected evaluation value of a bid for a particular issue.
527 * @throws Exception
528 */
529 private double getExpectedEvaluationValue(Bid bid, int number) throws Exception {
530 double expectedEval = 0;
531 for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(number)) {
532 expectedEval += evaluatorHypothesis.getProbability()
533 * evaluatorHypothesis.getEvaluator().getEvaluation(utilitySpace, bid, utilitySpace.getIssue(number).getNumber());
534 }
535 return expectedEval;
536 }
537
538 /**
539 * Get the partial utility of a bid, excluding a specific issue.
540 * @param bid The bid to get the partial utility of.
541 * @param number The number of the issue to exclude.
542 * @return the partial utility of a bid, excluding a specific issue.
543 * @throws Exception
544 */
545 private double getPartialUtility(Bid bid, int number) throws Exception {
546 double u = 0;
547 for (int i = 0; i < utilitySpace.getDomain().getIssues().size(); i++) {
548 if (number == i) {
549 continue;
550 }
551 double w = 0;
552 for (WeightHypothesis weightHypothesis : weightHypotheses.get(i))
553 w += weightHypothesis.getProbability() * weightHypothesis.getWeight();
554 u += w * getExpectedEvaluationValue(bid, i);
555 }
556 return u;
557 }
558
559 /**
560 * Get the expected weight of a particular issue.
561 * @param number The issue number.
562 * @return the expected weight of a particular issue.
563 */
564 public double getExpectedWeight(int number) {
565 double expectedWeight = 0;
566 for (WeightHypothesis weightHypothesis : weightHypotheses.get(number)) {
567 expectedWeight += weightHypothesis.getProbability() * weightHypothesis.getWeight();
568 }
569 return expectedWeight;
570 }
571
572 /**
573 * Print the best hypothesis.
574 */
575 public void printBestHypothesis() {
576 double[] bestWeights = new double[utilitySpace.getDomain().getIssues().size()];
577 EvaluatorHypothesis[] bestEvaluatorHypotheses = new EvaluatorHypothesis[utilitySpace.getDomain().getIssues().size()];
578 for (int i = 0; i < this.utilitySpace.getDomain().getIssues().size(); i++) {
579 for (WeightHypothesis weightHypothesis : weightHypotheses.get(i)) {
580 bestWeights[i] += weightHypothesis.getWeight() * weightHypothesis.getProbability();
581 }
582
583 bestEvaluatorHypotheses[i] = getBestHypothesis(i);
584 }
585
586 normalize(bestWeights);
587
588 String s;
589 s = "";
590 s += "Weights: ";
591 for (double weight : bestWeights) {
592 s += String.format("%1.5f", weight) + ", ";
593 }
594
595 s = "";
596 s += "Evaluators: ";
597 for (EvaluatorHypothesis evaluatorHypothesis : bestEvaluatorHypotheses) {
598 s += evaluatorHypothesis + ", ";
599 }
600 }
601
602
603 public EvaluatorHypothesis getBestHypothesis(int issue) {
604 double maxEvaluatorProbability = -1;
605 EvaluatorHypothesis bestEvaluatorHypothesis = null;
606 for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(issue)) {
607 if (evaluatorHypothesis.getProbability() > maxEvaluatorProbability) {
608 maxEvaluatorProbability = evaluatorHypothesis.getProbability();
609 bestEvaluatorHypothesis = evaluatorHypothesis;
610 }
611 }
612 return bestEvaluatorHypothesis;
613 }
614
615
616 /**
617 * Print the details of all of the hypotheses.
618 */
619 public void printHypotheses() {
620 printHypotheses(this.weightHypotheses, this.evaluatorHypotheses);
621 }
622
623 /**
624 * Print the details of the specified weight and evaluator hypotheses.
625 * @param weightHypotheses The weight hypotheses.
626 * @param evaluatorHypotheses The evaluator hypotheses.
627 */
628 private void printHypotheses(ArrayList<ArrayList<WeightHypothesis>> weightHypotheses, ArrayList<ArrayList<EvaluatorHypothesis>> evaluatorHypotheses) {
629 for (int i = 0; i < this.utilitySpace.getDomain().getIssues().size(); i++) {
630 if (weightHypotheses != null) {
631 for (WeightHypothesis weightHypothesis : weightHypotheses.get(i)) {
632 String s = String.format("%1.2f ", weightHypothesis.getWeight());
633 for (int j = 0; j < weightHypothesis.getProbability() * 100; j++)
634 s += "-";
635 s += String.format(" %1.5f ", weightHypothesis.getProbability());
636 }
637 }
638
639 if (evaluatorHypotheses != null) {
640 for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(i)) {
641 String s = String.format("%19s ", evaluatorHypothesis);
642 for (int j = 0; j < evaluatorHypothesis.getProbability() * 100; j++)
643 s += "-";
644 s += String.format(" %1.5f ", evaluatorHypothesis.getProbability());
645 }
646 }
647 }
648 }
649
650
651 /**
652 * Get the first bid.
653 * @return the first bid.
654 */
655 public Bid getFirstBid() {
656 return biddingHistory.get(0);
657 }
658
659 public Hypothesis getHypothesis(int index) {
660 return this.evaluatorHypotheses.get(index).get(index);
661 }
662}
Note: See TracBrowser for help on using the repository browser.