source: src/main/java/agents/anac/y2019/podagent/Group1_BOA.java

Last change on this file was 200, checked in by Katsuhide Fujita, 5 years ago

Add ANAC 2019 agents

  • Property svn:executable set to *
File size: 6.7 KB
Line 
1package agents.anac.y2019.podagent;
2
3import genius.core.Bid;
4import genius.core.bidding.BidDetails;
5import genius.core.boaframework.*;
6import genius.core.issue.IssueDiscrete;
7import genius.core.issue.Value;
8import genius.core.issue.ValueDiscrete;
9import genius.core.parties.NegotiationInfo;
10import genius.core.timeline.DiscreteTimeline;
11import genius.core.uncertainty.AdditiveUtilitySpaceFactory;
12import genius.core.utility.AbstractUtilitySpace;
13import negotiator.boaframework.omstrategy.NullStrategy;
14
15import java.util.ArrayList;
16import java.util.Collections;
17import java.util.HashMap;
18import java.util.HashSet;
19import java.util.List;
20import java.util.Map;
21import java.util.Random;
22
23
24@SuppressWarnings("serial")
25public class Group1_BOA extends BoaParty {
26 @Override
27 public void init(NegotiationInfo info) {
28 // The choice for each component is made here
29 AcceptanceStrategy ac = new Group1_AS();
30 OfferingStrategy os = new Group1_BS();
31 OpponentModel om = new Group1_OM();
32 // OMS is part of the opponent model in our agent
33 OMStrategy oms = new NullStrategy();
34
35 // All component parameters can be set below.
36 Map<String, Double> noparams = Collections.emptyMap();
37
38 // Initialize all the components of this party to the choices defined above
39 configure(ac, noparams, os, noparams, om, noparams, oms, noparams);
40 super.init(info);
41 }
42
43 /*
44 * Estimate utility function in case of preference uncertainty.
45 *
46 * @see genius.core.parties.AbstractNegotiationParty#estimateUtilitySpace()
47 */
48 @Override
49 public AbstractUtilitySpace estimateUtilitySpace() {
50 AdditiveUtilitySpaceFactory factory = new AdditiveUtilitySpaceFactory(getDomain());
51 // Order of bids from low to high
52 List<Bid> bidOrder = userModel.getBidRanking().getBidOrder();
53 ArrayList<Bid> bidOrderArrayList = new ArrayList(bidOrder);
54
55 //Assign utilities to bids that are not in the specified bidOrder
56// for(BidDetails bid: outcomeSpace.getAllOutcomes()) {
57// if(bidOrderArrayList.contains(bid.getBid()))
58// continue;
59//
60// int bestPosition = 0;
61// double bestDistanceTop = 0;
62// double bestDistanceBottom = 0;
63//
64// for(int i = 0; i < bidOrderArrayList.size() - 1; i++ ) {
65// Bid higherBid = bidOrderArrayList.get(i);
66// Bid lowerBid = bidOrderArrayList.get(i + 1);
67// double higher = getBidDistance(bid.getBid(), higherBid);
68// double lower = getBidDistance(bid.getBid(), lowerBid);
69// if(higher > bestDistanceTop && lower > bestDistanceBottom) {
70// bestDistanceTop = lower;
71// bestDistanceBottom = higher;
72// bestPosition = i;
73// }
74// }
75// bidOrderArrayList.add(bestPosition + 1, bid.getBid());
76// }
77 Random r = new Random();
78
79 //Assign utilities to bids that are not in the specified bidOrder
80 for(int j = bidOrder.size(); j < 100; j++) {
81 Bid bid = factory.getDomain().getRandomBid(r);
82 if(bidOrderArrayList.contains(bid))
83 continue;
84
85 int bestPosition = 0;
86 double bestDistanceTop = 0;
87 double bestDistanceBottom = 0;
88
89 for(int i = 0; i < bidOrderArrayList.size() - 1; i++ ) {
90 Bid higherBid = bidOrderArrayList.get(i);
91 Bid lowerBid = bidOrderArrayList.get(i + 1);
92 double higher = getBidDistance(bid, higherBid);
93 double lower = getBidDistance(bid, lowerBid);
94 if(higher > bestDistanceTop && lower > bestDistanceBottom) {
95 bestDistanceTop = lower;
96 bestDistanceBottom = higher;
97 bestPosition = i;
98 }
99 }
100 bidOrderArrayList.add(bestPosition + 1, bid);
101 }
102
103
104 // Utility of highest and lowest bid
105 double low = userModel.getBidRanking().getLowUtility();
106 double high = userModel.getBidRanking().getHighUtility();
107 List<IssueDiscrete> issues = factory.getIssues();
108 // Initialize issues and all weights with 0
109 for (IssueDiscrete i : issues) {
110 factory.setWeight(i, 1.0 / (double) issues.size());
111 for (ValueDiscrete v : i.getValues()) {
112 factory.setUtility(i, v, 0.0);
113 }
114 }
115 // Count the number of occurrences of each value
116 HashMap<String, Integer> valCounter = new HashMap<String, Integer>();
117 for (int i = 0; i < bidOrderArrayList.size(); i++) {
118 // Estimate utility of bids in between high and low depending on their position
119 // in the ordering
120 // Position of bid correlates to it's utility
121 // Linear utility function
122 // double currentUtil = low + (high-low)*i/bidOrder.size();
123 // Exponential utility function that shifts the distribution of utility values
124 // towards the higher end of the ordering
125 double currentUtil = low + (high - low) * Math.pow(i / (double) bidOrderArrayList.size(), 2);
126 Bid currentBid = bidOrderArrayList.get(i);
127 // Add the estimated utility of the bid to its values
128 for (IssueDiscrete issue : issues) {
129 int no = issue.getNumber();
130 ValueDiscrete v = (ValueDiscrete) currentBid.getValue(no);
131 // Count occurrences
132 valCounter.put(v.getValue(), valCounter.getOrDefault(v.getValue(), 0) + 1);
133 double oldUtil = factory.getUtility(issue, v);
134 factory.setUtility(issue, v, oldUtil + currentUtil);
135 }
136 }
137 ArrayList<Double> issueWeights = new ArrayList<Double>();
138
139 for (IssueDiscrete i : issues) {
140 // Calculate the variance of values in the issue
141 ArrayList<Integer> weights = new ArrayList<Integer>();
142 // Average value weights by taking their average utility
143 double avg = 0;
144 double counter = 0;
145 for (ValueDiscrete v : i.getValues()) {
146 factory.setUtility(i, v, factory.getUtility(i, v) / (double) valCounter.getOrDefault(v.getValue(), 0));
147 weights.add(valCounter.getOrDefault(v.getValue(), 0));
148 if (factory.getUtility(i, v) != 0.0) {
149 avg += factory.getUtility(i, v);
150 counter++;
151 }
152 }
153 // Square numbers of value occurrences to estimate how varied the responses are
154 double var = 0;
155 for (int w : weights) {
156 var += Math.pow(w, 2);
157 }
158 issueWeights.add(var);
159
160 avg = avg / counter;
161 // set 0 values to the average
162 for (ValueDiscrete v : i.getValues()) {
163 if (factory.getUtility(i, v) == 0.0) {
164 factory.setUtility(i, v, avg);
165 }
166 }
167 }
168 // Invert and normalize weights
169 double sum = 0;
170 for (int i = 0; i < issueWeights.size(); i++) {
171 // More variance = less utility
172 issueWeights.set(i, 1 - issueWeights.get(i));
173 sum += issueWeights.get(i);
174 }
175 // Normalize the weights and set the issue weight
176 for (int i = 0; i < issueWeights.size(); i++) {
177 issueWeights.set(i, issueWeights.get(i) / sum);
178 factory.setWeight(issues.get(i), issueWeights.get(i));
179 }
180 factory.normalizeWeights();
181 return factory.getUtilitySpace();
182 }
183
184 @Override
185 public String getDescription() {
186 return "Group1_BOA";
187 }
188
189 public double getBidDistance(Bid bid1, Bid bid2) {
190 HashSet<Value> merged = new HashSet(bid1.getValues().values());
191 merged.addAll(bid2.getValues().values());
192 return bid1.countEqualValues(bid2) / merged.size();
193 }
194
195}
Note: See TracBrowser for help on using the repository browser.