1 | package genius.core.boaframework;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 |
|
---|
5 | import java.io.Serializable;
|
---|
6 |
|
---|
7 | import negotiator.boaframework.agent.TheBOAagent;
|
---|
8 |
|
---|
9 | import genius.core.Agent;
|
---|
10 | import genius.core.Bid;
|
---|
11 | import genius.core.NegotiationResult;
|
---|
12 | import genius.core.actions.Accept;
|
---|
13 | import genius.core.actions.Action;
|
---|
14 | import genius.core.actions.EndNegotiation;
|
---|
15 | import genius.core.actions.Offer;
|
---|
16 | import genius.core.bidding.BidDetails;
|
---|
17 | import genius.core.misc.Pair;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * This class describes a basic decoupled agent. Available for backwards
|
---|
21 | * compatibility with old bilateral BOA agents. The
|
---|
22 | * {@link TheBOAagent} class extends this class and sets the required
|
---|
23 | * parameters.
|
---|
24 | *
|
---|
25 | * For more information, see: Baarslag T., Hindriks K.V., Hendrikx M.,
|
---|
26 | * Dirkzwager A., Jonker C.M. Decoupling Negotiating Agents to Explore the Space
|
---|
27 | * of Negotiation Strategies. Proceedings of The Fifth International Workshop on
|
---|
28 | * Agent-based Complex Automated Negotiations (ACAN 2012), 2012.
|
---|
29 | * https://homepages.cwi.nl/~baarslag/pub/Decoupling_Negotiating_Agents_to_Explore_the_Space_of_Negotiation_Strategies_ACAN_2012.pdf
|
---|
30 | */
|
---|
31 | @Deprecated
|
---|
32 | @SuppressWarnings("serial")
|
---|
33 | public abstract class BOAagentBilateral extends Agent {
|
---|
34 | /** Decides when to accept */
|
---|
35 | protected AcceptanceStrategy acceptConditions;
|
---|
36 | /** Decides what to offer */
|
---|
37 | protected OfferingStrategy offeringStrategy;
|
---|
38 | /** Approximates the utility of a bid for the opponent */
|
---|
39 | protected OpponentModel opponentModel;
|
---|
40 | /** Links to the negotiation domain */
|
---|
41 | protected NegotiationSession negotiationSession;
|
---|
42 | /** Selects which bid to send when using an opponent model */
|
---|
43 | protected OMStrategy omStrategy;
|
---|
44 | /** Store {@link Multi_AcceptanceCondition} outcomes */
|
---|
45 | public ArrayList<Pair<Bid, String>> savedOutcomes;
|
---|
46 | /** Contains the space of possible bids */
|
---|
47 | protected OutcomeSpace outcomeSpace;
|
---|
48 | private Bid oppBid;
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Initializes the agent and creates a new negotiation session object.
|
---|
52 | */
|
---|
53 | @Override
|
---|
54 | public void init() {
|
---|
55 | super.init();
|
---|
56 | Serializable storedData = this.loadSessionData();
|
---|
57 | SessionData sessionData;
|
---|
58 | if (storedData == null) {
|
---|
59 | sessionData = new SessionData();
|
---|
60 | } else {
|
---|
61 | sessionData = (SessionData) storedData;
|
---|
62 | }
|
---|
63 | negotiationSession = new NegotiationSession(sessionData, utilitySpace,
|
---|
64 | timeline, null, null, null);
|
---|
65 | agentSetup();
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Method used to setup the agent. The method is called directly after
|
---|
70 | * initialization of the agent.
|
---|
71 | */
|
---|
72 | public abstract void agentSetup();
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Sets the components of the decoupled agent.
|
---|
76 | *
|
---|
77 | * @param ac
|
---|
78 | * the acceptance strategy
|
---|
79 | * @param os
|
---|
80 | * the offering strategy
|
---|
81 | * @param om
|
---|
82 | * the opponent model
|
---|
83 | * @param oms
|
---|
84 | * the opponent model strategy
|
---|
85 | */
|
---|
86 | public void setDecoupledComponents(AcceptanceStrategy ac,
|
---|
87 | OfferingStrategy os, OpponentModel om, OMStrategy oms) {
|
---|
88 | acceptConditions = ac;
|
---|
89 | offeringStrategy = os;
|
---|
90 | opponentModel = om;
|
---|
91 | omStrategy = oms;
|
---|
92 | }
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Unique identifier for the BOA agent. The default method in agent does not
|
---|
96 | * suffice as all BOA agents have the same classpath.
|
---|
97 | */
|
---|
98 | @Override
|
---|
99 | protected String getUniqueIdentifier() {
|
---|
100 | return getName().hashCode() + "";
|
---|
101 | }
|
---|
102 |
|
---|
103 | @Override
|
---|
104 | public String getVersion() {
|
---|
105 | return "1.0";
|
---|
106 | }
|
---|
107 |
|
---|
108 | @Override
|
---|
109 | public abstract String getName();
|
---|
110 |
|
---|
111 | @Override
|
---|
112 | public void ReceiveMessage(Action opponentAction) {
|
---|
113 | // 1. if the opponent made a bid
|
---|
114 | if (opponentAction instanceof Offer) {
|
---|
115 | oppBid = ((Offer) opponentAction).getBid();
|
---|
116 | // 2. store the opponent's trace
|
---|
117 | try {
|
---|
118 | BidDetails opponentBid = new BidDetails(oppBid,
|
---|
119 | negotiationSession.getUtilitySpace().getUtility(oppBid),
|
---|
120 | negotiationSession.getTime());
|
---|
121 | negotiationSession.getOpponentBidHistory().add(opponentBid);
|
---|
122 | } catch (Exception e) {
|
---|
123 | e.printStackTrace();
|
---|
124 | }
|
---|
125 | // 3. if there is an opponent model, receiveMessage it using the
|
---|
126 | // opponent's
|
---|
127 | // bid
|
---|
128 | if (opponentModel != null && !(opponentModel instanceof NoModel)) {
|
---|
129 | if (omStrategy.canUpdateOM()) {
|
---|
130 | opponentModel.updateModel(oppBid);
|
---|
131 | } else {
|
---|
132 | if (!opponentModel.isCleared()) {
|
---|
133 | opponentModel.cleanUp();
|
---|
134 | }
|
---|
135 | }
|
---|
136 | }
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Chooses an action to perform.
|
---|
142 | *
|
---|
143 | * @return Action the agent performs
|
---|
144 | */
|
---|
145 | @Override
|
---|
146 | public Action chooseAction() {
|
---|
147 |
|
---|
148 | BidDetails bid;
|
---|
149 |
|
---|
150 | // if our history is empty, then make an opening bid
|
---|
151 | if (negotiationSession.getOwnBidHistory().getHistory().isEmpty()) {
|
---|
152 | bid = offeringStrategy.determineOpeningBid();
|
---|
153 | } else {
|
---|
154 | // else make a normal bid
|
---|
155 | bid = offeringStrategy.determineNextBid();
|
---|
156 | if (offeringStrategy.isEndNegotiation()) {
|
---|
157 | return new EndNegotiation(getAgentID());
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 | // if the offering strategy made a mistake and didn't set a bid: accept
|
---|
162 | if (bid == null) {
|
---|
163 | System.out.println("Error in code, null bid was given");
|
---|
164 | return new Accept(getAgentID(), oppBid);
|
---|
165 | } else {
|
---|
166 | offeringStrategy.setNextBid(bid);
|
---|
167 | }
|
---|
168 |
|
---|
169 | // check if the opponent bid should be accepted
|
---|
170 | Actions decision = Actions.Reject;
|
---|
171 | if (!negotiationSession.getOpponentBidHistory().getHistory()
|
---|
172 | .isEmpty()) {
|
---|
173 | decision = acceptConditions.determineAcceptability();
|
---|
174 | }
|
---|
175 |
|
---|
176 | // check if the agent decided to break off the negotiation
|
---|
177 | if (decision.equals(Actions.Break)) {
|
---|
178 | System.out.println("send EndNegotiation");
|
---|
179 | return new EndNegotiation(getAgentID());
|
---|
180 | }
|
---|
181 | // if agent does not accept, it offers the counter bid
|
---|
182 | if (decision.equals(Actions.Reject)) {
|
---|
183 | negotiationSession.getOwnBidHistory().add(bid);
|
---|
184 | return new Offer(getAgentID(), bid.getBid());
|
---|
185 | } else {
|
---|
186 | return new Accept(getAgentID(), oppBid);
|
---|
187 | }
|
---|
188 | }
|
---|
189 |
|
---|
190 | /**
|
---|
191 | * Returns the offering strategy of the agent.
|
---|
192 | *
|
---|
193 | * @return offeringstrategy of the agent.
|
---|
194 | */
|
---|
195 | public OfferingStrategy getOfferingStrategy() {
|
---|
196 | return offeringStrategy;
|
---|
197 | }
|
---|
198 |
|
---|
199 | /**
|
---|
200 | * Returns the opponent model of the agent.
|
---|
201 | *
|
---|
202 | * @return opponent model of the agent.
|
---|
203 | */
|
---|
204 | public OpponentModel getOpponentModel() {
|
---|
205 | return opponentModel;
|
---|
206 | }
|
---|
207 |
|
---|
208 | /**
|
---|
209 | * Returns the acceptance strategy of the agent.
|
---|
210 | *
|
---|
211 | * @return acceptance strategy of the agent.
|
---|
212 | */
|
---|
213 | public AcceptanceStrategy getAcceptanceStrategy() {
|
---|
214 | return acceptConditions;
|
---|
215 | }
|
---|
216 |
|
---|
217 | /**
|
---|
218 | * Method that first calls the endSession method of each component to
|
---|
219 | * receiveMessage the session data and then stores the session data if it is
|
---|
220 | * not empty and is changed.
|
---|
221 | */
|
---|
222 | @Override
|
---|
223 | public void endSession(NegotiationResult result) {
|
---|
224 | offeringStrategy.endSession(result);
|
---|
225 | acceptConditions.endSession(result);
|
---|
226 | opponentModel.endSession(result);
|
---|
227 | SessionData savedData = negotiationSession.getSessionData();
|
---|
228 | if (!savedData.isEmpty() && savedData.isChanged()) {
|
---|
229 | savedData.changesCommitted();
|
---|
230 | saveSessionData(savedData);
|
---|
231 | }
|
---|
232 | }
|
---|
233 |
|
---|
234 | /**
|
---|
235 | * Clears the agent's variables.
|
---|
236 | */
|
---|
237 | public void cleanUp() {
|
---|
238 | offeringStrategy = null;
|
---|
239 | acceptConditions = null;
|
---|
240 | omStrategy = null;
|
---|
241 | opponentModel = null;
|
---|
242 | outcomeSpace = null;
|
---|
243 | negotiationSession = null;
|
---|
244 | }
|
---|
245 | } |
---|