1 | package agents.anac.y2017.parsagent3;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import java.util.HashMap;
|
---|
7 | import java.util.Map;
|
---|
8 | import java.util.Random;
|
---|
9 | import java.util.Set;
|
---|
10 |
|
---|
11 | import negotiator.parties.AbstractTimeDependentNegotiationParty;
|
---|
12 |
|
---|
13 | import genius.core.AgentID;
|
---|
14 | import genius.core.Bid;
|
---|
15 | import genius.core.actions.Accept;
|
---|
16 | import genius.core.actions.Action;
|
---|
17 | import genius.core.actions.EndNegotiation;
|
---|
18 | import genius.core.actions.Offer;
|
---|
19 | import genius.core.boaframework.SortedOutcomeSpace;
|
---|
20 | import genius.core.issue.Issue;
|
---|
21 | import genius.core.issue.IssueDiscrete;
|
---|
22 | import genius.core.list.Tuple;
|
---|
23 | import genius.core.parties.NegotiationInfo;
|
---|
24 | import genius.core.persistent.PersistentDataType;
|
---|
25 | import genius.core.persistent.StandardInfo;
|
---|
26 | import genius.core.persistent.StandardInfoList;
|
---|
27 | import genius.core.timeline.DiscreteTimeline;
|
---|
28 |
|
---|
29 | public class ShahAgent extends AbstractTimeDependentNegotiationParty {
|
---|
30 | Bid lastBid;
|
---|
31 | Bid myLastBid;
|
---|
32 | Bid myBestBid;
|
---|
33 | Bid lastReceivedBid;
|
---|
34 | String oppAName;
|
---|
35 | String oppBName;
|
---|
36 | private StandardInfoList history;
|
---|
37 | boolean fornullAgent = false;
|
---|
38 | int round;
|
---|
39 | Integer TimePeriod;
|
---|
40 | ArrayList<Bid> oppABids = new ArrayList<Bid>();
|
---|
41 | ArrayList<Bid> oppBBids = new ArrayList<Bid>();
|
---|
42 | ArrayList<Cluster> clusterA;
|
---|
43 | ArrayList<Cluster> clusterB;
|
---|
44 | ClusterHistory clusterHistoryA;
|
---|
45 | ClusterHistory clusterHistoryB;
|
---|
46 | int numberOfclusters = 20;
|
---|
47 | int slotNum = 100;
|
---|
48 | double myConcessionRate = 0.15d;
|
---|
49 | double ConstantUtility = 1.0d;
|
---|
50 | float myReservation = 0.8f;
|
---|
51 | int currentSlotA;
|
---|
52 | int currentSlotB;
|
---|
53 | boolean clusterIsRefreshA;
|
---|
54 | boolean clusterIsRefreshB;
|
---|
55 | float concessionA;
|
---|
56 | float sumConcessionA;
|
---|
57 | float sumConcessionB;
|
---|
58 | int concessionNumber;
|
---|
59 | // ArrayList<Float> concessionAHis;
|
---|
60 | // ArrayList<Float> concessionBHis;
|
---|
61 | float concessionB;
|
---|
62 | ArrayList<Bid> centsA = new ArrayList<Bid>();
|
---|
63 | ArrayList<Bid> centsB = new ArrayList<Bid>();
|
---|
64 | private double rValue;
|
---|
65 | private double dFactor;
|
---|
66 | SortedOutcomeSpace outcomeSpace;
|
---|
67 | float minLimit = 0.85f;
|
---|
68 | boolean conceed = true;
|
---|
69 |
|
---|
70 | public ShahAgent() {
|
---|
71 | fornullAgent = false;
|
---|
72 | }
|
---|
73 |
|
---|
74 | public void clusterOpponentBidWithoutFirstLevel(ArrayList<Bid> newCenters,
|
---|
75 | ArrayList<Bid> bidHistory, String opParty, boolean repeat) {
|
---|
76 |
|
---|
77 | int k = numberOfclusters;
|
---|
78 | ArrayList<Cluster> clusters;
|
---|
79 | if (opParty.equals("A"))
|
---|
80 | clusters = clusterA;
|
---|
81 | else
|
---|
82 | clusters = clusterB;
|
---|
83 | if (!repeat) {
|
---|
84 |
|
---|
85 | if (opParty.equals("A"))
|
---|
86 | clusterA = clusters;
|
---|
87 | else
|
---|
88 | clusterB = clusters;
|
---|
89 | }
|
---|
90 | for (int i = 0; i < newCenters.size(); ++i)
|
---|
91 | defineCluster(clusters, newCenters.get(i));
|
---|
92 | if (refreshClusterCenters(clusters)) {
|
---|
93 |
|
---|
94 | for (int i = 0; i < clusters.size(); ++i) {
|
---|
95 | clusters.get(i).getMembers().clear();
|
---|
96 |
|
---|
97 | }
|
---|
98 | clusterOpponentBid(bidHistory, opParty, true);
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | public void clusterOpponentBid(ArrayList<Bid> bidHistory, String opParty,
|
---|
103 | boolean repeat) {
|
---|
104 |
|
---|
105 | int k = numberOfclusters;
|
---|
106 | ArrayList<Cluster> clusters;
|
---|
107 | if (opParty.equals("A"))
|
---|
108 | clusters = clusterA;
|
---|
109 | else
|
---|
110 | clusters = clusterB;
|
---|
111 | if (bidHistory.size() > k) {
|
---|
112 | if (!repeat) {
|
---|
113 | if (clusters == null) {
|
---|
114 | clusters = new ArrayList<Cluster>(k);
|
---|
115 | for (int i = 0; i < k; ++i) {
|
---|
116 | clusters.add(new Cluster());
|
---|
117 | }
|
---|
118 | }
|
---|
119 | if (opParty.equals("A"))
|
---|
120 | clusterA = clusters;
|
---|
121 | else
|
---|
122 | clusterB = clusters;
|
---|
123 |
|
---|
124 | int next = bidHistory.size() / k;
|
---|
125 | int temp = 0;
|
---|
126 | for (int i = 0; i < k; ++i) {
|
---|
127 | clusters.get(i).setCenter(bidHistory.get(temp));
|
---|
128 | temp += next;
|
---|
129 | }
|
---|
130 | for (int i = 0; i < clusters.size(); ++i) {
|
---|
131 | if (clusters.get(i).getMembers() != null)
|
---|
132 | clusters.get(i).getMembers().clear();
|
---|
133 | }
|
---|
134 | }
|
---|
135 | for (int i = 0; i < bidHistory.size(); ++i) {
|
---|
136 | defineCluster(clusters, bidHistory.get(i));
|
---|
137 | }
|
---|
138 | if (refreshClusterCenters(clusters)) {
|
---|
139 |
|
---|
140 | for (int i = 0; i < clusters.size(); ++i) {
|
---|
141 | clusters.get(i).getMembers().clear();
|
---|
142 | }
|
---|
143 | clusterOpponentBid(bidHistory, opParty, true);
|
---|
144 | }
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | public boolean refreshClusterCenters(ArrayList<Cluster> clusters) {
|
---|
149 | // ArrayList<Issue> dissues = utilitySpace.getDomain().getIssues();
|
---|
150 | boolean needRefresh = false;
|
---|
151 | for (int i = 0; i < clusters.size(); ++i) {
|
---|
152 | Cluster clus = clusters.get(i);
|
---|
153 | clus.getMembers().add(0, clus.getCenter());
|
---|
154 | float[] dist = new float[clus.getMembers().size()];
|
---|
155 | float[][] dismatrix = new float[clus.getMembers().size()][clus
|
---|
156 | .getMembers().size()];
|
---|
157 | for (int j = 0; j < clus.getMembers().size(); ++j) {
|
---|
158 | Bid checkBid = clus.getMembers().get(j);
|
---|
159 | float distance = 0;
|
---|
160 | for (int k = 0; k < j; ++k) {
|
---|
161 | distance += dismatrix[k][j];
|
---|
162 | }
|
---|
163 | for (int k = j + 1; k < clus.getMembers().size(); ++k) {
|
---|
164 | // if (k != j) {
|
---|
165 | float temp = calDist(checkBid, clus.getMembers().get(k));
|
---|
166 | distance += temp;
|
---|
167 | dismatrix[j][k] = temp;
|
---|
168 |
|
---|
169 | }
|
---|
170 | dist[j] = distance / clus.getMembers().size();
|
---|
171 | distance = 0f;
|
---|
172 | }
|
---|
173 | float min = dist[0];
|
---|
174 | String out = dist[0] + "";
|
---|
175 |
|
---|
176 | int index = 0;
|
---|
177 | for (int n = 1; n < dist.length; ++n) {
|
---|
178 | // out += " " + dist[n];
|
---|
179 |
|
---|
180 | if (dist[n] < min) {
|
---|
181 | min = dist[n];
|
---|
182 | index = n;
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | if (index != 0) {
|
---|
187 | needRefresh = true;
|
---|
188 | }
|
---|
189 |
|
---|
190 | clus.setCenter(clus.getMembers().get(index));
|
---|
191 | clus.getMembers().remove(index);
|
---|
192 |
|
---|
193 | }
|
---|
194 | return needRefresh;
|
---|
195 | }
|
---|
196 |
|
---|
197 | public void defineCluster(ArrayList<Cluster> clusters, Bid bid) {
|
---|
198 |
|
---|
199 | float[] dises = new float[clusters.size()];
|
---|
200 | for (int i = 0; i < clusters.size(); ++i) {
|
---|
201 | dises[i] = calDist(bid, clusters.get(i).getCenter());
|
---|
202 | if (clusters.get(i).members == null)
|
---|
203 | clusters.get(i).members = new ArrayList<Bid>();
|
---|
204 | }
|
---|
205 | float min = dises[0];
|
---|
206 | int index = 0;
|
---|
207 | for (int j = 0; j < dises.length; ++j) {
|
---|
208 | if (dises[j] < min) {
|
---|
209 | min = dises[j];
|
---|
210 | index = j;
|
---|
211 | }
|
---|
212 | }
|
---|
213 |
|
---|
214 | clusters.get(index).members.add(bid);
|
---|
215 |
|
---|
216 | }
|
---|
217 |
|
---|
218 | @Override
|
---|
219 | public String getDescription() {
|
---|
220 | return "ANAC2017";
|
---|
221 | }
|
---|
222 |
|
---|
223 | class ClusterHistory {
|
---|
224 | ArrayList<ArrayList<Bid>> prevCenters;
|
---|
225 | ArrayList<Float> maxDistance;
|
---|
226 | ArrayList<Float> distributionFactor;
|
---|
227 | ArrayList<Integer> submitTime;
|
---|
228 | }
|
---|
229 |
|
---|
230 | class Cluster {
|
---|
231 | Bid center;
|
---|
232 | ArrayList<Bid> members;
|
---|
233 |
|
---|
234 | public void setCenter(Bid center) {
|
---|
235 | this.center = center;
|
---|
236 | }
|
---|
237 |
|
---|
238 | public Bid getCenter() {
|
---|
239 | return center;
|
---|
240 | }
|
---|
241 |
|
---|
242 | public void setMembers(ArrayList<Bid> members) {
|
---|
243 | this.members = members;
|
---|
244 | }
|
---|
245 |
|
---|
246 | public ArrayList<Bid> getMembers() {
|
---|
247 | return members;
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|
251 | @Override
|
---|
252 | public void init(NegotiationInfo info) {
|
---|
253 | super.init(info);
|
---|
254 | rValue = utilitySpace.getReservationValue().doubleValue();
|
---|
255 | dFactor = utilitySpace.getDiscountFactor();
|
---|
256 | outcomeSpace = new SortedOutcomeSpace(getUtilitySpace());
|
---|
257 |
|
---|
258 | if (getData().getPersistentDataType() != PersistentDataType.STANDARD) {
|
---|
259 | throw new IllegalStateException("need standard persistent data");
|
---|
260 | }
|
---|
261 | history = (StandardInfoList) getData().get();
|
---|
262 |
|
---|
263 | if (!history.isEmpty()) {
|
---|
264 | // System.out.println("sizeeee " + history.size());
|
---|
265 | Map<String, Double> maxutils = new HashMap<String, Double>();
|
---|
266 | Map<String, Double> minutils = new HashMap<String, Double>();
|
---|
267 | StandardInfo lastinfo = history.get(history.size() - 1);
|
---|
268 | int i = 0;
|
---|
269 | for (Tuple<String, Double> offered : lastinfo.getUtilities()) {
|
---|
270 | ++i;
|
---|
271 | String party = offered.get1().indexOf("@") != -1 ? offered
|
---|
272 | .get1().substring(0, offered.get1().indexOf("@"))
|
---|
273 | : offered.get1();
|
---|
274 | Double util = offered.get2();
|
---|
275 | maxutils.put(party, maxutils.containsKey(party)
|
---|
276 | ? Math.max(maxutils.get(party), util) : util);
|
---|
277 | minutils.put(party, minutils.containsKey(party)
|
---|
278 | ? Math.min(minutils.get(party), util) : util);
|
---|
279 | }
|
---|
280 | Set keys = maxutils.keySet();
|
---|
281 | double conceedA = 0;
|
---|
282 | double conceedB = 0;
|
---|
283 | for (Object partyK : keys) {
|
---|
284 | if (((String) partyK).indexOf("ShahAgent") == -1) {
|
---|
285 | if (conceedA == 0) {
|
---|
286 | conceedA = maxutils.get(partyK) - minutils.get(partyK);
|
---|
287 | } else
|
---|
288 | conceedB = maxutils.get(partyK) - minutils.get(partyK);
|
---|
289 | }
|
---|
290 |
|
---|
291 | }
|
---|
292 | if (conceedA < 0.3 || conceedB < 0.3)
|
---|
293 | conceed = false; // for choosing policy of conceesion
|
---|
294 |
|
---|
295 | if (conceedA > 0.8 && conceedB > 0.8) {
|
---|
296 | minLimit = 0.7f;
|
---|
297 | }
|
---|
298 | if (conceedA > 0.6 && conceedB > 0.6) {
|
---|
299 | minLimit = 0.8f;
|
---|
300 | }
|
---|
301 | }
|
---|
302 |
|
---|
303 | }
|
---|
304 |
|
---|
305 | public boolean isLastSecond() {
|
---|
306 | double time = timeline.getTime();
|
---|
307 | double second = time * 3.0 * 60.0;
|
---|
308 | if (second >= (3.0 * 60 - 1.0))
|
---|
309 | return true;
|
---|
310 | return false;
|
---|
311 | }
|
---|
312 |
|
---|
313 | public boolean isLastTime() {
|
---|
314 | double time = timeline.getTime();
|
---|
315 | double second = time * 3.0 * 60.0;
|
---|
316 | if (second >= (3.0 * 60 - 1.0) + 0.8)
|
---|
317 | return true;
|
---|
318 | return false;
|
---|
319 | }
|
---|
320 |
|
---|
321 | @Override
|
---|
322 | public Action chooseAction(List validActions) {
|
---|
323 |
|
---|
324 | if (round == 100)
|
---|
325 | round = 0;
|
---|
326 | ++round;
|
---|
327 | double time = timeline.getTime();
|
---|
328 | if (selectEndNegotiation(time) && utilitySpace
|
---|
329 | .getUtility(lastBid) < rValue * Math.pow(dFactor, time)) {
|
---|
330 | return new EndNegotiation(getPartyId());
|
---|
331 |
|
---|
332 | }
|
---|
333 | if (lastBid != null
|
---|
334 | && utilitySpace.getUtility(lastBid) >= getMyutility()) {
|
---|
335 | return new Accept(getPartyId(), lastReceivedBid);
|
---|
336 | // } else if (isLastSecond() &&
|
---|
337 | // (lastBid != null && utilitySpace.getUtility(lastBid) >=
|
---|
338 | // (getMyutility() - 0.1))) {
|
---|
339 | // return new Accept(getPartyId(),lastReceivedBid);
|
---|
340 | } else if (isLastTime() && (lastBid != null && utilitySpace
|
---|
341 | .getUtility(lastBid) >= (getMyutility() - 0.05))) {
|
---|
342 | return new Accept(getPartyId(), lastReceivedBid);
|
---|
343 | } else { // propose a new bid
|
---|
344 | Bid newBid;
|
---|
345 |
|
---|
346 | try {
|
---|
347 | double random;
|
---|
348 | double temp = getLowerBound();
|
---|
349 | if (temp < minLimit)
|
---|
350 | temp = minLimit;
|
---|
351 |
|
---|
352 | do {
|
---|
353 | random = new Random().nextDouble();
|
---|
354 | } while (random <= temp);
|
---|
355 | newBid = outcomeSpace.getBidNearUtility(random).getBid();
|
---|
356 |
|
---|
357 | } catch (Exception e) {
|
---|
358 | newBid = outcomeSpace.getBidNearUtility(0.9).getBid();
|
---|
359 | }
|
---|
360 | myLastBid = newBid;
|
---|
361 | lastBid = myLastBid;
|
---|
362 | return new Offer(getPartyId(), newBid);
|
---|
363 | }
|
---|
364 |
|
---|
365 | }
|
---|
366 |
|
---|
367 | public double getLowerBound() {
|
---|
368 | double offset = (timeline instanceof DiscreteTimeline)
|
---|
369 | ? 1.0D / ((DiscreteTimeline) timeline).getTotalRounds() : 0.0D;
|
---|
370 | if (conceed)
|
---|
371 | minLimit = myReservation;
|
---|
372 | return (minLimit
|
---|
373 | + ((0.9f - minLimit) * (1 - myF(timeline.getTime() - offset))));
|
---|
374 | }
|
---|
375 |
|
---|
376 | /**
|
---|
377 | * All offers proposed by the other parties will be received as a message.
|
---|
378 | * You can use this information to your advantage, for example to predict
|
---|
379 | * their utility.
|
---|
380 | *
|
---|
381 | * @param sender
|
---|
382 | * The party that did the action.
|
---|
383 | * @param action
|
---|
384 | * The action that party did.
|
---|
385 | */
|
---|
386 | @Override
|
---|
387 | public void receiveMessage(AgentID sender, Action action) {
|
---|
388 | super.receiveMessage(sender, action);
|
---|
389 | String agentName = sender != null ? sender.toString() : "null";
|
---|
390 | fornullAgent = !fornullAgent;
|
---|
391 | if (action != null && action instanceof Offer) {
|
---|
392 | Bid newBid = ((Offer) action).getBid();
|
---|
393 | lastReceivedBid = ((Offer) action).getBid();
|
---|
394 | try {
|
---|
395 | if (oppAName != null && oppAName.equals(agentName)) {
|
---|
396 | addBidToList(oppABids, newBid);
|
---|
397 | currentSlotA++;
|
---|
398 |
|
---|
399 | } else if (oppBName != null && oppBName.equals(agentName)) {
|
---|
400 | addBidToList(oppBBids, newBid);
|
---|
401 | currentSlotB++;
|
---|
402 |
|
---|
403 | } else if (oppAName == null) {
|
---|
404 | oppAName = agentName;
|
---|
405 | } else if (oppBName == null) {
|
---|
406 | oppBName = agentName;
|
---|
407 | }
|
---|
408 |
|
---|
409 | lastBid = newBid;
|
---|
410 | } catch (Exception e) {
|
---|
411 | // System.out.println("Exception 33 " + e.getMessage());
|
---|
412 | }
|
---|
413 | } else if (action != null && action instanceof Accept) {
|
---|
414 | Bid newBid = lastBid;
|
---|
415 | if (oppAName != null && oppAName.equals(agentName)) {
|
---|
416 | addBidToList(oppABids, newBid);
|
---|
417 | currentSlotA++;
|
---|
418 |
|
---|
419 | } else if (oppBName != null && oppBName.equals(agentName)) {
|
---|
420 | addBidToList(oppBBids, newBid);
|
---|
421 | currentSlotB++;
|
---|
422 |
|
---|
423 | } else if (oppAName == null) {
|
---|
424 | oppAName = agentName;
|
---|
425 | } else if (oppBName == null) {
|
---|
426 | oppBName = agentName;
|
---|
427 | }
|
---|
428 | }
|
---|
429 | if (round == slotNum && oppAName != null
|
---|
430 | && oppAName.equals(agentName)) {
|
---|
431 |
|
---|
432 | clusterOpponentBid(oppABids, "A", false);
|
---|
433 | clusterIsRefreshA = true;
|
---|
434 | TimePeriod = new Integer(
|
---|
435 | (new Double(timeline.getCurrentTime() / 60)).intValue()
|
---|
436 | + 1);
|
---|
437 |
|
---|
438 | }
|
---|
439 | if (round == slotNum && oppBName != null
|
---|
440 | && oppBName.equals(agentName)) {
|
---|
441 |
|
---|
442 | clusterOpponentBid(oppBBids, "B", false);
|
---|
443 |
|
---|
444 | clusterIsRefreshB = true;
|
---|
445 | TimePeriod = new Integer(
|
---|
446 | (new Double(timeline.getCurrentTime() / 60)).intValue()
|
---|
447 | + 1);
|
---|
448 | }
|
---|
449 |
|
---|
450 | // Here you can listen to other parties' messages
|
---|
451 | }
|
---|
452 |
|
---|
453 | public void addBidToList(ArrayList<Bid> mybids, Bid newbid) {
|
---|
454 | mybids.add(newbid);
|
---|
455 | }
|
---|
456 |
|
---|
457 | public float calDist(Bid b1, Bid b2) {
|
---|
458 | List<Issue> dissues = utilitySpace.getDomain().getIssues();
|
---|
459 | float distance = 0;
|
---|
460 | Set<Integer> keys = b1.getValues().keySet();
|
---|
461 | Object[] keyCenterVals = b2.getValues().keySet().toArray();
|
---|
462 | Object[] keyVals = keys.toArray();
|
---|
463 | for (int j = 0; j < dissues.size(); ++j) {
|
---|
464 |
|
---|
465 | if (dissues.get(j) instanceof IssueDiscrete) {
|
---|
466 |
|
---|
467 | if (!b1.getValues().get(keyVals[j]).toString().equals(
|
---|
468 | b2.getValues().get(keyCenterVals[j]).toString())) {
|
---|
469 | distance += 1;
|
---|
470 | }
|
---|
471 | } else {
|
---|
472 | float dis = ((Float
|
---|
473 | .parseFloat(b1.getValues().get(keyVals[j]).toString()))
|
---|
474 | - (Float.parseFloat(b2.getValues().get(keyCenterVals[j])
|
---|
475 | .toString())) / dissues.get(j).getChildCount());
|
---|
476 | distance += dis < 0 ? dis * -1f : dis;
|
---|
477 | }
|
---|
478 | }
|
---|
479 |
|
---|
480 | return distance;
|
---|
481 | }
|
---|
482 |
|
---|
483 | public double getMyTargetUtility(float pmin) {
|
---|
484 |
|
---|
485 | double offset = (timeline instanceof DiscreteTimeline)
|
---|
486 | ? 1.0D / ((DiscreteTimeline) timeline).getTotalRounds() : 0.0D;
|
---|
487 | return (pmin + ((1.0f - pmin) * (1 - myF(timeline.getTime() - offset))))
|
---|
488 | * Math.pow(dFactor, timeline.getTime());
|
---|
489 | }
|
---|
490 |
|
---|
491 | public double myF(double t) {
|
---|
492 | if (getE() == 0.0D)
|
---|
493 | return 0.0D;
|
---|
494 | else
|
---|
495 | return Math.pow(t, 1.0D / getE());
|
---|
496 | }
|
---|
497 |
|
---|
498 | public double getMyutility() {
|
---|
499 | int clusterHistoryASize = 0;
|
---|
500 | int clusterHistoryBSize = 0;
|
---|
501 | float w1 = 0.4f, w2 = 0.2f, w3 = 0.4f;
|
---|
502 | if (clusterIsRefreshA && clusterA != null) {
|
---|
503 | ArrayList<Bid> centersA = new ArrayList<Bid>();
|
---|
504 | float[][] distA = new float[numberOfclusters][numberOfclusters];
|
---|
505 | float unormalA = 0;
|
---|
506 | float normal = 1.0f / numberOfclusters;
|
---|
507 | for (int i = 0; i < clusterA.size(); ++i) {
|
---|
508 | if (clusterA.get(i).getMembers().size() != 0)
|
---|
509 | centersA.add(clusterA.get(i).getCenter());
|
---|
510 |
|
---|
511 | float temp = normal
|
---|
512 | - ((float) clusterA.get(i).getMembers().size())
|
---|
513 | / (float) oppABids.size();
|
---|
514 | unormalA += temp < 0 ? -1 * temp : temp;
|
---|
515 | }
|
---|
516 |
|
---|
517 | float maxA = 0;
|
---|
518 |
|
---|
519 | for (int i = 0; i < numberOfclusters && i < centersA.size(); ++i) {
|
---|
520 | for (int j = i + 1; j < numberOfclusters
|
---|
521 | && j < centersA.size(); ++j) {
|
---|
522 | distA[i][j] = calDist(centersA.get(i), centersA.get(j));
|
---|
523 | if (distA[i][j] > maxA)
|
---|
524 | maxA = distA[i][j];
|
---|
525 |
|
---|
526 | }
|
---|
527 | }
|
---|
528 | if (clusterHistoryA == null) {
|
---|
529 | clusterHistoryA = new ClusterHistory();
|
---|
530 | clusterHistoryA.distributionFactor = new ArrayList<Float>();
|
---|
531 | clusterHistoryA.submitTime = new ArrayList<Integer>();
|
---|
532 | clusterHistoryA.prevCenters = new ArrayList<ArrayList<Bid>>();
|
---|
533 | clusterHistoryA.maxDistance = new ArrayList<Float>();
|
---|
534 | }
|
---|
535 |
|
---|
536 | clusterHistoryA.distributionFactor.add(
|
---|
537 | clusterHistoryA.distributionFactor.size(),
|
---|
538 | new Float(unormalA));
|
---|
539 | clusterHistoryA.maxDistance.add(clusterHistoryA.maxDistance.size(),
|
---|
540 | new Float(maxA));
|
---|
541 | clusterHistoryA.prevCenters.add(clusterHistoryA.prevCenters.size(),
|
---|
542 | new ArrayList<Bid>(centersA));
|
---|
543 | clusterHistoryA.submitTime.add(clusterHistoryA.submitTime.size(),
|
---|
544 | TimePeriod);
|
---|
545 | clusterHistoryASize = clusterHistoryA.distributionFactor.size() - 1;
|
---|
546 | for (int i = 0; i < clusterA.size(); ++i) {
|
---|
547 |
|
---|
548 | clusterA.get(i).getMembers().clear();
|
---|
549 | oppABids.clear();
|
---|
550 |
|
---|
551 | }
|
---|
552 |
|
---|
553 | }
|
---|
554 | if (clusterIsRefreshB && clusterB != null) {
|
---|
555 | ArrayList<Bid> centersB = new ArrayList<Bid>();
|
---|
556 |
|
---|
557 | float[][] distB = new float[numberOfclusters][numberOfclusters];
|
---|
558 |
|
---|
559 | float unormalB = 0;
|
---|
560 | float normal = 1.0f / numberOfclusters;
|
---|
561 |
|
---|
562 | for (int i = 0; i < clusterB.size(); ++i) {
|
---|
563 | if (clusterB.get(i).getMembers().size() != 0)
|
---|
564 | centersB.add(clusterB.get(i).getCenter());
|
---|
565 | float temp = normal
|
---|
566 | - ((float) clusterB.get(i).getMembers().size())
|
---|
567 | / (float) oppBBids.size();
|
---|
568 | unormalB += temp < 0 ? -1 * temp : temp;
|
---|
569 | }
|
---|
570 |
|
---|
571 | float maxB = 0;
|
---|
572 | for (int i = 0; i < numberOfclusters && i < centersB.size(); ++i) {
|
---|
573 | for (int j = i + 1; j < numberOfclusters
|
---|
574 | && j < centersB.size(); ++j) {
|
---|
575 | distB[i][j] = calDist(centersB.get(i), centersB.get(j));
|
---|
576 | if (distB[i][j] > maxB)
|
---|
577 | maxB = distB[i][j];
|
---|
578 | }
|
---|
579 | }
|
---|
580 |
|
---|
581 | if (clusterHistoryB == null) {
|
---|
582 | clusterHistoryB = new ClusterHistory();
|
---|
583 | clusterHistoryB.distributionFactor = new ArrayList<Float>();
|
---|
584 | clusterHistoryB.prevCenters = new ArrayList<ArrayList<Bid>>();
|
---|
585 | clusterHistoryB.maxDistance = new ArrayList<Float>();
|
---|
586 | clusterHistoryB.submitTime = new ArrayList<Integer>();
|
---|
587 | }
|
---|
588 | clusterHistoryB.distributionFactor.add(
|
---|
589 | clusterHistoryB.distributionFactor.size(),
|
---|
590 | new Float(unormalB));
|
---|
591 | clusterHistoryB.maxDistance.add(clusterHistoryB.maxDistance.size(),
|
---|
592 | new Float(maxB));
|
---|
593 | clusterHistoryB.prevCenters.add(clusterHistoryB.prevCenters.size(),
|
---|
594 | new ArrayList<Bid>(centersB));
|
---|
595 | clusterHistoryB.submitTime.add(clusterHistoryB.submitTime.size(),
|
---|
596 | TimePeriod);
|
---|
597 | clusterHistoryBSize = clusterHistoryB.distributionFactor.size() - 1;
|
---|
598 | for (int i = 0; i < clusterB.size(); ++i) {
|
---|
599 | clusterB.get(i).getMembers().clear();
|
---|
600 | oppBBids.clear();
|
---|
601 | }
|
---|
602 | }
|
---|
603 | if (clusterIsRefreshA && clusterA != null) {
|
---|
604 | clusterIsRefreshA = false;
|
---|
605 |
|
---|
606 | ArrayList<Bid> tempArr = new ArrayList<Bid>();
|
---|
607 | for (int j = 0; j < clusterHistoryA.prevCenters
|
---|
608 | .get(clusterHistoryASize).size(); ++j) {
|
---|
609 | centsA.add(clusterHistoryA.prevCenters.get(clusterHistoryASize)
|
---|
610 | .get(j));
|
---|
611 | tempArr.add(clusterHistoryA.prevCenters.get(clusterHistoryASize)
|
---|
612 | .get(j));
|
---|
613 | }
|
---|
614 |
|
---|
615 | clusterOpponentBidWithoutFirstLevel(tempArr, centsA, "A", false);
|
---|
616 | float unormalA = 0;
|
---|
617 |
|
---|
618 | float normal = 1.0f / numberOfclusters;
|
---|
619 | for (int i = 0; i < clusterA.size(); ++i) {
|
---|
620 |
|
---|
621 | float temp = normal
|
---|
622 | - ((float) clusterA.get(i).getMembers().size())
|
---|
623 | / (float) centsA.size();
|
---|
624 | unormalA += temp < 0 ? -1 * temp : temp;
|
---|
625 | }
|
---|
626 | float maxA = 0;
|
---|
627 | float[][] distA = new float[numberOfclusters][numberOfclusters];
|
---|
628 | for (int i = 0; i < numberOfclusters; ++i) {
|
---|
629 | for (int j = i + 1; j < numberOfclusters; ++j) {
|
---|
630 | distA[i][j] = calDist(clusterA.get(i).getCenter(),
|
---|
631 | clusterA.get(j).getCenter());
|
---|
632 | if (distA[i][j] > maxA)
|
---|
633 | maxA = distA[i][j];
|
---|
634 |
|
---|
635 | }
|
---|
636 | }
|
---|
637 | float meanDistributionA = 0f;
|
---|
638 | float maxCenterDistanceA = 0f;
|
---|
639 | int issueSize = utilitySpace.getDomain().getIssues().size();
|
---|
640 | maxCenterDistanceA = maxA / issueSize;
|
---|
641 | meanDistributionA = unormalA
|
---|
642 | / (1.0f + (numberOfclusters - 2) * normal);
|
---|
643 |
|
---|
644 | w1 = 0.6f;
|
---|
645 | w3 = 0.4f;
|
---|
646 | float ca = (w1 * maxCenterDistanceA - w3 * meanDistributionA);
|
---|
647 |
|
---|
648 | ca = ca < 0 ? 0 : ca;
|
---|
649 | concessionA = concessionA > ca ? concessionA : ca;
|
---|
650 | float temp;
|
---|
651 | if (conceed)
|
---|
652 | temp = (concessionA + concessionB) / 2.0f;
|
---|
653 | else
|
---|
654 | temp = concessionA > concessionB ? concessionB : concessionA;
|
---|
655 | myReservation = 1.0f - temp < myReservation ? 1.0f - temp
|
---|
656 | : myReservation; // for
|
---|
657 | // bilateral
|
---|
658 | myConcessionRate = temp > myConcessionRate ? temp
|
---|
659 | : myConcessionRate;
|
---|
660 | double tempConstant = getMyTargetUtility(myReservation);
|
---|
661 | if (tempConstant < ConstantUtility)
|
---|
662 | ConstantUtility = tempConstant;
|
---|
663 | for (int i = 0; i < clusterA.size(); ++i) {
|
---|
664 | clusterA.get(i).getMembers().clear();
|
---|
665 | }
|
---|
666 |
|
---|
667 | }
|
---|
668 | if (clusterIsRefreshB && clusterB != null) {
|
---|
669 | clusterIsRefreshB = false;
|
---|
670 | ArrayList<Bid> tempArr = new ArrayList<Bid>();
|
---|
671 | for (int j = 0; j < clusterHistoryB.prevCenters
|
---|
672 | .get(clusterHistoryBSize).size(); ++j) {
|
---|
673 | centsB.add(clusterHistoryB.prevCenters.get(clusterHistoryBSize)
|
---|
674 | .get(j));
|
---|
675 | tempArr.add(clusterHistoryB.prevCenters.get(clusterHistoryBSize)
|
---|
676 | .get(j));
|
---|
677 | }
|
---|
678 | clusterOpponentBidWithoutFirstLevel(tempArr, centsB, "B", false);
|
---|
679 | float unormalA = 0;
|
---|
680 |
|
---|
681 | float normal = 1.0f / numberOfclusters;
|
---|
682 | for (int i = 0; i < clusterB.size(); ++i) {
|
---|
683 |
|
---|
684 | float temp = normal
|
---|
685 | - ((float) clusterB.get(i).getMembers().size())
|
---|
686 | / (float) centsB.size();
|
---|
687 | unormalA += temp < 0 ? -1 * temp : temp;
|
---|
688 | }
|
---|
689 | float maxA = 0;
|
---|
690 | float[][] distA = new float[numberOfclusters][numberOfclusters];
|
---|
691 | for (int i = 0; i < numberOfclusters; ++i) {
|
---|
692 | for (int j = i + 1; j < numberOfclusters; ++j) {
|
---|
693 | distA[i][j] = calDist(clusterB.get(i).getCenter(),
|
---|
694 | clusterB.get(j).getCenter());
|
---|
695 | if (distA[i][j] > maxA)
|
---|
696 | maxA = distA[i][j];
|
---|
697 |
|
---|
698 | }
|
---|
699 | }
|
---|
700 | float meanDistributionB = 0f;
|
---|
701 | float maxCenterDistanceB = 0f;
|
---|
702 |
|
---|
703 | int issueSize = utilitySpace.getDomain().getIssues().size();
|
---|
704 | maxCenterDistanceB = maxA / issueSize;
|
---|
705 | meanDistributionB = unormalA
|
---|
706 | / (1.0f + (numberOfclusters - 2) * normal);
|
---|
707 | w1 = 0.6f;
|
---|
708 | w3 = 0.4f;
|
---|
709 | float cb = (w1 * maxCenterDistanceB - w3 * meanDistributionB);
|
---|
710 | cb = cb < 0 ? 0 : cb;
|
---|
711 | concessionB = concessionB > cb ? concessionB : cb;
|
---|
712 | float temp;
|
---|
713 | if (conceed)
|
---|
714 | temp = (concessionA + concessionB) / 2.0f;
|
---|
715 | else
|
---|
716 | temp = concessionA > concessionB ? concessionB : concessionA;
|
---|
717 | myReservation = 1.0f - temp < myReservation ? 1.0f - temp
|
---|
718 | : myReservation;
|
---|
719 | myConcessionRate = temp > myConcessionRate ? temp
|
---|
720 | : myConcessionRate;
|
---|
721 | double tempConstant = getMyTargetUtility(myReservation);
|
---|
722 | if (tempConstant < ConstantUtility)
|
---|
723 | ConstantUtility = tempConstant;
|
---|
724 | for (int i = 0; i < clusterB.size(); ++i) {
|
---|
725 | clusterB.get(i).getMembers().clear();
|
---|
726 | }
|
---|
727 |
|
---|
728 | }
|
---|
729 | return ConstantUtility;
|
---|
730 | }
|
---|
731 |
|
---|
732 | @Override
|
---|
733 | public double getE() {
|
---|
734 | return myConcessionRate;
|
---|
735 | }
|
---|
736 |
|
---|
737 | public boolean selectEndNegotiation(double time) {
|
---|
738 | return rValue * Math.pow(dFactor, time) >= getMyutility();
|
---|
739 | }
|
---|
740 |
|
---|
741 | }
|
---|