[1] | 1 | package agents.anac.y2010.AgentSmith;
|
---|
| 2 |
|
---|
| 3 | import java.util.HashMap;
|
---|
| 4 | import java.util.List;
|
---|
| 5 |
|
---|
| 6 | import genius.core.Bid;
|
---|
| 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.ValueDiscrete;
|
---|
| 13 | import genius.core.issue.ValueInteger;
|
---|
| 14 | import genius.core.issue.ValueReal;
|
---|
| 15 |
|
---|
| 16 | /**
|
---|
| 17 | * Class that is used to determine the bounds of an issue.
|
---|
| 18 | */
|
---|
| 19 | public class Bounds {
|
---|
| 20 | private double fLower;
|
---|
| 21 | private double fUpper;
|
---|
| 22 | private double fAmtSteps;
|
---|
| 23 |
|
---|
| 24 | /**
|
---|
| 25 | * Constructor
|
---|
| 26 | */
|
---|
| 27 | public Bounds() {
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | /**
|
---|
| 31 | * Constructor. Sets the bounds for a given issue based on its type
|
---|
| 32 | * (discrete, real or integer)
|
---|
| 33 | */
|
---|
| 34 | public Bounds(Issue pIssue) {
|
---|
| 35 | switch (pIssue.getType()) {
|
---|
| 36 | case DISCRETE:
|
---|
| 37 | IssueDiscrete lIssueDiscrete = ((IssueDiscrete) pIssue);
|
---|
| 38 | setUpper(lIssueDiscrete.getNumberOfValues());
|
---|
| 39 | setLower(0);
|
---|
| 40 | setAmtSteps(lIssueDiscrete.getNumberOfValues());
|
---|
| 41 | break;
|
---|
| 42 | case REAL:
|
---|
| 43 | IssueReal lIssueReal = ((IssueReal) pIssue);
|
---|
| 44 | setUpper(lIssueReal.getUpperBound());
|
---|
| 45 | setLower(lIssueReal.getLowerBound());
|
---|
| 46 | setAmtSteps(10);
|
---|
| 47 | break;
|
---|
| 48 | case INTEGER:
|
---|
| 49 | IssueInteger lIssueInteger = ((IssueInteger) pIssue);
|
---|
| 50 | setUpper(lIssueInteger.getUpperBound());
|
---|
| 51 | setLower(lIssueInteger.getLowerBound());
|
---|
| 52 | setAmtSteps(10);
|
---|
| 53 | break;
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | /**
|
---|
| 58 | * returns the lower bound
|
---|
| 59 | */
|
---|
| 60 | public double getLower() {
|
---|
| 61 | return fLower;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | /**
|
---|
| 65 | * returns the upper bound
|
---|
| 66 | */
|
---|
| 67 | public double getUpper() {
|
---|
| 68 | return fUpper;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | /**
|
---|
| 72 | * returns the amount of steps
|
---|
| 73 | */
|
---|
| 74 | public double getAmtSteps() {
|
---|
| 75 | return fAmtSteps;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | /**
|
---|
| 79 | * returns the number of steps
|
---|
| 80 | */
|
---|
| 81 | public double getStepSize() {
|
---|
| 82 | return (fUpper - fLower) / fAmtSteps;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | /**
|
---|
| 86 | * sets the lower bound
|
---|
| 87 | */
|
---|
| 88 | public void setLower(double pLower) {
|
---|
| 89 | this.fLower = pLower;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | /**
|
---|
| 93 | * sets the upper bound
|
---|
| 94 | */
|
---|
| 95 | public void setUpper(double pUpper) {
|
---|
| 96 | this.fUpper = pUpper;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | /**
|
---|
| 100 | * set the number of steps to take
|
---|
| 101 | */
|
---|
| 102 | public void setAmtSteps(double pAmtSteps) {
|
---|
| 103 | this.fAmtSteps = pAmtSteps;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | /**
|
---|
| 107 | * Creates a hashmap with for each of the issues the bounds
|
---|
| 108 | */
|
---|
| 109 | public static HashMap<Integer, Bounds> getIssueBounds(List<Issue> pIssues) {
|
---|
| 110 | HashMap<Integer, Bounds> bounds = new HashMap<Integer, Bounds>();
|
---|
| 111 |
|
---|
| 112 | for (Issue lIssue : pIssues) {
|
---|
| 113 | Bounds b = new Bounds(lIssue);
|
---|
| 114 |
|
---|
| 115 | bounds.put(lIssue.getNumber(), b);
|
---|
| 116 |
|
---|
| 117 | }
|
---|
| 118 | return bounds;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | /**
|
---|
| 122 | * returns a Value object with the value of an issue at the given index
|
---|
| 123 | * works for real, discrete and integer objects
|
---|
| 124 | */
|
---|
| 125 | public static Value getIssueValue(Issue pIssue, double pIndex) {
|
---|
| 126 | Value v = null;
|
---|
| 127 | switch (pIssue.getType()) {
|
---|
| 128 | case DISCRETE:
|
---|
| 129 | v = ((IssueDiscrete) pIssue).getValue((int) pIndex);
|
---|
| 130 | break;
|
---|
| 131 | case REAL:
|
---|
| 132 | v = new ValueReal(pIndex);
|
---|
| 133 | break;
|
---|
| 134 | case INTEGER:
|
---|
| 135 | v = new ValueInteger((int) pIndex);
|
---|
| 136 | break;
|
---|
| 137 | }
|
---|
| 138 | return v;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | /**
|
---|
| 142 | * returns the scaled value of the (discrete, real or integer) issue. it is
|
---|
| 143 | * scaled by the difference between the value and the lower bound divided by
|
---|
| 144 | * the length of the bounds
|
---|
| 145 | */
|
---|
| 146 | public static double getScaledIssueValue(Bounds pBounds, Bid pBid,
|
---|
| 147 | Issue pIssue) throws Exception {
|
---|
| 148 |
|
---|
| 149 | Value v = pBid.getValue(pIssue.getNumber());
|
---|
| 150 |
|
---|
| 151 | double value = 0;
|
---|
| 152 |
|
---|
| 153 | switch (pIssue.getType()) {
|
---|
| 154 | case DISCRETE:
|
---|
| 155 | value = ((IssueDiscrete) pIssue).getValueIndex(((ValueDiscrete) v)
|
---|
| 156 | .getValue());
|
---|
| 157 | break;
|
---|
| 158 | case REAL:
|
---|
| 159 | value = ((ValueReal) v).getValue();
|
---|
| 160 | break;
|
---|
| 161 | case INTEGER:
|
---|
| 162 | value = ((ValueInteger) v).getValue();
|
---|
| 163 | break;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | return (value - pBounds.getLower())
|
---|
| 167 | / (pBounds.getUpper() - pBounds.getLower());
|
---|
| 168 |
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | /**
|
---|
| 172 | * returns a normalized version of a value
|
---|
| 173 | */
|
---|
| 174 | public double normalize(double pValue) {
|
---|
| 175 | return (pValue - getLower()) / (getUpper() - getLower());
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | /**
|
---|
| 179 | * returns a string with the upper and lower bounds
|
---|
| 180 | */
|
---|
| 181 | public String toString() {
|
---|
| 182 | return "Upper: " + getUpper() + " Lower: " + getLower();
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | }
|
---|