1 | package agents.anac.y2017.mosateam;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.HashMap;
|
---|
5 | import java.util.LinkedHashMap;
|
---|
6 | import java.util.LinkedList;
|
---|
7 | import java.util.List;
|
---|
8 | import java.util.Map;
|
---|
9 | import java.util.Map.Entry;
|
---|
10 | import java.util.Set;
|
---|
11 |
|
---|
12 | import genius.core.AgentID;
|
---|
13 | import genius.core.Bid;
|
---|
14 | import genius.core.actions.Accept;
|
---|
15 | import genius.core.actions.Action;
|
---|
16 | import genius.core.actions.Offer;
|
---|
17 | import genius.core.issue.Issue;
|
---|
18 | import genius.core.issue.IssueDiscrete;
|
---|
19 | import genius.core.issue.IssueInteger;
|
---|
20 | import genius.core.issue.Objective;
|
---|
21 | import genius.core.issue.Value;
|
---|
22 | import genius.core.issue.ValueDiscrete;
|
---|
23 | import genius.core.issue.ValueInteger;
|
---|
24 | import genius.core.list.Tuple;
|
---|
25 | import genius.core.parties.AbstractNegotiationParty;
|
---|
26 | import genius.core.parties.NegotiationInfo;
|
---|
27 | import genius.core.persistent.PersistentDataType;
|
---|
28 | import genius.core.persistent.StandardInfo;
|
---|
29 | import genius.core.persistent.StandardInfoList;
|
---|
30 | import genius.core.utility.AbstractUtilitySpace;
|
---|
31 | import genius.core.utility.Evaluator;
|
---|
32 | import genius.core.utility.EvaluatorDiscrete;
|
---|
33 | import genius.core.utility.EvaluatorInteger;
|
---|
34 | import genius.core.utility.UtilitySpace;
|
---|
35 | import genius.core.xml.SimpleElement;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Sample party that accepts the Nth offer, where N is the number of sessions
|
---|
39 | * this [agent-profile] already did.
|
---|
40 | *
|
---|
41 | * Members: Lichun Yuan (Southwest University), Jiancheng Wu (Southwest
|
---|
42 | * University). Affiliation: Southwest University
|
---|
43 | */
|
---|
44 |
|
---|
45 | public class Mosa extends AbstractNegotiationParty {
|
---|
46 |
|
---|
47 | private Bid lastReceivedBid = null;
|
---|
48 | private int nrChosenActions;
|
---|
49 | private StandardInfoList history;
|
---|
50 | private int numOfIssues;
|
---|
51 | private int numOfParties;
|
---|
52 | private double reservationValue;
|
---|
53 | private double initialUpper;
|
---|
54 | private double initialExponent;
|
---|
55 | private double upper;
|
---|
56 | private double lower;
|
---|
57 | private double exponent;
|
---|
58 | private double acceptUtil;
|
---|
59 | private double utility;
|
---|
60 | private List<Bid>[] proposedBids;
|
---|
61 | private int[] numOfBids;
|
---|
62 | private Map<Integer, Map<Value, Integer>>[] valueFrequences;
|
---|
63 | private Map<Integer, Integer>[] issueChangeFrequences;
|
---|
64 | private double[] maxUtils;
|
---|
65 | private double[] minUtils;
|
---|
66 | private LinkedList<Bid>[] proposedMaxBid;
|
---|
67 | private LinkedList<Bid>[] proposedMinBid;
|
---|
68 | private List<Bid>[] topBidsInOppsSpace;
|
---|
69 | private LinkedList<Bid>[] topBidsInMySpace;
|
---|
70 | private Bid myBid;
|
---|
71 | private List<Bid> fullUtilBids;
|
---|
72 | private int myIndex;
|
---|
73 | private String oppName;
|
---|
74 | private int oppIndex;
|
---|
75 | private boolean[] acceptAction;
|
---|
76 | private PreferModel[] pModel;
|
---|
77 | private Bid lastConcessionPoint;
|
---|
78 | private List<Bid>[] acceptableBidsWithOppValues;
|
---|
79 | private List<Bid> candidateBids;
|
---|
80 | private List<Bid> lastPeriodBidList;
|
---|
81 | private int myNextPartyIndex;
|
---|
82 | private int myLastPartyIndex;
|
---|
83 | private List<Bid>[] maxProductBids;
|
---|
84 | private List<Bid> maxUtilAdditionBidByOpps;
|
---|
85 | private double maxUtilAdditionByOpps;
|
---|
86 | private double time1;
|
---|
87 | private double time2;
|
---|
88 | private double time3;
|
---|
89 | private boolean hasHistory;
|
---|
90 | private boolean hasHistWithRightPosition;
|
---|
91 | private boolean hasInitParamByHist;
|
---|
92 | private List<Tuple<Bid, Double>> agreements;
|
---|
93 | private boolean hasAgreementHist;
|
---|
94 | private List<Bid> maxAgreedBids;
|
---|
95 | private Map<String, List<Double>>[] histUtils;
|
---|
96 | private Map<String, Double>[] maxUtilsInHist;
|
---|
97 | private List<Bid>[] maxUtilBidsByHist;
|
---|
98 | private List<Bid> sameBidsInOpps;
|
---|
99 |
|
---|
100 | @Override
|
---|
101 | public void init(NegotiationInfo info) {
|
---|
102 |
|
---|
103 | super.init(info);
|
---|
104 |
|
---|
105 | if (getData().getPersistentDataType() != PersistentDataType.STANDARD) {
|
---|
106 | throw new IllegalStateException("need standard persistent data");
|
---|
107 | }
|
---|
108 | history = (StandardInfoList) getData().get();
|
---|
109 |
|
---|
110 | if (!history.isEmpty()) {
|
---|
111 | Map<String, Double> maxutils = new HashMap<String, Double>();
|
---|
112 | StandardInfo lastinfo = history.get(history.size() - 1);
|
---|
113 | for (Tuple<String, Double> offered : lastinfo.getUtilities()) {
|
---|
114 | String party = offered.get1();
|
---|
115 | Double util = offered.get2();
|
---|
116 | maxutils.put(party, maxutils.containsKey(party)
|
---|
117 | ? Math.max(maxutils.get(party), util) : util);
|
---|
118 | }
|
---|
119 | }
|
---|
120 | hasAgreementHist = false;
|
---|
121 | if (!history.isEmpty()) {
|
---|
122 | hasHistory = true;
|
---|
123 | hasInitParamByHist = false;
|
---|
124 | agreements = new ArrayList<>();
|
---|
125 | maxAgreedBids = new ArrayList<>();
|
---|
126 | int numOfAgent = history.get(0).getAgentProfiles().size();
|
---|
127 | histUtils = new HashMap[numOfAgent];
|
---|
128 | maxUtilsInHist = new HashMap[numOfAgent];
|
---|
129 | maxUtilBidsByHist = new ArrayList[numOfAgent];
|
---|
130 | for (int i = 0; i < numOfAgent; i++) {
|
---|
131 | histUtils[i] = new HashMap<>();
|
---|
132 | maxUtilsInHist[i] = new HashMap<>();
|
---|
133 | maxUtilBidsByHist[i] = new ArrayList<>();
|
---|
134 | }
|
---|
135 | for (StandardInfo sessionInfo : history) {
|
---|
136 | if (sessionInfo.getAgreement().get1() != null) {
|
---|
137 | agreements.add(sessionInfo.getAgreement());
|
---|
138 | hasAgreementHist = true;
|
---|
139 | }
|
---|
140 | for (Tuple<String, Double> offered : sessionInfo
|
---|
141 | .getUtilities()) {
|
---|
142 | String party = offered.get1();
|
---|
143 | double util = offered.get2();
|
---|
144 | int index = Integer.parseInt(party.split("@")[1])
|
---|
145 | % numOfAgent;
|
---|
146 | if (!histUtils[index].containsKey(party)) {
|
---|
147 | List<Double> utils = new ArrayList<>();
|
---|
148 | utils.add(util);
|
---|
149 | histUtils[index].put(party, utils);
|
---|
150 | } else {
|
---|
151 | histUtils[index].get(party).add(util);
|
---|
152 | }
|
---|
153 | }
|
---|
154 | }
|
---|
155 | maxAgreedBids = getMaxBidsInAgreements();
|
---|
156 | for (int partyIndex = 0; partyIndex < numOfAgent; partyIndex++) {
|
---|
157 | for (String party : histUtils[partyIndex].keySet()) {
|
---|
158 | String partyName = party.split("@")[0];
|
---|
159 | List<Double> utils = histUtils[partyIndex].get(party);
|
---|
160 | double maxUtil = getMaxInArray(utils);
|
---|
161 | if (!maxUtilsInHist[partyIndex].containsKey(partyName)) {
|
---|
162 | maxUtilsInHist[partyIndex].put(partyName, maxUtil);
|
---|
163 | } else if (maxUtilsInHist[partyIndex]
|
---|
164 | .get(partyName) < maxUtil) {
|
---|
165 | maxUtilsInHist[partyIndex].put(partyName, maxUtil);
|
---|
166 | }
|
---|
167 | }
|
---|
168 | }
|
---|
169 | } else {
|
---|
170 | hasHistory = false;
|
---|
171 | hasHistWithRightPosition = false;
|
---|
172 | }
|
---|
173 |
|
---|
174 | nrChosenActions = 0;
|
---|
175 | numOfIssues = info.getUtilitySpace().getDomain().getIssues().size();
|
---|
176 | fullUtilBids = new ArrayList<>();
|
---|
177 | fullUtilBids = getFullUtilBid(info.getUtilitySpace());
|
---|
178 | reservationValue = getUtilitySpace().getReservationValue();
|
---|
179 | sameBidsInOpps = new ArrayList<>();
|
---|
180 | maxUtilAdditionBidByOpps = new ArrayList<>();
|
---|
181 | lastPeriodBidList = new ArrayList<>();
|
---|
182 | maxUtilAdditionByOpps = 0.0;
|
---|
183 | initialUpper = 0.95;
|
---|
184 | initialExponent = 50;
|
---|
185 | upper = initialUpper;
|
---|
186 | lower = reservationValue;
|
---|
187 | exponent = initialExponent;
|
---|
188 | time1 = 0.9;
|
---|
189 | time2 = 0.99;
|
---|
190 | time3 = 0.996;
|
---|
191 | hasInitParamByHist = false;
|
---|
192 | }
|
---|
193 |
|
---|
194 | @Override
|
---|
195 | public Action chooseAction(List<Class<? extends Action>> validActions) {
|
---|
196 | nrChosenActions++;
|
---|
197 | Action action = null;
|
---|
198 | Bid bid = null;
|
---|
199 | acceptUtil = getAccept();
|
---|
200 | if (lastReceivedBid != null) {
|
---|
201 | if (utility >= acceptUtil
|
---|
202 | && !hasProposedMyLastRound(lastReceivedBid)) {
|
---|
203 | bid = new Bid(lastReceivedBid);
|
---|
204 | action = new Accept(getPartyId(), bid);
|
---|
205 | } else {
|
---|
206 | if (timeline.getTime() > time3) {
|
---|
207 | if (hasHistory) {
|
---|
208 | if (!maxAgreedBids.isEmpty()) {
|
---|
209 | bid = maxAgreedBids.get(
|
---|
210 | nrChosenActions % maxAgreedBids.size());
|
---|
211 | action = new Offer(getPartyId(), bid);
|
---|
212 | } else {
|
---|
213 | if (!lastPeriodBidList.isEmpty()) {
|
---|
214 | bid = lastPeriodBidList.get(nrChosenActions
|
---|
215 | % lastPeriodBidList.size());
|
---|
216 | action = new Offer(getPartyId(), bid);
|
---|
217 | } else {
|
---|
218 | if (utility > reservationValue) {
|
---|
219 | bid = lastReceivedBid;
|
---|
220 | action = new Accept(getPartyId(), bid);
|
---|
221 | return action;
|
---|
222 | } else {
|
---|
223 | bid = proposedBids[myIndex]
|
---|
224 | .get(nrChosenActions
|
---|
225 | % numOfBids[myIndex]);
|
---|
226 | }
|
---|
227 | }
|
---|
228 | }
|
---|
229 | } else {
|
---|
230 | if (!lastPeriodBidList.isEmpty()) {
|
---|
231 | bid = lastPeriodBidList.get(
|
---|
232 | nrChosenActions % lastPeriodBidList.size());
|
---|
233 | } else {
|
---|
234 | if (utility > reservationValue) {
|
---|
235 | bid = lastReceivedBid;
|
---|
236 | action = new Accept(getPartyId(), bid);
|
---|
237 | myBid = bid;
|
---|
238 | return action;
|
---|
239 | } else {
|
---|
240 | bid = proposedBids[myIndex].get(
|
---|
241 | nrChosenActions % numOfBids[myIndex]);
|
---|
242 | }
|
---|
243 | }
|
---|
244 | }
|
---|
245 | action = new Offer(getPartyId(), bid);
|
---|
246 | myBid = bid;
|
---|
247 | } else if (timeline.getTime() > time2) {
|
---|
248 | if (nrChosenActions % 3 == 1) {
|
---|
249 | if (candidateBids.isEmpty()) {
|
---|
250 | if (!acceptAction[myNextPartyIndex]
|
---|
251 | && !acceptAction[myLastPartyIndex]) {
|
---|
252 | generateCandidateFromMyTopBids(acceptUtil,
|
---|
253 | candidateBids);
|
---|
254 | generateCandidateFromOppTopBids(acceptUtil,
|
---|
255 | candidateBids);
|
---|
256 | } else if (!acceptAction[myNextPartyIndex]) {
|
---|
257 | generateCandidateFromMyFullAndOppTopBids(
|
---|
258 | acceptUtil, myNextPartyIndex,
|
---|
259 | candidateBids);
|
---|
260 | generateCandidateFromOppTopAndMyTopBids(
|
---|
261 | myNextPartyIndex, acceptUtil,
|
---|
262 | candidateBids);
|
---|
263 | } else {
|
---|
264 | generateCandidateFromMyFullAndOppTopBids(
|
---|
265 | acceptUtil, myLastPartyIndex,
|
---|
266 | candidateBids);
|
---|
267 | generateCandidateFromOppTopAndMyTopBids(
|
---|
268 | myLastPartyIndex, acceptUtil,
|
---|
269 | candidateBids);
|
---|
270 | }
|
---|
271 | }
|
---|
272 | if (!candidateBids.isEmpty()) {
|
---|
273 | bid = candidateBids.remove(0);
|
---|
274 | if (hasProposedMyLastRound(bid)) {
|
---|
275 | bid = proposedBids[myIndex].get(
|
---|
276 | nrChosenActions % numOfBids[myIndex]);
|
---|
277 | }
|
---|
278 | } else {
|
---|
279 | bid = proposedBids[myIndex]
|
---|
280 | .get(nrChosenActions % numOfBids[myIndex]);
|
---|
281 | }
|
---|
282 | action = new Offer(getPartyId(), bid);
|
---|
283 | } else if (nrChosenActions % 3 == 0) {
|
---|
284 | if (candidateBids.isEmpty()) {
|
---|
285 | generateCandidateFromMyFullBids(
|
---|
286 | proposedBids[myIndex]);
|
---|
287 | generateCandidateFromMyTopBids(acceptUtil,
|
---|
288 | proposedBids[myIndex]);
|
---|
289 | }
|
---|
290 | if (!candidateBids.isEmpty()) {
|
---|
291 | bid = candidateBids.remove(0);
|
---|
292 | } else {
|
---|
293 | bid = proposedBids[myIndex]
|
---|
294 | .get(nrChosenActions % numOfBids[myIndex]);
|
---|
295 | }
|
---|
296 | action = new Offer(getPartyId(), bid);
|
---|
297 | } else {
|
---|
298 | bid = proposedBids[myIndex]
|
---|
299 | .get(nrChosenActions % numOfBids[myIndex]);
|
---|
300 | action = new Offer(getPartyId(), bid);
|
---|
301 | }
|
---|
302 | if (lastPeriodBidList.isEmpty()) {
|
---|
303 | lastPeriodBidList = getMaxUtilBidsInList(
|
---|
304 | sameBidsInOpps);
|
---|
305 | }
|
---|
306 | if (lastPeriodBidList.isEmpty()) {
|
---|
307 | mergeBids(proposedBids[myNextPartyIndex].get(0),
|
---|
308 | proposedBids[myLastPartyIndex].get(0), lower,
|
---|
309 | lastPeriodBidList, lastPeriodBidList);
|
---|
310 | }
|
---|
311 | } else if (timeline.getTime() > time1) {
|
---|
312 | if (candidateBids.isEmpty()) {
|
---|
313 | if (nrChosenActions % 3 == 0) {
|
---|
314 | if (!acceptAction[myNextPartyIndex]) {
|
---|
315 | generateCandidateFromMyFullAndOppTopBids(
|
---|
316 | acceptUtil, myNextPartyIndex,
|
---|
317 | candidateBids);
|
---|
318 | generateCandidateFromMyFullAndMyTopBids(
|
---|
319 | acceptUtil, myNextPartyIndex,
|
---|
320 | candidateBids);
|
---|
321 | generateCandidateFromOppTopAndMyTopBids(
|
---|
322 | myNextPartyIndex, acceptUtil,
|
---|
323 | candidateBids);
|
---|
324 | }
|
---|
325 | if (!acceptAction[myLastPartyIndex]) {
|
---|
326 | generateCandidateFromMyFullAndOppTopBids(
|
---|
327 | acceptUtil, myLastPartyIndex,
|
---|
328 | candidateBids);
|
---|
329 | generateCandidateFromMyFullAndMyTopBids(
|
---|
330 | acceptUtil, myLastPartyIndex,
|
---|
331 | candidateBids);
|
---|
332 | generateCandidateFromOppTopAndMyTopBids(
|
---|
333 | myLastPartyIndex, acceptUtil,
|
---|
334 | candidateBids);
|
---|
335 | }
|
---|
336 | } else if (nrChosenActions % 3 == 1) {
|
---|
337 | generateCandidateFromOppTopBids(acceptUtil,
|
---|
338 | candidateBids);
|
---|
339 | generateCandidateFromMyTopBids(acceptUtil,
|
---|
340 | candidateBids);
|
---|
341 | } else {
|
---|
342 | generateCandidateFromMyFullBids(
|
---|
343 | proposedBids[myIndex]);
|
---|
344 | generateCandidateFromMyTopBids(acceptUtil,
|
---|
345 | proposedBids[myIndex]);
|
---|
346 | }
|
---|
347 | }
|
---|
348 | if (!candidateBids.isEmpty()) {
|
---|
349 | bid = candidateBids.remove(0);
|
---|
350 | if (hasProposedMyLastRound(bid)) {
|
---|
351 | bid = proposedBids[myIndex]
|
---|
352 | .get(nrChosenActions % numOfBids[myIndex]);
|
---|
353 | }
|
---|
354 | } else {
|
---|
355 | bid = proposedBids[myIndex]
|
---|
356 | .get(nrChosenActions % numOfBids[myIndex]);
|
---|
357 | }
|
---|
358 | } else {
|
---|
359 | if (candidateBids.isEmpty()) {
|
---|
360 | generateCandidateFromMyFullBids(proposedBids[myIndex]);
|
---|
361 | generateCandidateFromMyTopBids(acceptUtil,
|
---|
362 | proposedBids[myIndex]);
|
---|
363 | generateCandidateFromMyFullAndMyTopBids(acceptUtil,
|
---|
364 | myNextPartyIndex, proposedBids[myIndex]);
|
---|
365 | generateCandidateFromMyFullAndMyTopBids(acceptUtil,
|
---|
366 | myLastPartyIndex, proposedBids[myIndex]);
|
---|
367 | }
|
---|
368 | if (!candidateBids.isEmpty()) {
|
---|
369 | bid = candidateBids.remove(0);
|
---|
370 | } else {
|
---|
371 | Bid nBid = fullUtilBids
|
---|
372 | .get(nrChosenActions % fullUtilBids.size());
|
---|
373 | if (proposedBids[myIndex].contains(nBid)) {
|
---|
374 | bid = proposedBids[myIndex]
|
---|
375 | .get(nrChosenActions % numOfBids[myIndex]);
|
---|
376 | } else {
|
---|
377 | bid = nBid;
|
---|
378 | }
|
---|
379 | }
|
---|
380 | }
|
---|
381 | if (bid == null) {
|
---|
382 | lastConcessionPoint = getBidWithLessBoundedUtil(
|
---|
383 | lastConcessionPoint, acceptUtil);
|
---|
384 | bid = lastConcessionPoint;
|
---|
385 | if (hasProposedMyLastRound(bid)) {
|
---|
386 | bid = proposedBids[myIndex]
|
---|
387 | .get(nrChosenActions % numOfBids[myIndex]);
|
---|
388 | }
|
---|
389 | }
|
---|
390 | if (bid == null) {
|
---|
391 | bid = myBid;
|
---|
392 | }
|
---|
393 | action = new Offer(getPartyId(), bid);
|
---|
394 | }
|
---|
395 | } else {
|
---|
396 | bid = new Bid(
|
---|
397 | fullUtilBids.get(nrChosenActions % fullUtilBids.size()));
|
---|
398 | action = new Offer(getPartyId(), bid);
|
---|
399 | }
|
---|
400 | myBid = bid;
|
---|
401 | numOfBids[myIndex]++;
|
---|
402 | proposedBids[myIndex].add(bid);
|
---|
403 | return action;
|
---|
404 | }
|
---|
405 |
|
---|
406 | @SuppressWarnings("unchecked")
|
---|
407 | @Override
|
---|
408 | public void receiveMessage(AgentID sender, Action action) {
|
---|
409 | super.receiveMessage(sender, action);
|
---|
410 | if (sender == null) {
|
---|
411 | numOfParties = getNumberOfParties();
|
---|
412 | myIndex = Integer.parseInt(getPartyId().toString().split("@")[1])
|
---|
413 | % numOfParties;
|
---|
414 | myNextPartyIndex = (myIndex + 1) % numOfParties;
|
---|
415 | myLastPartyIndex = (myIndex + numOfParties - 1) % numOfParties;
|
---|
416 | proposedBids = new ArrayList[numOfParties];
|
---|
417 | numOfBids = new int[numOfParties];
|
---|
418 | valueFrequences = new HashMap[numOfParties];
|
---|
419 | issueChangeFrequences = new HashMap[numOfParties];
|
---|
420 | acceptAction = new boolean[numOfParties];
|
---|
421 | maxUtils = new double[numOfParties];
|
---|
422 | minUtils = new double[numOfParties];
|
---|
423 | proposedMaxBid = new LinkedList[numOfParties];
|
---|
424 | proposedMinBid = new LinkedList[numOfParties];
|
---|
425 | pModel = new PreferModel[numOfParties];
|
---|
426 | acceptableBidsWithOppValues = new ArrayList[numOfParties];
|
---|
427 | candidateBids = new ArrayList<>();
|
---|
428 | maxProductBids = new ArrayList[numOfParties];
|
---|
429 | topBidsInOppsSpace = new ArrayList[numOfParties];
|
---|
430 | topBidsInMySpace = new LinkedList[numOfParties];
|
---|
431 | for (int i = 0; i < numOfParties; i++) {
|
---|
432 | proposedBids[i] = new ArrayList<>();
|
---|
433 | valueFrequences[i] = new HashMap<>();
|
---|
434 | issueChangeFrequences[i] = new HashMap<>();
|
---|
435 | proposedMaxBid[i] = new LinkedList<>();
|
---|
436 | proposedMinBid[i] = new LinkedList<>();
|
---|
437 | pModel[i] = new PreferModel(getUtilitySpace(), numOfIssues);
|
---|
438 | acceptableBidsWithOppValues[i] = new ArrayList<>();
|
---|
439 | maxProductBids[i] = new ArrayList<>();
|
---|
440 | topBidsInOppsSpace[i] = new ArrayList<>();
|
---|
441 | topBidsInMySpace[i] = new LinkedList<>();
|
---|
442 | }
|
---|
443 | } else {
|
---|
444 | oppName = sender.toString().split("@")[0];
|
---|
445 | oppIndex = Integer.parseInt(sender.toString().split("@")[1])
|
---|
446 | % numOfParties;
|
---|
447 | if (action instanceof Offer) {
|
---|
448 | acceptAction[oppIndex] = false;
|
---|
449 | lastReceivedBid = ((Offer) action).getBid();
|
---|
450 | }
|
---|
451 | if (action instanceof Accept) {
|
---|
452 | acceptAction[oppIndex] = true;
|
---|
453 | lastReceivedBid = ((Accept) action).getBid();
|
---|
454 | }
|
---|
455 | utility = getUtility(lastReceivedBid);
|
---|
456 | proposedBids[oppIndex].add(lastReceivedBid);
|
---|
457 | numOfBids[oppIndex]++;
|
---|
458 | updateMaxOrMinBids(oppIndex);
|
---|
459 | if (isDifferentBid(oppIndex)) {
|
---|
460 | updateSameBidsInOpps(oppIndex, lastReceivedBid);
|
---|
461 | updateTopBidsInOppsSpace(oppIndex);
|
---|
462 | updateTopBidsInMySpace(oppIndex);
|
---|
463 | }
|
---|
464 | if (hasHistory) {
|
---|
465 | if (!hasInitParamByHist) {
|
---|
466 | hasHistWithRightPosition = false;
|
---|
467 | for (String name : maxUtilsInHist[oppIndex].keySet()) {
|
---|
468 | if (oppName.equals(name)) {
|
---|
469 | hasHistWithRightPosition = true;
|
---|
470 | }
|
---|
471 | }
|
---|
472 | if (hasHistWithRightPosition) {
|
---|
473 | double[] arrs = new double[3];
|
---|
474 | for (int i = 0; i < getNumberOfParties(); i++) {
|
---|
475 | if (i == myIndex) {
|
---|
476 | continue;
|
---|
477 | }
|
---|
478 | for (String name : maxUtilsInHist[i].keySet()) {
|
---|
479 | if (oppIndex == i) {
|
---|
480 | arrs[i] = maxUtilsInHist[oppIndex]
|
---|
481 | .get(oppName);
|
---|
482 | } else {
|
---|
483 | if (!name.equals(oppName)) {
|
---|
484 | arrs[i] = maxUtilsInHist[i].get(name);
|
---|
485 | }
|
---|
486 | }
|
---|
487 | }
|
---|
488 | }
|
---|
489 | double max = 0.0;
|
---|
490 | double min = 1.0;
|
---|
491 | for (int i = 0; i < 3; i++) {
|
---|
492 | if (i == myIndex) {
|
---|
493 | continue;
|
---|
494 | }
|
---|
495 | if (max < arrs[i]) {
|
---|
496 | max = arrs[i];
|
---|
497 | }
|
---|
498 | if (min > arrs[i]) {
|
---|
499 | min = arrs[i];
|
---|
500 | }
|
---|
501 | }
|
---|
502 | if (maxAgreedBids.isEmpty()) {
|
---|
503 | if (min - 0.1 > reservationValue) {
|
---|
504 | lower = min - 0.1;
|
---|
505 | } else {
|
---|
506 | lower = reservationValue;
|
---|
507 | }
|
---|
508 | } else {
|
---|
509 | double agreedUtil = getUtility(
|
---|
510 | maxAgreedBids.get(0));
|
---|
511 | double[] utilArrs = { max, min, agreedUtil };
|
---|
512 | upper = getMaxInArray(utilArrs);
|
---|
513 | for (int i = 0; i < utilArrs.length; i++) {
|
---|
514 | if (utilArrs[i] == upper) {
|
---|
515 | utilArrs[i] = 0.0;
|
---|
516 | }
|
---|
517 | }
|
---|
518 | lower = getMinInArray(utilArrs) - 0.05;
|
---|
519 | if (lower <= 0) {
|
---|
520 | lower = reservationValue;
|
---|
521 | }
|
---|
522 | }
|
---|
523 | exponent = initialExponent * (upper - lower);
|
---|
524 | } else {
|
---|
525 | double[] arrs = new double[3];
|
---|
526 | for (int i = 0; i < getNumberOfParties(); i++) {
|
---|
527 | if (i == myIndex) {
|
---|
528 | continue;
|
---|
529 | }
|
---|
530 | for (String name : maxUtilsInHist[i].keySet()) {
|
---|
531 | arrs[i] = maxUtilsInHist[i].get(name);
|
---|
532 | }
|
---|
533 | }
|
---|
534 | double max = 0.0;
|
---|
535 | double min = 1.0;
|
---|
536 | for (int i = 0; i < 3; i++) {
|
---|
537 | if (i == myIndex) {
|
---|
538 | continue;
|
---|
539 | }
|
---|
540 | if (max < arrs[i]) {
|
---|
541 | max = arrs[i];
|
---|
542 | }
|
---|
543 | if (min > arrs[i]) {
|
---|
544 | min = arrs[i];
|
---|
545 | }
|
---|
546 | }
|
---|
547 | if (maxAgreedBids.isEmpty()) {
|
---|
548 | if (min - 0.1 > reservationValue) {
|
---|
549 | lower = min - 0.1;
|
---|
550 | } else {
|
---|
551 | lower = reservationValue;
|
---|
552 | }
|
---|
553 | } else {
|
---|
554 | double agreedUtil = getUtility(
|
---|
555 | maxAgreedBids.get(0));
|
---|
556 | double[] utilArrs = { max, min, agreedUtil, 0.9 };
|
---|
557 | upper = getMaxInArray(utilArrs);
|
---|
558 | for (int i = 0; i < utilArrs.length; i++) {
|
---|
559 | if (utilArrs[i] == upper) {
|
---|
560 | utilArrs[i] = 0.0;
|
---|
561 | }
|
---|
562 | }
|
---|
563 | lower = getMinInArray(utilArrs) - 0.1;
|
---|
564 | if (lower <= 0) {
|
---|
565 | lower = reservationValue;
|
---|
566 | }
|
---|
567 | }
|
---|
568 | exponent = initialExponent * (upper - lower);
|
---|
569 | }
|
---|
570 | hasInitParamByHist = true;
|
---|
571 | }
|
---|
572 | if (hasInitParamByHist) {
|
---|
573 | if (hasHistWithRightPosition) {
|
---|
574 |
|
---|
575 | } else {
|
---|
576 |
|
---|
577 | }
|
---|
578 | }
|
---|
579 | } else {
|
---|
580 | if (isDifferentBid(oppIndex)) {
|
---|
581 | pModel[oppIndex].updateEvaluators(lastReceivedBid);
|
---|
582 | if (timeline.getTime() > 0.5 && timeline.getTime() < 0.9) {
|
---|
583 | updateMaxUtilAddition(oppIndex, lastReceivedBid);
|
---|
584 | }
|
---|
585 | }
|
---|
586 | updateConcessionParam();
|
---|
587 | }
|
---|
588 | }
|
---|
589 | }
|
---|
590 |
|
---|
591 | @Override
|
---|
592 | public String getDescription() {
|
---|
593 | return "ANAC2017";
|
---|
594 | }
|
---|
595 |
|
---|
596 | private double getAccept() {
|
---|
597 | double accept = 0.9;
|
---|
598 | accept = upper - (upper + 0.001 - lower)
|
---|
599 | * Math.pow(timeline.getTime(), exponent);
|
---|
600 | return accept;
|
---|
601 | }
|
---|
602 |
|
---|
603 | private List<Bid> getFullUtilBid(AbstractUtilitySpace utilitySpace) {
|
---|
604 | Bid bid = null;
|
---|
605 | List<Bid> bidList = new ArrayList<>();
|
---|
606 | try {
|
---|
607 | bid = utilitySpace.getMaxUtilityBid();
|
---|
608 | } catch (Exception e) {
|
---|
609 | e.printStackTrace();
|
---|
610 | System.err.println(e.toString());
|
---|
611 | }
|
---|
612 | if (!bidList.contains(bid)) {
|
---|
613 | bidList.add(bid);
|
---|
614 | }
|
---|
615 | List<Issue> issues = getUtilitySpace().getDomain().getIssues();
|
---|
616 | for (Issue item : issues) {
|
---|
617 | Bid newBid = null;
|
---|
618 | switch (item.getType()) {
|
---|
619 | case DISCRETE:
|
---|
620 | IssueDiscrete discrete = (IssueDiscrete) item;
|
---|
621 | for (Value value : discrete.getValues()) {
|
---|
622 | newBid = bid.putValue(discrete.getNumber(), value);
|
---|
623 | if (getUtility(newBid) == 1.0
|
---|
624 | && !bidList.contains(newBid)) {
|
---|
625 | bidList.add(newBid);
|
---|
626 | }
|
---|
627 | }
|
---|
628 | break;
|
---|
629 | case INTEGER:
|
---|
630 | break;
|
---|
631 | default:
|
---|
632 | break;
|
---|
633 | }
|
---|
634 | }
|
---|
635 | return bidList;
|
---|
636 | }
|
---|
637 |
|
---|
638 | @SuppressWarnings("unused")
|
---|
639 | private Bid getBidWithLessUtil(Bid bid) {
|
---|
640 | Bid srcBid = null;
|
---|
641 | Bid nBid = null;
|
---|
642 | if (bid == null) {
|
---|
643 | srcBid = fullUtilBids.get(0);
|
---|
644 | } else {
|
---|
645 | srcBid = new Bid(bid);
|
---|
646 | }
|
---|
647 | double oldU = getUtility(srcBid);
|
---|
648 | List<Bid> bidList = new ArrayList<>();
|
---|
649 | for (int i = 0; i < numOfIssues; i++) {
|
---|
650 | Issue issue = srcBid.getIssues().get(i);
|
---|
651 | switch (issue.getType()) {
|
---|
652 | case DISCRETE:
|
---|
653 | IssueDiscrete issueDiscrete = (IssueDiscrete) issue;
|
---|
654 | for (Value value : issueDiscrete.getValues()) {
|
---|
655 | nBid = srcBid.putValue(i + 1, value);
|
---|
656 | if (oldU > getUtility(nBid)) {
|
---|
657 | bidList.add(nBid);
|
---|
658 | }
|
---|
659 | }
|
---|
660 | break;
|
---|
661 | case INTEGER:
|
---|
662 | IssueInteger issueInteger = (IssueInteger) issue;
|
---|
663 | for (int j = issueInteger.getLowerBound(); j <= issueInteger
|
---|
664 | .getUpperBound(); j++) {
|
---|
665 | nBid = srcBid.putValue(i + 1, new ValueInteger(j));
|
---|
666 | if (oldU > getUtility(nBid)) {
|
---|
667 | bidList.add(nBid);
|
---|
668 | }
|
---|
669 | }
|
---|
670 | break;
|
---|
671 | default:
|
---|
672 | break;
|
---|
673 | }
|
---|
674 | }
|
---|
675 | if (bidList.isEmpty()) {
|
---|
676 | nBid = new Bid(srcBid);
|
---|
677 | } else {
|
---|
678 | double distance = oldU - 0.0;
|
---|
679 | for (Bid item : bidList) {
|
---|
680 | double distance2 = oldU - getUtility(item);
|
---|
681 | if (distance2 < distance) {
|
---|
682 | nBid = new Bid(item);
|
---|
683 | distance = distance2;
|
---|
684 | }
|
---|
685 | }
|
---|
686 | }
|
---|
687 | return nBid;
|
---|
688 | }
|
---|
689 |
|
---|
690 | private Bid getBidWithLessBoundedUtil(Bid bid, double min) {
|
---|
691 | Bid srcBid = null;
|
---|
692 | Bid nBid = null;
|
---|
693 | if (bid == null) {
|
---|
694 | srcBid = fullUtilBids.get(0);
|
---|
695 | } else {
|
---|
696 | srcBid = new Bid(bid);
|
---|
697 | }
|
---|
698 | double oldU = getUtility(srcBid);
|
---|
699 | List<Bid> bidList = new ArrayList<>();
|
---|
700 | for (int i = 0; i < numOfIssues; i++) {
|
---|
701 | Issue issue = srcBid.getIssues().get(i);
|
---|
702 | double newU = 0.0;
|
---|
703 | switch (issue.getType()) {
|
---|
704 | case DISCRETE:
|
---|
705 | IssueDiscrete issueDiscrete = (IssueDiscrete) issue;
|
---|
706 | for (Value value : issueDiscrete.getValues()) {
|
---|
707 | nBid = srcBid.putValue(i + 1, value);
|
---|
708 | newU = getUtility(nBid);
|
---|
709 | if (oldU > newU && newU >= min) {
|
---|
710 | bidList.add(nBid);
|
---|
711 | }
|
---|
712 | }
|
---|
713 | break;
|
---|
714 | case INTEGER:
|
---|
715 | IssueInteger issueInteger = (IssueInteger) issue;
|
---|
716 | for (int j = issueInteger.getLowerBound(); j <= issueInteger
|
---|
717 | .getUpperBound(); j++) {
|
---|
718 | nBid = srcBid.putValue(i + 1, new ValueInteger(j));
|
---|
719 | newU = getUtility(nBid);
|
---|
720 | if (oldU > newU && newU >= min) {
|
---|
721 | bidList.add(nBid);
|
---|
722 | }
|
---|
723 | }
|
---|
724 | break;
|
---|
725 | default:
|
---|
726 | break;
|
---|
727 | }
|
---|
728 | }
|
---|
729 | if (bidList.isEmpty()) {
|
---|
730 | nBid = new Bid(srcBid);
|
---|
731 | } else {
|
---|
732 | double distance = oldU - 0.0;
|
---|
733 | for (Bid item : bidList) {
|
---|
734 | double distance2 = oldU - getUtility(item);
|
---|
735 | if (distance2 < distance) {
|
---|
736 | nBid = new Bid(item);
|
---|
737 | distance = distance2;
|
---|
738 | }
|
---|
739 | }
|
---|
740 | }
|
---|
741 | return nBid;
|
---|
742 | }
|
---|
743 |
|
---|
744 | private void updateProposedMaxBid(int partyId) {
|
---|
745 | if (proposedMaxBid[partyId].isEmpty()) {
|
---|
746 | if (utility > maxUtils[partyId]) {
|
---|
747 | maxUtils[partyId] = utility;
|
---|
748 | proposedMaxBid[partyId].add(lastReceivedBid);
|
---|
749 | }
|
---|
750 | } else {
|
---|
751 | if (maxUtils[partyId] > utility) {
|
---|
752 | return;
|
---|
753 | }
|
---|
754 | if (maxUtils[partyId] == utility
|
---|
755 | && !proposedMaxBid[partyId].contains(lastReceivedBid)) {
|
---|
756 | proposedMaxBid[partyId].add(lastReceivedBid);
|
---|
757 | }
|
---|
758 | if (maxUtils[partyId] < utility) {
|
---|
759 | proposedMaxBid[partyId].clear();
|
---|
760 | proposedMaxBid[partyId].add(lastReceivedBid);
|
---|
761 | maxUtils[partyId] = utility;
|
---|
762 | }
|
---|
763 | }
|
---|
764 | }
|
---|
765 |
|
---|
766 | private void updateProposedMinBid(int partyId) {
|
---|
767 | if (proposedMinBid[partyId].isEmpty()) {
|
---|
768 | proposedMinBid[partyId].add(lastReceivedBid);
|
---|
769 | if (0 >= minUtils[partyId]) {
|
---|
770 | minUtils[partyId] = utility;
|
---|
771 | }
|
---|
772 | } else {
|
---|
773 | if (minUtils[partyId] < utility) {
|
---|
774 | return;
|
---|
775 | }
|
---|
776 | if (minUtils[partyId] == utility
|
---|
777 | && !proposedMinBid[partyId].contains(lastReceivedBid)) {
|
---|
778 | proposedMinBid[partyId].add(lastReceivedBid);
|
---|
779 | }
|
---|
780 | if (minUtils[partyId] > utility) {
|
---|
781 | proposedMinBid[partyId].clear();
|
---|
782 | proposedMinBid[partyId].add(lastReceivedBid);
|
---|
783 | minUtils[partyId] = utility;
|
---|
784 | }
|
---|
785 | }
|
---|
786 | }
|
---|
787 |
|
---|
788 | private void updateMaxOrMinBids(int partyId) {
|
---|
789 | updateProposedMaxBid(partyId);
|
---|
790 | updateProposedMinBid(partyId);
|
---|
791 | }
|
---|
792 |
|
---|
793 | private void updateTopBidsInOppsSpace(int partyId) {
|
---|
794 | if (topBidsInOppsSpace[partyId].size() < 5
|
---|
795 | && !topBidsInOppsSpace[partyId].contains(lastReceivedBid)) {
|
---|
796 | topBidsInOppsSpace[partyId].add(lastReceivedBid);
|
---|
797 | }
|
---|
798 | }
|
---|
799 |
|
---|
800 | private void updateTopBidsInMySpace(int partyId) {
|
---|
801 | if (topBidsInMySpace[partyId].contains(lastReceivedBid)) {
|
---|
802 | return;
|
---|
803 | } else {
|
---|
804 | topBidsInMySpace[partyId] = proposedMaxBid[partyId];
|
---|
805 | }
|
---|
806 | }
|
---|
807 |
|
---|
808 | private void updateConcessionParam() {
|
---|
809 | if (!hasHistory) {
|
---|
810 | // ����Ϊ�����������С��utility
|
---|
811 | double maxInMinUtil = 0.0;
|
---|
812 | double minInMinUtil = 1.0;
|
---|
813 | double minInMaxUtil = 1.0;
|
---|
814 | double[] avgUtil = new double[numOfParties];
|
---|
815 | for (int i = 0; i < numOfParties; i++) {
|
---|
816 | if (i == myIndex) {
|
---|
817 | avgUtil[i] = 1.0;
|
---|
818 | continue;
|
---|
819 | }
|
---|
820 | if (maxUtils[i] == 0.0 || minUtils[i] == 0.0) {
|
---|
821 | continue;
|
---|
822 | }
|
---|
823 | double utilInMin2 = minUtils[i];
|
---|
824 | if (utilInMin2 > maxInMinUtil) {
|
---|
825 | maxInMinUtil = utilInMin2;
|
---|
826 | }
|
---|
827 | if (utilInMin2 < minInMinUtil) {
|
---|
828 | minInMinUtil = utilInMin2;
|
---|
829 | }
|
---|
830 | double utilInMax = maxUtils[i];
|
---|
831 | if (minInMaxUtil > utilInMax) {
|
---|
832 | minInMaxUtil = utilInMax;
|
---|
833 | }
|
---|
834 | avgUtil[i] = (3 * maxUtils[i] + minUtils[i]) / 4;
|
---|
835 | }
|
---|
836 | double lowerbound = 0.0;
|
---|
837 | double minAvg = getMinInArray(avgUtil);
|
---|
838 | if (reservationValue > minAvg - 0.001) {
|
---|
839 | lowerbound = reservationValue;
|
---|
840 | } else {
|
---|
841 | lowerbound = minAvg - 0.001;
|
---|
842 | }
|
---|
843 | lower = lowerbound;
|
---|
844 | if (minInMaxUtil <= 0.0) {
|
---|
845 | exponent = initialExponent;
|
---|
846 | } else {
|
---|
847 | exponent = initialExponent * minInMaxUtil;
|
---|
848 | }
|
---|
849 | } else {
|
---|
850 |
|
---|
851 | }
|
---|
852 | }
|
---|
853 |
|
---|
854 | private double getMinInArray(double arr[]) {
|
---|
855 | double min = arr[0];
|
---|
856 | for (int i = 0; i < arr.length; i++) {
|
---|
857 | if (min > arr[i]) {
|
---|
858 | min = arr[i];
|
---|
859 | }
|
---|
860 | }
|
---|
861 | return min;
|
---|
862 | }
|
---|
863 |
|
---|
864 | private double getMaxInArray(double[] arr) {
|
---|
865 | double max = 0.0;
|
---|
866 | for (int i = 0; i < arr.length; i++) {
|
---|
867 | if (max < arr[i]) {
|
---|
868 | max = arr[i];
|
---|
869 | }
|
---|
870 | }
|
---|
871 | return max;
|
---|
872 | }
|
---|
873 |
|
---|
874 | private double getMaxInArray(List<Double> list) {
|
---|
875 | double max = 0.0;
|
---|
876 | for (double item : list) {
|
---|
877 | if (item > max) {
|
---|
878 | max = item;
|
---|
879 | }
|
---|
880 | }
|
---|
881 | return max;
|
---|
882 | }
|
---|
883 |
|
---|
884 | private boolean isDifferentBid(int partyId) {
|
---|
885 | if (proposedBids[partyId].size() < 2) {
|
---|
886 | return true;
|
---|
887 | } else {
|
---|
888 | if (proposedBids[partyId].get(numOfBids[partyId] - 1).equals(
|
---|
889 | proposedBids[partyId].get(numOfBids[partyId] - 2))) {
|
---|
890 | return false;
|
---|
891 | } else {
|
---|
892 | return true;
|
---|
893 | }
|
---|
894 | }
|
---|
895 | }
|
---|
896 |
|
---|
897 | private void alterBidValue(Bid srcBid, Map<Integer, Value> valueMap,
|
---|
898 | int issueNr, double acceptableUtil, List<Bid> bidList,
|
---|
899 | List<Bid> validationList) {
|
---|
900 | Bid nBid = new Bid(srcBid);
|
---|
901 | if (getUtility(nBid) >= acceptableUtil
|
---|
902 | && !validationList.contains(nBid)) {
|
---|
903 | bidList.add(nBid);
|
---|
904 | }
|
---|
905 | if (!valueMap.containsKey(issueNr)) {
|
---|
906 | return;
|
---|
907 | }
|
---|
908 | for (int j = issueNr; j <= valueMap.size(); j++) {
|
---|
909 | Value value = valueMap.get(j);
|
---|
910 | if (value.equals(srcBid.getValue(j))) {
|
---|
911 | continue;
|
---|
912 | }
|
---|
913 | nBid = srcBid.putValue(j, value);
|
---|
914 | int item = j + 1;
|
---|
915 | alterBidValue(nBid, valueMap, item, acceptableUtil, bidList,
|
---|
916 | validationList);
|
---|
917 | }
|
---|
918 | }
|
---|
919 |
|
---|
920 | private void mergeBids(Bid fir, Bid sec, double acceptableUtil,
|
---|
921 | List<Bid> bidList, List<Bid> validationList) {
|
---|
922 | if (fir == null || sec == null) {
|
---|
923 | return;
|
---|
924 | }
|
---|
925 | if (fir.equals(sec)) {
|
---|
926 | if (!validationList.contains(fir)) {
|
---|
927 | bidList.add(fir);
|
---|
928 | }
|
---|
929 | return;
|
---|
930 | }
|
---|
931 | alterBidValue(fir, sec.getValues(), 1, acceptableUtil, bidList,
|
---|
932 | validationList);
|
---|
933 | }
|
---|
934 |
|
---|
935 | private void generateCandidateFromMyFullBidsAndOppsTopBids(double minUtil,
|
---|
936 | int oppIndex, List<Bid> validationList) {
|
---|
937 | if (proposedBids[oppIndex].isEmpty()) {
|
---|
938 | return;
|
---|
939 | }
|
---|
940 | for (Bid item : fullUtilBids) {
|
---|
941 | for (Bid item2 : topBidsInOppsSpace[oppIndex]) {
|
---|
942 | if (item.equals(item2)) {
|
---|
943 | continue;
|
---|
944 | }
|
---|
945 | mergeBids(item, item2, minUtil, candidateBids, validationList);
|
---|
946 | }
|
---|
947 | }
|
---|
948 | }
|
---|
949 |
|
---|
950 | private List<Bid> getMaxSocialWelfareBidsInList(List<Bid> bidList) {
|
---|
951 | List<Bid> maxAdditionBids = new ArrayList<>();
|
---|
952 | List<Bid> maxProductBids = new ArrayList<>();
|
---|
953 | List<Bid> maxSocialWelfareBids = new ArrayList<>();
|
---|
954 | double maxAddition = 0.0;
|
---|
955 | double maxProduct = 0.0;
|
---|
956 | for (Bid bid : bidList) {
|
---|
957 | double bidAddition = 0.0;
|
---|
958 | double bidProduct = 1.0;
|
---|
959 | bidAddition = getUtilAddition(bid);
|
---|
960 | bidProduct = getUtilProduct(bid);
|
---|
961 | if (bidAddition > maxAddition) {
|
---|
962 | maxAdditionBids.clear();
|
---|
963 | maxAdditionBids.add(bid);
|
---|
964 | maxAddition = bidAddition;
|
---|
965 | } else if (bidAddition == maxAddition
|
---|
966 | && !maxAdditionBids.contains(bid)) {
|
---|
967 | maxAdditionBids.add(bid);
|
---|
968 | }
|
---|
969 | if (bidProduct > maxProduct) {
|
---|
970 | maxProductBids.clear();
|
---|
971 | maxProductBids.add(bid);
|
---|
972 | maxProduct = bidProduct;
|
---|
973 | } else if (bidProduct == maxProduct
|
---|
974 | && !maxProductBids.contains(bid)) {
|
---|
975 | maxProductBids.add(bid);
|
---|
976 | }
|
---|
977 | }
|
---|
978 | maxSocialWelfareBids.addAll(maxAdditionBids);
|
---|
979 | maxSocialWelfareBids.addAll(maxProductBids);
|
---|
980 | return maxSocialWelfareBids;
|
---|
981 | }
|
---|
982 |
|
---|
983 | private double getUtilProduct(Bid bid) {
|
---|
984 | double product = 1.0;
|
---|
985 | for (int i = 0; i < numOfParties; i++) {
|
---|
986 | if (i == myIndex) {
|
---|
987 | product *= getUtility(bid);
|
---|
988 | }
|
---|
989 | product *= pModel[i].getUtil(bid);
|
---|
990 | }
|
---|
991 | return product;
|
---|
992 | }
|
---|
993 |
|
---|
994 | private double getUtilAddition(Bid bid) {
|
---|
995 | double addition = 0.0;
|
---|
996 | for (int i = 0; i < numOfParties; i++) {
|
---|
997 | if (i == myIndex) {
|
---|
998 | addition += getUtility(bid);
|
---|
999 | }
|
---|
1000 | addition += pModel[i].getUtil(bid);
|
---|
1001 | }
|
---|
1002 | return addition;
|
---|
1003 | }
|
---|
1004 |
|
---|
1005 | private List<Bid> getMaxUtilBidsInList(List<Bid> bidList) {
|
---|
1006 | List<Bid> bids = new ArrayList<>();
|
---|
1007 | double maxUtil = 0.0;
|
---|
1008 | for (Bid item : bidList) {
|
---|
1009 | double util = getUtility(item);
|
---|
1010 | if (util < maxUtil) {
|
---|
1011 | continue;
|
---|
1012 | }
|
---|
1013 | if (util > maxUtil) {
|
---|
1014 | bids.clear();
|
---|
1015 | bids.add(item);
|
---|
1016 | maxUtil = util;
|
---|
1017 | } else {
|
---|
1018 | bids.add(item);
|
---|
1019 | }
|
---|
1020 | }
|
---|
1021 | return bids;
|
---|
1022 | }
|
---|
1023 |
|
---|
1024 | private void updateSameBidsInOpps(int proposedPartyId, Bid bid) {
|
---|
1025 | boolean bidHasProposedByAllOpps = true;
|
---|
1026 | for (int i = 0; i < numOfParties; i++) {
|
---|
1027 | if (i == myIndex || i == proposedPartyId) {
|
---|
1028 | continue;
|
---|
1029 | }
|
---|
1030 | if (!proposedBids[i].contains(bid)) {
|
---|
1031 | bidHasProposedByAllOpps = false;
|
---|
1032 | return;
|
---|
1033 | } else {
|
---|
1034 | bidHasProposedByAllOpps = true;
|
---|
1035 | }
|
---|
1036 | }
|
---|
1037 | if (bidHasProposedByAllOpps) {
|
---|
1038 | sameBidsInOpps.add(bid);
|
---|
1039 | }
|
---|
1040 | }
|
---|
1041 |
|
---|
1042 | private void updateMaxUtilAddition(int partyId, Bid bid) {
|
---|
1043 | double utilAddition = 0.0;
|
---|
1044 | for (int i = 0; i < numOfParties; i++) {
|
---|
1045 | if (partyId == myIndex) {
|
---|
1046 | utilAddition += getUtility(bid);
|
---|
1047 | } else {
|
---|
1048 | utilAddition += pModel[i].getUtil(bid);
|
---|
1049 | }
|
---|
1050 | }
|
---|
1051 | if (utilAddition < maxUtilAdditionByOpps) {
|
---|
1052 | return;
|
---|
1053 | }
|
---|
1054 | if (utilAddition > maxUtilAdditionByOpps) {
|
---|
1055 | maxUtilAdditionBidByOpps.clear();
|
---|
1056 | maxUtilAdditionBidByOpps.add(bid);
|
---|
1057 | maxUtilAdditionByOpps = utilAddition;
|
---|
1058 | } else {
|
---|
1059 | maxUtilAdditionBidByOpps.add(bid);
|
---|
1060 | }
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | private void generateCandidateFromOppTopAndMyTopBids(int partyId,
|
---|
1064 | double minUtil, List<Bid> validationList) {
|
---|
1065 | if (proposedBids[partyId].isEmpty()) {
|
---|
1066 | return;
|
---|
1067 | }
|
---|
1068 | for (Bid item : topBidsInOppsSpace[partyId]) {
|
---|
1069 | for (Bid maxBid : topBidsInMySpace[partyId]) {
|
---|
1070 | mergeBids(maxBid, item, minUtil, candidateBids, candidateBids);
|
---|
1071 | }
|
---|
1072 | }
|
---|
1073 | }
|
---|
1074 |
|
---|
1075 | private List<Bid> getMaxBidsInAgreements() {
|
---|
1076 | double maxUtil = 0.0;
|
---|
1077 | List<Bid> maxBids = new ArrayList<>();
|
---|
1078 | for (Tuple<Bid, Double> item : agreements) {
|
---|
1079 | if (item.get2() < maxUtil) {
|
---|
1080 | continue;
|
---|
1081 | }
|
---|
1082 | if (item.get2() > maxUtil) {
|
---|
1083 | maxBids.clear();
|
---|
1084 | maxBids.add(item.get1());
|
---|
1085 | maxUtil = item.get2();
|
---|
1086 | } else {
|
---|
1087 | if (!maxBids.contains(item.get1())) {
|
---|
1088 | maxBids.add(item.get1());
|
---|
1089 | }
|
---|
1090 | }
|
---|
1091 | }
|
---|
1092 | return maxBids;
|
---|
1093 | }
|
---|
1094 |
|
---|
1095 | private boolean hasProposedMyLastRound(Bid bid) {
|
---|
1096 | if (numOfBids[myIndex] <= 0) {
|
---|
1097 | return false;
|
---|
1098 | }
|
---|
1099 | Bid lastRoundBid = proposedBids[myIndex].get(numOfBids[myIndex] - 1);
|
---|
1100 | return lastRoundBid.equals(bid);
|
---|
1101 | }
|
---|
1102 |
|
---|
1103 | private void generateCandidateFromMyFullBids(List<Bid> validationList) {
|
---|
1104 | for (Bid item1 : fullUtilBids) {
|
---|
1105 | for (Bid item2 : fullUtilBids) {
|
---|
1106 | if (item1.equals(item2)) {
|
---|
1107 | if (validationList.contains(item1)) {
|
---|
1108 | continue;
|
---|
1109 | } else {
|
---|
1110 | candidateBids.add(item1);
|
---|
1111 | continue;
|
---|
1112 | }
|
---|
1113 | } else {
|
---|
1114 | mergeBids(item1, item2, 0.9, candidateBids, validationList);
|
---|
1115 | }
|
---|
1116 | }
|
---|
1117 | }
|
---|
1118 | }
|
---|
1119 |
|
---|
1120 | private void generateCandidateFromMyFullAndMyTopBids(double accept,
|
---|
1121 | int partyId, List<Bid> validationList) {
|
---|
1122 | for (Bid item1 : fullUtilBids) {
|
---|
1123 | for (Bid item2 : topBidsInMySpace[partyId]) {
|
---|
1124 | mergeBids(item1, item2, accept, candidateBids, validationList);
|
---|
1125 | }
|
---|
1126 | }
|
---|
1127 | }
|
---|
1128 |
|
---|
1129 | private void generateCandidateFromMyFullAndOppTopBids(double accept,
|
---|
1130 | int partyId, List<Bid> validationList) {
|
---|
1131 | for (Bid item1 : fullUtilBids) {
|
---|
1132 | for (Bid item2 : topBidsInOppsSpace[partyId]) {
|
---|
1133 | mergeBids(item1, item2, accept, candidateBids, validationList);
|
---|
1134 | }
|
---|
1135 | }
|
---|
1136 | }
|
---|
1137 |
|
---|
1138 | private void generateCandidateFromMyTopBids(double acceptableUtil,
|
---|
1139 | List<Bid> validationList) {
|
---|
1140 | for (Bid fBid : topBidsInMySpace[myNextPartyIndex]) {
|
---|
1141 | for (Bid sBid : topBidsInMySpace[myLastPartyIndex]) {
|
---|
1142 | alterBidValue(fBid, sBid.getValues(), 1, acceptableUtil,
|
---|
1143 | candidateBids, validationList);
|
---|
1144 | }
|
---|
1145 | }
|
---|
1146 | }
|
---|
1147 |
|
---|
1148 | private void generateCandidateFromOppTopBids(double acceptableUtil,
|
---|
1149 | List<Bid> validationList) {
|
---|
1150 | if (numOfBids[myLastPartyIndex] == 0
|
---|
1151 | || numOfBids[myNextPartyIndex] == 0) {
|
---|
1152 | return;
|
---|
1153 | }
|
---|
1154 | for (Bid item1 : topBidsInOppsSpace[myNextPartyIndex]) {
|
---|
1155 | for (Bid item2 : topBidsInOppsSpace[myLastPartyIndex]) {
|
---|
1156 | if (item1.equals(item2)) {
|
---|
1157 | continue;
|
---|
1158 | }
|
---|
1159 | mergeBids(item1, item2, acceptableUtil, candidateBids,
|
---|
1160 | validationList);
|
---|
1161 | }
|
---|
1162 | }
|
---|
1163 | }
|
---|
1164 |
|
---|
1165 | public class PreferModel {
|
---|
1166 |
|
---|
1167 | private UtilitySpace utilitySpace;
|
---|
1168 | private Set<Entry<Objective, Evaluator>> evaluators;
|
---|
1169 | private int numOfIssues;
|
---|
1170 | private double[] weights;
|
---|
1171 | private int[] indexOfMaxFreq;
|
---|
1172 | private int numOfValues;
|
---|
1173 | private int learnRate;
|
---|
1174 |
|
---|
1175 | public PreferModel(UtilitySpace utilitySpace, int num) {
|
---|
1176 | this.utilitySpace = utilitySpace;
|
---|
1177 | numOfIssues = num;
|
---|
1178 | weights = new double[num];
|
---|
1179 | initWeights();
|
---|
1180 | initEvaluators();
|
---|
1181 | setNumOfValues();
|
---|
1182 | learnRate = 1;
|
---|
1183 | }
|
---|
1184 |
|
---|
1185 | public Set<Entry<Objective, Evaluator>> getEvaluators() {
|
---|
1186 | return evaluators;
|
---|
1187 | }
|
---|
1188 |
|
---|
1189 | private void setEvaluators(
|
---|
1190 | Set<Entry<Objective, Evaluator>> evaluators) {
|
---|
1191 | this.evaluators = evaluators;
|
---|
1192 | }
|
---|
1193 |
|
---|
1194 | public double[] getWeights() {
|
---|
1195 | return weights;
|
---|
1196 | }
|
---|
1197 |
|
---|
1198 | public void setWeights(double weights[]) {
|
---|
1199 | this.weights = weights;
|
---|
1200 | }
|
---|
1201 |
|
---|
1202 | public int[] getIndexOfMaxFreq() {
|
---|
1203 | return indexOfMaxFreq;
|
---|
1204 | }
|
---|
1205 |
|
---|
1206 | public void setIndexOfMaxFreq(int[] indexOfMaxFreq) {
|
---|
1207 | this.indexOfMaxFreq = indexOfMaxFreq;
|
---|
1208 | }
|
---|
1209 |
|
---|
1210 | public int getNumOfValues() {
|
---|
1211 | return numOfValues;
|
---|
1212 | }
|
---|
1213 |
|
---|
1214 | public void setNumOfValues() {
|
---|
1215 | int num = 0;
|
---|
1216 | List<Issue> issues = utilitySpace.getDomain().getIssues();
|
---|
1217 | for (Issue issue : issues) {
|
---|
1218 | switch (issue.getType()) {
|
---|
1219 | case DISCRETE:
|
---|
1220 | IssueDiscrete discrete = (IssueDiscrete) issue;
|
---|
1221 | num += discrete.getNumberOfValues();
|
---|
1222 | break;
|
---|
1223 | case INTEGER:
|
---|
1224 | IssueInteger integer = (IssueInteger) issue;
|
---|
1225 | int distance = integer.getUpperBound()
|
---|
1226 | - integer.getLowerBound();
|
---|
1227 | num += (distance + 1);
|
---|
1228 | break;
|
---|
1229 | default:
|
---|
1230 | break;
|
---|
1231 | }
|
---|
1232 | }
|
---|
1233 | numOfValues = num;
|
---|
1234 | }
|
---|
1235 |
|
---|
1236 | private void initEvaluators() {
|
---|
1237 | try {
|
---|
1238 | Object[] issuesXML = ((SimpleElement) (utilitySpace.toXML()
|
---|
1239 | .getChildByTagName("objective")[0]))
|
---|
1240 | .getChildByTagName("issue").clone();
|
---|
1241 | Map<Objective, Evaluator> map = new LinkedHashMap<>();
|
---|
1242 | for (int i = 0; i < numOfIssues; i++) {
|
---|
1243 | Issue issue = utilitySpace.getDomain().getIssues().get(i);
|
---|
1244 | switch (issue.getType()) {
|
---|
1245 | case DISCRETE:
|
---|
1246 | List<ValueDiscrete> values = ((IssueDiscrete) utilitySpace
|
---|
1247 | .getDomain().getIssues().get(i)).getValues();
|
---|
1248 | EvaluatorDiscrete ed = new EvaluatorDiscrete();
|
---|
1249 | ed.loadFromXML((SimpleElement) issuesXML[i]);
|
---|
1250 | ed.setWeight(weights[i]);
|
---|
1251 | for (ValueDiscrete item : values) {
|
---|
1252 | ed.addEvaluation(item, 1);
|
---|
1253 | }
|
---|
1254 | map.put(issue, ed);
|
---|
1255 | break;
|
---|
1256 | case INTEGER:
|
---|
1257 | EvaluatorInteger et = new EvaluatorInteger();
|
---|
1258 | et.loadFromXML((SimpleElement) issuesXML[i]);
|
---|
1259 | et.setWeight(weights[i]);
|
---|
1260 | et.setLinearFunction(0.0, 1.0);
|
---|
1261 | map.put(issue, et);
|
---|
1262 | break;
|
---|
1263 | default:
|
---|
1264 | System.err.println(
|
---|
1265 | "Unsuported issue type " + issue.getType());
|
---|
1266 | break;
|
---|
1267 | }
|
---|
1268 | setEvaluators((map.entrySet()));
|
---|
1269 | }
|
---|
1270 | } catch (Exception e) {
|
---|
1271 | // TODO Auto-generated catch block
|
---|
1272 | e.printStackTrace();
|
---|
1273 | }
|
---|
1274 | }
|
---|
1275 |
|
---|
1276 | public void loadEvaluatorFromMyPrefer() {
|
---|
1277 | try {
|
---|
1278 | Object[] issuesXML = ((SimpleElement) (utilitySpace.toXML()
|
---|
1279 | .getChildByTagName("objective")[0]))
|
---|
1280 | .getChildByTagName("issue").clone();
|
---|
1281 | Object[] weightXML = ((SimpleElement) (utilitySpace.toXML()
|
---|
1282 | .getChildByTagName("objective")[0]))
|
---|
1283 | .getChildByTagName("weight");
|
---|
1284 | Map<Objective, Evaluator> map = new LinkedHashMap<>();
|
---|
1285 | for (int i = 0; i < numOfIssues; i++) {
|
---|
1286 | Issue issue = utilitySpace.getDomain().getIssues().get(i);
|
---|
1287 | switch (issue.getType()) {
|
---|
1288 | case DISCRETE:
|
---|
1289 | EvaluatorDiscrete ed = new EvaluatorDiscrete();
|
---|
1290 | ed.loadFromXML((SimpleElement) issuesXML[i]);
|
---|
1291 | ed.setWeight(Double
|
---|
1292 | .parseDouble(((SimpleElement) weightXML[i])
|
---|
1293 | .getAttribute("value")));
|
---|
1294 | map.put(issue, ed);
|
---|
1295 | break;
|
---|
1296 | case INTEGER:
|
---|
1297 | EvaluatorInteger et = new EvaluatorInteger();
|
---|
1298 | et.loadFromXML((SimpleElement) issuesXML[i]);
|
---|
1299 | et.setWeight(Double
|
---|
1300 | .parseDouble(((SimpleElement) weightXML[i])
|
---|
1301 | .getAttribute("value")));
|
---|
1302 | map.put(issue, et);
|
---|
1303 | break;
|
---|
1304 | default:
|
---|
1305 | System.err.println(
|
---|
1306 | "Unsuported issue type " + issue.getType());
|
---|
1307 | break;
|
---|
1308 | }
|
---|
1309 | setEvaluators((map.entrySet()));
|
---|
1310 | }
|
---|
1311 | } catch (Exception e) {
|
---|
1312 | // TODO Auto-generated catch block
|
---|
1313 | e.printStackTrace();
|
---|
1314 | }
|
---|
1315 | }
|
---|
1316 |
|
---|
1317 | public void updateEvaluators(Bid bid, int learnRate) {
|
---|
1318 | HashMap<Integer, Value> values = bid.getValues();
|
---|
1319 | List<Issue> issues = bid.getIssues();
|
---|
1320 | int i = 0;
|
---|
1321 | for (Entry<Objective, Evaluator> evaluator : evaluators) {
|
---|
1322 | evaluator.getValue().setWeight(weights[i]);
|
---|
1323 | try {
|
---|
1324 | Value value = values.get(i + 1);
|
---|
1325 | Issue issue = issues.get(i);
|
---|
1326 | for (int j = 0; j < numOfIssues; j++) {
|
---|
1327 | if (evaluator.getKey().toString()
|
---|
1328 | .equals(issues.get(j).toString())) {
|
---|
1329 | value = values.get(j + 1);
|
---|
1330 | issue = issues.get(j);
|
---|
1331 | break;
|
---|
1332 | }
|
---|
1333 | }
|
---|
1334 | switch (value.getType()) {
|
---|
1335 | case DISCRETE:
|
---|
1336 | ValueDiscrete valueDiscrete = (ValueDiscrete) values
|
---|
1337 | .get(i + 1);
|
---|
1338 | int old = ((EvaluatorDiscrete) evaluator.getValue())
|
---|
1339 | .getEvaluationNotNormalized(valueDiscrete);
|
---|
1340 | ((EvaluatorDiscrete) evaluator.getValue())
|
---|
1341 | .setEvaluation(value, old + learnRate);
|
---|
1342 | break;
|
---|
1343 | case INTEGER:
|
---|
1344 | EvaluatorInteger ei = ((EvaluatorInteger) evaluator
|
---|
1345 | .getValue());
|
---|
1346 | if (ei.weightLocked()) {
|
---|
1347 | continue;
|
---|
1348 | }
|
---|
1349 | IssueInteger issueInteger = (IssueInteger) issue;
|
---|
1350 | ValueInteger valueInteger = (ValueInteger) value;
|
---|
1351 | int iValue = valueInteger.getValue();
|
---|
1352 | int distanceToUpper = Math
|
---|
1353 | .abs(issueInteger.getUpperBound() - iValue);
|
---|
1354 | int distanceToLower = Math
|
---|
1355 | .abs(issueInteger.getLowerBound() - iValue);
|
---|
1356 | if (distanceToUpper < distanceToLower) {
|
---|
1357 | ei.setLinearFunction(0.0, 1.0);
|
---|
1358 | } else {
|
---|
1359 | ei.setLinearFunction(1.0, 0.0);
|
---|
1360 | }
|
---|
1361 | ei.lockWeight();
|
---|
1362 | break;
|
---|
1363 | default:
|
---|
1364 | break;
|
---|
1365 | }
|
---|
1366 |
|
---|
1367 | } catch (Exception e) {
|
---|
1368 | // TODO Auto-generated catch block
|
---|
1369 | e.printStackTrace();
|
---|
1370 | }
|
---|
1371 | i++;
|
---|
1372 | }
|
---|
1373 |
|
---|
1374 | }
|
---|
1375 |
|
---|
1376 | private void initWeights() {
|
---|
1377 | for (int i = 0; i < weights.length; i++) {
|
---|
1378 | weights[i] = 1D / numOfIssues;
|
---|
1379 | }
|
---|
1380 | }
|
---|
1381 |
|
---|
1382 | public void updateEvaluators(Bid bid) {
|
---|
1383 | boolean hasUpadated = false;
|
---|
1384 | HashMap<Integer, Value> values = bid.getValues();
|
---|
1385 | List<Issue> issues = bid.getIssues();
|
---|
1386 | int i = 0;
|
---|
1387 | for (Entry<Objective, Evaluator> evaluator : evaluators) {
|
---|
1388 | try {
|
---|
1389 | Value value = values.get(i + 1);
|
---|
1390 | Issue issue = issues.get(i);
|
---|
1391 | for (int j = 0; j < numOfIssues; j++) {
|
---|
1392 | if (evaluator.getKey().toString()
|
---|
1393 | .equals(issues.get(j).toString())) {
|
---|
1394 | value = values.get(j + 1);
|
---|
1395 | issue = issues.get(j);
|
---|
1396 | break;
|
---|
1397 | }
|
---|
1398 | }
|
---|
1399 | switch (value.getType()) {
|
---|
1400 | case DISCRETE:
|
---|
1401 | ValueDiscrete valueDiscrete = (ValueDiscrete) values
|
---|
1402 | .get(i + 1);
|
---|
1403 | int old = ((EvaluatorDiscrete) evaluator.getValue())
|
---|
1404 | .getEvaluationNotNormalized(valueDiscrete);
|
---|
1405 | ((EvaluatorDiscrete) evaluator.getValue())
|
---|
1406 | .setEvaluation(value, old + 1);
|
---|
1407 | hasUpadated = true;
|
---|
1408 | break;
|
---|
1409 | case INTEGER:
|
---|
1410 | EvaluatorInteger ei = ((EvaluatorInteger) evaluator
|
---|
1411 | .getValue());
|
---|
1412 | if (ei.weightLocked()) {
|
---|
1413 | continue;
|
---|
1414 | }
|
---|
1415 | IssueInteger issueInteger = (IssueInteger) issue;
|
---|
1416 | ValueInteger valueInteger = (ValueInteger) value;
|
---|
1417 | int iValue = valueInteger.getValue();
|
---|
1418 | int distanceToUpper = Math
|
---|
1419 | .abs(issueInteger.getUpperBound() - iValue);
|
---|
1420 | int distanceToLower = Math
|
---|
1421 | .abs(issueInteger.getLowerBound() - iValue);
|
---|
1422 | if (distanceToUpper < distanceToLower) {
|
---|
1423 | ei.setLinearFunction(0.0, 1.0);
|
---|
1424 | } else {
|
---|
1425 | ei.setLinearFunction(1.0, 0.0);
|
---|
1426 | }
|
---|
1427 | hasUpadated = true;
|
---|
1428 | ei.lockWeight();
|
---|
1429 | break;
|
---|
1430 | default:
|
---|
1431 | break;
|
---|
1432 | }
|
---|
1433 | } catch (Exception e) {
|
---|
1434 | // TODO Auto-generated catch block
|
---|
1435 | e.printStackTrace();
|
---|
1436 | }
|
---|
1437 | i++;
|
---|
1438 | }
|
---|
1439 | if (hasUpadated) {
|
---|
1440 | learnRate--;
|
---|
1441 | }
|
---|
1442 | }
|
---|
1443 |
|
---|
1444 | public double getUtil(Bid bid) {
|
---|
1445 | double util = 0D;
|
---|
1446 | Map<Integer, Value> values = bid.getValues();
|
---|
1447 | int issueNr = 1;
|
---|
1448 | for (Entry<Objective, Evaluator> evaluator : evaluators) {
|
---|
1449 | try {
|
---|
1450 | Value value = values.get(issueNr);
|
---|
1451 | double weight = evaluator.getValue().getWeight();
|
---|
1452 | double valueEvaluation = 0.0;
|
---|
1453 | switch (value.getType()) {
|
---|
1454 | case DISCRETE:
|
---|
1455 | EvaluatorDiscrete dEvaluator = (EvaluatorDiscrete) evaluator
|
---|
1456 | .getValue();
|
---|
1457 | valueEvaluation = dEvaluator
|
---|
1458 | .getEvaluation((ValueDiscrete) value);
|
---|
1459 | util += weight * valueEvaluation;
|
---|
1460 | break;
|
---|
1461 | case INTEGER:
|
---|
1462 | EvaluatorInteger iEvaluator = (EvaluatorInteger) evaluator
|
---|
1463 | .getValue();
|
---|
1464 | valueEvaluation = iEvaluator.getEvaluation(
|
---|
1465 | Integer.parseInt(value.toString()));
|
---|
1466 | util += weight * valueEvaluation;
|
---|
1467 | break;
|
---|
1468 | default:
|
---|
1469 | break;
|
---|
1470 | }
|
---|
1471 | } catch (Exception e) {
|
---|
1472 | // TODO Auto-generated catch block
|
---|
1473 | e.printStackTrace();
|
---|
1474 | }
|
---|
1475 | issueNr++;
|
---|
1476 | }
|
---|
1477 | return util;
|
---|
1478 | }
|
---|
1479 |
|
---|
1480 | public double getValueEvaluation(int issueNr, Value value) {
|
---|
1481 | double evaluation = 0.0;
|
---|
1482 | int i = 1;
|
---|
1483 | for (Entry<Objective, Evaluator> evaluator : evaluators) {
|
---|
1484 | if (i != issueNr) {
|
---|
1485 | i++;
|
---|
1486 | continue;
|
---|
1487 | } else {
|
---|
1488 | switch (value.getType()) {
|
---|
1489 | case DISCRETE:
|
---|
1490 | ValueDiscrete dValue = (ValueDiscrete) value;
|
---|
1491 | EvaluatorDiscrete dEvaluator = (EvaluatorDiscrete) evaluator
|
---|
1492 | .getValue();
|
---|
1493 | try {
|
---|
1494 | evaluation = dEvaluator.getWeight()
|
---|
1495 | * dEvaluator.getEvaluation(dValue);
|
---|
1496 | } catch (Exception e) {
|
---|
1497 | // TODO Auto-generated catch block
|
---|
1498 | e.printStackTrace();
|
---|
1499 | }
|
---|
1500 | break;
|
---|
1501 | case INTEGER:
|
---|
1502 | ValueInteger vInteger = (ValueInteger) value;
|
---|
1503 | EvaluatorInteger iEvaluator = (EvaluatorInteger) evaluator
|
---|
1504 | .getValue();
|
---|
1505 | evaluation = iEvaluator.getWeight()
|
---|
1506 | * iEvaluator.getEvaluation(vInteger.getValue());
|
---|
1507 | break;
|
---|
1508 | default:
|
---|
1509 | System.err.println(
|
---|
1510 | "Unsupported value type: " + value.getType());
|
---|
1511 | break;
|
---|
1512 | }
|
---|
1513 | i++;
|
---|
1514 | }
|
---|
1515 | }
|
---|
1516 | return evaluation;
|
---|
1517 | }
|
---|
1518 | }
|
---|
1519 | } |
---|