1 | package agents.anac.y2017.mamenchis;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.HashMap;
|
---|
5 | import java.util.LinkedList;
|
---|
6 | import java.util.List;
|
---|
7 | import java.util.Map;
|
---|
8 |
|
---|
9 | import genius.core.AgentID;
|
---|
10 | import genius.core.Bid;
|
---|
11 | import genius.core.actions.Accept;
|
---|
12 | import genius.core.actions.Action;
|
---|
13 | import genius.core.actions.Offer;
|
---|
14 | import genius.core.issue.Issue;
|
---|
15 | import genius.core.issue.IssueDiscrete;
|
---|
16 | import genius.core.issue.IssueInteger;
|
---|
17 | import genius.core.issue.Value;
|
---|
18 | import genius.core.issue.ValueInteger;
|
---|
19 | import genius.core.list.Tuple;
|
---|
20 | import genius.core.parties.AbstractNegotiationParty;
|
---|
21 | import genius.core.parties.NegotiationInfo;
|
---|
22 | import genius.core.persistent.PersistentDataType;
|
---|
23 | import genius.core.persistent.StandardInfo;
|
---|
24 | import genius.core.persistent.StandardInfoList;
|
---|
25 | import genius.core.utility.AbstractUtilitySpace;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Sample party that accepts the Nth offer, where N is the number of sessions
|
---|
29 | * this [agent-profile] already did.
|
---|
30 | */
|
---|
31 |
|
---|
32 | public class Mamenchis extends AbstractNegotiationParty {
|
---|
33 |
|
---|
34 | private Bid lastReceivedBid = null;
|
---|
35 | private int nrChosenActions;
|
---|
36 | private StandardInfoList history;
|
---|
37 | private int numOfIssues;
|
---|
38 | private int numOfParties;
|
---|
39 | private double reservationValue;
|
---|
40 | private double initialUpper;
|
---|
41 | private double initialExponent;
|
---|
42 | private double upper;
|
---|
43 | private double lower;
|
---|
44 | private double exponent;
|
---|
45 | private double acceptUtil;
|
---|
46 | private double utility;
|
---|
47 | private List<Bid>[] proposedBids;
|
---|
48 | private int[] numOfBids;
|
---|
49 | private Map<Integer, Map<Value, Integer>>[] valueFrequences;
|
---|
50 | private Map<Integer, Integer>[] issueChangeFrequences;
|
---|
51 | private double[] maxUtils;
|
---|
52 | private double[] minUtils;
|
---|
53 | private LinkedList<Bid>[] proposedMaxBid;
|
---|
54 | private LinkedList<Bid>[] proposedMinBid;
|
---|
55 | private List<Bid>[] topBidsInOppsSpace;
|
---|
56 | private LinkedList<Bid>[] topBidsInMySpace;
|
---|
57 | private Bid myBid;
|
---|
58 | private List<Bid> fullUtilBids;
|
---|
59 | private int myIndex;
|
---|
60 | private String oppName;
|
---|
61 | private int oppIndex;
|
---|
62 | private boolean[] acceptAction;
|
---|
63 | private PreferModel[] pModel;
|
---|
64 | private Bid lastConcessionPoint;
|
---|
65 | private List<Bid>[] acceptableBidsWithOppValues;
|
---|
66 | private List<Bid> candidateBids;
|
---|
67 | private List<Bid> lastPeriodBidList;
|
---|
68 | private int myNextPartyIndex;
|
---|
69 | private int myLastPartyIndex;
|
---|
70 | private List<Bid>[] maxProductBids;
|
---|
71 | private List<Bid> maxUtilAdditionBidByOpps;
|
---|
72 | private double maxUtilAdditionByOpps;
|
---|
73 | private double time1;
|
---|
74 | private double time2;
|
---|
75 | private double time3;
|
---|
76 | private boolean hasHistory;
|
---|
77 | private boolean hasHistWithRightPosition;
|
---|
78 | private boolean hasInitParamByHist;
|
---|
79 | private List<Tuple<Bid, Double>> agreements;
|
---|
80 | private boolean hasAgreementHist;
|
---|
81 | private List<Bid> maxAgreedBids;
|
---|
82 | private Map<String, List<Double>>[] histUtils;
|
---|
83 | private Map<String, Double>[] maxUtilsInHist;
|
---|
84 | private List<Bid>[] maxUtilBidsByHist;
|
---|
85 | private List<Bid> sameBidsInOpps;
|
---|
86 |
|
---|
87 | @Override
|
---|
88 | public void init(NegotiationInfo info) {
|
---|
89 |
|
---|
90 | super.init(info);
|
---|
91 |
|
---|
92 | if (getData().getPersistentDataType() != PersistentDataType.STANDARD) {
|
---|
93 | throw new IllegalStateException("need standard persistent data");
|
---|
94 | }
|
---|
95 | history = (StandardInfoList) getData().get();
|
---|
96 |
|
---|
97 | if (!history.isEmpty()) {
|
---|
98 | Map<String, Double> maxutils = new HashMap<String, Double>();
|
---|
99 | StandardInfo lastinfo = history.get(history.size() - 1);
|
---|
100 | for (Tuple<String, Double> offered : lastinfo.getUtilities()) {
|
---|
101 | String party = offered.get1();
|
---|
102 | Double util = offered.get2();
|
---|
103 | maxutils.put(party, maxutils.containsKey(party)
|
---|
104 | ? Math.max(maxutils.get(party), util) : util);
|
---|
105 | }
|
---|
106 | }
|
---|
107 | hasAgreementHist = false;
|
---|
108 | if (!history.isEmpty()) {
|
---|
109 | hasHistory = true;
|
---|
110 | hasInitParamByHist = false;
|
---|
111 | agreements = new ArrayList<>();
|
---|
112 | maxAgreedBids = new ArrayList<>();
|
---|
113 | int numOfAgent = history.get(0).getAgentProfiles().size();
|
---|
114 | histUtils = new HashMap[numOfAgent];
|
---|
115 | maxUtilsInHist = new HashMap[numOfAgent];
|
---|
116 | maxUtilBidsByHist = new ArrayList[numOfAgent];
|
---|
117 | for (int i = 0; i < numOfAgent; i++) {
|
---|
118 | histUtils[i] = new HashMap<>();
|
---|
119 | maxUtilsInHist[i] = new HashMap<>();
|
---|
120 | maxUtilBidsByHist[i] = new ArrayList<>();
|
---|
121 | }
|
---|
122 | for (StandardInfo sessionInfo : history) {
|
---|
123 | if (sessionInfo.getAgreement().get1() != null) {
|
---|
124 | agreements.add(sessionInfo.getAgreement());
|
---|
125 | hasAgreementHist = true;
|
---|
126 | }
|
---|
127 | for (Tuple<String, Double> offered : sessionInfo
|
---|
128 | .getUtilities()) {
|
---|
129 | String party = offered.get1();
|
---|
130 | double util = offered.get2();
|
---|
131 | int index = Integer.parseInt(party.split("@")[1])
|
---|
132 | % numOfAgent;
|
---|
133 | if (!histUtils[index].containsKey(party)) {
|
---|
134 | List<Double> utils = new ArrayList<>();
|
---|
135 | utils.add(util);
|
---|
136 | histUtils[index].put(party, utils);
|
---|
137 | } else {
|
---|
138 | histUtils[index].get(party).add(util);
|
---|
139 | }
|
---|
140 | }
|
---|
141 | }
|
---|
142 | maxAgreedBids = getMaxBidsInAgreements();
|
---|
143 | for (int partyIndex = 0; partyIndex < numOfAgent; partyIndex++) {
|
---|
144 | for (String party : histUtils[partyIndex].keySet()) {
|
---|
145 | String partyName = party.split("@")[0];
|
---|
146 | List<Double> utils = histUtils[partyIndex].get(party);
|
---|
147 | double maxUtil = getMaxInArray(utils);
|
---|
148 | if (!maxUtilsInHist[partyIndex].containsKey(partyName)) {
|
---|
149 | maxUtilsInHist[partyIndex].put(partyName, maxUtil);
|
---|
150 | } else if (maxUtilsInHist[partyIndex]
|
---|
151 | .get(partyName) < maxUtil) {
|
---|
152 | maxUtilsInHist[partyIndex].put(partyName, maxUtil);
|
---|
153 | }
|
---|
154 | }
|
---|
155 | }
|
---|
156 | } else {
|
---|
157 | hasHistory = false;
|
---|
158 | hasHistWithRightPosition = false;
|
---|
159 | }
|
---|
160 |
|
---|
161 | nrChosenActions = 0;
|
---|
162 | numOfIssues = info.getUtilitySpace().getDomain().getIssues().size();
|
---|
163 | fullUtilBids = new ArrayList<>();
|
---|
164 | fullUtilBids = getFullUtilBid(info.getUtilitySpace());
|
---|
165 | reservationValue = getUtilitySpace().getReservationValue();
|
---|
166 | sameBidsInOpps = new ArrayList<>();
|
---|
167 | maxUtilAdditionBidByOpps = new ArrayList<>();
|
---|
168 | lastPeriodBidList = new ArrayList<>();
|
---|
169 | maxUtilAdditionByOpps = 0.0;
|
---|
170 | initialUpper = 0.9;
|
---|
171 | initialExponent = 20;
|
---|
172 | upper = initialUpper;
|
---|
173 | lower = reservationValue;
|
---|
174 | exponent = initialExponent;
|
---|
175 | time1 = 0.9;
|
---|
176 | time2 = 0.99;
|
---|
177 | time3 = 0.995;
|
---|
178 | hasInitParamByHist = false;
|
---|
179 | }
|
---|
180 |
|
---|
181 | @Override
|
---|
182 | public Action chooseAction(List<Class<? extends Action>> validActions) {
|
---|
183 | nrChosenActions++;
|
---|
184 | Action action = null;
|
---|
185 | Bid bid = null;
|
---|
186 | acceptUtil = getAccept();
|
---|
187 | if (lastReceivedBid != null) {
|
---|
188 | if (utility >= acceptUtil
|
---|
189 | && !hasProposedMyLastRound(lastReceivedBid)) {
|
---|
190 | bid = new Bid(lastReceivedBid);
|
---|
191 | action = new Accept(getPartyId(), bid);
|
---|
192 | } else {
|
---|
193 | if (timeline.getTime() > time3) {
|
---|
194 | if (hasHistory) {
|
---|
195 | if (!maxAgreedBids.isEmpty()) {
|
---|
196 | bid = maxAgreedBids.get(
|
---|
197 | nrChosenActions % maxAgreedBids.size());
|
---|
198 | action = new Offer(getPartyId(), bid);
|
---|
199 | } else {
|
---|
200 | if (!lastPeriodBidList.isEmpty()) {
|
---|
201 | bid = lastPeriodBidList.get(nrChosenActions
|
---|
202 | % lastPeriodBidList.size());
|
---|
203 | action = new Offer(getPartyId(), bid);
|
---|
204 | } else {
|
---|
205 | bid = lastReceivedBid;
|
---|
206 | action = new Accept(getPartyId(), bid);
|
---|
207 | return action;
|
---|
208 | }
|
---|
209 | }
|
---|
210 | } else {
|
---|
211 | if (!lastPeriodBidList.isEmpty()) {
|
---|
212 | bid = lastPeriodBidList.get(
|
---|
213 | nrChosenActions % lastPeriodBidList.size());
|
---|
214 | } else {
|
---|
215 | bid = lastReceivedBid;
|
---|
216 | action = new Accept(getPartyId(), bid);
|
---|
217 | myBid = bid;
|
---|
218 | return action;
|
---|
219 | }
|
---|
220 | }
|
---|
221 | action = new Offer(getPartyId(), bid);
|
---|
222 | myBid = bid;
|
---|
223 | } else if (timeline.getTime() > time2) {
|
---|
224 | if (nrChosenActions % 2 == 1) {
|
---|
225 | if (maxProductBids[myIndex].size() <= 0) {
|
---|
226 | maxProductBids[myIndex] = getMaxSocialWelfareBidsInList(
|
---|
227 | proposedBids[myIndex]);
|
---|
228 | }
|
---|
229 | if (maxProductBids[myIndex].size() > 0) {
|
---|
230 | Bid nBid = maxProductBids[myIndex]
|
---|
231 | .get(nrChosenActions
|
---|
232 | % maxProductBids[myIndex].size());
|
---|
233 | if (hasProposedMyLastRound(nBid)) {
|
---|
234 | bid = proposedBids[myIndex].get(
|
---|
235 | nrChosenActions % numOfBids[myIndex]);
|
---|
236 | } else {
|
---|
237 | bid = nBid;
|
---|
238 | }
|
---|
239 | } else {
|
---|
240 | bid = proposedBids[myIndex]
|
---|
241 | .get(nrChosenActions % numOfBids[myIndex]);
|
---|
242 | }
|
---|
243 | } else {
|
---|
244 | if (candidateBids.isEmpty()) {
|
---|
245 | if (!acceptAction[myNextPartyIndex]
|
---|
246 | && !acceptAction[myLastPartyIndex]) {
|
---|
247 | generateCandidateFromOppTopBids(acceptUtil,
|
---|
248 | candidateBids);
|
---|
249 | generateCandidateFromMyTopBids(acceptUtil,
|
---|
250 | candidateBids);
|
---|
251 | } else if (!acceptAction[myNextPartyIndex]
|
---|
252 | && acceptAction[myLastPartyIndex]) {
|
---|
253 | generateCandidateFromOppTopAndMyTopBids(
|
---|
254 | myNextPartyIndex, acceptUtil,
|
---|
255 | candidateBids);
|
---|
256 | generateCandidateFromMyFullAndOppTopBids(
|
---|
257 | acceptUtil, myNextPartyIndex,
|
---|
258 | candidateBids);
|
---|
259 | } else {
|
---|
260 | generateCandidateFromOppTopAndMyTopBids(
|
---|
261 | myLastPartyIndex, acceptUtil,
|
---|
262 | candidateBids);
|
---|
263 | generateCandidateFromMyFullAndOppTopBids(
|
---|
264 | acceptUtil, myLastPartyIndex,
|
---|
265 | candidateBids);
|
---|
266 | }
|
---|
267 | }
|
---|
268 | if (!candidateBids.isEmpty()) {
|
---|
269 | bid = candidateBids.remove(0);
|
---|
270 | if (hasProposedMyLastRound(bid)) {
|
---|
271 | bid = proposedBids[myIndex].get(
|
---|
272 | nrChosenActions % numOfBids[myIndex]);
|
---|
273 | }
|
---|
274 | } else {
|
---|
275 | bid = proposedBids[myIndex]
|
---|
276 | .get(nrChosenActions % numOfBids[myIndex]);
|
---|
277 | }
|
---|
278 | action = new Offer(getPartyId(), bid);
|
---|
279 | }
|
---|
280 | if (lastPeriodBidList.isEmpty()) {
|
---|
281 | lastPeriodBidList = getMaxUtilBidsInList(
|
---|
282 | sameBidsInOpps);
|
---|
283 | }
|
---|
284 | if (lastPeriodBidList.isEmpty()) {
|
---|
285 | mergeBids(proposedBids[myNextPartyIndex].get(0),
|
---|
286 | proposedBids[myLastPartyIndex].get(0), lower,
|
---|
287 | lastPeriodBidList, lastPeriodBidList);
|
---|
288 | }
|
---|
289 | } else if (timeline.getTime() > time1) {
|
---|
290 | if (candidateBids.isEmpty()) {
|
---|
291 | if (nrChosenActions % 3 == 0) {
|
---|
292 | generateCandidateFromOppTopBids(acceptUtil,
|
---|
293 | candidateBids);
|
---|
294 | generateCandidateFromMyTopBids(acceptUtil,
|
---|
295 | candidateBids);
|
---|
296 | } else {
|
---|
297 | if (!acceptAction[myNextPartyIndex]) {
|
---|
298 | generateCandidateFromMyFullAndOppTopBids(
|
---|
299 | acceptUtil, myNextPartyIndex,
|
---|
300 | candidateBids);
|
---|
301 | generateCandidateFromMyFullAndMyTopBids(
|
---|
302 | acceptUtil, myNextPartyIndex,
|
---|
303 | candidateBids);
|
---|
304 | generateCandidateFromOppTopAndMyTopBids(
|
---|
305 | myNextPartyIndex, acceptUtil,
|
---|
306 | candidateBids);
|
---|
307 | }
|
---|
308 | if (!acceptAction[myLastPartyIndex]) {
|
---|
309 | generateCandidateFromMyFullAndOppTopBids(
|
---|
310 | acceptUtil, myLastPartyIndex,
|
---|
311 | candidateBids);
|
---|
312 | generateCandidateFromMyFullAndMyTopBids(
|
---|
313 | acceptUtil, myLastPartyIndex,
|
---|
314 | candidateBids);
|
---|
315 | generateCandidateFromOppTopAndMyTopBids(
|
---|
316 | myLastPartyIndex, acceptUtil,
|
---|
317 | candidateBids);
|
---|
318 | }
|
---|
319 | }
|
---|
320 | }
|
---|
321 | if (!candidateBids.isEmpty()) {
|
---|
322 | bid = candidateBids.remove(0);
|
---|
323 | if (hasProposedMyLastRound(bid)) {
|
---|
324 | bid = proposedBids[myIndex]
|
---|
325 | .get(nrChosenActions % numOfBids[myIndex]);
|
---|
326 | }
|
---|
327 | } else {
|
---|
328 | bid = proposedBids[myIndex]
|
---|
329 | .get(nrChosenActions % numOfBids[myIndex]);
|
---|
330 | }
|
---|
331 | } else {
|
---|
332 | if (candidateBids.isEmpty()) {
|
---|
333 | generateCandidateFromMyFullBids(proposedBids[myIndex]);
|
---|
334 | generateCandidateFromMyTopBids(acceptUtil,
|
---|
335 | proposedBids[myIndex]);
|
---|
336 | generateCandidateFromMyFullAndMyTopBids(acceptUtil,
|
---|
337 | myNextPartyIndex, proposedBids[myIndex]);
|
---|
338 | generateCandidateFromMyFullAndMyTopBids(acceptUtil,
|
---|
339 | myLastPartyIndex, proposedBids[myIndex]);
|
---|
340 | }
|
---|
341 | if (!candidateBids.isEmpty()) {
|
---|
342 | bid = candidateBids.remove(0);
|
---|
343 | } else {
|
---|
344 | Bid nBid = fullUtilBids
|
---|
345 | .get(nrChosenActions % fullUtilBids.size());
|
---|
346 | if (proposedBids[myIndex].contains(nBid)) {
|
---|
347 | bid = proposedBids[myIndex]
|
---|
348 | .get(nrChosenActions % numOfBids[myIndex]);
|
---|
349 | } else {
|
---|
350 | bid = nBid;
|
---|
351 | }
|
---|
352 | }
|
---|
353 | }
|
---|
354 | if (bid == null) {
|
---|
355 | lastConcessionPoint = getBidWithLessBoundedUtil(
|
---|
356 | lastConcessionPoint, acceptUtil);
|
---|
357 | bid = lastConcessionPoint;
|
---|
358 | if (hasProposedMyLastRound(bid)) {
|
---|
359 | bid = proposedBids[myIndex]
|
---|
360 | .get(nrChosenActions % numOfBids[myIndex]);
|
---|
361 | }
|
---|
362 | }
|
---|
363 | if (bid == null) {
|
---|
364 | bid = myBid;
|
---|
365 | }
|
---|
366 | action = new Offer(getPartyId(), bid);
|
---|
367 | }
|
---|
368 | } else {
|
---|
369 | bid = new Bid(
|
---|
370 | fullUtilBids.get(nrChosenActions % fullUtilBids.size()));
|
---|
371 | action = new Offer(getPartyId(), bid);
|
---|
372 | }
|
---|
373 | myBid = bid;
|
---|
374 | numOfBids[myIndex]++;
|
---|
375 | proposedBids[myIndex].add(bid);
|
---|
376 | return action;
|
---|
377 | }
|
---|
378 |
|
---|
379 | @SuppressWarnings("unchecked")
|
---|
380 | @Override
|
---|
381 | public void receiveMessage(AgentID sender, Action action) {
|
---|
382 | super.receiveMessage(sender, action);
|
---|
383 | if (sender == null) {
|
---|
384 | numOfParties = getNumberOfParties();
|
---|
385 | myIndex = Integer.parseInt(getPartyId().toString().split("@")[1])
|
---|
386 | % numOfParties;
|
---|
387 | myNextPartyIndex = (myIndex + 1) % numOfParties;
|
---|
388 | myLastPartyIndex = (myIndex + numOfParties - 1) % numOfParties;
|
---|
389 | proposedBids = new ArrayList[numOfParties];
|
---|
390 | numOfBids = new int[numOfParties];
|
---|
391 | valueFrequences = new HashMap[numOfParties];
|
---|
392 | issueChangeFrequences = new HashMap[numOfParties];
|
---|
393 | acceptAction = new boolean[numOfParties];
|
---|
394 | maxUtils = new double[numOfParties];
|
---|
395 | minUtils = new double[numOfParties];
|
---|
396 | proposedMaxBid = new LinkedList[numOfParties];
|
---|
397 | proposedMinBid = new LinkedList[numOfParties];
|
---|
398 | pModel = new PreferModel[numOfParties];
|
---|
399 | acceptableBidsWithOppValues = new ArrayList[numOfParties];
|
---|
400 | candidateBids = new ArrayList<>();
|
---|
401 | maxProductBids = new ArrayList[numOfParties];
|
---|
402 | topBidsInOppsSpace = new ArrayList[numOfParties];
|
---|
403 | topBidsInMySpace = new LinkedList[numOfParties];
|
---|
404 | for (int i = 0; i < numOfParties; i++) {
|
---|
405 | proposedBids[i] = new ArrayList<>();
|
---|
406 | valueFrequences[i] = new HashMap<>();
|
---|
407 | issueChangeFrequences[i] = new HashMap<>();
|
---|
408 | proposedMaxBid[i] = new LinkedList<>();
|
---|
409 | proposedMinBid[i] = new LinkedList<>();
|
---|
410 | pModel[i] = new PreferModel(getUtilitySpace(), numOfIssues);
|
---|
411 | acceptableBidsWithOppValues[i] = new ArrayList<>();
|
---|
412 | maxProductBids[i] = new ArrayList<>();
|
---|
413 | topBidsInOppsSpace[i] = new ArrayList<>();
|
---|
414 | topBidsInMySpace[i] = new LinkedList<>();
|
---|
415 | }
|
---|
416 | } else {
|
---|
417 | oppName = sender.toString().split("@")[0];
|
---|
418 | oppIndex = Integer.parseInt(sender.toString().split("@")[1])
|
---|
419 | % numOfParties;
|
---|
420 | if (action instanceof Offer) {
|
---|
421 | acceptAction[oppIndex] = false;
|
---|
422 | lastReceivedBid = ((Offer) action).getBid();
|
---|
423 | }
|
---|
424 | if (action instanceof Accept) {
|
---|
425 | acceptAction[oppIndex] = true;
|
---|
426 | lastReceivedBid = ((Accept) action).getBid();
|
---|
427 | }
|
---|
428 | utility = getUtility(lastReceivedBid);
|
---|
429 | proposedBids[oppIndex].add(lastReceivedBid);
|
---|
430 | numOfBids[oppIndex]++;
|
---|
431 | updateMaxOrMinBids(oppIndex);
|
---|
432 | if (isDifferentBid(oppIndex)) {
|
---|
433 | updateSameBidsInOpps(oppIndex, lastReceivedBid);
|
---|
434 | updateTopBidsInOppsSpace(oppIndex);
|
---|
435 | updateTopBidsInMySpace(oppIndex);
|
---|
436 | }
|
---|
437 | if (hasHistory) {
|
---|
438 | if (!hasInitParamByHist) {
|
---|
439 | hasHistWithRightPosition = false;
|
---|
440 | for (String name : maxUtilsInHist[oppIndex].keySet()) {
|
---|
441 | if (oppName.equals(name)) {
|
---|
442 | hasHistWithRightPosition = true;
|
---|
443 | }
|
---|
444 | }
|
---|
445 | if (hasHistWithRightPosition) {
|
---|
446 | double[] arrs = new double[3];
|
---|
447 | for (int i = 0; i < getNumberOfParties(); i++) {
|
---|
448 | if (i == myIndex) {
|
---|
449 | continue;
|
---|
450 | }
|
---|
451 | for (String name : maxUtilsInHist[i].keySet()) {
|
---|
452 | if (oppIndex == i) {
|
---|
453 | arrs[i] = maxUtilsInHist[oppIndex]
|
---|
454 | .get(oppName);
|
---|
455 | } else {
|
---|
456 | if (!name.equals(oppName)) {
|
---|
457 | arrs[i] = maxUtilsInHist[i].get(name);
|
---|
458 | }
|
---|
459 | }
|
---|
460 | }
|
---|
461 | }
|
---|
462 | double max = 0.0;
|
---|
463 | double min = 1.0;
|
---|
464 | for (int i = 0; i < 3; i++) {
|
---|
465 | if (i == myIndex) {
|
---|
466 | continue;
|
---|
467 | }
|
---|
468 | if (max < arrs[i]) {
|
---|
469 | max = arrs[i];
|
---|
470 | }
|
---|
471 | if (min > arrs[i]) {
|
---|
472 | min = arrs[i];
|
---|
473 | }
|
---|
474 | }
|
---|
475 | if (maxAgreedBids.isEmpty()) {
|
---|
476 | if (min - 0.3 > reservationValue) {
|
---|
477 | lower = min - 0.3;
|
---|
478 | } else {
|
---|
479 | lower = reservationValue;
|
---|
480 | }
|
---|
481 | } else {
|
---|
482 | double agreedUtil = getUtility(
|
---|
483 | maxAgreedBids.get(0));
|
---|
484 | double[] utilArrs = { max, min, agreedUtil };
|
---|
485 | upper = getMaxInArray(utilArrs);
|
---|
486 | for (int i = 0; i < utilArrs.length; i++) {
|
---|
487 | if (utilArrs[i] == upper) {
|
---|
488 | utilArrs[i] = 0.0;
|
---|
489 | }
|
---|
490 | }
|
---|
491 | lower = getMinInArray(utilArrs) - 0.1;
|
---|
492 | if (lower <= 0) {
|
---|
493 | lower = reservationValue;
|
---|
494 | }
|
---|
495 | }
|
---|
496 | exponent = initialExponent * (upper - lower) / 2;
|
---|
497 | } else {
|
---|
498 | double[] arrs = new double[3];
|
---|
499 | for (int i = 0; i < getNumberOfParties(); i++) {
|
---|
500 | if (i == myIndex) {
|
---|
501 | continue;
|
---|
502 | }
|
---|
503 | for (String name : maxUtilsInHist[i].keySet()) {
|
---|
504 | arrs[i] = maxUtilsInHist[i].get(name);
|
---|
505 | }
|
---|
506 | }
|
---|
507 | double max = 0.0;
|
---|
508 | double min = 1.0;
|
---|
509 | for (int i = 0; i < 3; i++) {
|
---|
510 | if (i == myIndex) {
|
---|
511 | continue;
|
---|
512 | }
|
---|
513 | if (max < arrs[i]) {
|
---|
514 | max = arrs[i];
|
---|
515 | }
|
---|
516 | if (min > arrs[i]) {
|
---|
517 | min = arrs[i];
|
---|
518 | }
|
---|
519 | }
|
---|
520 | if (maxAgreedBids.isEmpty()) {
|
---|
521 | if (min - 0.3 > reservationValue) {
|
---|
522 | lower = min - 0.3;
|
---|
523 | } else {
|
---|
524 | lower = reservationValue;
|
---|
525 | }
|
---|
526 | } else {
|
---|
527 | double agreedUtil = getUtility(
|
---|
528 | maxAgreedBids.get(0));
|
---|
529 | double[] utilArrs = { max, min, agreedUtil, 0.9 };
|
---|
530 | upper = getMaxInArray(utilArrs);
|
---|
531 | for (int i = 0; i < utilArrs.length; i++) {
|
---|
532 | if (utilArrs[i] == upper) {
|
---|
533 | utilArrs[i] = 0.0;
|
---|
534 | }
|
---|
535 | }
|
---|
536 | lower = getMinInArray(utilArrs) - 0.2;
|
---|
537 | if (lower <= 0) {
|
---|
538 | lower = reservationValue;
|
---|
539 | }
|
---|
540 | }
|
---|
541 | exponent = initialExponent * (upper - lower) / 2;
|
---|
542 | }
|
---|
543 | hasInitParamByHist = true;
|
---|
544 | }
|
---|
545 | if (hasInitParamByHist) {
|
---|
546 | if (hasHistWithRightPosition) {
|
---|
547 |
|
---|
548 | } else {
|
---|
549 |
|
---|
550 | }
|
---|
551 | }
|
---|
552 | } else {
|
---|
553 | if (isDifferentBid(oppIndex)) {
|
---|
554 | pModel[oppIndex].updateEvaluators(lastReceivedBid);
|
---|
555 | if (timeline.getTime() > 0.5 && timeline.getTime() < 0.9) {
|
---|
556 | updateMaxUtilAddition(oppIndex, lastReceivedBid);
|
---|
557 | }
|
---|
558 | }
|
---|
559 | updateConcessionParam();
|
---|
560 | }
|
---|
561 | }
|
---|
562 | }
|
---|
563 |
|
---|
564 | @Override
|
---|
565 | public String getDescription() {
|
---|
566 | return "ANAC2017";
|
---|
567 | }
|
---|
568 |
|
---|
569 | private double getAccept() {
|
---|
570 | double accept = 1.0;
|
---|
571 | accept = upper - (upper + 0.001 - lower)
|
---|
572 | * Math.pow(timeline.getTime(), exponent);
|
---|
573 | return accept;
|
---|
574 | }
|
---|
575 |
|
---|
576 | private List<Bid> getFullUtilBid(AbstractUtilitySpace utilitySpace) {
|
---|
577 | Bid bid = null;
|
---|
578 | List<Bid> bidList = new ArrayList<>();
|
---|
579 | try {
|
---|
580 | bid = utilitySpace.getMaxUtilityBid();
|
---|
581 | } catch (Exception e) {
|
---|
582 | e.printStackTrace();
|
---|
583 | System.err.println(e.toString());
|
---|
584 | }
|
---|
585 | if (!bidList.contains(bid)) {
|
---|
586 | bidList.add(bid);
|
---|
587 | }
|
---|
588 | List<Issue> issues = getUtilitySpace().getDomain().getIssues();
|
---|
589 | for (Issue item : issues) {
|
---|
590 | Bid newBid = null;
|
---|
591 | switch (item.getType()) {
|
---|
592 | case DISCRETE:
|
---|
593 | IssueDiscrete discrete = (IssueDiscrete) item;
|
---|
594 | for (Value value : discrete.getValues()) {
|
---|
595 | newBid = bid.putValue(discrete.getNumber(), value);
|
---|
596 | if (getUtility(newBid) == 1.0
|
---|
597 | && !bidList.contains(newBid)) {
|
---|
598 | bidList.add(newBid);
|
---|
599 | }
|
---|
600 | }
|
---|
601 | break;
|
---|
602 | case INTEGER:
|
---|
603 | break;
|
---|
604 | default:
|
---|
605 | break;
|
---|
606 | }
|
---|
607 | }
|
---|
608 | return bidList;
|
---|
609 | }
|
---|
610 |
|
---|
611 | @SuppressWarnings("unused")
|
---|
612 | private Bid getBidWithLessUtil(Bid bid) {
|
---|
613 | Bid srcBid = null;
|
---|
614 | Bid nBid = null;
|
---|
615 | if (bid == null) {
|
---|
616 | srcBid = fullUtilBids.get(0);
|
---|
617 | } else {
|
---|
618 | srcBid = new Bid(bid);
|
---|
619 | }
|
---|
620 | double oldU = getUtility(srcBid);
|
---|
621 | List<Bid> bidList = new ArrayList<>();
|
---|
622 | for (int i = 0; i < numOfIssues; i++) {
|
---|
623 | Issue issue = srcBid.getIssues().get(i);
|
---|
624 | switch (issue.getType()) {
|
---|
625 | case DISCRETE:
|
---|
626 | IssueDiscrete issueDiscrete = (IssueDiscrete) issue;
|
---|
627 | for (Value value : issueDiscrete.getValues()) {
|
---|
628 | nBid = srcBid.putValue(i + 1, value);
|
---|
629 | if (oldU > getUtility(nBid)) {
|
---|
630 | bidList.add(nBid);
|
---|
631 | }
|
---|
632 | }
|
---|
633 | break;
|
---|
634 | case INTEGER:
|
---|
635 | IssueInteger issueInteger = (IssueInteger) issue;
|
---|
636 | for (int j = issueInteger.getLowerBound(); j <= issueInteger
|
---|
637 | .getUpperBound(); j++) {
|
---|
638 | nBid = srcBid.putValue(i + 1, new ValueInteger(j));
|
---|
639 | if (oldU > getUtility(nBid)) {
|
---|
640 | bidList.add(nBid);
|
---|
641 | }
|
---|
642 | }
|
---|
643 | break;
|
---|
644 | default:
|
---|
645 | break;
|
---|
646 | }
|
---|
647 | }
|
---|
648 | if (bidList.isEmpty()) {
|
---|
649 | nBid = new Bid(srcBid);
|
---|
650 | } else {
|
---|
651 | double distance = oldU - 0.0;
|
---|
652 | for (Bid item : bidList) {
|
---|
653 | double distance2 = oldU - getUtility(item);
|
---|
654 | if (distance2 < distance) {
|
---|
655 | nBid = new Bid(item);
|
---|
656 | distance = distance2;
|
---|
657 | }
|
---|
658 | }
|
---|
659 | }
|
---|
660 | return nBid;
|
---|
661 | }
|
---|
662 |
|
---|
663 | private Bid getBidWithLessBoundedUtil(Bid bid, double min) {
|
---|
664 | Bid srcBid = null;
|
---|
665 | Bid nBid = null;
|
---|
666 | if (bid == null) {
|
---|
667 | srcBid = fullUtilBids.get(0);
|
---|
668 | } else {
|
---|
669 | srcBid = new Bid(bid);
|
---|
670 | }
|
---|
671 | double oldU = getUtility(srcBid);
|
---|
672 | List<Bid> bidList = new ArrayList<>();
|
---|
673 | for (int i = 0; i < numOfIssues; i++) {
|
---|
674 | Issue issue = srcBid.getIssues().get(i);
|
---|
675 | double newU = 0.0;
|
---|
676 | switch (issue.getType()) {
|
---|
677 | case DISCRETE:
|
---|
678 | IssueDiscrete issueDiscrete = (IssueDiscrete) issue;
|
---|
679 | for (Value value : issueDiscrete.getValues()) {
|
---|
680 | nBid = srcBid.putValue(i + 1, value);
|
---|
681 | newU = getUtility(nBid);
|
---|
682 | if (oldU > newU && newU >= min) {
|
---|
683 | bidList.add(nBid);
|
---|
684 | }
|
---|
685 | }
|
---|
686 | break;
|
---|
687 | case INTEGER:
|
---|
688 | IssueInteger issueInteger = (IssueInteger) issue;
|
---|
689 | for (int j = issueInteger.getLowerBound(); j <= issueInteger
|
---|
690 | .getUpperBound(); j++) {
|
---|
691 | nBid = srcBid.putValue(i + 1, new ValueInteger(j));
|
---|
692 | newU = getUtility(nBid);
|
---|
693 | if (oldU > newU && newU >= min) {
|
---|
694 | bidList.add(nBid);
|
---|
695 | }
|
---|
696 | }
|
---|
697 | break;
|
---|
698 | default:
|
---|
699 | break;
|
---|
700 | }
|
---|
701 | }
|
---|
702 | if (bidList.isEmpty()) {
|
---|
703 | nBid = new Bid(srcBid);
|
---|
704 | } else {
|
---|
705 | double distance = oldU - 0.0;
|
---|
706 | for (Bid item : bidList) {
|
---|
707 | double distance2 = oldU - getUtility(item);
|
---|
708 | if (distance2 < distance) {
|
---|
709 | nBid = new Bid(item);
|
---|
710 | distance = distance2;
|
---|
711 | }
|
---|
712 | }
|
---|
713 | }
|
---|
714 | return nBid;
|
---|
715 | }
|
---|
716 |
|
---|
717 | private void updateProposedMaxBid(int partyId) {
|
---|
718 | if (proposedMaxBid[partyId].isEmpty()) {
|
---|
719 | if (utility > maxUtils[partyId]) {
|
---|
720 | maxUtils[partyId] = utility;
|
---|
721 | proposedMaxBid[partyId].add(lastReceivedBid);
|
---|
722 | }
|
---|
723 | } else {
|
---|
724 | if (maxUtils[partyId] > utility) {
|
---|
725 | return;
|
---|
726 | }
|
---|
727 | if (maxUtils[partyId] == utility
|
---|
728 | && !proposedMaxBid[partyId].contains(lastReceivedBid)) {
|
---|
729 | proposedMaxBid[partyId].add(lastReceivedBid);
|
---|
730 | }
|
---|
731 | if (maxUtils[partyId] < utility) {
|
---|
732 | proposedMaxBid[partyId].clear();
|
---|
733 | proposedMaxBid[partyId].add(lastReceivedBid);
|
---|
734 | maxUtils[partyId] = utility;
|
---|
735 | }
|
---|
736 | }
|
---|
737 | }
|
---|
738 |
|
---|
739 | private void updateProposedMinBid(int partyId) {
|
---|
740 | if (proposedMinBid[partyId].isEmpty()) {
|
---|
741 | proposedMinBid[partyId].add(lastReceivedBid);
|
---|
742 | if (0 >= minUtils[partyId]) {
|
---|
743 | minUtils[partyId] = utility;
|
---|
744 | }
|
---|
745 | } else {
|
---|
746 | if (minUtils[partyId] < utility) {
|
---|
747 | return;
|
---|
748 | }
|
---|
749 | if (minUtils[partyId] == utility
|
---|
750 | && !proposedMinBid[partyId].contains(lastReceivedBid)) {
|
---|
751 | proposedMinBid[partyId].add(lastReceivedBid);
|
---|
752 | }
|
---|
753 | if (minUtils[partyId] > utility) {
|
---|
754 | proposedMinBid[partyId].clear();
|
---|
755 | proposedMinBid[partyId].add(lastReceivedBid);
|
---|
756 | minUtils[partyId] = utility;
|
---|
757 | }
|
---|
758 | }
|
---|
759 | }
|
---|
760 |
|
---|
761 | private void updateMaxOrMinBids(int partyId) {
|
---|
762 | updateProposedMaxBid(partyId);
|
---|
763 | updateProposedMinBid(partyId);
|
---|
764 | }
|
---|
765 |
|
---|
766 | private void updateTopBidsInOppsSpace(int partyId) {
|
---|
767 | if (topBidsInOppsSpace[partyId].size() < 5
|
---|
768 | && !topBidsInOppsSpace[partyId].contains(lastReceivedBid)) {
|
---|
769 | topBidsInOppsSpace[partyId].add(lastReceivedBid);
|
---|
770 | }
|
---|
771 | }
|
---|
772 |
|
---|
773 | private void updateTopBidsInMySpace(int partyId) {
|
---|
774 | if (topBidsInMySpace[partyId].contains(lastReceivedBid)) {
|
---|
775 | return;
|
---|
776 | } else {
|
---|
777 | if (topBidsInMySpace[partyId].size() < 5) {
|
---|
778 | topBidsInMySpace[partyId].add(lastReceivedBid);
|
---|
779 | } else {
|
---|
780 | int removeIndex = -1;
|
---|
781 | double maxDistance = 0.0;
|
---|
782 | for (int i = 0; i < topBidsInMySpace[partyId].size(); i++) {
|
---|
783 | double distance = utility
|
---|
784 | - getUtility(topBidsInMySpace[partyId].get(i));
|
---|
785 | if (distance > maxDistance) {
|
---|
786 | maxDistance = distance;
|
---|
787 | removeIndex = i;
|
---|
788 | }
|
---|
789 | }
|
---|
790 | if (removeIndex != -1) {
|
---|
791 | topBidsInMySpace[partyId].set(removeIndex, lastReceivedBid);
|
---|
792 | }
|
---|
793 | }
|
---|
794 | }
|
---|
795 | }
|
---|
796 |
|
---|
797 | private void updateConcessionParam() {
|
---|
798 | if (!hasHistory) {
|
---|
799 | // ����Ϊ�����������С��utility
|
---|
800 | double maxInMinUtil = 0.0;
|
---|
801 | double minInMinUtil = 1.0;
|
---|
802 | double minInMaxUtil = 1.0;
|
---|
803 | // double[] avgUtil = new double[numOfParties];
|
---|
804 | for (int i = 0; i < numOfParties; i++) {
|
---|
805 | if (i == myIndex) {
|
---|
806 | // avgUtil[i] = 1.0;
|
---|
807 | continue;
|
---|
808 | }
|
---|
809 | if (maxUtils[i] == 0.0 || minUtils[i] == 0.0) {
|
---|
810 | continue;
|
---|
811 | }
|
---|
812 | double utilInMin2 = minUtils[i];
|
---|
813 | if (utilInMin2 > maxInMinUtil) {
|
---|
814 | maxInMinUtil = utilInMin2;
|
---|
815 | }
|
---|
816 | if (utilInMin2 < minInMinUtil) {
|
---|
817 | minInMinUtil = utilInMin2;
|
---|
818 | }
|
---|
819 | double utilInMax = maxUtils[i];
|
---|
820 | if (minInMaxUtil > utilInMax) {
|
---|
821 | minInMaxUtil = utilInMax;
|
---|
822 | }
|
---|
823 | // avgUtil[i] = (maxUtils[i]+minUtils[i])/2;
|
---|
824 | }
|
---|
825 | double lowerbound = 0.0;
|
---|
826 | if (reservationValue > minInMinUtil - 0.01) {
|
---|
827 | lowerbound = reservationValue;
|
---|
828 | } else {
|
---|
829 | lowerbound = minInMinUtil - 0.01;
|
---|
830 | }
|
---|
831 | lower = lowerbound;
|
---|
832 | if (minInMaxUtil <= 0.0) {
|
---|
833 | exponent = 1.0;
|
---|
834 | } else {
|
---|
835 | exponent = initialExponent * minInMaxUtil;
|
---|
836 | }
|
---|
837 | } else {
|
---|
838 |
|
---|
839 | }
|
---|
840 | }
|
---|
841 |
|
---|
842 | private double getMinInArray(double arr[]) {
|
---|
843 | double min = arr[0];
|
---|
844 | for (int i = 0; i < arr.length; i++) {
|
---|
845 | if (min > arr[i]) {
|
---|
846 | min = arr[i];
|
---|
847 | }
|
---|
848 | }
|
---|
849 | return min;
|
---|
850 | }
|
---|
851 |
|
---|
852 | private double getMaxInArray(double[] arr) {
|
---|
853 | double max = 0.0;
|
---|
854 | for (int i = 0; i < arr.length; i++) {
|
---|
855 | if (max < arr[i]) {
|
---|
856 | max = arr[i];
|
---|
857 | }
|
---|
858 | }
|
---|
859 | return max;
|
---|
860 | }
|
---|
861 |
|
---|
862 | private double getMaxInArray(List<Double> list) {
|
---|
863 | double max = 0.0;
|
---|
864 | for (double item : list) {
|
---|
865 | if (item > max) {
|
---|
866 | max = item;
|
---|
867 | }
|
---|
868 | }
|
---|
869 | return max;
|
---|
870 | }
|
---|
871 |
|
---|
872 | private boolean isDifferentBid(int partyId) {
|
---|
873 | if (proposedBids[partyId].size() < 2) {
|
---|
874 | return true;
|
---|
875 | } else {
|
---|
876 | if (proposedBids[partyId].get(numOfBids[partyId] - 1).equals(
|
---|
877 | proposedBids[partyId].get(numOfBids[partyId] - 2))) {
|
---|
878 | return false;
|
---|
879 | } else {
|
---|
880 | return true;
|
---|
881 | }
|
---|
882 | }
|
---|
883 | }
|
---|
884 |
|
---|
885 | private void alterBidValue(Bid srcBid, Map<Integer, Value> valueMap,
|
---|
886 | int issueNr, double acceptableUtil, List<Bid> bidList,
|
---|
887 | List<Bid> validationList) {
|
---|
888 | Bid nBid = new Bid(srcBid);
|
---|
889 | if (getUtility(nBid) >= acceptableUtil
|
---|
890 | && !validationList.contains(nBid)) {
|
---|
891 | bidList.add(nBid);
|
---|
892 | }
|
---|
893 | if (!valueMap.containsKey(issueNr)) {
|
---|
894 | return;
|
---|
895 | }
|
---|
896 | for (int j = issueNr; j <= valueMap.size(); j++) {
|
---|
897 | Value value = valueMap.get(j);
|
---|
898 | if (value.equals(srcBid.getValue(j))) {
|
---|
899 | continue;
|
---|
900 | }
|
---|
901 | nBid = srcBid.putValue(j, value);
|
---|
902 | int item = j + 1;
|
---|
903 | alterBidValue(nBid, valueMap, item, acceptableUtil, bidList,
|
---|
904 | validationList);
|
---|
905 | }
|
---|
906 | }
|
---|
907 |
|
---|
908 | private void mergeBids(Bid fir, Bid sec, double acceptableUtil,
|
---|
909 | List<Bid> bidList, List<Bid> validationList) {
|
---|
910 | if (fir == null || sec == null) {
|
---|
911 | return;
|
---|
912 | }
|
---|
913 | if (fir.equals(sec)) {
|
---|
914 | if (!validationList.contains(fir)) {
|
---|
915 | bidList.add(fir);
|
---|
916 | }
|
---|
917 | return;
|
---|
918 | }
|
---|
919 | alterBidValue(fir, sec.getValues(), 1, acceptableUtil, bidList,
|
---|
920 | validationList);
|
---|
921 | }
|
---|
922 |
|
---|
923 | private void generateCandidateFromMyFullBidsAndOppsTopBids(double minUtil,
|
---|
924 | int oppIndex, List<Bid> validationList) {
|
---|
925 | if (proposedBids[oppIndex].isEmpty()) {
|
---|
926 | return;
|
---|
927 | }
|
---|
928 | for (Bid item : fullUtilBids) {
|
---|
929 | for (Bid item2 : topBidsInOppsSpace[oppIndex]) {
|
---|
930 | if (item.equals(item2)) {
|
---|
931 | continue;
|
---|
932 | }
|
---|
933 | mergeBids(item, item2, minUtil, candidateBids, validationList);
|
---|
934 | }
|
---|
935 | }
|
---|
936 | }
|
---|
937 |
|
---|
938 | private void generateCandidate(double acceptableUtil,
|
---|
939 | List<Bid> validationList) {
|
---|
940 | generateCandidateFromMyTopBids(acceptableUtil, validationList);
|
---|
941 | generateCandidateFromOppTopBids(acceptableUtil, validationList);
|
---|
942 | }
|
---|
943 |
|
---|
944 | private List<Bid> getMaxSocialWelfareBidsInList(List<Bid> bidList) {
|
---|
945 | List<Bid> maxAdditionBids = new ArrayList<>();
|
---|
946 | List<Bid> maxProductBids = new ArrayList<>();
|
---|
947 | List<Bid> maxSocialWelfareBids = new ArrayList<>();
|
---|
948 | double maxAddition = 0.0;
|
---|
949 | double maxProduct = 0.0;
|
---|
950 | for (Bid bid : bidList) {
|
---|
951 | double bidAddition = 0.0;
|
---|
952 | double bidProduct = 1.0;
|
---|
953 | bidAddition = getUtilAddition(bid);
|
---|
954 | bidProduct = getUtilProduct(bid);
|
---|
955 | if (bidAddition > maxAddition) {
|
---|
956 | maxAdditionBids.clear();
|
---|
957 | maxAdditionBids.add(bid);
|
---|
958 | maxAddition = bidAddition;
|
---|
959 | } else if (bidAddition == maxAddition
|
---|
960 | && !maxAdditionBids.contains(bid)) {
|
---|
961 | maxAdditionBids.add(bid);
|
---|
962 | }
|
---|
963 | if (bidProduct > maxProduct) {
|
---|
964 | maxProductBids.clear();
|
---|
965 | maxProductBids.add(bid);
|
---|
966 | maxProduct = bidProduct;
|
---|
967 | } else if (bidProduct == maxProduct
|
---|
968 | && !maxProductBids.contains(bid)) {
|
---|
969 | maxProductBids.add(bid);
|
---|
970 | }
|
---|
971 | }
|
---|
972 | maxSocialWelfareBids.addAll(maxAdditionBids);
|
---|
973 | maxSocialWelfareBids.addAll(maxProductBids);
|
---|
974 | return maxSocialWelfareBids;
|
---|
975 | }
|
---|
976 |
|
---|
977 | private double getUtilProduct(Bid bid) {
|
---|
978 | double product = 1.0;
|
---|
979 | for (int i = 0; i < numOfParties; i++) {
|
---|
980 | if (i == myIndex) {
|
---|
981 | product *= getUtility(bid);
|
---|
982 | }
|
---|
983 | product *= pModel[i].getUtil(bid);
|
---|
984 | }
|
---|
985 | return product;
|
---|
986 | }
|
---|
987 |
|
---|
988 | private double getUtilAddition(Bid bid) {
|
---|
989 | double addition = 0.0;
|
---|
990 | for (int i = 0; i < numOfParties; i++) {
|
---|
991 | if (i == myIndex) {
|
---|
992 | addition += getUtility(bid);
|
---|
993 | }
|
---|
994 | addition += pModel[i].getUtil(bid);
|
---|
995 | }
|
---|
996 | return addition;
|
---|
997 | }
|
---|
998 |
|
---|
999 | private List<Bid> getMaxUtilBidsInList(List<Bid> bidList) {
|
---|
1000 | List<Bid> bids = new ArrayList<>();
|
---|
1001 | double maxUtil = 0.0;
|
---|
1002 | for (Bid item : bidList) {
|
---|
1003 | double util = getUtility(item);
|
---|
1004 | if (util < maxUtil) {
|
---|
1005 | continue;
|
---|
1006 | }
|
---|
1007 | if (util > maxUtil) {
|
---|
1008 | bids.clear();
|
---|
1009 | bids.add(item);
|
---|
1010 | maxUtil = util;
|
---|
1011 | } else {
|
---|
1012 | bids.add(item);
|
---|
1013 | }
|
---|
1014 | }
|
---|
1015 | return bids;
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | private void updateSameBidsInOpps(int proposedPartyId, Bid bid) {
|
---|
1019 | boolean bidHasProposedByAllOpps = true;
|
---|
1020 | for (int i = 0; i < numOfParties; i++) {
|
---|
1021 | if (i == myIndex || i == proposedPartyId) {
|
---|
1022 | continue;
|
---|
1023 | }
|
---|
1024 | if (!proposedBids[i].contains(bid)) {
|
---|
1025 | bidHasProposedByAllOpps = false;
|
---|
1026 | return;
|
---|
1027 | } else {
|
---|
1028 | bidHasProposedByAllOpps = true;
|
---|
1029 | }
|
---|
1030 | }
|
---|
1031 | if (bidHasProposedByAllOpps) {
|
---|
1032 | sameBidsInOpps.add(bid);
|
---|
1033 | }
|
---|
1034 | }
|
---|
1035 |
|
---|
1036 | private void updateMaxUtilAddition(int partyId, Bid bid) {
|
---|
1037 | double utilAddition = 0.0;
|
---|
1038 | for (int i = 0; i < numOfParties; i++) {
|
---|
1039 | if (partyId == myIndex) {
|
---|
1040 | utilAddition += getUtility(bid);
|
---|
1041 | } else {
|
---|
1042 | utilAddition += pModel[i].getUtil(bid);
|
---|
1043 | }
|
---|
1044 | }
|
---|
1045 | if (utilAddition < maxUtilAdditionByOpps) {
|
---|
1046 | return;
|
---|
1047 | }
|
---|
1048 | if (utilAddition > maxUtilAdditionByOpps) {
|
---|
1049 | maxUtilAdditionBidByOpps.clear();
|
---|
1050 | maxUtilAdditionBidByOpps.add(bid);
|
---|
1051 | maxUtilAdditionByOpps = utilAddition;
|
---|
1052 | } else {
|
---|
1053 | maxUtilAdditionBidByOpps.add(bid);
|
---|
1054 | }
|
---|
1055 | }
|
---|
1056 |
|
---|
1057 | private void generateCandidateFromOppTopAndMyTopBids(int partyId,
|
---|
1058 | double minUtil, List<Bid> validationList) {
|
---|
1059 | if (proposedBids[partyId].isEmpty()) {
|
---|
1060 | return;
|
---|
1061 | }
|
---|
1062 | for (Bid item : topBidsInOppsSpace[partyId]) {
|
---|
1063 | for (Bid maxBid : topBidsInMySpace[partyId]) {
|
---|
1064 | mergeBids(maxBid, item, minUtil, candidateBids, validationList);
|
---|
1065 | }
|
---|
1066 | }
|
---|
1067 | }
|
---|
1068 |
|
---|
1069 | private List<Bid> getMaxBidsInAgreements() {
|
---|
1070 | double maxUtil = 0.0;
|
---|
1071 | List<Bid> maxBids = new ArrayList<>();
|
---|
1072 | for (Tuple<Bid, Double> item : agreements) {
|
---|
1073 | if (item.get2() < maxUtil) {
|
---|
1074 | continue;
|
---|
1075 | }
|
---|
1076 | if (item.get2() > maxUtil) {
|
---|
1077 | maxBids.clear();
|
---|
1078 | maxBids.add(item.get1());
|
---|
1079 | maxUtil = item.get2();
|
---|
1080 | } else {
|
---|
1081 | if (!maxBids.contains(item.get1())) {
|
---|
1082 | maxBids.add(item.get1());
|
---|
1083 | }
|
---|
1084 | }
|
---|
1085 | }
|
---|
1086 | return maxBids;
|
---|
1087 | }
|
---|
1088 |
|
---|
1089 | private boolean hasProposedMyLastRound(Bid bid) {
|
---|
1090 | if (numOfBids[myIndex] <= 0) {
|
---|
1091 | return false;
|
---|
1092 | }
|
---|
1093 | Bid lastRoundBid = proposedBids[myIndex].get(numOfBids[myIndex] - 1);
|
---|
1094 | return lastRoundBid.equals(bid);
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 | private void generateCandidateFromMyFullBids(List<Bid> validationList) {
|
---|
1098 | for (Bid item1 : fullUtilBids) {
|
---|
1099 | for (Bid item2 : fullUtilBids) {
|
---|
1100 | if (item1.equals(item2)) {
|
---|
1101 | if (validationList.contains(item1)) {
|
---|
1102 | continue;
|
---|
1103 | } else {
|
---|
1104 | candidateBids.add(item1);
|
---|
1105 | continue;
|
---|
1106 | }
|
---|
1107 | } else {
|
---|
1108 | mergeBids(item1, item2, 0.9, candidateBids, validationList);
|
---|
1109 | }
|
---|
1110 | }
|
---|
1111 | }
|
---|
1112 | }
|
---|
1113 |
|
---|
1114 | private void generateCandidateFromMyFullAndMyTopBids(double accept,
|
---|
1115 | int partyId, List<Bid> validationList) {
|
---|
1116 | for (Bid item1 : fullUtilBids) {
|
---|
1117 | for (Bid item2 : topBidsInMySpace[partyId]) {
|
---|
1118 | mergeBids(item1, item2, accept, candidateBids, validationList);
|
---|
1119 | }
|
---|
1120 | }
|
---|
1121 | }
|
---|
1122 |
|
---|
1123 | private void generateCandidateFromMyFullAndOppTopBids(double accept,
|
---|
1124 | int partyId, List<Bid> validationList) {
|
---|
1125 | for (Bid item1 : fullUtilBids) {
|
---|
1126 | for (Bid item2 : topBidsInOppsSpace[partyId]) {
|
---|
1127 | mergeBids(item1, item2, accept, candidateBids, validationList);
|
---|
1128 | }
|
---|
1129 | }
|
---|
1130 | }
|
---|
1131 |
|
---|
1132 | private void generateCandidateFromMyTopBids(double acceptableUtil,
|
---|
1133 | List<Bid> validationList) {
|
---|
1134 | for (Bid fBid : topBidsInMySpace[myNextPartyIndex]) {
|
---|
1135 | for (Bid sBid : topBidsInMySpace[myLastPartyIndex]) {
|
---|
1136 | alterBidValue(fBid, sBid.getValues(), 1, acceptableUtil,
|
---|
1137 | candidateBids, validationList);
|
---|
1138 | }
|
---|
1139 | }
|
---|
1140 | }
|
---|
1141 |
|
---|
1142 | private void generateCandidateFromOppTopBids(double acceptableUtil,
|
---|
1143 | List<Bid> validationList) {
|
---|
1144 | if (numOfBids[myLastPartyIndex] == 0
|
---|
1145 | || numOfBids[myNextPartyIndex] == 0) {
|
---|
1146 | return;
|
---|
1147 | }
|
---|
1148 | for (Bid item1 : topBidsInOppsSpace[myNextPartyIndex]) {
|
---|
1149 | for (Bid item2 : topBidsInOppsSpace[myLastPartyIndex]) {
|
---|
1150 | if (item1.equals(item2)) {
|
---|
1151 | continue;
|
---|
1152 | }
|
---|
1153 | mergeBids(item1, item2, acceptableUtil, candidateBids,
|
---|
1154 | validationList);
|
---|
1155 | }
|
---|
1156 | }
|
---|
1157 | }
|
---|
1158 | } |
---|