1 | package genius.core.boaframework;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import java.io.Serializable;
|
---|
6 |
|
---|
7 | import genius.core.Bid;
|
---|
8 | import genius.core.BidHistory;
|
---|
9 | import genius.core.Domain;
|
---|
10 | import genius.core.bidding.BidDetails;
|
---|
11 | import genius.core.issue.Issue;
|
---|
12 | import genius.core.timeline.TimeLineInfo;
|
---|
13 | import genius.core.uncertainty.User;
|
---|
14 | import genius.core.uncertainty.UserModel;
|
---|
15 | import genius.core.utility.AbstractUtilitySpace;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * This is a class which manages all the negotiation session pertinent
|
---|
19 | * information to a single agent. This class is designed for bilateral
|
---|
20 | * negotiations.
|
---|
21 | *
|
---|
22 | */
|
---|
23 | public class NegotiationSession
|
---|
24 | {
|
---|
25 | /** Optional outcomespace which should be set manually. */
|
---|
26 | protected OutcomeSpace outcomeSpace;
|
---|
27 | /** History of bids made by the opponent. */
|
---|
28 | protected final BidHistory opponentBidHistory;
|
---|
29 | /** History of bids made by the agent. */
|
---|
30 | protected final BidHistory ownBidHistory;
|
---|
31 | /** If not null, this overrides utilitySpace. */
|
---|
32 | private final UserModel userModel;
|
---|
33 | /** Reference to the agent's preference profile for the domain. */
|
---|
34 | protected final AbstractUtilitySpace utilitySpace;
|
---|
35 | /**Reference to the agent's user; */
|
---|
36 | protected final User user;
|
---|
37 | /** Reference to the timeline. */
|
---|
38 | protected final TimeLineInfo timeline;
|
---|
39 | private final SessionData sessionData;
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Create a negotiation session which is used to keep track of the
|
---|
43 | * negotiation state.
|
---|
44 | *
|
---|
45 | * @param utilitySpace
|
---|
46 | * of the agent. May be overridden by outcomeSpace
|
---|
47 | * @param timeline
|
---|
48 | * of the current negotiation.
|
---|
49 | * @param outcomeSpace
|
---|
50 | * representation of the possible outcomes. Can be null.
|
---|
51 | * @param userModel
|
---|
52 | * the usermodel. Can be null. If not null, this overrides
|
---|
53 | * utilitySpace.
|
---|
54 | */
|
---|
55 | public NegotiationSession(SessionData sessionData,
|
---|
56 | AbstractUtilitySpace utilitySpace, TimeLineInfo timeline,
|
---|
57 | OutcomeSpace outcomeSpace, UserModel userModel, User user) {
|
---|
58 | // this.sessionData = sessionData;
|
---|
59 | this.utilitySpace = utilitySpace;
|
---|
60 | this.timeline = timeline;
|
---|
61 | this.opponentBidHistory = new BidHistory();
|
---|
62 | this.ownBidHistory = new BidHistory();
|
---|
63 | this.outcomeSpace = outcomeSpace;
|
---|
64 | this.sessionData = new SessionData();
|
---|
65 | this.userModel = userModel;
|
---|
66 | this.user = user;
|
---|
67 |
|
---|
68 | }
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Returns the bidding history of the opponent.
|
---|
72 | *
|
---|
73 | * @return bidding history of the opponent.
|
---|
74 | */
|
---|
75 | public BidHistory getOpponentBidHistory() {
|
---|
76 | return opponentBidHistory;
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Returns the bidding history of the agent.
|
---|
81 | *
|
---|
82 | * @return bidding history of the agent.
|
---|
83 | */
|
---|
84 | public BidHistory getOwnBidHistory() {
|
---|
85 | return ownBidHistory;
|
---|
86 | }
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Returns the discount factor of the utilityspace. Each utilityspace has a
|
---|
90 | * unique discount factor.
|
---|
91 | *
|
---|
92 | * @return discount factor of the utilityspace.
|
---|
93 | */
|
---|
94 | public double getDiscountFactor() {
|
---|
95 | return utilitySpace.getDiscountFactor();
|
---|
96 | }
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * @return issues of the domain.
|
---|
100 | */
|
---|
101 | public List<Issue> getIssues() {
|
---|
102 | return utilitySpace.getDomain().getIssues();
|
---|
103 | }
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * @return timeline of the negotiation.
|
---|
107 | */
|
---|
108 | public TimeLineInfo getTimeline() {
|
---|
109 | return timeline;
|
---|
110 | }
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Returns the normalized time (t = [0,1])
|
---|
114 | *
|
---|
115 | * @return normalized time.
|
---|
116 | */
|
---|
117 | public double getTime() {
|
---|
118 | return timeline.getTime();
|
---|
119 | }
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Returns the negotiation domain.
|
---|
123 | *
|
---|
124 | * @return domain of the negotiation.
|
---|
125 | */
|
---|
126 | public Domain getDomain() {
|
---|
127 | if (utilitySpace != null) {
|
---|
128 | return utilitySpace.getDomain();
|
---|
129 | }
|
---|
130 | return null;
|
---|
131 | }
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Returns the utilityspace of the agent.
|
---|
135 | *
|
---|
136 | * @return utilityspace of the agent.
|
---|
137 | */
|
---|
138 | public AbstractUtilitySpace getUtilitySpace() {
|
---|
139 | return utilitySpace;
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * Returns the space of possible outcomes in the domain. The returned value
|
---|
145 | * may be null.
|
---|
146 | *
|
---|
147 | * @return outcomespace if available.
|
---|
148 | */
|
---|
149 | public OutcomeSpace getOutcomeSpace() {
|
---|
150 | return outcomeSpace;
|
---|
151 | }
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Method used to set the outcomespace. Setting an outcomespace makes method
|
---|
155 | * such as getMaxBidinDomain much more efficient.
|
---|
156 | *
|
---|
157 | * @param outcomeSpace
|
---|
158 | * to be set.
|
---|
159 | */
|
---|
160 | public void setOutcomeSpace(OutcomeSpace outcomeSpace) {
|
---|
161 | this.outcomeSpace = outcomeSpace;
|
---|
162 | }
|
---|
163 |
|
---|
164 | /**
|
---|
165 | * Returns the best bid in the domain. If the outcomespace is set, it is
|
---|
166 | * used in this step. Else a highly inefficient method is used.
|
---|
167 | *
|
---|
168 | * @return bid with highest possible utility.
|
---|
169 | */
|
---|
170 | public BidDetails getMaxBidinDomain() {
|
---|
171 | BidDetails maxBid = null;
|
---|
172 | if (outcomeSpace == null) {
|
---|
173 | try {
|
---|
174 | Bid maximumBid = utilitySpace.getMaxUtilityBid();
|
---|
175 | maxBid = new BidDetails(maximumBid,
|
---|
176 | utilitySpace.getUtility(maximumBid), -1);
|
---|
177 | } catch (Exception e) {
|
---|
178 | e.printStackTrace();
|
---|
179 | }
|
---|
180 | } else {
|
---|
181 | maxBid = outcomeSpace.getMaxBidPossible();
|
---|
182 | }
|
---|
183 | return maxBid;
|
---|
184 | }
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * Returns the worst bid in the domain. If the outcomespace is set, it is
|
---|
188 | * used in this step. Else a highly inefficient method is used.
|
---|
189 | *
|
---|
190 | * @return bid with lowest possible utility.
|
---|
191 | */
|
---|
192 | public BidDetails getMinBidinDomain() {
|
---|
193 | BidDetails minBid = null;
|
---|
194 | if (outcomeSpace == null) {
|
---|
195 | try {
|
---|
196 | Bid minimumBidBid = utilitySpace.getMinUtilityBid();
|
---|
197 | minBid = new BidDetails(minimumBidBid,
|
---|
198 | utilitySpace.getUtility(minimumBidBid), -1);
|
---|
199 | } catch (Exception e) {
|
---|
200 | e.printStackTrace();
|
---|
201 | }
|
---|
202 | } else {
|
---|
203 | minBid = outcomeSpace.getMinBidPossible();
|
---|
204 | }
|
---|
205 | return minBid;
|
---|
206 | }
|
---|
207 |
|
---|
208 | /**
|
---|
209 | * Method used o store the data of a component. For agent programming please
|
---|
210 | * use the storeData() method of the BOA component.
|
---|
211 | *
|
---|
212 | * @param component
|
---|
213 | * from which the data is stored.
|
---|
214 | * @param data
|
---|
215 | * to be stored.
|
---|
216 | */
|
---|
217 | public void setData(BoaType component, Serializable data) {
|
---|
218 | sessionData.setData(component, data);
|
---|
219 | }
|
---|
220 |
|
---|
221 | /**
|
---|
222 | * Method used to load the data saved by a component. For agent programming
|
---|
223 | * please use the loadData() method of the BOA component.
|
---|
224 | *
|
---|
225 | * @param component
|
---|
226 | * from which the data is requested.
|
---|
227 | * @return data saved by the component.
|
---|
228 | */
|
---|
229 | public Serializable getData(BoaType component) {
|
---|
230 | return sessionData.getData(component);
|
---|
231 | }
|
---|
232 |
|
---|
233 | /**
|
---|
234 | * Returns the discounted utility of a bid given the bid and the time at
|
---|
235 | * which it was offered.
|
---|
236 | *
|
---|
237 | * @param bid
|
---|
238 | * which discount utility is requested.
|
---|
239 | * @param time
|
---|
240 | * at which the bid was offered.
|
---|
241 | * @return discounted utility of the given bid at the given time.
|
---|
242 | */
|
---|
243 | public double getDiscountedUtility(Bid bid, double time) {
|
---|
244 | return utilitySpace.getUtilityWithDiscount(bid, time);
|
---|
245 | }
|
---|
246 |
|
---|
247 | public SessionData getSessionData() {
|
---|
248 | return sessionData;
|
---|
249 | }
|
---|
250 |
|
---|
251 | /**
|
---|
252 | * @return A partial profile. If not null, this supersedes the value
|
---|
253 | * returned by {@link #getUtilitySpace()}.
|
---|
254 | */
|
---|
255 | public UserModel getUserModel() {
|
---|
256 | return userModel;
|
---|
257 | }
|
---|
258 |
|
---|
259 | /**
|
---|
260 | * @return the agent's user
|
---|
261 | */
|
---|
262 | public User getUser(){
|
---|
263 | return user;
|
---|
264 | }
|
---|
265 | } |
---|