source: src/main/java/parties/in4010/q12015/group17/OfferStrat.java@ 126

Last change on this file since 126 was 126, checked in by Aron Hammond, 6 years ago

Added function to calculate opposition to MultiLateralAnalysis.java

Moved code to add RLBOA listeners to RLBOAUtils is misc package

Added input for strategyParameters to SessionPanel (gui)

!! close SessionInfo after tournament; this caused /tmp/ to fill up with GeniusData files

Our own package:

  • Added opponents and strategies that are mentioned in the report
  • Change class hierarchy, agents can now extend from RLBOAagentBilateral to inherit RL functionality.
  • States extend from AbstractState
File size: 4.7 KB
Line 
1package parties.in4010.q12015.group17;
2
3import java.util.HashMap;
4import java.util.Iterator;
5import java.util.List;
6
7import genius.core.Bid;
8import genius.core.bidding.BidDetails;
9import genius.core.boaframework.NegotiationSession;
10import genius.core.boaframework.OfferingStrategy;
11import genius.core.boaframework.SortedOutcomeSpace;
12import genius.core.misc.Range;
13
14public class OfferStrat extends OfferingStrategy {
15
16 /**
17 * This is the offer strategy class. Class variables.
18 */
19 private SortedOutcomeSpace sos;
20 private OpMod om;
21 private List<BidDetails> bidsList;
22 private Range bidRange = new Range(0.8, 1);
23 private int RECENT = 5;
24
25 /**
26 * Initialisation method for {@link NegotiationSession},
27 * {@link SortedOutcomeSpace}, {@link OpMod} and bidsList.
28 */
29 public void init(NegotiationSession negotiationSession, SortedOutcomeSpace sos, OpMod om) {
30 super.init(negotiationSession, new HashMap<String, Double>());
31 this.sos = sos;
32 this.om = om;
33 this.bidsList = sos.getBidsinRange(bidRange);
34 System.out.println("Offer strategy init has run!");
35 }
36
37 /**
38 * Determines bid for early negotiation, utility starts at one and decreases
39 * with a quadratic function.
40 *
41 * @param relativeTime
42 * between 0 and 0.2
43 * @return {@link BidDetails} near a specific utility
44 */
45 private BidDetails determineEarlyBid(double relativeTime) {
46 double utility = 1 - 2.5 * Math.pow(relativeTime, 2);
47 return sos.getBidNearUtility(utility);
48 }
49
50 /**
51 * Determines bids for mid negotiation.
52 *
53 * @return {@link BidDetails} with the highest group-based utility (within
54 * range of 0.8-1.0 for own utility)
55 * @throws Exception
56 */
57 private BidDetails determineMidBid() throws Exception {
58
59 // Reserve value for bestBid, if something goes wrong this makes sure no
60 // 'null' is returned at the end
61 Iterator<BidDetails> possibleBids = bidsList.iterator();
62 double utilBestBid = Double.MIN_VALUE;
63 BidDetails bestBid = sos.getMaxBidPossible();
64
65 while (possibleBids.hasNext()) {
66 BidDetails currentBid = possibleBids.next();
67
68 if (isRecentBid(currentBid, RECENT)) {
69 continue;
70 }
71
72 // Group utility of current bid
73 // The earlier it is the more important our own weight is
74 double utilCurrentBid = om.getGroupUtility(currentBid.getBid(),
75 5 - (negotiationSession.getTimeline().getTime() * 4));
76
77 if (utilCurrentBid > utilBestBid) {
78 utilBestBid = utilCurrentBid;
79 bestBid = currentBid;
80 }
81 }
82 return bestBid;
83 }
84
85 /**
86 * Determines bid for late negotiation.
87 *
88 * @return {@link BidDetails} with the highest group-based utility (within
89 * range of 0.7-1.0 for own utility)
90 * @throws Exception
91 */
92 private BidDetails determineLateBid(double lowerBound) throws Exception {
93 if (bidRange.getLowerbound() != lowerBound) {
94 bidRange.setLowerbound(lowerBound);
95 bidsList = sos.getBidsinRange(bidRange);
96 }
97 return determineMidBid();
98 }
99
100 /**
101 * Determines what decision method should be called depending on the current
102 * time.
103 *
104 * @returns {@link BidDetails} of the upcoming bid for our agent
105 */
106 @Override
107 public BidDetails determineNextBid() {
108 double relativeTime = negotiationSession.getTimeline().getTime();
109
110 if (relativeTime < 0.2) {
111 return determineEarlyBid(relativeTime);
112 }
113
114 else if (relativeTime >= 0.2 && relativeTime <= 0.9) {
115 try {
116 return determineMidBid();
117 } catch (Exception e) {
118 e.printStackTrace();
119 }
120
121 } else if (relativeTime >= 0.9 && relativeTime <= 0.95) {
122 try {
123 return determineLateBid(0.7);
124 } catch (Exception e) {
125 e.printStackTrace();
126 }
127 } else if (relativeTime > 0.95 && relativeTime < 0.985) {
128 try {
129 return determineLateBid(0.6);
130 } catch (Exception e) {
131 e.printStackTrace();
132 }
133 } else if (relativeTime >= 0.985) {
134 try {
135 return determineLateBid(0.55);
136 } catch (Exception e) {
137 e.printStackTrace();
138 }
139 }
140 return nextBid;
141 }
142
143 /**
144 * Checks if the provided {@link Bid} is the same as one of the X previously
145 * offered {@link Bid}s.
146 *
147 * @param bid
148 * is the provided {@link Bid}
149 * @param recent
150 * is the number of previously offered {@link Bid}s checked
151 * @return {@code TRUE} if this bid was recently offered, otherwise
152 * {@code FALSE}
153 */
154 private boolean isRecentBid(BidDetails bid, int recent) {
155 List<BidDetails> bidList = negotiationSession.getOwnBidHistory().getHistory();
156 for (int i = bidList.size() - 1; i >= bidList.size() - recent; i--) {
157 if (i >= 0 && bidList.get(i).getBid().equals(bid.getBid())) {
158 return true;
159 }
160 }
161 return false;
162 }
163
164 /**
165 * Unused silly method which is not needed
166 */
167 @Override
168 public BidDetails determineOpeningBid() {
169 return null;
170 }
171
172 @Override
173 public String getName() {
174 return "in4010 q12015 group17";
175 }
176}
Note: See TracBrowser for help on using the repository browser.