1 | package genius.core.boaframework;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import java.util.Map;
|
---|
6 |
|
---|
7 | import genius.core.AgentID;
|
---|
8 | import genius.core.Bid;
|
---|
9 | import genius.core.NegotiationResult;
|
---|
10 | import genius.core.actions.Accept;
|
---|
11 | import genius.core.actions.Action;
|
---|
12 | import genius.core.actions.EndNegotiation;
|
---|
13 | import genius.core.actions.Offer;
|
---|
14 | import genius.core.bidding.BidDetails;
|
---|
15 | import genius.core.parties.AbstractNegotiationParty;
|
---|
16 | import genius.core.parties.NegotiationInfo;
|
---|
17 | import genius.core.parties.NegotiationParty;
|
---|
18 | import genius.core.persistent.PersistentDataType;
|
---|
19 | import genius.core.repository.boa.BoaPartyRepItem;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * This class is used to convert a BOA party to a real agent.
|
---|
23 | *
|
---|
24 | * This class is special in that it is constructed directly by a
|
---|
25 | * {@link BoaPartyRepItem}.
|
---|
26 | * <p>
|
---|
27 | * You can extend this directly to build your own BoaParty from your BOA
|
---|
28 | * components. To do this, override the {@link #init(NegotiationInfo)} call like
|
---|
29 | * this:<br>
|
---|
30 | *
|
---|
31 | * <pre>
|
---|
32 | * <code>
|
---|
33 | * @Override
|
---|
34 | * public void init(NegotiationInfo info) {
|
---|
35 | * .. setup your_ac, acparams etc...
|
---|
36 | * configure(your_ac, acparams, your_os,osparams, your_om, omparams,
|
---|
37 | * your_oms, omsparams);
|
---|
38 | * super.init(info);
|
---|
39 | * } </code>
|
---|
40 | * </pre>
|
---|
41 | *
|
---|
42 | * And of course you should do the usual override's of {@link NegotiationParty}
|
---|
43 | * functions.
|
---|
44 | * <p>
|
---|
45 | * For more information, see: Baarslag T., Hindriks K.V., Hendrikx M.,
|
---|
46 | * Dirkzwager A., Jonker C.M. Decoupling Negotiating Agents to Explore the Space
|
---|
47 | * of Negotiation Strategies. Proceedings of The Fifth International Workshop on
|
---|
48 | * Agent-based Complex Automated Negotiations (ACAN 2012), 2012.
|
---|
49 | * https://homepages.cwi.nl/~baarslag/pub/Decoupling_Negotiating_Agents_to_Explore_the_Space_of_Negotiation_Strategies_ACAN_2012.pdf
|
---|
50 | *
|
---|
51 | */
|
---|
52 | @SuppressWarnings("serial")
|
---|
53 | public abstract class BoaParty extends AbstractNegotiationParty {
|
---|
54 | /** Decides when to accept */
|
---|
55 | protected AcceptanceStrategy acceptConditions;
|
---|
56 | /** Decides what to offer */
|
---|
57 | protected OfferingStrategy offeringStrategy;
|
---|
58 | /** Approximates the utility of a bid for the opponent */
|
---|
59 | protected OpponentModel opponentModel;
|
---|
60 | /** Selects which bid to send when using an opponent model */
|
---|
61 | protected OMStrategy omStrategy;
|
---|
62 |
|
---|
63 | // init params for all components.
|
---|
64 | private Map<String, Double> acParams;
|
---|
65 | private Map<String, Double> osParams;
|
---|
66 | private Map<String, Double> omParams;
|
---|
67 | private Map<String, Double> omsParams;
|
---|
68 |
|
---|
69 | /** Links to the negotiation domain */
|
---|
70 | protected NegotiationSession negotiationSession;
|
---|
71 | /** Contains the space of possible bids */
|
---|
72 | protected OutcomeSpace outcomeSpace;
|
---|
73 | private Bid oppBid;
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Stores all relevant values for initializing the components. Will be used
|
---|
77 | * when init is called. This has therefore to be called either as first call
|
---|
78 | * in init, or before the call to init.
|
---|
79 | *
|
---|
80 | * @param ac
|
---|
81 | * {@link AcceptanceStrategy}
|
---|
82 | * @param acParams
|
---|
83 | * a Map<String,Double> containing the init parameters for the
|
---|
84 | * AcceptanceStrategy
|
---|
85 | * @param os
|
---|
86 | * {@link OfferingStrategy}
|
---|
87 | * @param osParams
|
---|
88 | * a Map<String,Double> containing the init parameters for the
|
---|
89 | * OfferingStrategy
|
---|
90 | * @param om
|
---|
91 | * {@link OpponentModel}
|
---|
92 | * @param omParams
|
---|
93 | * a Map<String,Double> containing the init parameters for the
|
---|
94 | * OpponentModel
|
---|
95 | * @param oms
|
---|
96 | * {@link OMStrategy}
|
---|
97 | * @param omsParams
|
---|
98 | * a Map<String,Double> containing the init parameters for the
|
---|
99 | * OMStrategy
|
---|
100 | */
|
---|
101 | public BoaParty configure(AcceptanceStrategy ac,
|
---|
102 | Map<String, Double> acParams, OfferingStrategy os,
|
---|
103 | Map<String, Double> osParams, OpponentModel om,
|
---|
104 | Map<String, Double> omParams, OMStrategy oms,
|
---|
105 | Map<String, Double> omsParams) {
|
---|
106 | acceptConditions = ac;
|
---|
107 | this.acParams = acParams;
|
---|
108 | offeringStrategy = os;
|
---|
109 | this.osParams = osParams;
|
---|
110 | opponentModel = om;
|
---|
111 | this.omParams = omParams;
|
---|
112 | omStrategy = oms;
|
---|
113 | this.omsParams = omsParams;
|
---|
114 |
|
---|
115 | return this;
|
---|
116 | }
|
---|
117 |
|
---|
118 | @Override
|
---|
119 | public void init(NegotiationInfo info) {
|
---|
120 | // Note that utility space is estimated here in case of uncertainty
|
---|
121 | super.init(info);
|
---|
122 |
|
---|
123 | SessionData sessionData = null;
|
---|
124 | if (info.getPersistentData()
|
---|
125 | .getPersistentDataType() == PersistentDataType.SERIALIZABLE) {
|
---|
126 | sessionData = (SessionData) info.getPersistentData().get();
|
---|
127 | }
|
---|
128 | if (sessionData == null) {
|
---|
129 | sessionData = new SessionData();
|
---|
130 | }
|
---|
131 | negotiationSession = new NegotiationSession(sessionData, utilitySpace,
|
---|
132 | timeline, null, info.getUserModel(), info.getUser());
|
---|
133 | initStrategies();
|
---|
134 | }
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * Follows the BOA flow for receiving an offer: 1. store the details of the
|
---|
138 | * received bid. 2. tell the {@link OpponentModel} to update itself based on
|
---|
139 | * the received bid.
|
---|
140 | */
|
---|
141 | @Override
|
---|
142 | public void receiveMessage(AgentID sender, Action opponentAction) {
|
---|
143 | // 1. if the opponent made a bid
|
---|
144 | if (opponentAction instanceof Offer) {
|
---|
145 | oppBid = ((Offer) opponentAction).getBid();
|
---|
146 | // 2. store the opponent's trace
|
---|
147 | try {
|
---|
148 | BidDetails opponentBid = new BidDetails(oppBid,
|
---|
149 | negotiationSession.getUtilitySpace().getUtility(oppBid),
|
---|
150 | negotiationSession.getTime());
|
---|
151 | negotiationSession.getOpponentBidHistory().add(opponentBid);
|
---|
152 | } catch (Exception e) {
|
---|
153 | e.printStackTrace();
|
---|
154 | }
|
---|
155 | // 3. if there is an opponent model, update it using the opponent's
|
---|
156 | // bid
|
---|
157 | if (opponentModel != null && !(opponentModel instanceof NoModel)) {
|
---|
158 | if (omStrategy.canUpdateOM()) {
|
---|
159 | opponentModel.updateModel(oppBid);
|
---|
160 | } else {
|
---|
161 | if (!opponentModel.isCleared()) {
|
---|
162 | opponentModel.cleanUp();
|
---|
163 | }
|
---|
164 | }
|
---|
165 | }
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Follows the BOA flow for making an offer: 1. ask the
|
---|
171 | * {@link OfferingStrategy} for a bid. 2. ask the {@link AcceptanceStrategy}
|
---|
172 | * if the opponent bid needs to be accepted instead.
|
---|
173 | */
|
---|
174 | @Override
|
---|
175 | public Action chooseAction(List<Class<? extends Action>> possibleActions) {
|
---|
176 |
|
---|
177 | BidDetails bid;
|
---|
178 |
|
---|
179 | // if our history is empty, then make an opening bid
|
---|
180 | if (negotiationSession.getOwnBidHistory().getHistory().isEmpty()) {
|
---|
181 | bid = offeringStrategy.determineOpeningBid();
|
---|
182 | } else {
|
---|
183 | // else make a normal bid
|
---|
184 | bid = offeringStrategy.determineNextBid();
|
---|
185 | if (offeringStrategy.isEndNegotiation()) {
|
---|
186 | return new EndNegotiation(getPartyId());
|
---|
187 | }
|
---|
188 | }
|
---|
189 |
|
---|
190 | // if the offering strategy made a mistake and didn't set a bid: accept
|
---|
191 | if (bid == null) {
|
---|
192 | System.out.println("Error in code, null bid was given");
|
---|
193 | return new Accept(getPartyId(), oppBid);
|
---|
194 | } else {
|
---|
195 | offeringStrategy.setNextBid(bid);
|
---|
196 | }
|
---|
197 |
|
---|
198 | // check if the opponent bid should be accepted
|
---|
199 | Actions decision = Actions.Reject;
|
---|
200 | if (!negotiationSession.getOpponentBidHistory().getHistory()
|
---|
201 | .isEmpty()) {
|
---|
202 | decision = acceptConditions.determineAcceptability();
|
---|
203 | }
|
---|
204 |
|
---|
205 | // check if the agent decided to break off the negotiation
|
---|
206 | if (decision.equals(Actions.Break)) {
|
---|
207 | System.out.println("send EndNegotiation");
|
---|
208 | return new EndNegotiation(getPartyId());
|
---|
209 | }
|
---|
210 | // if agent does not accept, it offers the counter bid
|
---|
211 | if (decision.equals(Actions.Reject)) {
|
---|
212 | negotiationSession.getOwnBidHistory().add(bid);
|
---|
213 | return new Offer(getPartyId(), bid.getBid());
|
---|
214 | } else {
|
---|
215 | return new Accept(getPartyId(), oppBid);
|
---|
216 | }
|
---|
217 | }
|
---|
218 |
|
---|
219 | /**
|
---|
220 | * Method that first calls the endSession method of each component to
|
---|
221 | * receiveMessage the session data and then stores the session data if it is
|
---|
222 | * not empty and is changed.
|
---|
223 | */
|
---|
224 | public void endSession(NegotiationResult result)
|
---|
225 | {
|
---|
226 | offeringStrategy.endSession(result);
|
---|
227 | acceptConditions.endSession(result);
|
---|
228 | opponentModel.endSession(result);
|
---|
229 | SessionData savedData = negotiationSession.getSessionData();
|
---|
230 | if (!savedData.isEmpty() && savedData.isChanged()) {
|
---|
231 | savedData.changesCommitted();
|
---|
232 | getData().put(savedData);
|
---|
233 | }
|
---|
234 | }
|
---|
235 |
|
---|
236 | /**
|
---|
237 | * Clears the agent's variables.
|
---|
238 | */
|
---|
239 | public void cleanUp() {
|
---|
240 | offeringStrategy = null;
|
---|
241 | acceptConditions = null;
|
---|
242 | omStrategy = null;
|
---|
243 | opponentModel = null;
|
---|
244 | outcomeSpace = null;
|
---|
245 | negotiationSession = null;
|
---|
246 | }
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * Returns the offering strategy of the agent.
|
---|
250 | *
|
---|
251 | * @return offeringstrategy of the agent.
|
---|
252 | */
|
---|
253 | public OfferingStrategy getOfferingStrategy() {
|
---|
254 | return offeringStrategy;
|
---|
255 | }
|
---|
256 |
|
---|
257 | /**
|
---|
258 | * Returns the opponent model of the agent.
|
---|
259 | *
|
---|
260 | * @return opponent model of the agent.
|
---|
261 | */
|
---|
262 | public OpponentModel getOpponentModel() {
|
---|
263 | return opponentModel;
|
---|
264 | }
|
---|
265 |
|
---|
266 | /**
|
---|
267 | * Returns the acceptance strategy of the agent.
|
---|
268 | *
|
---|
269 | * @return acceptance strategy of the agent.
|
---|
270 | */
|
---|
271 | public AcceptanceStrategy getAcceptanceStrategy() {
|
---|
272 | return acceptConditions;
|
---|
273 | }
|
---|
274 |
|
---|
275 | private void initStrategies() {
|
---|
276 | // init the components.
|
---|
277 | try {
|
---|
278 | opponentModel.init(negotiationSession, omParams);
|
---|
279 | // opponentModel.setOpponentUtilitySpace((BilateralAtomicNegotiationSession)fNegotiation);
|
---|
280 | omStrategy.init(negotiationSession, opponentModel, omsParams);
|
---|
281 | offeringStrategy.init(negotiationSession, opponentModel, omStrategy,
|
---|
282 | osParams);
|
---|
283 | acceptConditions.init(negotiationSession, offeringStrategy,
|
---|
284 | opponentModel, acParams);
|
---|
285 | // acceptConditions.setOpponentUtilitySpace(fNegotiation);
|
---|
286 | } catch (Exception e) {
|
---|
287 | e.printStackTrace();
|
---|
288 | }
|
---|
289 | }
|
---|
290 | } |
---|