source: anac2020/BlingBling/src/main/java/geniusweb/blingbling/OpponentProfile.java@ 14

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

#1910 added anac2020 parties

File size: 5.8 KB
Line 
1package geniusweb.blingbling;
2
3import java.util.LinkedHashMap;
4import java.util.Map;
5
6import javax.lang.model.util.ElementScanner6;
7
8import java.util.HashMap;
9import java.util.List;
10import java.util.ArrayList;
11
12
13import geniusweb.issuevalue.Bid;
14import geniusweb.issuevalue.Value;
15import geniusweb.issuevalue.ValueSet;
16import geniusweb.issuevalue.Domain;
17import geniusweb.profile.utilityspace.UtilitySpace;
18
19
20public class OpponentProfile {
21 private Distribution distOfferUtil = new Distribution();
22 private Distribution distOfferOppUtil = new Distribution();
23
24 private Map<String, Double> issueWeights = new LinkedHashMap<String, Double>();// 原issue使用number index,geniusweb中用insuusenam:string
25 private Map<String, IssueTracker> issueTrackers = new LinkedHashMap<String, IssueTracker>();
26
27 private Domain domain;
28// private UtilitySpace oppUtilitySpace;
29
30 private List<Bid> offers = new ArrayList<Bid>();
31
32 private Bid bestOffer = null;
33 private double bestOffer_util = 0.0;
34
35 private boolean oldWeights = false;//用于对比改进后的与原有的
36 private boolean oldEvaluation = false;
37
38 public OpponentProfile(Domain domain) {
39// this.oppUtilitySpace = oppUtilitySpace;
40 this.domain = domain;
41
42 for (String issuename : domain.getIssues())
43 issueTrackers.put(issuename, new IssueTracker(issuename, domain.getValues(issuename)));
44 }
45
46 public void registerOffer(Bid bid) {
47 offers.add(bid);
48
49// if (bid.getMyUndiscountedUtil() > bestOffer_util) {
50// bestOffer = bid;
51// bestOffer_util = bid.getMyUndiscountedUtil();
52// }
53
54 double totalWeight = 0.0;
55 for (String issuename : issueTrackers.keySet()) {
56 issueTrackers.get(issuename).registerValue(bid.getValue(issuename), offers.size());
57
58 double weight = issueTrackers.get(issuename).getWeight();
59 totalWeight += weight;
60 issueWeights.put(issuename, weight);
61 }
62
63 for (String issuename : issueWeights.keySet()) {
64 double putWeight = (totalWeight == 0.0) ? (1.0 / (double) issueWeights.size())
65 : (issueWeights.get(issuename) / totalWeight);
66 issueWeights.put(issuename, putWeight);
67 }
68 }
69
70 public double getPredOppUtility(Bid bid) {
71 if (offers.size() == 0 || bid == null)
72 return 0.0;
73
74 Map<String, Double> usedIssueWeights = (oldWeights) ? getOldIssueWeights() : issueWeights;
75
76 double predict = 0.0;
77 for (String issuename : issueTrackers.keySet()) {
78 Value value = bid.getValue(issuename);
79
80 IssueTracker it = issueTrackers.get(issuename);
81 double valueEvaluation = (oldEvaluation) ? it.getEvaluationOld(value) : it.getEvaluation(value);
82
83 predict += usedIssueWeights.get(issuename) * valueEvaluation;
84 }
85
86 return predict;
87 }
88
89 public void setMethod(boolean oldWeights, boolean oldEvaluation) {//确定用新的SFM还是老的SFM
90 this.oldWeights = oldWeights;
91 this.oldEvaluation = oldEvaluation;
92 }
93
94 public String getMethod() {
95 return "_" + (oldWeights ? "oldW" : "newW") + "_" + (oldEvaluation ? "oldE" : "newE");
96 }
97
98 private Map<String, Double> getOldIssueWeights() {//老SFM的计算issueweight的方法
99 Map<String, Double> oldIssueWeights = new LinkedHashMap<String, Double>();
100
101 double totalWeight = 0.0;
102 for (String issuename : issueTrackers.keySet()) {
103 double weight = issueTrackers.get(issuename).getOldWeight(offers.size());
104
105 totalWeight += weight;
106 oldIssueWeights.put(issuename, weight);
107 }
108
109 for (String issuename : oldIssueWeights.keySet())
110 oldIssueWeights.put(issuename, oldIssueWeights.get(issuename) / totalWeight);
111
112 return oldIssueWeights;
113 }
114
115 //get real utility via opponent utility
116// public double getOppUtility(Bid bid) {
117// return bid == null ? 0.0 : oppUtilitySpace.getUtility(bid);//return type
118// }
119
120 public Bid getPredOppMaxBid() {
121 if (offers.size() == 0)
122 return null;
123
124 HashMap<String, Value> values = new HashMap<String, Value>();
125
126 // For each issue, get the max value
127 for (String issuename : issueTrackers.keySet())
128 values.put(issuename, issueTrackers.get(issuename).getMaxValue());
129
130 // create and return bid
131 return new Bid(values);
132 }
133
134 public Bid getBestOffer() {
135 return bestOffer;
136 }
137
138 public Bid getLastOffer() {
139 return (offers.size() == 0) ? null : offers.get(offers.size() - 1);
140 }
141
142 public List<Bid> getOppOffers() {
143 return offers;
144 }
145
146// public UtilitySpace getOppUtilitySpace() {
147// return oppUtilitySpace;
148// }
149
150// public double getWindowAVG(double time) {
151// if (time < 0.5)
152// return 1.0;
153//
154// double start = 2 * time - 1;
155//
156// double sum = 0.0;
157// int count = 0;
158// for (Bid bid : offers) {
159// if (bid.getTime() > start) {
160// sum += bid.getMyUndiscountedUtil();
161// count++;
162// }
163// }
164//
165// return (count == 0) ? 1.0 : (sum / (double) count);
166// }
167//
168// public double getWindowMAX(double time) {
169// if (time < 0.5)
170// return 1.0;
171//
172// double start = 2 * time - 1;
173//
174// double max = 0.0;
175// for (BidDetails bid : offers) {
176// if (bid.getTime() > start) {
177// if (bid.getMyUndiscountedUtil() > max)
178// max = bid.getMyUndiscountedUtil();
179// }
180// }
181//
182// return (max == 0.0) ? 1.0 : max;
183// }
184
185 public String toString() {
186 return "\nWeights:\n" + issueWeights.toString() + "\n\nValues:\n" + issueTrackers.toString() + "\n";
187 }
188}
Note: See TracBrowser for help on using the repository browser.