[127] | 1 | package agents.similarity;
|
---|
| 2 |
|
---|
| 3 | import java.util.HashMap;
|
---|
| 4 |
|
---|
| 5 | import genius.core.Bid;
|
---|
| 6 | import genius.core.Domain;
|
---|
| 7 | import genius.core.issue.IssueReal;
|
---|
| 8 | import genius.core.issue.ValueReal;
|
---|
| 9 | import genius.core.utility.EVALFUNCTYPE;
|
---|
| 10 | import genius.core.utility.EVALUATORTYPE;
|
---|
| 11 | import genius.core.xml.SimpleElement;
|
---|
| 12 |
|
---|
| 13 | public class CriteriaReal implements Criteria {
|
---|
| 14 | // Class fields
|
---|
| 15 | // double lowerBound;
|
---|
| 16 | // double upperBound;
|
---|
| 17 | EVALFUNCTYPE type;
|
---|
| 18 | private int fIssueIndex;
|
---|
| 19 | private Domain fDomain;
|
---|
| 20 | HashMap<Integer, Double> fParam;
|
---|
| 21 |
|
---|
| 22 | public CriteriaReal(Domain pDomain, int pIssueIndex) {
|
---|
| 23 | fIssueIndex = pIssueIndex;
|
---|
| 24 | fDomain = pDomain;
|
---|
| 25 | fParam = new HashMap<Integer, Double>();
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | public double getValue(Bid pBid) {
|
---|
| 29 | double utility = 0;
|
---|
| 30 | try {
|
---|
| 31 | double value = ((ValueReal) pBid.getValue(fIssueIndex)).getValue();
|
---|
| 32 | switch (this.type) {
|
---|
| 33 | case FARATIN:
|
---|
| 34 | IssueReal lIssue = (IssueReal) (fDomain.getObjectivesRoot()
|
---|
| 35 | .getObjective(fIssueIndex));
|
---|
| 36 | utility = EVALFUNCTYPE.evalFaratin(value,
|
---|
| 37 | lIssue.getUpperBound(), lIssue.getLowerBound(),
|
---|
| 38 | this.fParam.get(0), this.fParam.get(1));
|
---|
| 39 | /*
|
---|
| 40 | * if (utility<0) utility = 0; else if (utility > 1) utility =
|
---|
| 41 | * 1;
|
---|
| 42 | */
|
---|
| 43 | return utility;
|
---|
| 44 |
|
---|
| 45 | case LINEAR:
|
---|
| 46 | utility = EVALFUNCTYPE.evalLinear(value, this.fParam.get(1),
|
---|
| 47 | this.fParam.get(0));
|
---|
| 48 | if (utility < 0)
|
---|
| 49 | utility = 0;
|
---|
| 50 | else if (utility > 1)
|
---|
| 51 | utility = 1;
|
---|
| 52 | return utility;
|
---|
| 53 | case CONSTANT:
|
---|
| 54 | return this.fParam.get(0);
|
---|
| 55 | default:
|
---|
| 56 | return -1.0;
|
---|
| 57 | }
|
---|
| 58 | } catch (Exception e) {
|
---|
| 59 | e.printStackTrace();
|
---|
| 60 | }
|
---|
| 61 | return utility;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | public EVALUATORTYPE getType() {
|
---|
| 65 | return EVALUATORTYPE.REAL;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | /*
|
---|
| 69 | * public double getLowerBound() { return lowerBound; }
|
---|
| 70 | *
|
---|
| 71 | * public double getUpperBound() { return lowerBound; }
|
---|
| 72 | */
|
---|
| 73 | public void loadFromXML(SimpleElement pRoot) {
|
---|
| 74 | // Object[] xml_item =
|
---|
| 75 | // ((SimpleElement)pRoot).getChildByTagName("range");
|
---|
| 76 | // this.lowerBound =
|
---|
| 77 | // Double.valueOf(((SimpleElement)xml_item[0]).getAttribute("lowerbound"));
|
---|
| 78 | // this.upperBound =
|
---|
| 79 | // Double.valueOf(((SimpleElement)xml_item[0]).getAttribute("upperbound"));
|
---|
| 80 | String ftype = pRoot.getAttribute("type");
|
---|
| 81 | if (ftype != null)
|
---|
| 82 | this.type = EVALFUNCTYPE.convertToType(ftype);
|
---|
| 83 | // TODO: define exception.
|
---|
| 84 | // TODO: DT: redefine this swith in more generic way
|
---|
| 85 | switch (this.type) {
|
---|
| 86 | case FARATIN:
|
---|
| 87 | this.fParam
|
---|
| 88 | .put(1, Double.valueOf(pRoot.getAttribute("parameter1")));
|
---|
| 89 | this.fParam
|
---|
| 90 | .put(0, Double.valueOf(pRoot.getAttribute("parameter0")));
|
---|
| 91 | break;
|
---|
| 92 | case LINEAR:
|
---|
| 93 | this.fParam
|
---|
| 94 | .put(1, Double.valueOf(pRoot.getAttribute("parameter1")));
|
---|
| 95 | case CONSTANT:
|
---|
| 96 | this.fParam
|
---|
| 97 | .put(0, Double.valueOf(pRoot.getAttribute("parameter0")));
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 | }
|
---|