source: src/main/java/agents/anac/y2014/Aster/Aster.java

Last change on this file was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 11.9 KB
Line 
1package agents.anac.y2014.Aster;
2
3import java.io.Serializable;
4import java.util.ArrayList;
5import java.util.Iterator;
6
7import genius.core.Agent;
8import genius.core.Bid;
9import genius.core.BidHistory;
10import genius.core.NegotiationResult;
11import genius.core.actions.Accept;
12import genius.core.actions.Action;
13import genius.core.actions.Offer;
14import genius.core.bidding.BidDetails;
15
16/**
17 * @author S.Morii Some improvements over the AgentMRK2.
18 *
19 **/
20
21public class Aster extends Agent {
22 private double time;
23 private double bidTarget;
24 private double acceptP;
25 private double opponentLastUtility;
26 private double opponentMaxUtility;
27 private double opponentMinUtility;
28 private double opponentPrevMaxUtility;
29 private double opponentPrevMinUtility;
30 private boolean immediateDecision;
31 private Bid myLastBid;
32 private Bid opponentMaxBid;
33 private Bid opponentLastBid;
34 private ArrayList<Bid> agreementBidList;
35 private ArrayList<Bid> selectAgreementBidList;
36 private ArrayList<Bid> selectMyBidList;
37 private ArrayList<Bid> selectOpponentBidList;
38 private BidHistory myBidHistory;
39 private BidHistory opponentBidHistory;
40 private ChooseAction chooseAction;
41 private GetAcceptProb getAcceptProb;
42 private SearchBid searchBid;
43 private SearchSA searchSA;
44 private static final double AGREE_EPSILON = 0.005;
45 private static final double DEAD_LINE = 0.990;
46 private static final double ACCEPT_CONCESSION = 0.95;
47 private static final double ACCEPT_PROB = 0.40;
48
49 @Override
50 public void init() {
51 this.bidTarget = 0.990;
52 this.opponentMinUtility = 1.0;
53 this.selectAgreementBidList = new ArrayList<Bid>();
54 this.selectMyBidList = new ArrayList<Bid>();
55 this.selectOpponentBidList = new ArrayList<Bid>();
56 this.myBidHistory = new BidHistory();
57 this.opponentBidHistory = new BidHistory();
58 this.chooseAction = new ChooseAction(utilitySpace);
59 this.getAcceptProb = new GetAcceptProb(utilitySpace);
60 this.searchBid = new SearchBid(utilitySpace);
61 this.searchSA = new SearchSA(utilitySpace, this.sessionNr);
62 this.beginSession();
63 }
64
65 @Override
66 public String getVersion() {
67 return "1.0.2";
68 }
69
70 @Override
71 public String getName() {
72 return "Aster";
73 }
74
75 @Override
76 public void ReceiveMessage(Action opponentAction) {
77 try {
78 if (opponentAction instanceof Offer) {
79 time = timeline.getTime();
80
81 // 相手�最終Bid
82 opponentLastBid = ((Offer) opponentAction).getBid();
83 opponentLastUtility = utilitySpace.getUtility(opponentLastBid);
84
85 // 相手�最�Bidを更新
86 if (opponentLastUtility < opponentMinUtility) {
87 opponentMinUtility = opponentLastUtility;
88 getAcceptProb.updateMinConcessionUtil(opponentMinUtility);
89 }
90
91 // 相手�最大Bidを更新
92 if (opponentLastUtility > opponentMaxUtility) {
93 opponentMaxBid = opponentLastBid;
94 opponentMaxUtility = opponentLastUtility;
95 if (opponentMaxUtility > opponentPrevMaxUtility) {
96 immediateDecision = false;
97 }
98 }
99
100 // 相手�Bidを�存
101 opponentBidHistory
102 .add(convertBidDetails(opponentLastBid, time));
103 }
104 } catch (Exception e) {
105 e.printStackTrace();
106 }
107 }
108
109 @Override
110 public Action chooseAction() {
111 Action action = null;
112 Bid actionBid = null;
113
114 try {
115 time = timeline.getTime();
116
117 // �期Bid
118 if ((myLastBid == null) || (opponentLastBid == null)) {
119 myLastBid = searchSA.getFirstBidbySA(bidTarget);
120 selectMyBidList.add(myLastBid);
121 return offerAndSaveBid(myLastBid);
122 }
123
124 // ��形�率�算出
125 double maxUtil = opponentMaxUtility > opponentPrevMaxUtility
126 ? opponentMaxUtility : opponentPrevMaxUtility;
127 acceptP = getAcceptProb.getAcceptProbability(opponentLastBid,
128 maxUtil, time);
129
130 // 閾値�算出
131 bidTarget = getAcceptProb.getCurrentBidTarget();
132
133 // ��判定
134 if (isAcceptable(time)) {
135 action = new Accept(getAgentID(), opponentLastBid);
136 return action;
137 }
138
139 // 譲歩判定
140 if ((actionBid = isConsiderable()) != null) {
141 return offerAndSaveBid(actionBid);
142 }
143
144 // Bid探索
145 // 相手�Bid�近�探索
146 selectOpponentBidList = searchBid.searchOfferingBid(
147 selectOpponentBidList, opponentLastBid, bidTarget);
148 if (!selectMyBidList.isEmpty()) {
149 addSelectBidList(bidTarget);
150 }
151
152 // SA�探索
153 actionBid = searchSA.getBidbySA(bidTarget);
154 if (actionBid != null) {
155 if (!selectMyBidList.contains(actionBid)) {
156 selectMyBidList.add(actionBid);
157 }
158 }
159
160 // Bid�決定
161 if (!selectOpponentBidList.isEmpty()) {
162 actionBid = chooseAction.nextOfferingBid(bidTarget,
163 selectMyBidList, selectOpponentBidList);
164 } else {
165 actionBid = chooseAction.nextOfferingBid(bidTarget,
166 selectMyBidList, true);
167 }
168
169 // FOR_DEBUG
170 // printCurrentDetails();
171
172 // アップデート
173 myLastBid = actionBid;
174
175 } catch (Exception e) {
176 e.printStackTrace();
177 }
178
179 // オファー
180 return offerAndSaveBid(actionBid);
181 }
182
183 @Override
184 public void endSession(NegotiationResult result) {
185 MyPrevSessionData mySessionData = null;
186
187 try {
188 boolean immediateDecision = false;
189 double resultUtil;
190 double agreediff = 0.0;
191
192 if (result.isAgreement()) {
193 Bid agreementBid = result.getLastBid();
194 resultUtil = utilitySpace.getUtility(agreementBid);
195
196 // �去���案�平�効用値
197 if (agreementBidList.size() >= this.sessionsTotal / 3) {
198 double agreementAverage = 0.0;
199 for (Bid bid : agreementBidList) {
200 agreementAverage += utilitySpace.getUtility(bid);
201 }
202 agreementAverage /= agreementBidList.size();
203 agreediff = Math.abs(agreementAverage - resultUtil);
204 if ((agreediff < AGREE_EPSILON)
205 && (utilitySpace.getDiscountFactor() < 0.95)) {
206 immediateDecision = true; // �去���平�値��差��分�����ら次回以��決
207 }
208 }
209
210 agreementBidList.add(agreementBid);
211
212 } else {
213 resultUtil = opponentMaxUtility;
214 }
215
216 // �去���最大効用値
217 if (resultUtil > opponentPrevMaxUtility) {
218 opponentPrevMaxUtility = resultUtil;
219 }
220
221 opponentPrevMinUtility = opponentBidHistory.getWorstBidDetails()
222 .getMyUndiscountedUtil();
223
224 mySessionData = new MyPrevSessionData(agreementBidList,
225 opponentBidHistory, result, opponentPrevMaxUtility,
226 opponentPrevMinUtility, time, immediateDecision);
227 } catch (Exception e) {
228 e.printStackTrace();
229 }
230
231 this.saveSessionData(mySessionData);
232 }
233
234 private void beginSession() {
235 Serializable prev = this.loadSessionData();
236 MyPrevSessionData mySessionData = (MyPrevSessionData) prev;
237
238 try {
239 if (mySessionData != null) {
240 agreementBidList = mySessionData.agreementBidList;
241 opponentPrevMaxUtility = mySessionData.opponentPrevMaxUtility;
242 opponentPrevMinUtility = mySessionData.opponentPrevMinUtility;
243 immediateDecision = mySessionData.immediateDecision;
244 } else {
245 agreementBidList = new ArrayList<Bid>();
246 opponentPrevMaxUtility = 0.0;
247 opponentPrevMinUtility = 0.0;
248 opponentMinUtility = 1.0;
249 immediateDecision = false;
250 }
251
252 double maxConcessionUtility = (1.0
253 - ((opponentMaxUtility - opponentPrevMinUtility)
254 / (1.0 - opponentPrevMinUtility)))
255 * 100;
256
257 // ��点�近�探索
258 if (!agreementBidList.isEmpty()) {
259 double target = opponentMaxUtility > opponentPrevMaxUtility
260 ? opponentMaxUtility : opponentPrevMaxUtility;
261 for (Bid bid : agreementBidList) {
262 selectAgreementBidList = searchBid.searchOfferingBid(
263 selectAgreementBidList, bid, target);
264 }
265 }
266
267 // 譲歩設定
268 getAcceptProb.setTargetParam(this.sessionNr, maxConcessionUtility,
269 opponentMinUtility);
270
271 } catch (Exception e) {
272 e.printStackTrace();
273 }
274 }
275
276 private Bid isConsiderable() {
277 Bid actionBid = null;
278 double concessionDeg = (opponentMaxUtility - opponentMinUtility)
279 / (1.0 - opponentMinUtility);
280
281 // �回�譲歩���
282 if (this.sessionNr < 1) {
283 return actionBid;
284 }
285
286 // ************ 譲歩判定 ************//
287 // 1.
288 // 相手�ACCEPT_CONCESSION以上譲歩����場�
289 // 2.
290 // �決判断�true��(相手�最大効用値)=(相手��去�最大効用値)�場�
291 // 3.
292 // 時間�DEAD_LINE��(相手�最大効用値)=(相手��去�最大効用値)�場�
293 // 4.
294 // DF�有効��相手�最良Bid�bidTarget以上����場�
295 if (concessionDeg >= ACCEPT_CONCESSION) {
296 actionBid = opponentMaxBid;
297 } else if ((immediateDecision)
298 && (opponentMaxUtility >= opponentPrevMaxUtility)) {
299 actionBid = opponentMaxBid;
300 } else if (time > DEAD_LINE) {
301 double standardUtil = opponentPrevMaxUtility < bidTarget
302 ? opponentPrevMaxUtility : bidTarget;
303 if (opponentMaxUtility >= standardUtil) {
304 actionBid = opponentMaxBid;
305 }
306 } else if (utilitySpace.getDiscountFactor() < 1.0) {
307 if (opponentMaxUtility > bidTarget) {
308 actionBid = opponentMaxBid;
309 }
310 }
311
312 return actionBid;
313 }
314
315 private boolean isAcceptable(double t) throws Exception {
316 boolean accept = false;
317 double minUtil = myBidHistory.getWorstBidDetails()
318 .getMyUndiscountedUtil();
319
320 // ************ ��判定 ************//
321 // 1.
322 // 相手�効用値�自分�閾値を超��場�
323 // 2.
324 // AcceptP�一定値を超��場�
325 if (opponentLastUtility >= minUtil) {
326 accept = true;
327 } else if (acceptP > ACCEPT_PROB) {
328 accept = true;
329 }
330
331 return accept;
332 }
333
334 private Action offerAndSaveBid(Bid actionBid) {
335 Action action = new Offer(getAgentID(), actionBid);
336 myBidHistory.add(convertBidDetails(actionBid, time));
337
338 return action;
339 }
340
341 private BidDetails convertBidDetails(Bid bid, double time) {
342 BidDetails bd = null;
343 try {
344 bd = new BidDetails(bid, utilitySpace.getUtility(bid), time);
345 } catch (Exception e) {
346 e.printStackTrace();
347 }
348 return bd;
349 }
350
351 private void addSelectBidList(double bidTarget) {
352 Bid bid;
353 double util;
354 try {
355 for (Iterator<Bid> it = selectAgreementBidList.iterator(); it
356 .hasNext();) {
357 bid = it.next();
358 util = utilitySpace.getUtility(bid);
359 if (util >= bidTarget) {
360 selectOpponentBidList.add(bid);
361 it.remove();
362 }
363 }
364 } catch (Exception e) {
365 e.printStackTrace();
366 }
367 }
368
369 // FOR_DEBUG
370 /*
371 * private void printCurrentDetails() {
372 * System.out.println("****CURRENT DETAILS****");
373 * System.out.println("bidTarget:" + bidTarget);
374 * System.out.println("estimateMax:" + getAcceptProb.getEstimateMax());
375 * System.out.println("opponentMax:" + opponentMaxUtility);
376 * System.out.println("opponentMin:" + opponentMinUtility); System.out
377 * .println("concessionDeg:" + ((opponentMaxUtility - opponentMinUtility) /
378 * (1.0 - opponentMinUtility)) 100 + "%"); System.out.println("prevMax:" +
379 * opponentPrevMaxUtility); System.out.println("prevMin:" +
380 * opponentPrevMinUtility); System.out.println("mySize:" +
381 * selectMyBidList.size()); System.out.println("opponentSize:" +
382 * selectOpponentBidList.size()); System.out.println("agreeSize:" +
383 * selectAgreementBidList.size()); System.out.println("immediateDecision:" +
384 * immediateDecision); }
385 */
386
387 @Override
388 public String getDescription() {
389 return "ANAC2014 compatible with non-linear utility spaces";
390 }
391}
Note: See TracBrowser for help on using the repository browser.