source: src/main/java/agents/anac/y2017/parsagent3/ShahAgent.java@ 1

Last change on this file since 1 was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

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