source: anac2020/Anaconda/src/main/java/geniusweb/exampleparties/anaconda/ImpMap.java

Last change on this file was 1, checked in by wouter, 4 years ago

#1910 added anac2020 parties

File size: 3.3 KB
Line 
1package geniusweb.exampleparties.anaconda;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6import java.util.Map;
7
8import geniusweb.issuevalue.Bid;
9import geniusweb.issuevalue.Domain;
10import geniusweb.issuevalue.Value;
11import geniusweb.issuevalue.ValueSet;
12import geniusweb.profile.PartialOrdering;
13
14@SuppressWarnings("serial")
15public 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}
Note: See TracBrowser for help on using the repository browser.