source: src/main/java/agents/similarity/CriteriaInteger.java@ 345

Last change on this file since 345 was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 2.0 KB
Line 
1package agents.similarity;
2
3import java.util.HashMap;
4
5import genius.core.Bid;
6import genius.core.issue.ValueInteger;
7import genius.core.utility.EVALFUNCTYPE;
8import genius.core.utility.EVALUATORTYPE;
9import genius.core.xml.SimpleElement;
10
11public class CriteriaInteger implements Criteria {
12 // Class fields
13 int lowerBound;
14 int upperBound;
15 int fIssueIndex;
16 EVALFUNCTYPE type;
17 HashMap<Integer, Integer> fParam;
18
19 // Class methods
20
21 public CriteriaInteger() {
22 fParam = new HashMap<Integer, Integer>();
23 }
24
25
26 public double getValue(Bid bid) {
27 Integer lTmp = null;
28 try {
29 lTmp = ((ValueInteger)bid.getValue(fIssueIndex)).getValue();
30 } catch(Exception e) {
31 e.printStackTrace();
32 }
33 switch(this.type) {
34 case LINEAR:
35 Double d = EVALFUNCTYPE.evalLinear(lTmp, this.fParam.get(1), this.fParam.get(0));
36 if (d<0)
37 d=0.0;
38 else if (d>1)
39 d=1.0;
40 return d.intValue();
41 case CONSTANT:
42 return this.fParam.get(0);
43 default:
44 return -1;
45 }
46 }
47
48 public EVALUATORTYPE getType() {
49 return EVALUATORTYPE.INTEGER;
50 }
51
52 public int getLowerBound() {
53 return lowerBound;
54 }
55
56 public int getUpperBound() {
57 return lowerBound;
58 }
59
60 public void loadFromXML(SimpleElement pRoot) {
61 Object[] xml_item = ((SimpleElement)pRoot).getChildByTagName("range");
62 this.lowerBound = Integer.valueOf(((SimpleElement)xml_item[0]).getAttribute("lowerBound"));
63 this.upperBound = Integer.valueOf(((SimpleElement)xml_item[0]).getAttribute("upperBound"));
64 Object[] xml_items = ((SimpleElement)pRoot).getChildByTagName("evaluator");
65 String ftype = ((SimpleElement)xml_items[0]).getAttribute("ftype");
66 if (ftype!=null)
67 this.type = EVALFUNCTYPE.convertToType(ftype);
68 // TODO: define exception.
69 switch(this.type) {
70 case LINEAR:
71 this.fParam.put(1, Integer.valueOf(((SimpleElement)xml_items[0]).getAttribute("parameter1")));
72 case CONSTANT:
73 this.fParam.put(0, Integer.valueOf(((SimpleElement)xml_items[0]).getAttribute("parameter0")));
74 }
75
76 }
77
78
79}
Note: See TracBrowser for help on using the repository browser.