1 | package geniusweb.blingbling;
|
---|
2 |
|
---|
3 | import java.math.BigInteger;
|
---|
4 | import java.util.HashMap;
|
---|
5 | import java.util.Map;
|
---|
6 |
|
---|
7 | import geniusweb.issuevalue.Bid;
|
---|
8 | import geniusweb.issuevalue.Value;
|
---|
9 | import geniusweb.issuevalue.DiscreteValueSet;
|
---|
10 | import geniusweb.issuevalue.ValueSet;
|
---|
11 |
|
---|
12 | //
|
---|
13 | //Old represent is the orignial SFM model.
|
---|
14 |
|
---|
15 | public class IssueTracker {
|
---|
16 | private String issue;
|
---|
17 | private int numValues;
|
---|
18 | private int seenValues = 0;
|
---|
19 |
|
---|
20 | private Map<Value, ValueTracker> valueTrackers = new HashMap<Value, ValueTracker>();
|
---|
21 | private Value maxValue = null;
|
---|
22 | private DiscreteValueSet valueset = null;
|
---|
23 | private int maxValueCount = 0;
|
---|
24 |
|
---|
25 | private double weight = 0.0;
|
---|
26 |
|
---|
27 | public IssueTracker(String issuename, ValueSet valueset) {
|
---|
28 | // if (valueset instanceof DiscreteValueSet)
|
---|
29 | // throw new RuntimeException("Opponent model is designed for discrete issues only");
|
---|
30 |
|
---|
31 | this.issue = issuename;
|
---|
32 | this.valueset = (DiscreteValueSet) valueset;
|
---|
33 | this.numValues = Integer.valueOf(this.valueset.size().toString());//transfer biginteger to int
|
---|
34 | }
|
---|
35 |
|
---|
36 | public void registerValue(Value value, int bidsReceived) {//bidsReceived指的是收到的bid的总长度。
|
---|
37 | // create value tracker if needed
|
---|
38 | if (valueTrackers.get(value) == null) {
|
---|
39 | valueTrackers.put(value, new ValueTracker());
|
---|
40 | seenValues++;
|
---|
41 | }
|
---|
42 |
|
---|
43 | // register max offered value with count
|
---|
44 | int valueCount = valueTrackers.get(value).incrementGet();
|
---|
45 | if (valueCount > maxValueCount) {
|
---|
46 | maxValueCount = valueCount;
|
---|
47 | maxValue = value;
|
---|
48 | }
|
---|
49 |
|
---|
50 | // update issue weight
|
---|
51 | if (numValues > 1) {
|
---|
52 | double equalShares = ((double) bidsReceived / (double) numValues);
|
---|
53 | weight = ((double) maxValueCount - equalShares) / ((double) bidsReceived - equalShares);
|
---|
54 | }
|
---|
55 |
|
---|
56 | // update all value evaluations
|
---|
57 | for (ValueTracker valueTracker : valueTrackers.values())
|
---|
58 | valueTracker.updateEvaluation(maxValueCount, weight);
|
---|
59 | }
|
---|
60 |
|
---|
61 | public double getEvaluationOld(Value value) {//原SFM的eval
|
---|
62 | return (valueTrackers.get(value) == null) ? 0.0
|
---|
63 | : ((double) valueTrackers.get(value).getCount() / (double) maxValueCount);
|
---|
64 | }
|
---|
65 |
|
---|
66 | public double getEvaluation(Value value) {
|
---|
67 | return (valueTrackers.get(value) == null) ? 0.0 : valueTrackers.get(value).getEvaluation();
|
---|
68 | }
|
---|
69 |
|
---|
70 | public double getWeight() {
|
---|
71 | return weight;
|
---|
72 | }
|
---|
73 |
|
---|
74 | public double getOldWeight(int bidsReceived) {
|
---|
75 | return (bidsReceived == 0) ? 0.0 : (double) maxValueCount / (double) bidsReceived;
|
---|
76 | }
|
---|
77 |
|
---|
78 | public Value getMaxValue() {
|
---|
79 | return maxValue;
|
---|
80 | }
|
---|
81 |
|
---|
82 | public String toString() {
|
---|
83 | return issue.toString() + ":\n" + valueTrackers.toString() + "\n";
|
---|
84 | }
|
---|
85 | } |
---|