source: src/main/java/parties/in4010/q12015/group15/AcceptanceStrategy.java@ 127

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

Initial import : Genius 9.0.0

File size: 3.6 KB
Line 
1package parties.in4010.q12015.group15;
2
3import genius.core.Bid;
4import genius.core.boaframework.Actions;
5import genius.core.timeline.TimeLineInfo;
6import genius.core.timeline.Timeline;
7import genius.core.utility.AdditiveUtilitySpace;
8
9/**
10 * Accepts only bids with high utility early in negotiation but lowers the
11 * standard with time. If it's the last round or very little time is left the
12 * agent will accept any offer.
13 *
14 */
15public class AcceptanceStrategy {
16 private AdditiveUtilitySpace utilitySpace;
17
18 public AcceptanceStrategy(AdditiveUtilitySpace utilitySpace) {
19 this.utilitySpace = utilitySpace;
20 }
21
22 /**
23 * @param bid
24 * from opponent
25 * @param time
26 * of bid received
27 * @return action Accept if bid is good enough, Reject if it's not
28 */
29 public Actions determineAcceptability(Bid bid, TimeLineInfo timeLine,
30 double roundTime) {
31 System.out.println("---- AS ----");
32
33 // First check if time is running out
34 Actions action;
35 if (timeLine.getType().equals(Timeline.Type.Rounds)) {
36 action = acceptIfLastRound(timeLine);
37 } else {
38 action = acceptIfLittleTimeIsLeft(timeLine, roundTime);
39 }
40 if (action != null) {
41 return action;
42 }
43
44 // If we have enough time we evaluate the bid according to our strategy
45 double timeLeft = 1 - timeLine.getTime();
46 try {
47 double utility = utilitySpace.getUtility(bid);
48 System.out.println("AS received bid: " + bid);
49 System.out.println("AS util: " + utility);
50 System.out.println("AS time left: " + timeLeft);
51 if ((timeLeft > 0.9 && timeLeft < 1.0 && utility > 0.95)
52 || (timeLeft > 0.7 && timeLeft < 0.9 && utility > 0.90)
53 || (timeLeft > 0.5 && timeLeft < 0.7 && utility > 0.85)
54 || (timeLeft > 0.3 && timeLeft < 0.5 && utility > 0.80)
55 || (timeLeft > 0.1 && timeLeft < 0.3 && utility > 0.75)
56 || (timeLeft < 0.1 && utility > 0.70)) {
57 System.out.println("AS Good enough utility");
58 System.out.println("AS action: " + Actions.Accept);
59 return Actions.Accept;
60 }
61 } catch (Exception e) {
62 System.out.println("AS Could not decide response to bid");
63 e.printStackTrace();
64 }
65
66 System.out.println("AS action: " + Actions.Reject);
67 return Actions.Reject;
68 }
69
70 /**
71 * @param timeLine
72 * @return Accept if it's the last round
73 */
74 public Actions acceptIfLastRound(TimeLineInfo timeLine) {
75 double totalRounds = timeLine.getTotalTime() - 1;
76 double roundsLeft = totalRounds - timeLine.getCurrentTime();
77
78 System.out.println("Total rounds: " + totalRounds);
79 System.out.println("Current round: " + timeLine.getCurrentTime());
80 System.out.println("Rounds left: " + roundsLeft);
81
82 if (roundsLeft == 0) {
83 System.out.println("AS Last round");
84 System.out.println("AS action: " + Actions.Accept);
85 return Actions.Accept;
86 }
87
88 return null;
89 }
90
91 /**
92 * @param timeLine
93 * @param roundTime
94 * @return Accept if there is very little time left. We evaluate
95 * "little time" as 2 times the average time a round takes.
96 */
97 public Actions acceptIfLittleTimeIsLeft(TimeLineInfo timeLine,
98 double roundTime) {
99 double totalSeconds = timeLine.getTotalTime();
100 double secondsLeft = totalSeconds - timeLine.getCurrentTime();
101
102 System.out.println("Total Seconds: " + totalSeconds);
103 System.out.println("Current seconds passed: "
104 + timeLine.getCurrentTime());
105 System.out.println("Seconds left: " + secondsLeft);
106
107 double timeLimit = 2 * roundTime;
108 System.out.println("timeLimit: " + timeLimit);
109 if (secondsLeft <= timeLimit) {
110 System.out.println("AS Last seconds");
111 System.out.println("AS action: " + Actions.Accept);
112 return Actions.Accept;
113 }
114
115 return null;
116 }
117}
Note: See TracBrowser for help on using the repository browser.