source: src/main/java/parties/in4010/q12015/group16/Group16.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: 5.2 KB
Line 
1package parties.in4010.q12015.group16;
2
3import java.util.List;
4
5import genius.core.AgentID;
6import genius.core.Bid;
7import genius.core.actions.Accept;
8import genius.core.actions.Action;
9import genius.core.actions.NoAction;
10import genius.core.actions.Offer;
11import genius.core.boaframework.SortedOutcomeSpace;
12import genius.core.parties.AbstractNegotiationParty;
13import genius.core.parties.NegotiationInfo;
14import genius.core.utility.AdditiveUtilitySpace;
15
16/**
17 * This is your negotiation party.
18 */
19public class Group16 extends AbstractNegotiationParty {
20 // Utility value below which no bids will be accepted
21 private double reservationValue = 0.7;
22 // Utility value of the worst bid we can make
23 private double bidLowerBound = 0.9;
24 // Utility value of the best bid we can make
25 private double bidUpperBound = 1.0;
26
27 // The general model
28 private GeneralModel GM;
29
30 // Index for all possible bids sorted by utility
31 private SortedOutcomeSpace outcomeSpace;
32
33 // The most recent action and offer received from an opponent, updated in
34 // receiveMessage
35 private Action lastReceivedAction = null;
36 private Bid lastReceivedOffer = null;
37
38 /**
39 * This is the first call made to a NegotiationParty after its
40 * instantiation. Tells which utility space and timeline we are running in.
41 * This is called one time only.
42 *
43 * @param utilSpace
44 * (a copy of/ read-only version of) the UtilitySpace to be used
45 * for this session.
46 * @param timeline
47 * the TimeLineInfo about current session.
48 * @param agentID
49 * the AgentID.
50 * @throws RuntimeException
51 * if init() fails.
52 */
53 @Override
54 public void init(NegotiationInfo info) {
55 super.init(info);
56
57 utilitySpace.setDiscount(0);
58 utilitySpace.setReservationValue(reservationValue);
59
60 try {
61 outcomeSpace = new SortedOutcomeSpace(utilitySpace);
62 } catch (Exception e) {
63 e.printStackTrace();
64 }
65
66 GM = new GeneralModel((AdditiveUtilitySpace) utilitySpace, outcomeSpace);
67 }
68
69 /**
70 * Each round this method gets called and ask you to accept or offer. The
71 * first party in the first round is a bit different, it can only propose an
72 * offer.
73 *
74 * @param validActions
75 * Either a list containing both accept and offer or only offer.
76 * @return The chosen action.
77 */
78 @Override
79 public Action chooseAction(List<Class<? extends Action>> validActions) {
80 Action action = new NoAction(getPartyId());
81
82 if (lastReceivedAction instanceof Offer || lastReceivedAction instanceof Accept) {
83 if (isAcceptable(lastReceivedOffer)) {
84 return new Accept(getPartyId(), lastReceivedOffer);
85 }
86 }
87 if (validActions.contains(Offer.class)) {
88 return new Offer(getPartyId(), getBid());
89 }
90
91 return action;
92 }
93
94 /**
95 * All offers proposed by the other parties will be received as a message.
96 * You can use this information to your advantage, for example to predict
97 * their utility.
98 *
99 * @param sender
100 * The party that did the action.
101 * @param action
102 * The action that party did.
103 */
104 @Override
105 public void receiveMessage(AgentID sender, Action action) {
106 super.receiveMessage(sender, action);
107 lastReceivedAction = action;
108
109 if (action instanceof Offer) {
110 try {
111 GM.getOpponent(action.getAgent()).update(((Offer) action).getBid());
112 lastReceivedOffer = ((Offer) action).getBid();
113 } catch (Exception e) {
114 e.printStackTrace();
115 }
116 }
117 }
118
119 /**
120 * If we're in the first half of the negotiation, returns bids within the
121 * [bidLowerBound, bidUpperBound] interval. If we're in the second half of
122 * the negotiation, tries to get the next bid from the GeneralModel. If this
123 * fails, falls back to the first method of returning bids.
124 *
125 * @return bid to offer next
126 */
127 private Bid getBid() {
128 Bid bid = null;
129 if (getTimeLine().getTime() <= 0.65) {
130 bid = getBidWithinBounds();
131 } else {
132 try {
133 if (!GM.isGenerated())
134 GM.generate();
135 bid = GM.getProposal();
136 if (bid == null) {
137 bidLowerBound = bidLowerBound - 0.1;
138 bidUpperBound = bidUpperBound - 0.1;
139 bid = getBidWithinBounds();
140 }
141 } catch (Exception e) {
142 e.printStackTrace();
143 }
144 }
145 return bid;
146 }
147
148 /**
149 * @return bid with utility in the [bidLowerBound, bidUpperBound] interval.
150 */
151 private Bid getBidWithinBounds() {
152 double randomUtility = bidLowerBound + (bidUpperBound - bidLowerBound) * rand.nextDouble();
153 return outcomeSpace.getBidNearUtility(randomUtility).getBid();
154 }
155
156 /**
157 * Determines whether b is acceptable
158 *
159 * @param b
160 * bid to accept or reject
161 * @return true if b should be accepted
162 */
163 private boolean isAcceptable(Bid b) {
164 if (getTimeLine().getTime() <= 0.5) {
165 // Before half of the negotiation, accept a bid if its utility is
166 // equal to or higher than the utility of the best bid we can make
167 return getUtility(b) >= bidUpperBound;
168 } else if (getTimeLine().getTime() <= 0.97) {
169 // Concede after half of the negotiation
170 return getUtility(b) >= reservationValue + 0.15;
171 } else {
172 // In the last phase of a negotiation, accept a bid if its utility
173 // is equal to or higher than our reservation value
174 return getUtility(b) >= reservationValue;
175 }
176 }
177
178 @Override
179 public String getDescription() {
180 return "This is Agent 16, deal with it";
181 }
182}
Note: See TracBrowser for help on using the repository browser.