source: src/main/java/agents/anac/y2016/yxagent/YXAgent.java@ 345

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

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 25.3 KB
Line 
1package agents.anac.y2016.yxagent;
2
3import java.util.List;
4
5import java.util.ArrayList;
6import java.util.HashMap;
7import java.util.Random;
8
9import genius.core.AgentID;
10import genius.core.Bid;
11import genius.core.actions.Accept;
12import genius.core.actions.Action;
13import genius.core.actions.EndNegotiation;
14import genius.core.actions.Offer;
15import genius.core.issue.Issue;
16import genius.core.issue.IssueDiscrete;
17import genius.core.issue.IssueInteger;
18import genius.core.issue.IssueReal;
19import genius.core.issue.Value;
20import genius.core.issue.ValueDiscrete;
21import genius.core.issue.ValueInteger;
22import genius.core.issue.ValueReal;
23import genius.core.parties.AbstractNegotiationParty;
24import genius.core.parties.NegotiationInfo;
25import genius.core.utility.AdditiveUtilitySpace;
26import genius.core.utility.UtilitySpace;
27
28public class YXAgent extends AbstractNegotiationParty {
29 private UtilitySpace utilitySpace;
30 private AdditiveUtilitySpace additiveUtilitySpace;
31 private List<Issue> issues;
32 private Action myAction = null;
33 private Bid myLastBid = null;
34 private Bid lastOpponentBid = null;
35 private double myUtility = 0.;
36 private double oppUtility = 0.;
37 private double rv;
38 private double discountFactor;
39 private int rounds;
40 private boolean updatedValueIntegerWeight;
41 private boolean issueContainIntegerType;
42 private boolean searchedDiscountWithRV;
43
44 private ArrayList<Object> opponents;
45 private ArrayList<Bid> allBids;
46 private HashMap<Object, ArrayList<Bid>> oppBidHistory;
47 private HashMap<Object, HashMap<Issue, Double>> oppIssueWeight;
48 private HashMap<Object, HashMap<Issue, ArrayList<ValueInteger>>> oppIssueIntegerValue;
49 private HashMap<Object, HashMap<Issue, HashMap<Value, Double>>> oppValueFrequency;
50 private HashMap<Object, Double> oppSumDiff;
51 private Object hardestOpp;
52
53 private long startTime;
54 private long currTime;
55 private long diff;
56 private double totalTime;
57 private long normalizedTime;
58
59 @Override
60 public void init(NegotiationInfo info) {
61 super.init(info);
62 this.utilitySpace = getUtilitySpace();
63 this.rv = utilitySpace.getReservationValue();
64 discountFactor = getUtilitySpace().getDiscountFactor();
65 issues = utilitySpace.getDomain().getIssues();
66 allBids = new ArrayList<Bid>();
67 opponents = new ArrayList<Object>();
68 oppBidHistory = new HashMap<Object, ArrayList<Bid>>();
69 oppIssueWeight = new HashMap<Object, HashMap<Issue, Double>>();
70 oppIssueIntegerValue = new HashMap<Object, HashMap<Issue, ArrayList<ValueInteger>>>();
71 oppValueFrequency = new HashMap<Object, HashMap<Issue, HashMap<Value, Double>>>();
72 oppSumDiff = new HashMap<Object, Double>();
73 rounds = 0;
74 updatedValueIntegerWeight = false;
75 issueContainIntegerType = false;
76 searchedDiscountWithRV = false;
77 initTime();
78 issueContainIntegerType();
79 }
80
81 @Override
82 public void receiveMessage(AgentID sender, Action opponentAction) {
83 super.receiveMessage(sender, opponentAction);
84
85 // initialize below
86 if (sender != null) {// sender == null is for Inform messages
87 if (!opponents.contains(sender)) {
88 opponents.add(sender);
89 initOpp(sender);
90 }
91 }
92
93 if (sender != null && opponentAction != null) {
94 if (opponentAction instanceof Offer) {
95
96 lastOpponentBid = ((Offer) opponentAction).getBid();
97 oppUtility = utilitySpace.getUtility(lastOpponentBid);
98 allBids.add(lastOpponentBid);
99
100 updateOpp(sender);
101 }
102 }
103 }
104
105 @Override
106 public Action chooseAction(List<Class<? extends Action>> possibleActions) {
107 updateTime();
108 rounds++;
109 Bid testBid = null;
110 Value v;
111 double calUtil = 0;
112 double calThreshold;
113 double tempThreshold;
114 double minimalThreshold = 0.7;
115 double deductThreshold = 0.1;
116 double calculatedThreshold = 1 - (opponents.size() * deductThreshold);
117
118 tempThreshold = Math.max(minimalThreshold, calculatedThreshold);
119 tempThreshold = Math.max(tempThreshold, rv);
120
121 // YXAgent Start 1st
122 if (!possibleActions.contains(Accept.class)) {
123 do {
124 myLastBid = generateRandomBid();
125 myUtility = utilitySpace.getUtility(myLastBid);
126
127 } while (myUtility < minimalThreshold); // YXAgent starts 1st, so
128 // YXAgent cant use
129 // calculatedThreshold as
130 // opponents.size = 0
131 return myAction = new Offer(getPartyId(), myLastBid);
132 }
133
134 // YXAgent Start 2nd
135 if (!searchedDiscountWithRV && rounds > 1) {
136 if (evaluateDiscountFactorNReservationValue()) {
137 return new EndNegotiation(getPartyId());
138 }
139 }
140
141 do {
142 testBid = generateRandomBid();
143 myUtility = utilitySpace.getUtility(testBid);
144
145 } while (myUtility < tempThreshold);
146
147 // Acceptance Criteria
148 if (rounds > 10 && normalizedTime <= 0.9) {// Initialization of Value
149 // Integer is available
150 // after 11 rounds
151 for (Issue issue : issues) {
152 v = lastOpponentBid.getValue(issue.getNumber());
153 // Retrieve ToughestOpp issue weight and value weight
154 if (issue.getType().toString().equals("INTEGER")) {
155 for (Value vv : oppValueFrequency.get(hardestOpp).get(issue)
156 .keySet()) { // Usual
157 // way
158 // of
159 // key
160 // retrieval
161 // of
162 // Hashmap
163 // does
164 // not
165 // work
166 // for
167 // INTEGER
168 // type,
169 // thats
170 // why
171 // need
172 // to
173 // loop
174 // through
175 if (Integer.parseInt(vv.toString()) == Integer
176 .parseInt(v.toString())) {
177 calUtil += oppIssueWeight.get(hardestOpp).get(issue)
178 * oppValueFrequency.get(hardestOpp)
179 .get(issue).get(vv);
180 break;
181 }
182 }
183 } else {
184 calUtil += oppIssueWeight.get(hardestOpp).get(issue)
185 * oppValueFrequency.get(hardestOpp).get(issue)
186 .get(v);
187 }
188 }
189
190 try {
191 calThreshold = (calUtil
192 - ((opponents.size() * deductThreshold) * 3 / 4));
193 calThreshold = Math.max(tempThreshold, calThreshold);
194 myAction = oppUtility > calThreshold
195 ? new Accept(getPartyId(), lastOpponentBid)
196 : new Offer(getPartyId(), testBid);
197 } catch (Exception e) {
198 e.printStackTrace();
199 }
200 return myAction;
201 } else { // Run when rounds <= 10 or normalizedTime > 0.9
202 try {
203 myAction = oppUtility > tempThreshold
204 ? new Accept(getPartyId(), lastOpponentBid)
205 : new Offer(getPartyId(), testBid);
206 } catch (Exception e) {
207 e.printStackTrace();
208 }
209 return myAction;
210 }
211 }
212
213 // ---------------------------------------------------------------------------------------------------------//
214 // Check Discount Factor wrt Reservation Value
215 private boolean evaluateDiscountFactorNReservationValue() {
216 double init = 1.0;
217 double initRV1 = 0.75;
218 double initRV2 = 0.86;
219 double initRV3 = 0.95;
220 double selfDiscount = 0.998;
221 double deduction = 0.005;
222 boolean endNegotiation = false;
223
224 if (opponents.size() >= 3) { // Applicable for 3 or more opponent
225 // scenario
226 for (double i = init; i >= 0.; i -= 0.01) {
227 String df = String.format("%.2f", i);
228 double df1 = Double.parseDouble(df);
229 if (discountFactor == df1 && rv >= initRV1) {
230 endNegotiation = true;
231 }
232 initRV1 -= 0.005; // Every "i" decrement 0.01, RV -= 0.005
233 }
234 searchedDiscountWithRV = true;
235 }
236
237 if (opponents.size() == 2) { // Applicable for 2 opponent scenario only
238 for (double i = init; i >= 0.; i -= 0.01) {
239 String df = String.format("%.2f", i);
240 double df1 = Double.parseDouble(df);
241 if (discountFactor == df1 && rv >= initRV2) {
242 endNegotiation = true;
243 }
244 initRV2 -= 0.006; // Every "i" decrement 0.01, RV -= 0.006
245 }
246 searchedDiscountWithRV = true;
247 }
248
249 if (opponents.size() == 1) { // Applicable for 1 opponent scenario only
250 for (double i = init; i >= 0.; i -= 0.01) {
251 String df = String.format("%.2f", i);
252 double df1 = Double.parseDouble(df);
253 if (discountFactor == df1 && rv >= initRV3) {
254 endNegotiation = true;
255 }
256 initRV3 = (initRV3 - deduction) * selfDiscount; // Every "i"
257 // decrement
258 // 0.01, RV =
259 // (RV -
260 // deduction) *
261 // selfDiscount;
262 }
263 searchedDiscountWithRV = true;
264 }
265 return endNegotiation;
266 }
267
268 // ---------------------------------------------------------------------------------------------------------//
269 // Update Opponent
270 private void updateOpp(AgentID sender) {
271
272 if (rounds <= 10) {
273 updateValueIntegerWeight(sender);
274 }
275 updateModelOppIssueWeight(sender);
276 updateModelOppValueWeight(sender);
277 oppBidHistory.get(sender).add(lastOpponentBid);
278 retrieveToughestOpp();
279 // printableWeight();
280 // printableValue();
281 // printableIntegerIssue();
282 // printableToughest();
283 }
284
285 private void updateValueIntegerWeight(AgentID sender) {
286 for (Issue issue : issues) {
287 if (issue.getType().toString().equals("INTEGER")) {
288 ValueInteger currIssueValueInteger = (ValueInteger) lastOpponentBid
289 .getValue(issue.getNumber());
290 oppIssueIntegerValue.get(sender).get(issue)
291 .add(currIssueValueInteger);
292 }
293 }
294 if (rounds == 10 && !updatedValueIntegerWeight) { // rounds = [0, 10]
295 // meant 11 value
296 // points
297 int sumLower;
298 int sumUpper;
299 for (Object o1 : oppIssueIntegerValue.keySet()) {
300 for (Issue issue : issues) {
301 if (issue.getType().toString().equals("INTEGER")) {
302 sumLower = 0;
303 sumUpper = 0;
304 int lowerB = ((IssueInteger) issue).getLowerBound();
305 int upperB = ((IssueInteger) issue).getUpperBound();
306 int mid = (lowerB + upperB) / 2;
307 double average = 1. / (upperB - lowerB);
308 double adjustment;
309
310 // Loop to retrieve sum of points which lie on upper or
311 // lower range
312 for (int i = 0; i < oppIssueIntegerValue.get(o1)
313 .get(issue).size(); i++) {
314 int vv = Integer.parseInt(oppIssueIntegerValue
315 .get(o1).get(issue).get(i).toString());
316 if (vv <= mid) {
317 sumLower += 1;
318 } else {
319 sumUpper += 1;
320 }
321 }
322 ValueInteger vL = new ValueInteger(lowerB);
323 ValueInteger vU = new ValueInteger(upperB);
324
325 if (sumLower > sumUpper) {
326 oppValueFrequency.get(o1).get(issue).put(vL, 1.);
327 oppValueFrequency.get(o1).get(issue).put(vU, 0.);
328
329 adjustment = 1.;
330 // for loop assigning values between
331 // lowerbound(exclusive) and upperbound(exclusive)
332 for (int i = lowerB + 1; i < upperB; i++) {
333 adjustment -= average;
334 ValueInteger vI = new ValueInteger(i);
335 oppValueFrequency.get(o1).get(issue).put(vI,
336 adjustment);
337 }
338 } else {
339 oppValueFrequency.get(o1).get(issue).put(vU, 1.);
340 oppValueFrequency.get(o1).get(issue).put(vL, 0.);
341
342 adjustment = 0.;
343 // for loop assigning values between
344 // lowerbound(exclusive) and upperbound(exclusive)
345 for (int i = lowerB + 1; i < upperB; i++) {
346 adjustment += average;
347 ValueInteger vI = new ValueInteger(i);
348 oppValueFrequency.get(o1).get(issue).put(vI,
349 adjustment);
350 }
351 }
352 }
353 }
354 }
355 updatedValueIntegerWeight = true;
356 }
357 }
358
359 private void updateModelOppIssueWeight(AgentID sender) {
360 if (oppBidHistory.get(sender).size() != 0 && rounds >= 10) {
361 Bid previousRoundBid = oppBidHistory.get(sender)
362 .get(oppBidHistory.get(sender).size() - 1);// -1
363 // since
364 // current
365 // lastOpponentBid
366 // not
367 // added
368 // yet
369 double issueWeightFormula = (Math.pow((1 - normalizedTime), 10))
370 / (issues.size() * 100);
371 double issueWeightInteger = (Math.pow((1 - normalizedTime), 10))
372 / (issues.size() * 10);
373 double issueSum = 0.;
374 double normalizedIssueW;
375
376 for (Issue issue : issues) {
377 Value prevIssueValue = previousRoundBid
378 .getValue(issue.getNumber());
379 Value currIssueValue = lastOpponentBid
380 .getValue(issue.getNumber());
381
382 if (issueContainIntegerType) { // For Discrete & Integer Mix
383 // Domain
384 if (issue.getType().toString().equals("INTEGER")) { // Integer
385 // Handling
386 if (incrementIntegerIssueWeight(issue, prevIssueValue,
387 currIssueValue)) {
388 oppIssueWeight.get(sender).put(issue,
389 oppIssueWeight.get(sender).get(issue)
390 + issueWeightInteger);
391 }
392 } else {// Discrete Handling
393 if (prevIssueValue == currIssueValue) {
394 oppIssueWeight.get(sender).put(issue,
395 oppIssueWeight.get(sender).get(issue)
396 + issueWeightInteger);
397 }
398 }
399 } else { // For Discrete Only Domain
400 if (prevIssueValue == currIssueValue) {
401 oppIssueWeight.get(sender).put(issue,
402 oppIssueWeight.get(sender).get(issue)
403 + issueWeightFormula);
404 }
405 }
406 issueSum += oppIssueWeight.get(sender).get(issue);
407 }
408
409 // After Sum computed, Normalized Issue Weight
410 for (Issue issue : issues) {
411 normalizedIssueW = oppIssueWeight.get(sender).get(issue)
412 / issueSum;
413 oppIssueWeight.get(sender).put(issue, normalizedIssueW);
414 }
415 }
416 }
417
418 public boolean incrementIntegerIssueWeight(Issue issue,
419 Value prevIssueValue, Value currIssueValue) {
420 double[] arraySlot = new double[5];
421 boolean sameSection = false;
422 double increment;// Store
423 int pastV = Integer.parseInt(prevIssueValue.toString()); // past bid
424 // value
425 int currV = Integer.parseInt(currIssueValue.toString()); // current bid
426 // value
427 int lowerB = ((IssueInteger) issue).getLowerBound();
428 int upperB = ((IssueInteger) issue).getUpperBound();
429 double formula = (upperB - lowerB + 1) / 5;
430
431 increment = lowerB + formula;
432
433 for (int i = 0; i < 4; i++) {
434 arraySlot[i] = increment;
435 increment += formula;
436 }
437 arraySlot[4] = upperB;
438
439 if (pastV <= arraySlot[0] && currV <= arraySlot[0]) {
440 sameSection = true;
441 } else if (pastV <= arraySlot[1] && currV <= arraySlot[1]
442 && pastV > arraySlot[0] && currV > arraySlot[0]) {
443 sameSection = true;
444 } else if (pastV <= arraySlot[2] && currV <= arraySlot[2]
445 && pastV > arraySlot[1] && currV > arraySlot[1]) {
446 sameSection = true;
447 } else if (pastV <= arraySlot[3] && currV <= arraySlot[3]
448 && pastV > arraySlot[2] && currV > arraySlot[2]) {
449 sameSection = true;
450 } else if (pastV <= arraySlot[4] && currV <= arraySlot[4]
451 && pastV > arraySlot[3] && currV > arraySlot[3]) {
452 sameSection = true;
453 }
454 return sameSection;
455 }
456
457 private void updateModelOppValueWeight(AgentID sender) {
458 double maxValueBase;
459 double currValueBase;
460 double normalizedValue;
461 double valueWeightFormula = Math.pow(0.2, normalizedTime) / 30000;
462 double valueWeightInteger = Math.pow(0.2, normalizedTime) / 955;
463 // (Normal Rounds avg - 11000 rounds, Integer issue type round avg - 350
464 // rounds)
465
466 for (Issue issue : issues) {
467 if (issueContainIntegerType) { // For Discrete & Integer Mix Domain
468 if (!issue.getType().toString().equals("INTEGER")) {
469 Value value = lastOpponentBid.getValue(issue.getNumber());
470 oppValueFrequency.get(sender).get(issue).put(value,
471 oppValueFrequency.get(sender).get(issue).get(value)
472 + valueWeightInteger);
473 }
474
475 } else { // For Discrete Only Domain
476 Value value = lastOpponentBid.getValue(issue.getNumber());
477 oppValueFrequency.get(sender).get(issue).put(value,
478 oppValueFrequency.get(sender).get(issue).get(value)
479 + valueWeightFormula);
480 }
481 }
482
483 // Normalization of Value Weight
484 for (Issue issue : issues) {
485 if (!issue.getType().toString().equals("INTEGER")) {
486 maxValueBase = 0;
487
488 // Compute Max Value for specific issue
489 for (Value v : oppValueFrequency.get(sender).get(issue)
490 .keySet()) {
491 currValueBase = oppValueFrequency.get(sender).get(issue)
492 .get(v);
493 if (currValueBase > maxValueBase) {
494 maxValueBase = currValueBase;
495 }
496 }
497
498 // After Max Value computed, Normalized Value Weight
499 for (Value v : oppValueFrequency.get(sender).get(issue)
500 .keySet()) {
501 normalizedValue = oppValueFrequency.get(sender).get(issue)
502 .get(v) / maxValueBase;
503 oppValueFrequency.get(sender).get(issue).put(v,
504 normalizedValue);
505 }
506 }
507 }
508 }
509
510 private void retrieveToughestOpp() {
511 double sumDiff;
512 double maxDiff;
513 double diff;
514 double hardestOppSumDiff = 0.;
515
516 // Compute SumDiff of each opponent using value weight
517 for (Object o : oppValueFrequency.keySet()) {
518 sumDiff = 0;
519 for (Issue issue : issues) {
520 maxDiff = 0;
521 for (Value v : oppValueFrequency.get(o).get(issue).keySet()) {
522 if (!issue.getType().toString().equals("INTEGER")) { // Exclusive
523 // of
524 // Integer
525 // Type
526 // Issues
527 diff = 1 - oppValueFrequency.get(o).get(issue).get(v);
528 if (diff > maxDiff) {
529 maxDiff = diff;
530 }
531 }
532 }
533 sumDiff += maxDiff;
534 }
535 oppSumDiff.put(o, sumDiff); // Store opponent with sumDiff
536 }
537
538 // Retrieve Toughest Opponent
539 for (Object o : oppSumDiff.keySet()) {
540 if (oppSumDiff.get(o) > hardestOppSumDiff) {
541 hardestOppSumDiff = oppSumDiff.get(o);
542 hardestOpp = o; // Update hardest opponent
543 }
544 }
545 }
546
547 /*
548 * private void printableWeight(){ PrintWriter aout = null; try { aout = new
549 * PrintWriter(new FileWriter("negotiationWeight")); } catch (IOException
550 * e1) { e1.printStackTrace(); }
551 *
552 * StringBuilder rez;
553 *
554 * for (Object a1 : oppIssueWeight.keySet()){ rez = new StringBuilder() ;
555 * rez.append(a1); rez.append("|"); rez.append(oppIssueWeight.get(a1));
556 * rez.append("|"); rez.append("\n"); aout.println(rez.toString()); }
557 *
558 * rez = new StringBuilder(); rez.append("\n");
559 * rez.append("Number of rounds: " + rounds); aout.println(rez.toString());
560 * aout.close(); }
561 *
562 * private void printableValue(){ PrintWriter aout = null; try { aout = new
563 * PrintWriter(new FileWriter("negotiationValue")); } catch (IOException e1)
564 * { e1.printStackTrace(); }
565 *
566 * StringBuilder rez;
567 *
568 * for (Object a1 : oppValueFrequency.keySet()){ rez = new StringBuilder();
569 * rez.append(a1); rez.append("|"); rez.append(oppValueFrequency.get(a1));
570 * rez.append("|"); rez.append("\n"); aout.println(rez.toString()); }
571 *
572 * rez = new StringBuilder(); rez.append("\n");
573 * rez.append("Number of rounds: " + rounds); aout.println(rez.toString());
574 * aout.close(); }
575 *
576 * private void printableIntegerIssue(){ PrintWriter aout = null; try { aout
577 * = new PrintWriter(new FileWriter("negotiationIntegerIssue")); } catch
578 * (IOException e1) { e1.printStackTrace(); }
579 *
580 * StringBuilder rez;
581 *
582 * for (Object a1 : oppIssueIntegerValue.keySet()){ rez = new
583 * StringBuilder(); rez.append(a1); rez.append("|");
584 * rez.append(oppIssueIntegerValue.get(a1)); rez.append("|");
585 * rez.append("\n"); aout.println(rez.toString()); } aout.close(); }
586 *
587 * private void printableToughest(){ PrintWriter aout = null; try { aout =
588 * new PrintWriter(new FileWriter("negotiationHardestOpp")); } catch
589 * (IOException e1) { e1.printStackTrace(); }
590 *
591 * StringBuilder rez;
592 *
593 * for (Object a1 : oppSumDiff.keySet()){ rez = new StringBuilder();
594 * rez.append(a1); rez.append("|"); rez.append(oppSumDiff.get(a1));
595 * rez.append("|"); rez.append("\n"); aout.println(rez.toString()); } rez =
596 * new StringBuilder(); rez.append("\n"); rez.append("Toughest Opp is: " +
597 * hardestOpp); aout.println(rez.toString());
598 *
599 * rez = new StringBuilder(); rez.append("\n");
600 * rez.append("Number of rounds: " + rounds); aout.println(rez.toString());
601 * aout.close(); }
602 */
603
604 // ---------------------------------------------------------------------------------------------------------//
605 // Initialize Opponent
606 private void initOpp(AgentID sender) {// Initialize new Agent and Issues
607 try {
608 issueIntegerHandler(sender);
609 initModelOppIssueWeight(sender);
610 initModelOppValueFrequency(sender);
611 oppBidHistory.put(sender, new ArrayList<Bid>());
612 } catch (Exception e) {
613 e.printStackTrace();
614 }
615 }
616
617 private void issueIntegerHandler(AgentID sender) {
618 oppIssueIntegerValue.put(sender,
619 new HashMap<Issue, ArrayList<ValueInteger>>());
620 for (Issue issue : issues) {
621 if (issue.getType().toString().equals("INTEGER")) {
622 oppIssueIntegerValue.get(sender).put(issue,
623 new ArrayList<ValueInteger>());
624 }
625 }
626 }
627
628 private void initModelOppIssueWeight(AgentID sender) {
629 int numIssues;
630 double avgW;
631 oppIssueWeight.put(sender, new HashMap<Issue, Double>());
632 for (Issue issue : issues) {
633 oppIssueWeight.get(sender).put(issue, 0.);
634 }
635
636 numIssues = oppIssueWeight.get(sender).keySet().size();
637 avgW = (double) 1 / numIssues;
638 for (Issue i : oppIssueWeight.get(sender).keySet()) {
639 oppIssueWeight.get(sender).put(i, avgW);
640 }
641 }
642
643 private void initModelOppValueFrequency(AgentID sender) {
644 ArrayList<Value> values = new ArrayList<Value>();
645 oppValueFrequency.put(sender,
646 new HashMap<Issue, HashMap<Value, Double>>());
647 for (Issue issue : issues) {
648 oppValueFrequency.get(sender).put(issue,
649 new HashMap<Value, Double>());
650 if (!issue.getType().toString().equals("INTEGER")) {
651 values = getValues(issue);
652 for (Value value : values) {
653 oppValueFrequency.get(sender).get(issue).put(value, 1.);
654 }
655 }
656 }
657 }
658
659 public ArrayList<Value> getValues(Issue issue) {
660 ArrayList<Value> values = new ArrayList<Value>();
661 switch (issue.getType()) {
662 case DISCRETE:
663 List<ValueDiscrete> valuesDis = ((IssueDiscrete) issue).getValues();
664 for (Value value : valuesDis) {
665 values.add(value);
666 }
667 break;
668 case INTEGER:
669 int min_value = ((IssueInteger) issue).getLowerBound();
670 int max_value = ((IssueInteger) issue).getUpperBound();
671 for (int i = min_value; i <= max_value; i++) {
672 Object valueObject = new Integer(i);
673 values.add((Value) valueObject);
674 }
675 break;
676 case REAL:
677 double min_value1 = ((IssueReal) issue).getLowerBound();
678 double max_value1 = ((IssueReal) issue).getUpperBound();
679 for (int i = (int) min_value1; i <= max_value1; i++) {
680 Object valueObject = new Integer(i);
681 values.add((Value) valueObject);
682 }
683 break;
684 default:
685 try {
686 throw new Exception("issue type: " + issue.getType());
687 } catch (Exception e) {
688 e.printStackTrace();
689 }
690 }
691 return values;
692 }
693
694 // ---------------------------------------------------------------------------------------------------------//
695 // Check for Integer Type in Issue
696 private void issueContainIntegerType() {
697 for (Issue issue : issues) {
698 if (issue.getType().toString().equals("INTEGER")) {
699 issueContainIntegerType = true;
700 break;
701 }
702 }
703 }
704
705 // ---------------------------------------------------------------------------------------------------------//
706 // Initialize and Update Time
707 private void updateTime() {
708 currTime = System.currentTimeMillis();
709 diff = currTime - startTime;
710 normalizedTime = (long) (diff / totalTime);
711 }
712
713 private void initTime() {
714 startTime = System.currentTimeMillis();
715 totalTime = 3 * 60 * 1000; // 3min total time converted to millsecond
716 diff = 0;
717 }
718
719 // ---------------------------------------------------------------------------------------------------------//
720 // Generate Random Bid
721 @Override
722 protected Bid generateRandomBid() {
723 Bid randomBid = null;
724 HashMap<Integer, Value> values = new HashMap<Integer, Value>();
725 List<Issue> issues = utilitySpace.getDomain().getIssues();
726 for (Issue currentIssue : issues) {
727 try {
728 values.put(currentIssue.getNumber(),
729 getRandomValue(currentIssue));
730 } catch (Exception e) {
731 e.printStackTrace();
732 }
733 }
734 try {
735 randomBid = new Bid(utilitySpace.getDomain(), values);
736 } catch (Exception e) {
737 e.printStackTrace();
738 }
739 return randomBid;
740 }
741
742 @Override
743 protected Value getRandomValue(Issue currentIssue) throws Exception {
744 Value currentValue = null;
745 int index = 0;
746
747 Random randomnr = new Random();
748 switch (currentIssue.getType()) {
749 case DISCRETE:
750 IssueDiscrete lIssueDiscrete = (IssueDiscrete) currentIssue;
751 index = randomnr.nextInt(lIssueDiscrete.getNumberOfValues());
752 currentValue = lIssueDiscrete.getValue(index);
753 break;
754 case REAL:
755 IssueReal lIssueReal = (IssueReal) currentIssue;
756 index = randomnr
757 .nextInt(lIssueReal.getNumberOfDiscretizationSteps());
758 currentValue = new ValueReal(
759 lIssueReal.getLowerBound() + (((lIssueReal.getUpperBound()
760 - lIssueReal.getLowerBound()))
761 / (lIssueReal.getNumberOfDiscretizationSteps()))
762 * index);
763 break;
764 case INTEGER:
765 IssueInteger lIssueInteger = (IssueInteger) currentIssue;
766 index = randomnr.nextInt(lIssueInteger.getUpperBound()
767 - lIssueInteger.getLowerBound() + 1);
768 currentValue = new ValueInteger(
769 lIssueInteger.getLowerBound() + index);
770 break;
771 default:
772 throw new Exception(
773 "issue type " + currentIssue.getType() + " not supported");
774 }
775 return currentValue;
776 }
777
778 /**
779 * @return the agentID
780 */
781 public String getName() {
782 return "YXAgent";
783 }
784
785 @Override
786 public String getDescription() {
787 return "ANAC2016";
788 }
789
790}
Note: See TracBrowser for help on using the repository browser.