source: src/main/java/agents/anac/y2012/IAMhaggler2012/utility/SouthamptonUtilitySpace.java

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

Initial import : Genius 9.0.0

File size: 3.4 KB
Line 
1package agents.anac.y2012.IAMhaggler2012.utility;
2
3import java.util.Enumeration;
4import java.util.HashMap;
5
6import genius.core.Bid;
7import genius.core.issue.Objective;
8import genius.core.issue.Value;
9import genius.core.issue.ValueInteger;
10import genius.core.issue.ValueReal;
11import genius.core.utility.AdditiveUtilitySpace;
12import genius.core.utility.Evaluator;
13import genius.core.utility.EvaluatorDiscrete;
14import genius.core.utility.EvaluatorInteger;
15import genius.core.utility.EvaluatorReal;
16
17public class SouthamptonUtilitySpace {
18
19 AdditiveUtilitySpace us;
20
21 public SouthamptonUtilitySpace(AdditiveUtilitySpace us) {
22 super();
23 this.us = us;
24 }
25
26 /**
27 * @return a bid with the maximum utility value attainable in this util space
28 * @throws Exception
29 * @author C.R.Williams
30 */
31 public final Bid getMaxUtilityBid() throws Exception
32 {
33 HashMap<Integer, Value> bid = new HashMap<Integer, Value>();
34
35 Objective root = us.getDomain().getObjectivesRoot();
36 Enumeration<Objective> issueEnum = root.getPreorderIssueEnumeration();
37 while(issueEnum.hasMoreElements()){
38 Objective is = issueEnum.nextElement();
39 bid.put(is.getNumber(), getMaxValue(is.getNumber()));
40 }
41
42 return new Bid(us.getDomain(), bid);
43 }
44
45 /**
46 * @param pIssueIndex the index of the issue to get the maximum value for
47 * @return a value that maximises the utility of the issue with the given index
48 * @author C.R.Williams
49 */
50 private Value getMaxValue(int pIssueIndex)
51 {
52 Evaluator lEvaluator = us.getEvaluator(pIssueIndex);
53 if(lEvaluator.getClass() == EvaluatorDiscrete.class)
54 {
55 return ((EvaluatorDiscrete)lEvaluator).getMaxValue();
56 }
57 if(lEvaluator.getClass() == EvaluatorInteger.class)
58 {
59 return getMaxValueInteger((EvaluatorInteger)lEvaluator);
60 }
61 if(lEvaluator.getClass() == EvaluatorReal.class)
62 {
63 return getMaxValueReal((EvaluatorReal)lEvaluator);
64 }
65 return null;
66 }
67
68 /**
69 * @return a value that maximises the utility
70 * @author C.R.Williams
71 */
72 private Value getMaxValueInteger(EvaluatorInteger eval) {
73 double utility = 0;
74 switch(eval.getFuncType()) {
75 case LINEAR:
76 utility = maxLinear(eval.getSlope(), eval.getOffset());
77 if (utility < eval.getLowerBound())
78 utility = eval.getLowerBound();
79 else if (utility > eval.getUpperBound())
80 utility = eval.getUpperBound();
81 break;
82 default:
83 return null;
84 }
85 return new ValueInteger((int)utility);
86 }
87
88 /**
89 * @return a value that maximises the utility
90 * @author C.R.Williams
91 */
92 private Value getMaxValueReal(EvaluatorReal eval) {
93 double utility = 0;
94 switch(eval.getFuncType()) {
95 case LINEAR:
96 utility = maxLinear(eval.getLinearParam(), eval.getConstantParam());
97 if (utility < eval.getLowerBound())
98 utility = eval.getLowerBound();
99 else if (utility > eval.getUpperBound())
100 utility = eval.getUpperBound();
101 break;
102 case CONSTANT:
103 utility = eval.getLowerBound();
104 break;
105 case TRIANGULAR:
106 case TRIANGULAR_VARIABLE_TOP:
107 utility = maxTriangular(eval.getLinearParam(), eval.getConstantParam(), eval.getTopParam());
108 break;
109 default:
110 return null;
111 }
112 return new ValueReal(utility);
113 }
114
115 private static double maxLinear(double coef1, double coef0) {
116 if(coef1 > 0)
117 return Double.MAX_VALUE;
118 else
119 return Double.MIN_VALUE;
120 }
121
122 private static double maxTriangular(double lowerBound, double upperBound, double top) {
123 return top;
124 }
125}
Note: See TracBrowser for help on using the repository browser.