1 | package geniusweb.exampleparties.anaconda;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.HashMap;
|
---|
5 | import java.util.List;
|
---|
6 | import java.util.Map;
|
---|
7 |
|
---|
8 | import geniusweb.issuevalue.Bid;
|
---|
9 | import geniusweb.issuevalue.Domain;
|
---|
10 | import geniusweb.issuevalue.Value;
|
---|
11 | import geniusweb.issuevalue.ValueSet;
|
---|
12 | import geniusweb.profile.PartialOrdering;
|
---|
13 |
|
---|
14 | @SuppressWarnings("serial")
|
---|
15 | public class ImpMap extends HashMap<String, List<impUnit>> {
|
---|
16 | private Domain domain;
|
---|
17 |
|
---|
18 | // importance map
|
---|
19 | public ImpMap(PartialOrdering profile) {
|
---|
20 | super();
|
---|
21 | this.domain = profile.getDomain();
|
---|
22 | // Create empty my import map and opponent's value map
|
---|
23 | for (String issue : domain.getIssues()) {
|
---|
24 | ValueSet values = domain.getValues(issue);
|
---|
25 | List<impUnit> issueImpUnit = new ArrayList<>();
|
---|
26 | for (Value value : values) {
|
---|
27 | issueImpUnit.add(new impUnit(value));
|
---|
28 | }
|
---|
29 | this.put(issue, issueImpUnit);
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | public void opponent_update(Bid receivedOfferBid) {
|
---|
34 | for (String issue : receivedOfferBid.getIssues()) {
|
---|
35 | ValueSet values = domain.getValues(issue);
|
---|
36 | List<impUnit> currentIssueList = this.get(issue);
|
---|
37 | for (impUnit currentUnit : currentIssueList) {
|
---|
38 | if (currentUnit.valueOfIssue
|
---|
39 | .equals(receivedOfferBid.getValue(issue))) {
|
---|
40 | currentUnit.probability += 1;
|
---|
41 | break;
|
---|
42 | }
|
---|
43 | }
|
---|
44 | }
|
---|
45 | for (List<impUnit> impUnitList : this.values()) {
|
---|
46 | impUnitList.sort(new impUnit.meanWeightSumComparator());
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | public void self_update(List<Bid> bidOrdering) {
|
---|
51 | int currentWeight = 0;
|
---|
52 | for (Bid bid : bidOrdering) {
|
---|
53 | currentWeight += 1;
|
---|
54 | for (String issue : bid.getIssues()) {
|
---|
55 | List<impUnit> currentIssueList = this.get(issue);
|
---|
56 | for (impUnit currentUnit : currentIssueList) {
|
---|
57 | if (currentUnit.valueOfIssue.toString()
|
---|
58 | .equals(bid.getValue(issue).toString())) {
|
---|
59 | currentUnit.victories += currentWeight;
|
---|
60 | currentUnit.total_count += 1;
|
---|
61 | break;
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|
66 | // Calculate weights
|
---|
67 | for (List<impUnit> impUnitList : this.values()) {
|
---|
68 | for (impUnit currentUnit : impUnitList) {
|
---|
69 | if (currentUnit.total_count == 0) {
|
---|
70 | currentUnit.probability = 0.0;
|
---|
71 | } else {
|
---|
72 | currentUnit.probability = (double) currentUnit.victories
|
---|
73 | / (double) currentUnit.total_count;
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 | // Sort
|
---|
78 | for (List<impUnit> impUnitList : this.values()) {
|
---|
79 | impUnitList.sort(new impUnit.meanWeightSumComparator());
|
---|
80 | }
|
---|
81 | // Find the minimum
|
---|
82 | double minMeanWeightSum = Double.POSITIVE_INFINITY;
|
---|
83 | for (Map.Entry<String, List<impUnit>> entry : this.entrySet()) {
|
---|
84 | double tempMeanWeightSum = entry.getValue()
|
---|
85 | .get(entry.getValue().size() - 1).probability;
|
---|
86 | if (tempMeanWeightSum < minMeanWeightSum) {
|
---|
87 | minMeanWeightSum = tempMeanWeightSum;
|
---|
88 | }
|
---|
89 | }
|
---|
90 | // Minus all values
|
---|
91 | for (List<impUnit> impUnitList : this.values()) {
|
---|
92 | for (impUnit currentUnit : impUnitList) {
|
---|
93 | currentUnit.probability -= minMeanWeightSum;
|
---|
94 | }
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | public double getImportance(Bid bid) {
|
---|
99 | double bidImportance = 0.0;
|
---|
100 | for (String issue : bid.getIssues()) {
|
---|
101 | Value value = bid.getValue(issue);
|
---|
102 | double valueImportance = 0.0;
|
---|
103 | for (impUnit i : this.get(issue)) {
|
---|
104 | if (i.valueOfIssue.equals(value)) {
|
---|
105 | valueImportance = i.probability;
|
---|
106 | break;
|
---|
107 | }
|
---|
108 | }
|
---|
109 | bidImportance += valueImportance;
|
---|
110 | }
|
---|
111 | return bidImportance;
|
---|
112 | }
|
---|
113 | }
|
---|