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