Last change
on this file since 148 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:
1.2 KB
|
Line | |
---|
1 | package parties.in4010.q12015.group13;
|
---|
2 |
|
---|
3 | import genius.core.issue.IssueInteger;
|
---|
4 | import genius.core.issue.ValueInteger;
|
---|
5 |
|
---|
6 | public class IntegerIssueModel implements IssueModel<ValueInteger> {
|
---|
7 | private double minFreq;
|
---|
8 | private double maxFreq;
|
---|
9 | private int min;
|
---|
10 | private int max;
|
---|
11 | private int half;
|
---|
12 |
|
---|
13 | public IntegerIssueModel(IssueInteger i) {
|
---|
14 | minFreq = maxFreq = 0;
|
---|
15 |
|
---|
16 | min = i.getLowerBound();
|
---|
17 | max = i.getUpperBound();
|
---|
18 |
|
---|
19 | half = min + (max - min) / 2;
|
---|
20 | }
|
---|
21 |
|
---|
22 | @Override
|
---|
23 | public void addBid(ValueInteger v) {
|
---|
24 | if (v.getValue() < half) {
|
---|
25 | minFreq += (half - v.getValue()) / (half - min);
|
---|
26 | } else if (v.getValue() > half) {
|
---|
27 | maxFreq += (v.getValue() - half) / (max - half);
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | @Override
|
---|
32 | public double estimateUtility(ValueInteger v) {
|
---|
33 | if (minFreq == 0 && maxFreq == 0) {
|
---|
34 | return 1;
|
---|
35 | }
|
---|
36 |
|
---|
37 | double m = minFreq >= maxFreq ? minFreq : maxFreq;
|
---|
38 |
|
---|
39 | double div = (max - min) * m;
|
---|
40 |
|
---|
41 | return ((max - v.getValue()) * minFreq + (v.getValue() - min) * maxFreq)
|
---|
42 | / div;
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public String toString() {
|
---|
47 | double m = minFreq >= maxFreq ? minFreq : maxFreq;
|
---|
48 |
|
---|
49 | return min + ": " + (minFreq / m) + ", " + max + ": " + (maxFreq / m);
|
---|
50 | }
|
---|
51 |
|
---|
52 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.