source: exampleparties/anac2019/agentgg/src/main/java/geniusweb/exampleparties/agentgg/ImpMap.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 4.0 KB
Line 
1package geniusweb.exampleparties.agentgg;
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/**
15 * Importance map. One is created for each party. The key (String) is the issue
16 * and value is list of Importances of the values.
17 *
18 */
19@SuppressWarnings("serial")
20public class ImpMap extends HashMap<String, List<impUnit>> {
21 private Domain domain;
22
23 // importance map
24 public ImpMap(PartialOrdering profile) {
25 super();
26 this.domain = profile.getDomain();
27 // Create empty my import map and opponent's value map
28 for (String issue : domain.getIssues()) {
29 ValueSet values = domain.getValues(issue);
30 List<impUnit> issueImpUnit = new ArrayList<>();
31 for (Value value : values) {
32 issueImpUnit.add(new impUnit(value));
33 }
34 this.put(issue, issueImpUnit);
35 }
36 }
37
38 /**
39 * Update opponent map. Increases the meanWeightSum of the values of this
40 * bid.
41 *
42 * @param receivedOfferBid tbe received opponent bid.
43 */
44 public void opponent_update(Bid receivedOfferBid) {
45 for (String issue : receivedOfferBid.getIssues()) {
46 ValueSet values = domain.getValues(issue);
47 List<impUnit> currentIssueList = this.get(issue);
48 for (impUnit currentUnit : currentIssueList) {
49 if (currentUnit.valueOfIssue
50 .equals(receivedOfferBid.getValue(issue))) {
51 currentUnit.meanWeightSum += 1;
52 break;
53 }
54 }
55 }
56 for (List<impUnit> impUnitList : this.values()) {
57 impUnitList.sort(new impUnit.meanWeightSumComparator());
58 }
59 }
60
61 /**
62 * Update your own importance map Traverse the known bidOrder and update the
63 * "weight sum" and "number of times" in the import table.
64 *
65 * @param bidOrdering a list of ordered bids, worst bid first, best bid last
66 */
67 public void self_update(List<Bid> bidOrdering) {
68 int currentWeight = 0;
69 for (Bid bid : bidOrdering) {
70 currentWeight += 1;
71 for (String issue : bid.getIssues()) {
72 List<impUnit> currentIssueList = this.get(issue);
73 for (impUnit currentUnit : currentIssueList) {
74 if (currentUnit.valueOfIssue.toString()
75 .equals(bid.getValue(issue).toString())) {
76 currentUnit.weightSum += currentWeight;
77 currentUnit.count += 1;
78 break;
79 }
80 }
81 }
82 }
83 // Calculate weights
84 for (List<impUnit> impUnitList : this.values()) {
85 for (impUnit currentUnit : impUnitList) {
86 if (currentUnit.count == 0) {
87 currentUnit.meanWeightSum = 0.0;
88 } else {
89 currentUnit.meanWeightSum = (double) currentUnit.weightSum
90 / (double) currentUnit.count;
91 }
92 }
93 }
94 // Sort
95 for (List<impUnit> impUnitList : this.values()) {
96 impUnitList.sort(new impUnit.meanWeightSumComparator());
97 }
98 // Find the minimum
99 double minMeanWeightSum = Double.POSITIVE_INFINITY;
100 for (Map.Entry<String, List<impUnit>> entry : this.entrySet()) {
101 double tempMeanWeightSum = entry.getValue()
102 .get(entry.getValue().size() - 1).meanWeightSum;
103 if (tempMeanWeightSum < minMeanWeightSum) {
104 minMeanWeightSum = tempMeanWeightSum;
105 }
106 }
107 // Minus all values
108 for (List<impUnit> impUnitList : this.values()) {
109 for (impUnit currentUnit : impUnitList) {
110 currentUnit.meanWeightSum -= minMeanWeightSum;
111 }
112 }
113 }
114
115 /**
116 * @param bid the bid to get the importance (utility?) of.
117 * @return the importance value of bid. Note, this this returns possibly
118 * large (&gt;1) values, as the importance is not normalized.
119 */
120 public double getImportance(Bid bid) {
121 double bidImportance = 0.0;
122 for (String issue : bid.getIssues()) {
123 Value value = bid.getValue(issue);
124 double valueImportance = 0.0;
125 for (impUnit i : this.get(issue)) {
126 if (i.valueOfIssue.equals(value)) {
127 valueImportance = i.meanWeightSum;
128 break;
129 }
130 }
131 bidImportance += valueImportance;
132 }
133 return bidImportance;
134 }
135}
Note: See TracBrowser for help on using the repository browser.