[127] | 1 | package agents.anac.y2011.ValueModelAgent;
|
---|
| 2 |
|
---|
| 3 | import java.util.HashMap;
|
---|
| 4 | import java.util.Map;
|
---|
| 5 |
|
---|
| 6 | import genius.core.issue.ISSUETYPE;
|
---|
| 7 | import genius.core.issue.Issue;
|
---|
| 8 | import genius.core.issue.IssueDiscrete;
|
---|
| 9 | import genius.core.issue.IssueInteger;
|
---|
| 10 | import genius.core.issue.IssueReal;
|
---|
| 11 | import genius.core.issue.Value;
|
---|
| 12 | import genius.core.issue.ValueInteger;
|
---|
| 13 | import genius.core.issue.ValueReal;
|
---|
| 14 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
| 15 |
|
---|
| 16 | //a class that translate the issue values of all issue types
|
---|
| 17 | //into our standart ValueDecrease.
|
---|
| 18 | public class IssuesDecreases{
|
---|
| 19 |
|
---|
| 20 | private Map<String,ValueDecrease> values;
|
---|
| 21 | private ISSUETYPE type;
|
---|
| 22 | private Issue origin;
|
---|
| 23 | //for use in real
|
---|
| 24 | private boolean goingDown;
|
---|
| 25 |
|
---|
| 26 | IssuesDecreases(AdditiveUtilitySpace space){
|
---|
| 27 | values = new HashMap<String,ValueDecrease>();
|
---|
| 28 | }
|
---|
| 29 | //at start assumes that all issues have the same value.
|
---|
| 30 | //also assumes that all values except the "optimal"
|
---|
| 31 | //have a decrease equal to the weight with a very high varience
|
---|
| 32 | public void initilize(Issue issue,Value maximalValue,int issueCount){
|
---|
| 33 | double initWeight = 1.0/issueCount;
|
---|
| 34 | type = issue.getType();
|
---|
| 35 | origin = issue;
|
---|
| 36 | switch(type){
|
---|
| 37 | case DISCRETE:
|
---|
| 38 | IssueDiscrete issueD = (IssueDiscrete)issue;
|
---|
| 39 | int s = issueD.getNumberOfValues();
|
---|
| 40 | for(int i=0;i<s;i++){
|
---|
| 41 | String key = issueD.getValue(i).toString();
|
---|
| 42 | ValueDecrease val;
|
---|
| 43 | if(key.equals(maximalValue.toString())){
|
---|
| 44 | val = new ValueDecrease(0,0.9,0.01);
|
---|
| 45 | }
|
---|
| 46 | else{
|
---|
| 47 | val = new ValueDecrease(initWeight,0.02,initWeight);
|
---|
| 48 | }
|
---|
| 49 | values.put(key, val);
|
---|
| 50 | }
|
---|
| 51 | break;
|
---|
| 52 | case REAL:
|
---|
| 53 | IssueReal issueR = (IssueReal)issue;
|
---|
| 54 | double lower = issueR.getLowerBound();
|
---|
| 55 | double higher = issueR.getUpperBound();
|
---|
| 56 | double maxValue = ((ValueReal)maximalValue).getValue();
|
---|
| 57 | ValueDecrease worst = new ValueDecrease(initWeight,0.1,initWeight);
|
---|
| 58 | values.put("WORST", worst);
|
---|
| 59 | //likely to be either lower or higher.
|
---|
| 60 | //but even if its not, that the first bid is likely to be
|
---|
| 61 | //closer to the optimal...
|
---|
| 62 | goingDown = maxValue<(lower+higher)/2;
|
---|
| 63 | break;
|
---|
| 64 | case INTEGER:
|
---|
| 65 | IssueInteger issueI = (IssueInteger)issue;
|
---|
| 66 | lower = issueI.getLowerBound();
|
---|
| 67 | higher = issueI.getUpperBound();
|
---|
| 68 | maxValue = ((ValueInteger)maximalValue).getValue();
|
---|
| 69 | worst = new ValueDecrease(initWeight,0.1,initWeight);
|
---|
| 70 | values.put("WORST", worst);
|
---|
| 71 | //likely to be either lower or higher.
|
---|
| 72 | //but even if its not, that the first bid is likely to be
|
---|
| 73 | //closer to the optimal...
|
---|
| 74 | goingDown = maxValue<(lower+higher)/2;
|
---|
| 75 | break;
|
---|
| 76 |
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | //change all costs so that the new maximal decrease equals the old, AND all
|
---|
| 82 | //others change proportionately.
|
---|
| 83 | //assumes that the normalization process accured because of a faulty
|
---|
| 84 | //scale when evaluating other player's bids
|
---|
| 85 | public void normalize(double newWeight){
|
---|
| 86 | double originalMinVal = 1;
|
---|
| 87 | for(ValueDecrease val: values.values()){
|
---|
| 88 | if(originalMinVal>val.getDecrease()){
|
---|
| 89 | originalMinVal=val.getDecrease();
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 | double originalMaxVal = weight();
|
---|
| 93 | if(originalMaxVal == originalMinVal){
|
---|
| 94 | for(ValueDecrease val: values.values()){
|
---|
| 95 | val.forceChangeDecrease(newWeight);
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | else{
|
---|
| 99 | double changeRatio = newWeight/(originalMaxVal-originalMinVal);
|
---|
| 100 | for(ValueDecrease val: values.values()){
|
---|
| 101 | val.forceChangeDecrease(
|
---|
| 102 | (val.getDecrease()-originalMinVal)*changeRatio);
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | }
|
---|
| 107 | //maximal decrease
|
---|
| 108 | public double weight(){
|
---|
| 109 | double maximalDecrease = 0;
|
---|
| 110 | for(ValueDecrease val: values.values()){
|
---|
| 111 | if(maximalDecrease<val.getDecrease()){
|
---|
| 112 | maximalDecrease=val.getDecrease();
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 | return maximalDecrease;
|
---|
| 116 | }
|
---|
| 117 | public ValueDecrease getExpectedDecrease(Value value){
|
---|
| 118 | switch(type){
|
---|
| 119 | case DISCRETE:
|
---|
| 120 | ValueDecrease val = values.get(value.toString());
|
---|
| 121 | if(val!=null) return val;
|
---|
| 122 | break;
|
---|
| 123 | case REAL:
|
---|
| 124 | IssueReal issueR = (IssueReal)origin;
|
---|
| 125 | double lower = issueR.getLowerBound();
|
---|
| 126 | double higher = issueR.getUpperBound();
|
---|
| 127 | double curValue = ((ValueReal)value).getValue();
|
---|
| 128 | double portionOfWorst = (curValue-lower)/(higher-lower);
|
---|
| 129 | if(!goingDown){
|
---|
| 130 | portionOfWorst = 1-portionOfWorst;
|
---|
| 131 | }
|
---|
| 132 | ValueDecrease worst = values.get("WORST");
|
---|
| 133 | if(worst!=null)return new RealValuedecreaseProxy(worst,portionOfWorst);
|
---|
| 134 | case INTEGER:
|
---|
| 135 | IssueInteger issueI = (IssueInteger)origin;
|
---|
| 136 | lower = issueI.getLowerBound();
|
---|
| 137 | higher = issueI.getUpperBound();
|
---|
| 138 | curValue = ((ValueInteger)value).getValue();
|
---|
| 139 | portionOfWorst = (curValue-lower)/(higher-lower);
|
---|
| 140 | if(!goingDown){
|
---|
| 141 | portionOfWorst = 1-portionOfWorst;
|
---|
| 142 | }
|
---|
| 143 | worst = values.get("WORST");
|
---|
| 144 | if(worst!=null)return new RealValuedecreaseProxy(worst,portionOfWorst);
|
---|
| 145 | }
|
---|
| 146 | //should choose something that will make the program recoverable
|
---|
| 147 |
|
---|
| 148 | return new ValueDecrease(1,0.01,1);
|
---|
| 149 | }
|
---|
[1] | 150 | } |
---|