1 | package agents.anac.y2014.AgentWhale;
|
---|
2 |
|
---|
3 | import java.io.Serializable;
|
---|
4 | import java.text.NumberFormat;
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import java.util.Comparator;
|
---|
7 | import java.util.HashMap;
|
---|
8 | import java.util.Random;
|
---|
9 | import java.util.TreeMap;
|
---|
10 |
|
---|
11 | import genius.core.Agent;
|
---|
12 | import genius.core.Bid;
|
---|
13 | import genius.core.NegotiationResult;
|
---|
14 | import genius.core.actions.Accept;
|
---|
15 | import genius.core.actions.Action;
|
---|
16 | import genius.core.actions.DefaultAction;
|
---|
17 | import genius.core.actions.Offer;
|
---|
18 | import genius.core.issue.IssueInteger;
|
---|
19 | import genius.core.issue.Value;
|
---|
20 | import genius.core.issue.ValueInteger;
|
---|
21 | import genius.core.timeline.Timeline;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * This agent is an example of how to create an ANAC2013 agent which learns
|
---|
25 | * during the tournament. This agent is a variant of the random agent.
|
---|
26 | *
|
---|
27 | * @author M. Hendrikx
|
---|
28 | */
|
---|
29 | public class WhaleAgent extends Agent {
|
---|
30 |
|
---|
31 | /** The minimum utility a bid should have to be accepted or offered. */
|
---|
32 | private double MINIMUM_BID_UTILITY;
|
---|
33 | private double MINIMUM_BID_UTILITY_OFFER = 1.0;
|
---|
34 |
|
---|
35 | private double offered_sum = 0.0;// ‘ŠŽè‚ªOffer‚µ‚Ä‚«‚½Bid‚ÌŒø—p’l‚Ì‘�˜a
|
---|
36 | private Bid opponentBestBid;// ‘ŠŽè‚ªOffer‚µ‚Ä‚«‚½Bid‚Ì‚¤‚¿�Å‘å‚ÌŒø—p’l‚Ì‚à‚Ì
|
---|
37 | private ArrayList<Bid> seedBidList;// ’T�õ‚ÌŽí‚Æ‚È‚éBidList
|
---|
38 | private Bid opponentLastBid;// The opponent's last action.
|
---|
39 | private Bid maxBid;// Bid with the highest possible utility.
|
---|
40 | private boolean flag_offer_bestbid_opponent = false;
|
---|
41 | private HashMap<Bid, Double> offeredBidMap;// ‘ŠŽè‚ÌOffer‚µ‚½Bid‚ð•Û‘¶‚µ‚Ä‚¨‚HashMap
|
---|
42 | private HashMap<String, Double> offeredMyBidMap;// Ž©•ª‚ÌOffer‚µ‚½Bid‚ð•Û‘¶‚µ‚Ä‚¨‚HashMap
|
---|
43 | private int countReSA = 0;
|
---|
44 | private double lastTime;
|
---|
45 | private boolean isFirstAction = false;
|
---|
46 | private boolean isSecondAction = false;
|
---|
47 | private ArrayList<Bid> offerBidLists = new ArrayList<Bid>();
|
---|
48 | private int firstOfferIndex = 0;
|
---|
49 | private int reOfferCount = 0;
|
---|
50 | private boolean isFirstSession;
|
---|
51 | private int actionType = 1;
|
---|
52 | private int offered_count = 0;
|
---|
53 | private double SAmax;
|
---|
54 |
|
---|
55 | private WhaleSessionData prevwData;
|
---|
56 |
|
---|
57 | public WhaleAgent() {
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Initialize the target utility to MAX(rv, max). Where rv is the
|
---|
62 | * reservation value of the preference profile and max is the highest
|
---|
63 | * utility received on the current preference profile.
|
---|
64 | */
|
---|
65 | @Override
|
---|
66 | public void init() {
|
---|
67 | // System.out.println("++ init here ++");
|
---|
68 |
|
---|
69 | Bid bid = utilitySpace.getDomain().getRandomBid(null);
|
---|
70 | SAmax = utilitySpace.getUtilityWithDiscount(
|
---|
71 | getBidSA(bid, 10000, 0.999, 0.90, 0), 0.0);
|
---|
72 |
|
---|
73 | // System.out.println("**SAmax "+SAmax);
|
---|
74 | setName("WhaleAgent");
|
---|
75 | // Serializable prev = this.loadSessionData();//
|
---|
76 | // ‘O‰ñ‚ÌŠl“¾Œø—p’l
|
---|
77 | // if (prev != null) {
|
---|
78 | // double previousOutcome = (Double) prev;
|
---|
79 | // MINIMUM_BID_UTILITY =
|
---|
80 | // Math.max(Math.max(utilitySpace.getReservationValueUndiscounted(),previousOutcome),
|
---|
81 | // 0.85);
|
---|
82 | // } else {
|
---|
83 | // MINIMUM_BID_UTILITY =
|
---|
84 | // Math.max(utilitySpace.getReservationValueUndiscounted(), 0.85);
|
---|
85 | // }
|
---|
86 | //
|
---|
87 | offered_sum = 0.0;
|
---|
88 | offered_count = 0;
|
---|
89 | MINIMUM_BID_UTILITY = 0.90;
|
---|
90 | initPrevSessionData();
|
---|
91 | // HashMap‚Ì�‰Šú‰»
|
---|
92 | offeredBidMap = new HashMap<Bid, Double>();
|
---|
93 | offeredMyBidMap = new HashMap<String, Double>();
|
---|
94 |
|
---|
95 | // predictType(true);
|
---|
96 |
|
---|
97 | // System.out.println("Minimum bid utility: " + MINIMUM_BID_UTILITY);
|
---|
98 | }
|
---|
99 |
|
---|
100 | // Žc‚莞ŠÔ‚ðŒ©‚Ä
|
---|
101 | // Offer‚·‚é�@ƒrƒbƒh‚Ì�Å‘å’l‚ð‰º‚°‚é
|
---|
102 | // Žc‚莞ŠÔ‚ðŒ©‚Ä Accept‚·‚é�@
|
---|
103 | public void calculateMyBid() {
|
---|
104 |
|
---|
105 | }
|
---|
106 |
|
---|
107 | private void calculateMinBidUtil() {
|
---|
108 | double time = timeline.getTime();
|
---|
109 | System.out.println("calculateMinBidUtil");
|
---|
110 | System.out.println("++ time : " + time);
|
---|
111 | double discount = utilitySpace.getDiscountFactor();
|
---|
112 | if (discount < 1.0) {
|
---|
113 | // Š„ˆøŒø—p‚ ‚è
|
---|
114 | MINIMUM_BID_UTILITY = 1.0 * Math.pow(discount, time);
|
---|
115 | } else {
|
---|
116 | // Š„ˆøŒø—p‚È‚µ
|
---|
117 | MINIMUM_BID_UTILITY = 1.0 - time;
|
---|
118 | }
|
---|
119 |
|
---|
120 | // System.out.println("Minimum bid utility: " + MINIMUM_BID_UTILITY);
|
---|
121 | }
|
---|
122 |
|
---|
123 | @Override
|
---|
124 | public String getVersion() {
|
---|
125 | return "1.0";
|
---|
126 | }
|
---|
127 |
|
---|
128 | @Override
|
---|
129 | public String getName() {
|
---|
130 | return "WhaleAgent";
|
---|
131 | }
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * ƒZƒbƒVƒ‡ƒ“ƒf�[ƒ^‚𕜌³‚·‚é
|
---|
135 | */
|
---|
136 | public void initPrevSessionData() {
|
---|
137 |
|
---|
138 | try {
|
---|
139 |
|
---|
140 | // System.out.println("Session Start Data");
|
---|
141 | // System.out.println("**sessionsTotal : "+sessionsTotal);
|
---|
142 | // System.out.println("**sessionNr : "+sessionNr);
|
---|
143 |
|
---|
144 | Serializable prev = this.loadSessionData();
|
---|
145 |
|
---|
146 | if (prev != null) {
|
---|
147 |
|
---|
148 | // WhaleSessionDataAll wAll = (WhaleSessionDataAll) prev;
|
---|
149 | WhaleSessionData wData = (WhaleSessionData) prev;
|
---|
150 | prevwData = wData;
|
---|
151 | HashMap<Bid, Double> tmpMap = new HashMap<Bid, Double>();
|
---|
152 | for (int i = 0; i < prevwData.bidLists.size(); i++) {
|
---|
153 | tmpMap.put(prevwData.bidLists.get(i),
|
---|
154 | utilitySpace.getUtility(prevwData.bidLists.get(i)));
|
---|
155 | }
|
---|
156 |
|
---|
157 | // Sort
|
---|
158 | TreeMap<Bid, Double> treeMap = new TreeMap<Bid, Double>(
|
---|
159 | new MapComparator(tmpMap));
|
---|
160 | treeMap.putAll(tmpMap);
|
---|
161 |
|
---|
162 | prevwData.bidLists = new ArrayList<Bid>();
|
---|
163 | for (Bid bid : treeMap.keySet()) {
|
---|
164 | prevwData.bidLists.add(bid);
|
---|
165 | }
|
---|
166 |
|
---|
167 | if (wData.getUtil >= 0.9) {
|
---|
168 | // ‘O‰ñ‚ÌUtility‚ª�‚‚¢Žž =>
|
---|
169 | // ‚»‚ÌBid‚ð‚·‚®‚ÉOffer‚·‚é‚悤‚É‚·‚é�iDiscount‚ª‚ ‚é‚Æ‚«�j
|
---|
170 | reOfferCount = 1;
|
---|
171 | isFirstAction = true;
|
---|
172 | offerBidLists.add(wData.accesptedBid);
|
---|
173 |
|
---|
174 | } else if (wData.getUtil >= 0.8) {
|
---|
175 | reOfferCount = 1;
|
---|
176 | isFirstAction = true;
|
---|
177 | offerBidLists.add(wData.accesptedBid);
|
---|
178 | }
|
---|
179 | // System.out.println(prev);
|
---|
180 | isFirstSession = false;
|
---|
181 | } else {
|
---|
182 | reOfferCount = 0;
|
---|
183 | isFirstSession = true;
|
---|
184 | offerBidLists = new ArrayList<Bid>();// �‰Šú‰»
|
---|
185 | }
|
---|
186 |
|
---|
187 | actionType = predictType(false);// Actionƒpƒ^�[ƒ“‚ð•Ï�X‚·‚é
|
---|
188 | // if(isFirstAction == false && actionType == 2){
|
---|
189 | // isFirstAction = true;
|
---|
190 | // }
|
---|
191 |
|
---|
192 | } catch (Exception e) {
|
---|
193 | // TODO Auto-generated catch block
|
---|
194 | e.printStackTrace();
|
---|
195 | }
|
---|
196 | }
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * Set the target utility for the next match on the same preference profile.
|
---|
200 | * If the received utility is higher than the current target, save the
|
---|
201 | * received utility as the new target utility.
|
---|
202 | */
|
---|
203 | @Override
|
---|
204 | public void endSession(NegotiationResult result) {
|
---|
205 | // System.out.println("endSession");
|
---|
206 | if (result.getMyDiscountedUtility() > MINIMUM_BID_UTILITY) {
|
---|
207 | // System.out.println("saveSession");
|
---|
208 | saveSessionData(new Double(result.getMyDiscountedUtility()));
|
---|
209 | // saveSessionData(offeredBidMap);
|
---|
210 | }
|
---|
211 | // System.out.println(result);
|
---|
212 | if (!result.isAgreement()) {
|
---|
213 | // �‡ˆÓ‚Å‚«‚È‚©‚Á‚½Žž
|
---|
214 |
|
---|
215 | // ŽŸ‰ñ‚©‚ç‘˦‚·‚é‚悤‚É‚·‚é
|
---|
216 | }
|
---|
217 |
|
---|
218 | ArrayList<Bid> bidLists;
|
---|
219 | double sumUtil = 0.0;
|
---|
220 | // HashMap<Bid, Double> bestMaps = getBestBids(3);
|
---|
221 | if (isFirstSession) {
|
---|
222 | bidLists = new ArrayList<Bid>();
|
---|
223 | } else {
|
---|
224 | sumUtil = prevwData.sumUtil + result.getMyDiscountedUtility();// recalculate
|
---|
225 | bidLists = new ArrayList<Bid>(prevwData.bidLists);
|
---|
226 |
|
---|
227 | }
|
---|
228 |
|
---|
229 | bidLists.add(result.getLastBid());
|
---|
230 |
|
---|
231 | WhaleSessionData sessionData = new WhaleSessionData(result.getLastBid(),
|
---|
232 | getBestBidOpponent(), result.getMyDiscountedUtility(),
|
---|
233 | result.isAgreement(), bidLists, sumUtil, actionType);
|
---|
234 |
|
---|
235 | saveSessionData(sessionData);
|
---|
236 | // System.out.println("**save");
|
---|
237 |
|
---|
238 | // TreeMap<Bid, Double> treeMap = new TreeMap<Bid, Double>(new
|
---|
239 | // IntegerMapComparator(bestMaps));
|
---|
240 | // treeMap.putAll(bestMaps);
|
---|
241 | // System.out.println(treeMap.values());
|
---|
242 |
|
---|
243 | }
|
---|
244 |
|
---|
245 | /**
|
---|
246 | * Offer‚·‚é‘O‚ÉHashMap‚É•Û‘¶‚·‚éƒ�ƒ\ƒbƒh
|
---|
247 | *
|
---|
248 | * @param bid
|
---|
249 | * @return
|
---|
250 | */
|
---|
251 | public Action preOffer(Bid bid) {
|
---|
252 | // Offer‚·‚é‘O‚ÉHashMap‚ÉŽ©•ª‚ªOffer‚µ‚½Bid‚ð•Û‘¶‚µ‚Ä‚¨‚
|
---|
253 | offeredMyBidMap.put(bid.toString(),
|
---|
254 | utilitySpace.getUtilityWithDiscount(bid, timeline.getTime()));
|
---|
255 | return new Offer(getAgentID(), bid);
|
---|
256 | }
|
---|
257 |
|
---|
258 | /**
|
---|
259 | * �¡‚Ü‚ÅŽ©•ª‚ªOffer‚µ‚Ä‚«‚½Bid‚©‚Ç‚¤‚©
|
---|
260 | *
|
---|
261 | * @param bid
|
---|
262 | * @return
|
---|
263 | */
|
---|
264 | public Boolean isCollideBid(Bid bid) {
|
---|
265 | if (offeredMyBidMap.containsKey(bid.toString())) {
|
---|
266 | return true;
|
---|
267 | } else {
|
---|
268 | return false;
|
---|
269 | }
|
---|
270 | }
|
---|
271 |
|
---|
272 | public Bid getBestSeedBid() {
|
---|
273 |
|
---|
274 | double best_util = 0.0;
|
---|
275 | Bid bestBid = utilitySpace.getDomain().getRandomBid(null);
|
---|
276 | // ‰ß‹Ž‚ÌBid‚æ‚èˆê’è‚Ì’l‚æ‚è‘å‚«‚¢Bid‚ðƒ‰ƒ“ƒ_ƒ€‚ÅSeed‚Æ‚µ‚Ä�Ì—p
|
---|
277 | for (Bid bid : offeredBidMap.keySet()) {
|
---|
278 | double recent_util = utilitySpace.getUtilityWithDiscount(bid,
|
---|
279 | timeline.getTime());
|
---|
280 | if (recent_util > best_util) {
|
---|
281 | bestBid = bid;
|
---|
282 | best_util = recent_util;
|
---|
283 | }
|
---|
284 | }
|
---|
285 | return bestBid;
|
---|
286 | }
|
---|
287 |
|
---|
288 | public Bid getMinBidMaps(HashMap<Bid, Double> maps) {
|
---|
289 | double min_util = 1.0;
|
---|
290 | Bid minBid = null;
|
---|
291 | for (Bid bid : maps.keySet()) {
|
---|
292 | double util = maps.get(bid);
|
---|
293 | if (min_util >= util) {
|
---|
294 | min_util = util;
|
---|
295 | minBid = bid;
|
---|
296 | }
|
---|
297 | }
|
---|
298 | return minBid;
|
---|
299 | }
|
---|
300 |
|
---|
301 | public HashMap<Bid, Double> getBestBids(int count) {
|
---|
302 | HashMap<Bid, Double> maps = new HashMap<Bid, Double>();
|
---|
303 |
|
---|
304 | try {
|
---|
305 |
|
---|
306 | // Sort
|
---|
307 | TreeMap<Bid, Double> treeMap = new TreeMap<Bid, Double>(
|
---|
308 | new MapComparator(offeredBidMap));
|
---|
309 | treeMap.putAll(offeredBidMap);
|
---|
310 |
|
---|
311 | int i = 0;
|
---|
312 | for (Bid bid : treeMap.keySet()) {
|
---|
313 | if (i < count) {
|
---|
314 | double recent_util;
|
---|
315 | recent_util = utilitySpace.getUtility(bid);
|
---|
316 |
|
---|
317 | maps.put(bid, recent_util);
|
---|
318 | }
|
---|
319 | i++;
|
---|
320 | }
|
---|
321 |
|
---|
322 | } catch (Exception e) {
|
---|
323 | // TODO Auto-generated catch block
|
---|
324 | e.printStackTrace();
|
---|
325 | }
|
---|
326 |
|
---|
327 | return maps;
|
---|
328 |
|
---|
329 | }
|
---|
330 |
|
---|
331 | /**
|
---|
332 | * ‘ŠŽè‚ÌOffer‚µ‚Ä‚«‚½Bid‚Ì‚¤‚¿�Å�‚‚ÌŒø—p’l‚ðŽ�‚‚à‚Ì‚ðŽæ“¾‚·‚é
|
---|
333 | *
|
---|
334 | * @return
|
---|
335 | */
|
---|
336 | public Bid getBestBidOpponent() {
|
---|
337 | double best_util = 0.0;
|
---|
338 | Bid bestBid = null;
|
---|
339 | // ‰ß‹Ž‚ÌBid‚æ‚èˆê’è‚Ì’l‚æ‚è‘å‚«‚¢Bid‚ðƒ‰ƒ“ƒ_ƒ€‚ÅSeed‚Æ‚µ‚Ä�Ì—p
|
---|
340 | for (Bid bid : offeredBidMap.keySet()) {
|
---|
341 | double recent_util = utilitySpace.getUtilityWithDiscount(bid,
|
---|
342 | timeline.getTime());
|
---|
343 | if (recent_util > best_util) {
|
---|
344 | bestBid = bid;
|
---|
345 | best_util = recent_util;
|
---|
346 | }
|
---|
347 | }
|
---|
348 | return bestBid;
|
---|
349 | }
|
---|
350 |
|
---|
351 | /**
|
---|
352 | * ‘ŠŽè‚Ì’ñˆÄ‚µ‚Ä‚«‚½Bid‚©‚çƒxƒXƒg‚ÈBid‚ðŽæ“¾‚·‚é
|
---|
353 | *
|
---|
354 | * @return
|
---|
355 | */
|
---|
356 | public Action getBestBidByOppo(int type) {
|
---|
357 |
|
---|
358 | Bid bestBid = getBestBidOpponent();
|
---|
359 | double best_util = utilitySpace.getUtilityWithDiscount(bestBid,
|
---|
360 | timeline.getTime());
|
---|
361 | if (flag_offer_bestbid_opponent == true || type == 0) {
|
---|
362 | // ‘ŠŽè‚ÌBestBid‚ðOffer‚µ‚½‚Ì‚É‹‘”Û‚³‚ꂽŽž
|
---|
363 | // System.out.println("**newoffer");
|
---|
364 | // ‘ŠŽè‚ÌBestBidŽü•Ó‚ð’T�õ
|
---|
365 | return preOffer(getNeighborBid(bestBid));
|
---|
366 | // return getBidLowSA(bestBid,100, 0.9,best_util,0);
|
---|
367 | }
|
---|
368 |
|
---|
369 | if (best_util >= utilitySpace
|
---|
370 | .getReservationValueWithDiscount(timeline.getTime())
|
---|
371 | && type == 1) {
|
---|
372 | // ‘ŠŽè‚ÌBestBid‚ðOffer‚·‚é
|
---|
373 | flag_offer_bestbid_opponent = true;
|
---|
374 |
|
---|
375 | return preOffer(bestBid);
|
---|
376 | } else {
|
---|
377 | Bid bid = utilitySpace.getDomain().getRandomBid(null);// ƒ‰ƒ“ƒ_ƒ€‚ÉBid‚ð�¶�¬
|
---|
378 | return preOffer(getNeighborBid(opponentLastBid));
|
---|
379 | // return getBidSA(bid);
|
---|
380 | }
|
---|
381 |
|
---|
382 | // Random rnd = new Random();
|
---|
383 | // if(rnd.nextInt(20000) % 5 == 0 ){
|
---|
384 | // //5‰ñ‚É1‰ñ‚ÍŽ©—R‚ÉOffer‚·‚é
|
---|
385 | // Bid bid = utilitySpace.getDomain().getRandomBid();//
|
---|
386 | // ƒ‰ƒ“ƒ_ƒ€‚ÉBid‚ð�¶�¬
|
---|
387 | // return getBidSA(bid);
|
---|
388 | // }
|
---|
389 |
|
---|
390 | // return new Offer(bestBid);
|
---|
391 | }
|
---|
392 |
|
---|
393 | /**
|
---|
394 | * i‰ñ‚©‚P‰ñtrue‚Æ‚È‚éƒ�ƒ\ƒbƒh
|
---|
395 | *
|
---|
396 | * @param i
|
---|
397 | * @return
|
---|
398 | */
|
---|
399 | public boolean getRandomTrue(int i) {
|
---|
400 | Random rnd = new Random();
|
---|
401 | int random_int = rnd.nextInt(10000);
|
---|
402 | return random_int % i == 0;
|
---|
403 |
|
---|
404 | }
|
---|
405 |
|
---|
406 | /**
|
---|
407 | * offeredBidMap‚æ‚èŒø—p’l‚Ì�‚‚¢BidŒS‚ðŽæ“¾‚·‚é
|
---|
408 | */
|
---|
409 | public Bid getSeedBid() {
|
---|
410 | seedBidList = new ArrayList<Bid>();
|
---|
411 |
|
---|
412 | // ‰ß‹Ž‚ÌBid‚æ‚èˆê’è‚Ì’l‚æ‚è‘å‚«‚¢Bid‚ðƒ‰ƒ“ƒ_ƒ€‚ÅSeed‚Æ‚µ‚Ä�Ì—p
|
---|
413 | for (Bid bid : offeredBidMap.keySet()) {
|
---|
414 | if (offeredBidMap.get(bid) > 0) {// TODO�@‚¢‚‚ˆÈ�ã‚Ìutil‚ðSeed‚Æ‚µ‚Ä�Ì—p‚·‚é‚©
|
---|
415 | seedBidList.add(bid);
|
---|
416 | }
|
---|
417 | }
|
---|
418 |
|
---|
419 | if (getRandomTrue(5)) {
|
---|
420 |
|
---|
421 | return utilitySpace.getDomain().getRandomBid(null);// ƒ‰ƒ“ƒ_ƒ€‚ÉBid‚ð�¶�¬
|
---|
422 | } else {
|
---|
423 | if (!seedBidList.isEmpty() && seedBidList.size() > 3) {
|
---|
424 | Random rnd = new Random();
|
---|
425 | int seed_id = rnd.nextInt(seedBidList.size() - 1);// •Ï�X‚·‚é
|
---|
426 | Bid seedBid = seedBidList.get(seed_id);
|
---|
427 |
|
---|
428 | return seedBid;
|
---|
429 |
|
---|
430 | } else {
|
---|
431 | // ‚Ü‚¾‘ŠŽè‚©‚ç‚ÌBid‚ª‚È‚¢‚Æ‚«
|
---|
432 | return utilitySpace.getDomain().getRandomBid(null);// ƒ‰ƒ“ƒ_ƒ€‚ÉBid‚ð�¶�¬
|
---|
433 |
|
---|
434 | }
|
---|
435 | }
|
---|
436 |
|
---|
437 | }
|
---|
438 |
|
---|
439 | /**
|
---|
440 | * Retrieve the bid from the opponent's last action.
|
---|
441 | */
|
---|
442 | @Override
|
---|
443 | public void ReceiveMessage(Action opponentAction) {
|
---|
444 |
|
---|
445 | opponentLastBid = DefaultAction.getBidFromAction(opponentAction);// ‘ŠŽè‚ÌlastBid
|
---|
446 |
|
---|
447 | if (opponentLastBid != null) {
|
---|
448 |
|
---|
449 | // ‘ŠŽè‚ÌOffer‚µ‚Ä‚«‚½Bid‚ðŽæ“¾‚µ�A•Û‘¶‚·‚é
|
---|
450 | double time = timeline.getTime();// Œo‰ßŽžŠÔ‚ðŽæ“¾
|
---|
451 | double offeredUtility = utilitySpace
|
---|
452 | .getUtilityWithDiscount(opponentLastBid, time);// discount‚³‚ꂽ‚à‚Ì‚ðŽæ“¾
|
---|
453 | offeredBidMap.put(opponentLastBid, offeredUtility);// HashMap‚É•Û‘¶‚·‚é
|
---|
454 | offered_count += 1;
|
---|
455 | offered_sum += offeredUtility;
|
---|
456 | }
|
---|
457 |
|
---|
458 | // System.out.println("+ oopo : "+opponentLastBid.getValues());
|
---|
459 | // System.out.println("+ReservationValue :
|
---|
460 | // "+utilitySpace.getReservationValue());
|
---|
461 | // System.out.println("++ opponet : "+getUtility(opponentLastBid));
|
---|
462 | // TODO
|
---|
463 | // lastBid‚ÌŠˆ—p�@‚µ‚«‚¢’l‚ð‰º‚°‚½‚è‚·‚é
|
---|
464 | // System.out.println("Time : "+timeline.getTime());
|
---|
465 |
|
---|
466 | // MINIMUM_BID_UTILITY_OFFER = sigmoid(timeline.getTime());
|
---|
467 | // MINIMUM_BID_UTILITY = sigmoid(timeline.getTime());
|
---|
468 |
|
---|
469 | }
|
---|
470 |
|
---|
471 | /**
|
---|
472 | * ‘ŠŽè‚Ì�s“®ƒpƒ^�[ƒ“‚©‚玩•ª‚Ì�s“®ƒpƒ^�[ƒ“‚ðŒˆ‚ß‚é
|
---|
473 | *
|
---|
474 | * @return
|
---|
475 | */
|
---|
476 | public int predictType(boolean isPre) {
|
---|
477 | if (isPre == false) {
|
---|
478 | // System.out.println(offered_count);
|
---|
479 | // System.out.println(offerBidLists.size());
|
---|
480 | // System.out.println("**offeredBidMap.size() =
|
---|
481 | // "+offeredBidMap.size());
|
---|
482 | // System.out.println("**offered_count = "+offered_count);
|
---|
483 | if (offered_count > 10
|
---|
484 | && offered_count > 2 * offeredBidMap.size()) {
|
---|
485 | // System.out.println("** 2 count");
|
---|
486 | return 2;
|
---|
487 | }
|
---|
488 | //
|
---|
489 | }
|
---|
490 |
|
---|
491 | if (isFirstSession) {
|
---|
492 | // ‰ß‹Ž‚ÌBid‚ª‚È‚¢�ê�‡
|
---|
493 | // System.out.println("** 1 first");
|
---|
494 | return 1;
|
---|
495 | } else {
|
---|
496 | // ‘O‰ñ‚Ì�î•ñ‚ð—˜—p‚·‚é
|
---|
497 |
|
---|
498 | if (prevwData.isAgreement == false) {
|
---|
499 | // System.out.println("** 2 not agreement");
|
---|
500 | return 2;
|
---|
501 | }
|
---|
502 | if (prevwData.getUtil < 0.7 * SAmax) {
|
---|
503 | // System.out.println("** 2 low util");
|
---|
504 | return 2;
|
---|
505 | }
|
---|
506 |
|
---|
507 | double sumUtil = prevwData.sumUtil;// ‚±‚̃ZƒbƒVƒ‡ƒ“‚Ü‚Å‚Ì�‡Œv
|
---|
508 | double avgUtil = sumUtil / (sessionNr + 1.0);
|
---|
509 | // System.out.println("**sessionNr "+sessionNr);
|
---|
510 | // •½‹Ï‚ª�‚‚¯‚ê‚Î
|
---|
511 | if (avgUtil > 0.8 * SAmax) {
|
---|
512 | // System.out.println("** 1 avg");
|
---|
513 | return 1;
|
---|
514 | }
|
---|
515 | // System.out.println("** prev end"+prevwData.actionType);
|
---|
516 | return prevwData.actionType;
|
---|
517 | }
|
---|
518 | // System.out.println("** 2 end");
|
---|
519 | // return 2;
|
---|
520 | }
|
---|
521 |
|
---|
522 | /**
|
---|
523 | * ‹‹C‚Ì�s“®‚ð‚·‚éƒ�ƒ\ƒbƒh
|
---|
524 | *
|
---|
525 | * @return
|
---|
526 | */
|
---|
527 | public Action actionType1() {
|
---|
528 | // System.out.println("**actionType1");
|
---|
529 | try {
|
---|
530 | // ŽžŠÔ‚ð�l—¶‚µ‚Ämin
|
---|
531 | // bid‚ð•Ï‰»‚³‚¹‚é
|
---|
532 | // calculateMinBidUtil();
|
---|
533 | // System.out.println("hashmap_count : "+offeredBidMap.size());
|
---|
534 | // System.out.println("hashmap_util : "+offered_sum);
|
---|
535 | // System.out.println("hashmap_avg :
|
---|
536 | // "+offered_sum/offeredBidMap.size());
|
---|
537 | if (isFirstAction) {
|
---|
538 |
|
---|
539 | for (int i = firstOfferIndex; i < offerBidLists.size(); i++) {
|
---|
540 | firstOfferIndex++;
|
---|
541 | if (firstOfferIndex == offerBidLists.size() - 1) {
|
---|
542 | isFirstAction = false;
|
---|
543 | reOfferCount = 2;
|
---|
544 | }
|
---|
545 | // System.out.println("**new first offer");
|
---|
546 | isSecondAction = true;
|
---|
547 | return preOffer(offerBidLists.get(i));
|
---|
548 | }
|
---|
549 | }
|
---|
550 |
|
---|
551 | if (opponentLastBid != null && utilitySpace
|
---|
552 | .getUtility(opponentLastBid) >= MINIMUM_BID_UTILITY) {
|
---|
553 | return new Accept(getAgentID(), opponentLastBid);
|
---|
554 |
|
---|
555 | } else if (opponentLastBid != null && utilitySpace.getUtility(
|
---|
556 | opponentLastBid) >= MINIMUM_BID_UTILITY - 0.05) {
|
---|
557 | // Œë�·‚ª0.1‚ÌŽž
|
---|
558 | if (getRandomTrue(3)) {
|
---|
559 | return new Accept(getAgentID(), opponentLastBid);
|
---|
560 | }
|
---|
561 |
|
---|
562 | }
|
---|
563 | if (!isFirstSession && !isFirstAction && reOfferCount == 2) {
|
---|
564 |
|
---|
565 | if (prevwData.acceptTime / 1.3 <= timeline.getTime()) {
|
---|
566 |
|
---|
567 | reOfferCount = 3;
|
---|
568 | return preOffer(offerBidLists.get(0));
|
---|
569 |
|
---|
570 | }
|
---|
571 | }
|
---|
572 | if (!isFirstSession && !isFirstAction && reOfferCount == 3) {
|
---|
573 | if (prevwData.acceptTime / 1.2 <= timeline.getTime()) {
|
---|
574 | reOfferCount = 4;
|
---|
575 | return preOffer(offerBidLists.get(0));
|
---|
576 | }
|
---|
577 | }
|
---|
578 | if (!isFirstSession && !isFirstAction && reOfferCount == 4) {
|
---|
579 | if (prevwData.acceptTime / 1.1 <= timeline.getTime()) {
|
---|
580 | reOfferCount = 5;
|
---|
581 | return preOffer(offerBidLists.get(0));
|
---|
582 | }
|
---|
583 | }
|
---|
584 | if (!isFirstSession && !isFirstAction && reOfferCount == 5) {
|
---|
585 | if (prevwData.acceptTime <= timeline.getTime()) {
|
---|
586 | reOfferCount = 6;
|
---|
587 | return preOffer(offerBidLists.get(0));
|
---|
588 | }
|
---|
589 | }
|
---|
590 | if (timeline.getTime() > 0.995) {
|
---|
591 | double util = getUtility(opponentLastBid);
|
---|
592 | if (util > utilitySpace
|
---|
593 | .getReservationValueWithDiscount(timeline)) { // TODO:Resevation
|
---|
594 | // Value‚Æ”ä‚ׂé•K—v‚ ‚è
|
---|
595 | return new Accept(getAgentID(), opponentLastBid);
|
---|
596 | }
|
---|
597 | // Žc‚莞ŠÔ‚ª�‚È‚¢Žž
|
---|
598 | // return
|
---|
599 | // getBestBidByOppo(1);//‘˦ƒ‚�[ƒh‚ÌŽž�H
|
---|
600 |
|
---|
601 | }
|
---|
602 | if (timeline.getTime() > 0.97) {
|
---|
603 |
|
---|
604 | // Žc‚莞ŠÔ‚ª�‚È‚¢Žž
|
---|
605 | // return getBestBidByOppo(1);
|
---|
606 |
|
---|
607 | }
|
---|
608 | if (timeline.getTime() > 0.91) {
|
---|
609 |
|
---|
610 | double util = utilitySpace.getUtilityWithDiscount(
|
---|
611 | getBestBidOpponent(), timeline.getTime());
|
---|
612 | if (util < MINIMUM_BID_UTILITY) {
|
---|
613 | // MINIMUM_BID_UTILITY =
|
---|
614 | // util*1.05;//TODO:‚±‚±‚ðƒRƒ�ƒ“ƒgƒAƒEƒg‚·‚é‚Æ“¦‚°‚é“®‚«‚ð‚·‚é‚Ì‚Å‚¢‚¢‚©‚à�H
|
---|
615 | }
|
---|
616 | // Žc‚莞ŠÔ‚ª�‚È‚¢Žž
|
---|
617 | // return getBestBidByOppo(0);
|
---|
618 |
|
---|
619 | }
|
---|
620 |
|
---|
621 | if (timeline.getTime() > 0.8) {
|
---|
622 | MINIMUM_BID_UTILITY = 0.99 * MINIMUM_BID_UTILITY * SAmax;
|
---|
623 |
|
---|
624 | // }else if(timeline.getTime() > 0.5){
|
---|
625 | // Bid bid =
|
---|
626 | // getSeedBid();//’T�õ‚ÌSeedBid‚ðŽæ“¾‚·‚é
|
---|
627 | // return getBidLowSA(bid,5000, 0.98,0.8,0);//5000
|
---|
628 | }
|
---|
629 |
|
---|
630 | if (timeline.getTime() > 0.1) {
|
---|
631 | // Bid bid = getSeedBid();
|
---|
632 |
|
---|
633 | Bid bid = getNeighborBid(getBestSeedBid());
|
---|
634 | double util = getUtility(bid);
|
---|
635 | if (util >= MINIMUM_BID_UTILITY) {
|
---|
636 | // System.out.println("** neighbor");
|
---|
637 | return preOffer(bid);
|
---|
638 | }
|
---|
639 | // return getBidHighClimb(bid, 50, 0.90, 0);
|
---|
640 | // return getBidLowSA(bid, 10000,0.999,0.90,0);
|
---|
641 | // return getBidLowSA(bid, 1000,0.8,0.90,0);
|
---|
642 |
|
---|
643 | // Bid bid = getBestBidOpponent();
|
---|
644 | // return getBidHighClimb(bid, 10000,0.98,0.90,0);
|
---|
645 | }
|
---|
646 |
|
---|
647 | // System.out.println("t1 : "+Timeline.Type.Time);
|
---|
648 | // System.out.println("t2 : "+timeline.getType());
|
---|
649 | if (timeline.getType().equals(Timeline.Type.Time)) {
|
---|
650 | // sleep(0.0005);//just for fun
|
---|
651 | }
|
---|
652 | // return getRandomBid(MINIMUM_BID_UTILITY);
|
---|
653 | // return getMyBid();
|
---|
654 |
|
---|
655 | // ƒ‰ƒ“ƒ_ƒ€‚ÉBid‚ð�¶�¬‚·‚é
|
---|
656 | // Bid bid = utilitySpace.getDomain().getRandomBid();//
|
---|
657 | // ƒ‰ƒ“ƒ_ƒ€‚ÉBid‚ð�¶�¬
|
---|
658 |
|
---|
659 | } catch (Exception e) {
|
---|
660 | // TODO Auto-generated catch block
|
---|
661 | e.printStackTrace();
|
---|
662 | }
|
---|
663 | // return getBidSA(bid);
|
---|
664 |
|
---|
665 | // Bid bid =
|
---|
666 | // getBestSeedBid();//’T�õ‚ÌSeedBid‚ðŽæ“¾‚·‚é
|
---|
667 | Bid bid = getSeedBid();
|
---|
668 | // return getBidLowSA(bid, 10000,0.98,0.90,0);
|
---|
669 | // System.out.println("** SA last");
|
---|
670 | return getBidLowSA(bid, 10000, 0.98, MINIMUM_BID_UTILITY * SAmax, 0);
|
---|
671 | }
|
---|
672 |
|
---|
673 | /**
|
---|
674 | * Žã‹C‚Ì�s“®‚ð‚·‚éƒ�ƒ\ƒbƒh
|
---|
675 | *
|
---|
676 | * @return
|
---|
677 | */
|
---|
678 | public Action actionType2() {
|
---|
679 |
|
---|
680 | // System.out.println("**actionType2");
|
---|
681 | try {
|
---|
682 | // ŽžŠÔ‚ð�l—¶‚µ‚Ämin
|
---|
683 | // bid‚ð•Ï‰»‚³‚¹‚é
|
---|
684 | // calculateMinBidUtil();
|
---|
685 | // System.out.println("hashmap_count : "+offeredBidMap.size());
|
---|
686 | // System.out.println("hashmap_util : "+offered_sum);
|
---|
687 | // System.out.println("hashmap_avg :
|
---|
688 | // "+offered_sum/offeredBidMap.size());
|
---|
689 | if (isFirstAction) {
|
---|
690 |
|
---|
691 | for (int i = firstOfferIndex; i < offerBidLists.size(); i++) {
|
---|
692 | firstOfferIndex++;
|
---|
693 | if (firstOfferIndex == offerBidLists.size() - 1) {
|
---|
694 | isFirstAction = false;
|
---|
695 | reOfferCount = 2;
|
---|
696 | }
|
---|
697 |
|
---|
698 | return preOffer(offerBidLists.get(i));
|
---|
699 | }
|
---|
700 | }
|
---|
701 |
|
---|
702 | if (opponentLastBid != null && utilitySpace
|
---|
703 | .getUtility(opponentLastBid) >= MINIMUM_BID_UTILITY) {
|
---|
704 | return new Accept(getAgentID(), opponentLastBid);
|
---|
705 |
|
---|
706 | } else if (opponentLastBid != null && utilitySpace.getUtility(
|
---|
707 | opponentLastBid) >= MINIMUM_BID_UTILITY - 0.05) {
|
---|
708 | // Œë�·‚ª0.1‚ÌŽž
|
---|
709 | if (getRandomTrue(3)) {
|
---|
710 | return new Accept(getAgentID(), opponentLastBid);
|
---|
711 | }
|
---|
712 |
|
---|
713 | }
|
---|
714 | if (!isFirstSession && !isFirstAction && reOfferCount == 2) {
|
---|
715 |
|
---|
716 | if (prevwData.acceptTime / 1.3 <= timeline.getTime()) {
|
---|
717 |
|
---|
718 | reOfferCount = 3;
|
---|
719 | return preOffer(offerBidLists.get(0));
|
---|
720 |
|
---|
721 | }
|
---|
722 | }
|
---|
723 | if (!isFirstSession && !isFirstAction && reOfferCount == 3) {
|
---|
724 | if (prevwData.acceptTime / 1.2 <= timeline.getTime()) {
|
---|
725 | reOfferCount = 4;
|
---|
726 | return preOffer(offerBidLists.get(0));
|
---|
727 | }
|
---|
728 | }
|
---|
729 | if (!isFirstSession && !isFirstAction && reOfferCount == 4) {
|
---|
730 | if (prevwData.acceptTime / 1.1 <= timeline.getTime()) {
|
---|
731 | reOfferCount = 5;
|
---|
732 | return preOffer(offerBidLists.get(0));
|
---|
733 | }
|
---|
734 | }
|
---|
735 | if (!isFirstSession && !isFirstAction && reOfferCount == 5) {
|
---|
736 | if (prevwData.acceptTime <= timeline.getTime()) {
|
---|
737 | reOfferCount = 6;
|
---|
738 | return preOffer(offerBidLists.get(0));
|
---|
739 | }
|
---|
740 | }
|
---|
741 | if (timeline.getTime() > 0.99) {
|
---|
742 | double util = getUtility(opponentLastBid);
|
---|
743 | if (util > utilitySpace.getReservationValue()) { // TODO:Resevation
|
---|
744 | // Value‚Æ”ä‚ׂé•K—v‚ ‚è
|
---|
745 | return new Accept(getAgentID(), opponentLastBid);
|
---|
746 | }
|
---|
747 | // Žc‚莞ŠÔ‚ª�‚È‚¢Žž
|
---|
748 | return getBestBidByOppo(1);// ‘˦ƒ‚�[ƒh‚ÌŽž�H
|
---|
749 |
|
---|
750 | }
|
---|
751 | if (timeline.getTime() > 0.97) {
|
---|
752 |
|
---|
753 | // Žc‚莞ŠÔ‚ª�‚È‚¢Žž
|
---|
754 | return getBestBidByOppo(1);
|
---|
755 |
|
---|
756 | }
|
---|
757 | if (timeline.getTime() > 0.91) {
|
---|
758 |
|
---|
759 | double util = utilitySpace.getUtilityWithDiscount(
|
---|
760 | getBestBidOpponent(), timeline.getTime());
|
---|
761 | if (util < MINIMUM_BID_UTILITY) {
|
---|
762 | MINIMUM_BID_UTILITY = util * 0.99 * SAmax;
|
---|
763 | }
|
---|
764 | // Žc‚莞ŠÔ‚ª�‚È‚¢Žž
|
---|
765 | return getBestBidByOppo(0);
|
---|
766 |
|
---|
767 | }
|
---|
768 |
|
---|
769 | if (timeline.getTime() > 0.8) {
|
---|
770 | MINIMUM_BID_UTILITY = 0.85 * SAmax;
|
---|
771 |
|
---|
772 | }
|
---|
773 |
|
---|
774 | if (timeline.getTime() > 0.5) {
|
---|
775 | // Bid bid =
|
---|
776 | // getSeedBid();//’T�õ‚ÌSeedBid‚ðŽæ“¾‚·‚é
|
---|
777 | //
|
---|
778 | // return getBidHighClimb(bid, 5, 0.80, 0);
|
---|
779 |
|
---|
780 | Bid bid = getNeighborBid(getBestSeedBid());
|
---|
781 | double util = getUtility(bid);
|
---|
782 | if (util >= MINIMUM_BID_UTILITY) {
|
---|
783 | return preOffer(bid);
|
---|
784 | }
|
---|
785 | // return getBidLowSA(bid,5000, 0.98,0.8,0);//5000
|
---|
786 | }
|
---|
787 |
|
---|
788 | if (timeline.getTime() > 0.5) {
|
---|
789 | MINIMUM_BID_UTILITY = 0.70 * SAmax;
|
---|
790 |
|
---|
791 | }
|
---|
792 | if (timeline.getTime() > 0.1) {
|
---|
793 | Bid bid = getNeighborBid(getBestSeedBid());
|
---|
794 | double util = getUtility(bid);
|
---|
795 | if (util >= 0.80 * SAmax) {
|
---|
796 | return preOffer(bid);
|
---|
797 | }
|
---|
798 |
|
---|
799 | // Bid bid = getSeedBid();
|
---|
800 | // return getBidHighClimb(bid, 5, 0.80, 0);
|
---|
801 | // return getBidLowSA(bid, 10000,0.98,0.90,0);
|
---|
802 | // Bid bid = getBestBidOpponent();
|
---|
803 | // return getBidHighClimb(bid, 10000,0.98,0.90,0);
|
---|
804 | }
|
---|
805 |
|
---|
806 | // System.out.println("t1 : "+Timeline.Type.Time);
|
---|
807 | // System.out.println("t2 : "+timeline.getType());
|
---|
808 | // if (timeline.getType().equals(Timeline.Type.Time)) {
|
---|
809 | // sleep(0.0005);//just for fun
|
---|
810 | // }
|
---|
811 | // return getRandomBid(MINIMUM_BID_UTILITY);
|
---|
812 | // return getMyBid();
|
---|
813 |
|
---|
814 | // ƒ‰ƒ“ƒ_ƒ€‚ÉBid‚ð�¶�¬‚·‚é
|
---|
815 | // Bid bid = utilitySpace.getDomain().getRandomBid();//
|
---|
816 | // ƒ‰ƒ“ƒ_ƒ€‚ÉBid‚ð�¶�¬
|
---|
817 |
|
---|
818 | } catch (Exception e) {
|
---|
819 | // TODO Auto-generated catch block
|
---|
820 | e.printStackTrace();
|
---|
821 | }
|
---|
822 | // return getBidSA(bid);
|
---|
823 |
|
---|
824 | Bid bid = getBestSeedBid();// ’T�õ‚ÌSeedBid‚ðŽæ“¾‚·‚é
|
---|
825 |
|
---|
826 | return getBidLowSA(bid, 10000, 0.98, 0.85 * SAmax, 0);
|
---|
827 |
|
---|
828 | }
|
---|
829 |
|
---|
830 | /**
|
---|
831 | * Accept if the utility of the opponent's is higher than the target
|
---|
832 | * utility; else return a random bid with a utility at least equal to the
|
---|
833 | * target utility.
|
---|
834 | */
|
---|
835 | @Override
|
---|
836 | public Action chooseAction() {// Ž©•ª‚ª‰½‚ð‚·‚é‚©
|
---|
837 | // System.out.println("chooseAction");
|
---|
838 |
|
---|
839 | actionType = predictType(false);// Actionƒpƒ^�[ƒ“‚ð•Ï�X‚·‚é
|
---|
840 |
|
---|
841 | if (actionType == 1) {
|
---|
842 | return actionType1();// ‹‹C‚Ì�s“®ƒpƒ^�[ƒ“
|
---|
843 | } else {
|
---|
844 | return actionType2();// Žã‹C‚Ì�s“®ƒpƒ^�[ƒ“
|
---|
845 | }
|
---|
846 |
|
---|
847 | }
|
---|
848 |
|
---|
849 | public double sigmoid(double x) {
|
---|
850 | // return (Math.exp(3*x)+Math.exp(-5*x))/(Math.exp(3*x)+Math.exp(-x));
|
---|
851 | // return 1.0/(Math.pow(x, 30)+Math.exp(Math.pow(x, 100)));
|
---|
852 | // return -1.0/(1+Math.exp(2/x))+1;
|
---|
853 | // return -4.0/(10+Math.exp(2.0/x))+1;
|
---|
854 |
|
---|
855 | //
|
---|
856 | // return
|
---|
857 | // (-1)/(1+Math.exp(-50*(x-1)))+1;//0.9•t‹ß‚©‚ç‹}�~‰º�@
|
---|
858 | return (-1) / (1 + Math.exp(-20 * (x - 1))) + 1;// 0.9•t‹ß‚©‚ç‹}�~‰º�@
|
---|
859 | // return (Math.pow(x,
|
---|
860 | // 16)+Math.exp(10*x-15))/(Math.exp(-x)+Math.exp(x))+1;//x=0.8•t‹ß‚©‚牺‚ª‚è�Ay=0.8‚‚ç‚¢‚܂ʼnº‚ª‚é
|
---|
861 | // return
|
---|
862 | // Math.sin(x)*Math.cos(x)+Math.exp(-x)-0.05;//�Å�‰ŠÉ‚�A�Ō㌵‚µ‚Œ^
|
---|
863 | // double result=
|
---|
864 | // Math.sin(x)*Math.cos(x)+Math.exp(-10*x+Math.log(10*x+0.02))+0.5;//‚Q‚‚̃s�[ƒN‚ðŽ�‚ƒOƒ‰ƒt
|
---|
865 |
|
---|
866 | // if(result < 0.8){
|
---|
867 | // return 0.8;
|
---|
868 | // }else{
|
---|
869 | // return result;
|
---|
870 | // }
|
---|
871 | // y=sin({x})|_cdot_cos({x})+exp({-10x+log({10x+0.02})})+0.5
|
---|
872 |
|
---|
873 | // return (-1.0)/(1.0+Math.exp(-30.0*x+31))+1;
|
---|
874 | }
|
---|
875 |
|
---|
876 | /**
|
---|
877 | * Žü•ÓBid‚ð’T�õ‚·‚é
|
---|
878 | *
|
---|
879 | * @param bid
|
---|
880 | * @return
|
---|
881 | */
|
---|
882 | public Bid getNeighborBid(Bid bid) {
|
---|
883 | try {
|
---|
884 | Random rnd = new Random();
|
---|
885 | int step = 3;
|
---|
886 | for (int i = 0; i < bid.getIssues().size(); i++) {
|
---|
887 | double bf = utilitySpace.getUtility(bid);
|
---|
888 | Bid bidChange = new Bid(bid);
|
---|
889 |
|
---|
890 | int flag = rnd.nextBoolean() ? 1 : -1;// 1=> plus , -1 => minus
|
---|
891 | // int change_id = i;
|
---|
892 | int change_id = rnd.nextInt(bid.getIssues().size());// •Ï�X‚·‚é
|
---|
893 | IssueInteger issueInteger = (IssueInteger) bid.getIssues()
|
---|
894 | .get(change_id);
|
---|
895 | int issueId = issueInteger.getNumber();
|
---|
896 | ValueInteger issueValue = (ValueInteger) bid.getValue(issueId);
|
---|
897 | int issueValueInt = Integer.valueOf(issueValue.toString())
|
---|
898 | .intValue();
|
---|
899 | int max = issueInteger.getUpperBound();// �Å‘å’l
|
---|
900 | int min = issueInteger.getLowerBound();// �Å�¬’l
|
---|
901 |
|
---|
902 | if (issueValueInt >= min && issueValueInt <= max) {
|
---|
903 |
|
---|
904 | if (issueValueInt + step > max) {
|
---|
905 | // ‘«‚·‚Æ–â‘è‚ ‚è
|
---|
906 | flag = -1;
|
---|
907 | } else if (issueValueInt - step < min) {
|
---|
908 | // ˆø‚‚Æ–â‘è‚ ‚è
|
---|
909 | flag = 1;
|
---|
910 | }
|
---|
911 |
|
---|
912 | }
|
---|
913 |
|
---|
914 | Value valueInteger = new ValueInteger(
|
---|
915 | issueValueInt + flag * step);// change
|
---|
916 | // value
|
---|
917 |
|
---|
918 | bidChange = bidChange.putValue(issueId, valueInteger);// change
|
---|
919 |
|
---|
920 | double af = utilitySpace.getUtility(bidChange);
|
---|
921 |
|
---|
922 | double bf_cost = 1.0 - bf;
|
---|
923 | double af_cost = 1.0 - af;
|
---|
924 |
|
---|
925 | if (af_cost < bf_cost) {
|
---|
926 | bid = new Bid(bidChange);
|
---|
927 | }
|
---|
928 |
|
---|
929 | }
|
---|
930 |
|
---|
931 | } catch (Exception e) {
|
---|
932 | // TODO Auto-generated catch block
|
---|
933 | e.printStackTrace();
|
---|
934 | }
|
---|
935 | return (bid);
|
---|
936 |
|
---|
937 | }
|
---|
938 |
|
---|
939 | /**
|
---|
940 | * ‰·“x’á‚ß‚ÌSA
|
---|
941 | *
|
---|
942 | * @param bid
|
---|
943 | * @param T
|
---|
944 | * @return
|
---|
945 | */
|
---|
946 | public Action getBidLowSA(Bid bid, double T, double cool, double bias,
|
---|
947 | int loop_count) {
|
---|
948 |
|
---|
949 | // �Ä‚«“Ý‚µ–@
|
---|
950 | // Bid bid = utilitySpace.getDomain().getRandomBid();//
|
---|
951 | // ƒ‰ƒ“ƒ_ƒ€‚ÉBid‚ð�¶�¬
|
---|
952 | // System.out.println(bid.getValues());
|
---|
953 | int count = 0;
|
---|
954 | try {
|
---|
955 | // T = 10000;
|
---|
956 |
|
---|
957 | int step = 1;// •Ï�X‚·‚é•�
|
---|
958 | // double cool = 0.6;// ‰·“x‚ð‰º‚°‚é•�
|
---|
959 | Random rnd = new Random();
|
---|
960 |
|
---|
961 | while (T > 0.0001) {
|
---|
962 | boolean ok_flag = false;
|
---|
963 | int ok_count = 0;
|
---|
964 | count++;
|
---|
965 | double bf = utilitySpace.getUtility(bid);
|
---|
966 | Bid bidChange = new Bid(bid);
|
---|
967 |
|
---|
968 | // bid change
|
---|
969 |
|
---|
970 | int change_id = rnd.nextInt(bid.getIssues().size());// •Ï�X‚·‚é
|
---|
971 | // IssueId‚̃Cƒ“ƒfƒbƒNƒX‚ðŒˆ’è
|
---|
972 | IssueInteger issueInteger = (IssueInteger) bid.getIssues()
|
---|
973 | .get(change_id);
|
---|
974 | int issueId = issueInteger.getNumber();
|
---|
975 | ValueInteger issueValue = (ValueInteger) bid.getValue(issueId);
|
---|
976 | int issueValueInt = Integer.valueOf(issueValue.toString())
|
---|
977 | .intValue();
|
---|
978 | int max = issueInteger.getUpperBound();// �Å‘å’l
|
---|
979 | int min = issueInteger.getLowerBound();// �Å�¬’l
|
---|
980 |
|
---|
981 | int flag = rnd.nextBoolean() ? 1 : -1;// 1=> plus , -1 => minus
|
---|
982 | if (issueValueInt >= min && issueValueInt <= max) {
|
---|
983 |
|
---|
984 | if (issueValueInt + step > max) {
|
---|
985 | // ‘«‚·‚Æ–â‘è‚ ‚è
|
---|
986 | flag = -1;
|
---|
987 | } else if (issueValueInt - step < min) {
|
---|
988 | // ˆø‚‚Æ–â‘è‚ ‚è
|
---|
989 | flag = 1;
|
---|
990 | }
|
---|
991 |
|
---|
992 | }
|
---|
993 |
|
---|
994 | Value valueInteger = new ValueInteger(
|
---|
995 | issueValueInt + flag * step);// change
|
---|
996 | // value
|
---|
997 | bidChange = bidChange.putValue(issueId, valueInteger);// change
|
---|
998 |
|
---|
999 | double af = utilitySpace.getUtility(bidChange);
|
---|
1000 |
|
---|
1001 | double bf_cost = 1.0 - bf;
|
---|
1002 | double af_cost = 1.0 - af;
|
---|
1003 | // System.out.println("af : "+af);
|
---|
1004 | double p = Math.pow(Math.E, -Math.abs(af_cost - bf_cost) / T);
|
---|
1005 | // System.out.println(" p = "+p);
|
---|
1006 | // System.out.println(" rnd = "+rnd.nextDouble());
|
---|
1007 |
|
---|
1008 | // System.out.println(rnd.nextDouble() < p);
|
---|
1009 | if ((af_cost < bf_cost || rnd.nextDouble() < p)
|
---|
1010 | && af <= MINIMUM_BID_UTILITY_OFFER) {
|
---|
1011 | bid = new Bid(bidChange);
|
---|
1012 | if (af >= bias) {// TODO:
|
---|
1013 | // ‚±‚ê‚Å‚¢‚¢‚Ì‚©�H
|
---|
1014 | ok_flag = true;
|
---|
1015 |
|
---|
1016 | if (ok_count >= rnd.nextInt(3)) {
|
---|
1017 | ok_count = 0;
|
---|
1018 | ok_flag = false;
|
---|
1019 | // break;
|
---|
1020 | }
|
---|
1021 |
|
---|
1022 | }
|
---|
1023 | if (ok_flag) {
|
---|
1024 | ok_count++;
|
---|
1025 | }
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 | NumberFormat format = NumberFormat.getInstance();
|
---|
1029 | format.setMaximumFractionDigits(1);
|
---|
1030 |
|
---|
1031 | T = T * cool;
|
---|
1032 |
|
---|
1033 | }
|
---|
1034 |
|
---|
1035 | if (utilitySpace.getUtility(bid) < bias) {
|
---|
1036 | // System.out.println("**reSA");
|
---|
1037 |
|
---|
1038 | countReSA = loop_count + 1;
|
---|
1039 | double t_cool = (0.999 - cool) / 20.0;
|
---|
1040 | return getBidLowSA(bid, step, cool + t_cool, bias,
|
---|
1041 | loop_count + 1);
|
---|
1042 | }
|
---|
1043 | } catch (Exception e) {
|
---|
1044 | // TODO Auto-generated catch block
|
---|
1045 | e.printStackTrace();
|
---|
1046 | }
|
---|
1047 | // System.out.println(count);
|
---|
1048 | if (loop_count > 0) {
|
---|
1049 | // System.out.println("loop_count: "+loop_count);
|
---|
1050 | }
|
---|
1051 |
|
---|
1052 | return preOffer(bid);
|
---|
1053 | }
|
---|
1054 |
|
---|
1055 | public Bid getBidSA(Bid bid, double T, double cool, double bias,
|
---|
1056 | int loop_count) {
|
---|
1057 |
|
---|
1058 | // �Ä‚«“Ý‚µ–@
|
---|
1059 | // Bid bid = utilitySpace.getDomain().getRandomBid();//
|
---|
1060 | // ƒ‰ƒ“ƒ_ƒ€‚ÉBid‚ð�¶�¬
|
---|
1061 | // System.out.println(bid.getValues());
|
---|
1062 | int count = 0;
|
---|
1063 | try {
|
---|
1064 | // T = 10000;
|
---|
1065 |
|
---|
1066 | int step = 1;// •Ï�X‚·‚é•�
|
---|
1067 | // double cool = 0.6;// ‰·“x‚ð‰º‚°‚é•�
|
---|
1068 | Random rnd = new Random();
|
---|
1069 |
|
---|
1070 | while (T > 0.0001) {
|
---|
1071 | boolean ok_flag = false;
|
---|
1072 | int ok_count = 0;
|
---|
1073 | count++;
|
---|
1074 | double bf = utilitySpace.getUtility(bid);
|
---|
1075 | Bid bidChange = new Bid(bid);
|
---|
1076 |
|
---|
1077 | // bid change
|
---|
1078 |
|
---|
1079 | int change_id = rnd.nextInt(bid.getIssues().size());// •Ï�X‚·‚é
|
---|
1080 | // IssueId‚̃Cƒ“ƒfƒbƒNƒX‚ðŒˆ’è
|
---|
1081 | IssueInteger issueInteger = (IssueInteger) bid.getIssues()
|
---|
1082 | .get(change_id);
|
---|
1083 | int issueId = issueInteger.getNumber();
|
---|
1084 | ValueInteger issueValue = (ValueInteger) bid.getValue(issueId);
|
---|
1085 | int issueValueInt = Integer.valueOf(issueValue.toString())
|
---|
1086 | .intValue();
|
---|
1087 | int max = issueInteger.getUpperBound();// �Å‘å’l
|
---|
1088 | int min = issueInteger.getLowerBound();// �Å�¬’l
|
---|
1089 |
|
---|
1090 | int flag = rnd.nextBoolean() ? 1 : -1;// 1=> plus , -1 => minus
|
---|
1091 | if (issueValueInt >= min && issueValueInt <= max) {
|
---|
1092 |
|
---|
1093 | if (issueValueInt + step > max) {
|
---|
1094 | // ‘«‚·‚Æ–â‘è‚ ‚è
|
---|
1095 | flag = -1;
|
---|
1096 | } else if (issueValueInt - step < min) {
|
---|
1097 | // ˆø‚‚Æ–â‘è‚ ‚è
|
---|
1098 | flag = 1;
|
---|
1099 | }
|
---|
1100 |
|
---|
1101 | }
|
---|
1102 |
|
---|
1103 | Value valueInteger = new ValueInteger(
|
---|
1104 | issueValueInt + flag * step);// change
|
---|
1105 | // value
|
---|
1106 | bidChange = bidChange.putValue(issueId, valueInteger);// change
|
---|
1107 |
|
---|
1108 | double af = utilitySpace.getUtility(bidChange);
|
---|
1109 |
|
---|
1110 | double bf_cost = 1.0 - bf;
|
---|
1111 | double af_cost = 1.0 - af;
|
---|
1112 | // System.out.println("af : "+af);
|
---|
1113 | double p = Math.pow(Math.E, -Math.abs(af_cost - bf_cost) / T);
|
---|
1114 | // System.out.println(" p = "+p);
|
---|
1115 | // System.out.println(" rnd = "+rnd.nextDouble());
|
---|
1116 |
|
---|
1117 | // System.out.println(rnd.nextDouble() < p);
|
---|
1118 | if ((af_cost < bf_cost || rnd.nextDouble() < p)
|
---|
1119 | && af <= MINIMUM_BID_UTILITY_OFFER) {
|
---|
1120 | bid = new Bid(bidChange);
|
---|
1121 | if (af >= bias) {// TODO:
|
---|
1122 | // ‚±‚ê‚Å‚¢‚¢‚Ì‚©�H
|
---|
1123 | ok_flag = true;
|
---|
1124 |
|
---|
1125 | if (ok_count >= rnd.nextInt(3)) {
|
---|
1126 | ok_count = 0;
|
---|
1127 | ok_flag = false;
|
---|
1128 | // break;
|
---|
1129 | }
|
---|
1130 |
|
---|
1131 | }
|
---|
1132 | if (ok_flag) {
|
---|
1133 | ok_count++;
|
---|
1134 | }
|
---|
1135 | }
|
---|
1136 |
|
---|
1137 | NumberFormat format = NumberFormat.getInstance();
|
---|
1138 | format.setMaximumFractionDigits(1);
|
---|
1139 |
|
---|
1140 | T = T * cool;
|
---|
1141 |
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 | if (utilitySpace.getUtility(bid) < bias) {
|
---|
1145 | // System.out.println("**reSA");
|
---|
1146 |
|
---|
1147 | countReSA = loop_count + 1;
|
---|
1148 | if (loop_count >= 10) {
|
---|
1149 | return bid;
|
---|
1150 | }
|
---|
1151 | double t_cool = (0.999 - cool) / 20.0;
|
---|
1152 | return getBidSA(bid, step, cool + t_cool, bias, loop_count + 1);
|
---|
1153 | }
|
---|
1154 | } catch (Exception e) {
|
---|
1155 | // TODO Auto-generated catch block
|
---|
1156 | e.printStackTrace();
|
---|
1157 | }
|
---|
1158 | // System.out.println(count);
|
---|
1159 | if (loop_count > 0) {
|
---|
1160 | // System.out.println("loop_count: "+loop_count);
|
---|
1161 | }
|
---|
1162 |
|
---|
1163 | return (bid);
|
---|
1164 | }
|
---|
1165 |
|
---|
1166 | /**
|
---|
1167 | * ‰ü—Ç”Å�Ä‚«‚È‚Ü‚µ�•ŽR“o‚è–@
|
---|
1168 | *
|
---|
1169 | * @param bid
|
---|
1170 | * @return
|
---|
1171 | */
|
---|
1172 | public Action getBidHighClimb(Bid bid, int loop, double bias,
|
---|
1173 | int loop_count) {
|
---|
1174 | try {
|
---|
1175 | // T = 10000;
|
---|
1176 |
|
---|
1177 | int count = 0;
|
---|
1178 | int step = 1;// •Ï�X‚·‚é•�
|
---|
1179 | // double cool = 0.6;// ‰·“x‚ð‰º‚°‚é•�
|
---|
1180 | Random rnd = new Random();
|
---|
1181 |
|
---|
1182 | while (loop > count) {
|
---|
1183 | boolean ok_flag = false;
|
---|
1184 | int ok_count = 0;
|
---|
1185 | count++;
|
---|
1186 | double bf = utilitySpace.getUtility(bid);
|
---|
1187 | Bid bidChange = new Bid(bid);
|
---|
1188 |
|
---|
1189 | // bid change
|
---|
1190 |
|
---|
1191 | int change_id = rnd.nextInt(bid.getIssues().size());// •Ï�X‚·‚é
|
---|
1192 | // IssueId‚̃Cƒ“ƒfƒbƒNƒX‚ðŒˆ’è
|
---|
1193 | IssueInteger issueInteger = (IssueInteger) bid.getIssues()
|
---|
1194 | .get(change_id);
|
---|
1195 | int issueId = issueInteger.getNumber();
|
---|
1196 | ValueInteger issueValue = (ValueInteger) bid.getValue(issueId);
|
---|
1197 | int issueValueInt = Integer.valueOf(issueValue.toString())
|
---|
1198 | .intValue();
|
---|
1199 | int max = issueInteger.getUpperBound();// �Å‘å’l
|
---|
1200 | int min = issueInteger.getLowerBound();// �Å�¬’l
|
---|
1201 |
|
---|
1202 | int flag = rnd.nextBoolean() ? 1 : -1;// 1=> plus , -1 => minus
|
---|
1203 | if (issueValueInt >= min && issueValueInt <= max) {
|
---|
1204 |
|
---|
1205 | if (issueValueInt + step > max) {
|
---|
1206 | // ‘«‚·‚Æ–â‘è‚ ‚è
|
---|
1207 | flag = -1;
|
---|
1208 | } else if (issueValueInt - step < min) {
|
---|
1209 | // ˆø‚‚Æ–â‘è‚ ‚è
|
---|
1210 | flag = 1;
|
---|
1211 | }
|
---|
1212 |
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 | Value valueInteger = new ValueInteger(
|
---|
1216 | issueValueInt + flag * step);// change
|
---|
1217 | // value
|
---|
1218 | bidChange = bidChange.putValue(issueId, valueInteger);// change
|
---|
1219 |
|
---|
1220 | double af = utilitySpace.getUtility(bidChange);
|
---|
1221 |
|
---|
1222 | double bf_cost = 1.0 - bf;
|
---|
1223 | double af_cost = 1.0 - af;
|
---|
1224 | // System.out.println("af : "+af);
|
---|
1225 | // double p = Math.pow(Math.E, -Math.abs(af_cost - bf_cost) /
|
---|
1226 | // T);
|
---|
1227 | // System.out.println(" p = "+p);
|
---|
1228 | // System.out.println(" rnd = "+rnd.nextDouble());
|
---|
1229 | if ((af_cost < bf_cost) && af <= MINIMUM_BID_UTILITY_OFFER) {
|
---|
1230 | // count++;
|
---|
1231 | bid = new Bid(bidChange);
|
---|
1232 | if (af >= bias) {// TODO:
|
---|
1233 | // ‚±‚ê‚Å‚¢‚¢‚Ì‚©�H
|
---|
1234 | ok_flag = true;
|
---|
1235 |
|
---|
1236 | if (ok_count >= rnd.nextInt(3)) {
|
---|
1237 | ok_count = 0;
|
---|
1238 | ok_flag = false;
|
---|
1239 | // break;
|
---|
1240 | }
|
---|
1241 |
|
---|
1242 | }
|
---|
1243 | if (ok_flag) {
|
---|
1244 | ok_count++;
|
---|
1245 | }
|
---|
1246 | }
|
---|
1247 |
|
---|
1248 | NumberFormat format = NumberFormat.getInstance();
|
---|
1249 | format.setMaximumFractionDigits(1);
|
---|
1250 |
|
---|
1251 | // T = T * cool;
|
---|
1252 |
|
---|
1253 | }
|
---|
1254 |
|
---|
1255 | if (utilitySpace.getUtility(bid) < bias) {
|
---|
1256 | // System.out.println("**reSA");
|
---|
1257 |
|
---|
1258 | countReSA = loop_count + 1;
|
---|
1259 | // double t_cool = (0.999 - cool)/20.0;
|
---|
1260 | if (loop_count > 5) {
|
---|
1261 |
|
---|
1262 | return getBidLowSA(bid, 10000, 0.98, bias, loop_count);
|
---|
1263 | }
|
---|
1264 | // System.out.println("**"+ loop_count);
|
---|
1265 | return getBidHighClimb(bid, loop, bias, loop_count + 1);
|
---|
1266 | }
|
---|
1267 | } catch (Exception e) {
|
---|
1268 | // TODO Auto-generated catch block
|
---|
1269 | e.printStackTrace();
|
---|
1270 | }
|
---|
1271 | // System.out.println(count);
|
---|
1272 | if (loop_count > 0) {
|
---|
1273 | // System.out.println("loop_count: "+loop_count);
|
---|
1274 | }
|
---|
1275 |
|
---|
1276 | return preOffer(bid);
|
---|
1277 | }
|
---|
1278 |
|
---|
1279 | /**
|
---|
1280 | * SA–@‚É‚æ‚éBid‚Ì’T�õƒ�ƒ\ƒbƒh
|
---|
1281 | *
|
---|
1282 | * @param bid
|
---|
1283 | * Ží‚Æ‚È‚éBid
|
---|
1284 | * @return
|
---|
1285 | */
|
---|
1286 | public Bid getBidSA(Bid bid) {
|
---|
1287 |
|
---|
1288 | // �Ä‚«“Ý‚µ–@
|
---|
1289 | // Bid bid = utilitySpace.getDomain().getRandomBid();//
|
---|
1290 | // ƒ‰ƒ“ƒ_ƒ€‚ÉBid‚ð�¶�¬
|
---|
1291 | // System.out.println(bid.getValues());
|
---|
1292 |
|
---|
1293 | try {
|
---|
1294 |
|
---|
1295 | double T = 10000;// 10000
|
---|
1296 | int step = 1;// •Ï�X‚·‚é•�
|
---|
1297 | double cool = 0.999;// ‰·“x‚ð‰º‚°‚é•�
|
---|
1298 | Random rnd = new Random();
|
---|
1299 |
|
---|
1300 | while (T > 0.0001) {
|
---|
1301 | double bf = utilitySpace.getUtility(bid);
|
---|
1302 | Bid bidChange = new Bid(bid);
|
---|
1303 |
|
---|
1304 | // bid change
|
---|
1305 |
|
---|
1306 | int change_id = rnd.nextInt(bid.getIssues().size());// •Ï�X‚·‚é
|
---|
1307 | // IssueId‚̃Cƒ“ƒfƒbƒNƒX‚ðŒˆ’è
|
---|
1308 | IssueInteger issueInteger = (IssueInteger) bid.getIssues()
|
---|
1309 | .get(change_id);
|
---|
1310 | int issueId = issueInteger.getNumber();
|
---|
1311 | ValueInteger issueValue = (ValueInteger) bid.getValue(issueId);
|
---|
1312 | int issueValueInt = Integer.valueOf(issueValue.toString())
|
---|
1313 | .intValue();
|
---|
1314 | int max = issueInteger.getUpperBound();// �Å‘å’l
|
---|
1315 | int min = issueInteger.getLowerBound();// �Å�¬’l
|
---|
1316 |
|
---|
1317 | int flag = rnd.nextBoolean() ? 1 : -1;// 1=> plus , -1 => minus
|
---|
1318 | if (issueValueInt >= min && issueValueInt <= max) {
|
---|
1319 |
|
---|
1320 | if (issueValueInt + step > max) {
|
---|
1321 | // ‘«‚·‚Æ–â‘è‚ ‚è
|
---|
1322 | flag = -1;
|
---|
1323 | } else if (issueValueInt - step < min) {
|
---|
1324 | // ˆø‚‚Æ–â‘è‚ ‚è
|
---|
1325 | flag = 1;
|
---|
1326 | }
|
---|
1327 |
|
---|
1328 | }
|
---|
1329 |
|
---|
1330 | Value valueInteger = new ValueInteger(
|
---|
1331 | issueValueInt + flag * step);// change
|
---|
1332 | // value
|
---|
1333 | bidChange = bidChange.putValue(issueId, valueInteger);// change
|
---|
1334 |
|
---|
1335 | double af = utilitySpace.getUtility(bidChange);
|
---|
1336 |
|
---|
1337 | double bf_cost = 1.0 - bf;
|
---|
1338 | double af_cost = 1.0 - af;
|
---|
1339 |
|
---|
1340 | double p = Math.pow(Math.E, -Math.abs(af_cost - bf_cost) / T);
|
---|
1341 | // System.out.println(" p = "+p);
|
---|
1342 | // System.out.println(" rnd = "+rnd.nextDouble());
|
---|
1343 | if ((af_cost < bf_cost || rnd.nextDouble() < p)
|
---|
1344 | && af <= MINIMUM_BID_UTILITY_OFFER) {
|
---|
1345 | bid = new Bid(bidChange);
|
---|
1346 | }
|
---|
1347 | NumberFormat format = NumberFormat.getInstance();
|
---|
1348 | format.setMaximumFractionDigits(1);
|
---|
1349 |
|
---|
1350 | T = T * cool;
|
---|
1351 |
|
---|
1352 | }
|
---|
1353 |
|
---|
1354 | } catch (Exception e) {
|
---|
1355 | // TODO Auto-generated catch block
|
---|
1356 | e.printStackTrace();
|
---|
1357 | }
|
---|
1358 |
|
---|
1359 | // String saveValue = "";
|
---|
1360 | // for (Entry<Integer, Value> e : bid.getValues().entrySet()) {
|
---|
1361 | // // System.out.println(" e: "+ e.getValue());
|
---|
1362 | // saveValue += e.getValue().toString();
|
---|
1363 | // }
|
---|
1364 |
|
---|
1365 | // System.out.println("e:"+saveValue);
|
---|
1366 |
|
---|
1367 | // if(new Double(format.format(af)) == 1){
|
---|
1368 |
|
---|
1369 | // if (!bidList10.contains(saveValue)) {
|
---|
1370 | // bidList10.add(saveValue);
|
---|
1371 | // System.out.println(bidList10.size());
|
---|
1372 | // } else {
|
---|
1373 | // System.out.println("ERRRRRORRORORRORRORORORO");
|
---|
1374 | // }
|
---|
1375 | // }
|
---|
1376 | return (bid);
|
---|
1377 | }
|
---|
1378 |
|
---|
1379 | @Override
|
---|
1380 | public String getDescription() {
|
---|
1381 | return "ANAC2014 compatible with non-linear utility spaces";
|
---|
1382 | }
|
---|
1383 |
|
---|
1384 | }
|
---|
1385 |
|
---|
1386 | class WhaleSessionData implements Serializable {
|
---|
1387 | Bid accesptedBid;
|
---|
1388 | double acceptTime;
|
---|
1389 | double getUtil;
|
---|
1390 | double sumUtil;
|
---|
1391 | int actionType;
|
---|
1392 | ArrayList<Bid> bidLists;
|
---|
1393 | Bid offeredBid;
|
---|
1394 | boolean isAgreement;
|
---|
1395 |
|
---|
1396 | public WhaleSessionData(Bid accesptedBid, Bid offeredBid, double getUtil,
|
---|
1397 | boolean isAgreement, ArrayList<Bid> bidLists, double sumUtil,
|
---|
1398 | int actionType) {
|
---|
1399 | this.accesptedBid = accesptedBid;
|
---|
1400 | this.offeredBid = offeredBid;
|
---|
1401 | this.getUtil = getUtil;
|
---|
1402 | this.isAgreement = isAgreement;
|
---|
1403 | this.bidLists = bidLists;
|
---|
1404 | this.sumUtil = sumUtil;
|
---|
1405 | this.actionType = actionType;
|
---|
1406 | }
|
---|
1407 | }
|
---|
1408 |
|
---|
1409 | //
|
---|
1410 | // class WhaleSessionDataAll implements Serializable{
|
---|
1411 | // ArrayList<WhaleSessionData> All;
|
---|
1412 | // public WhaleSessionDataAll(WhaleSessionData add){
|
---|
1413 | // this.All.add(add);
|
---|
1414 | // }
|
---|
1415 | //
|
---|
1416 | // public void add(WhaleSessionData add) {
|
---|
1417 | // this.All.add(add);
|
---|
1418 | // }
|
---|
1419 | // public WhaleSessionData get(int index){
|
---|
1420 | // return this.All.get(index);
|
---|
1421 | // }
|
---|
1422 | //
|
---|
1423 | // }
|
---|
1424 | /**
|
---|
1425 | * Map ‚Ì value
|
---|
1426 | * ‚Ń\�[ƒg‚·‚邽‚ß‚Ì”äŠr‚̃Nƒ‰ƒX
|
---|
1427 | */
|
---|
1428 | class MapComparator implements Comparator<Bid> {
|
---|
1429 | private HashMap<Bid, Double> map;
|
---|
1430 |
|
---|
1431 | public MapComparator(HashMap<Bid, Double> map) {
|
---|
1432 | this.map = map;
|
---|
1433 | }
|
---|
1434 |
|
---|
1435 | /**
|
---|
1436 | * key 2‚‚ª—^‚¦‚ç‚ꂽ‚Æ‚«‚É�A‚»‚Ì
|
---|
1437 | * value ‚Å”äŠr
|
---|
1438 | */
|
---|
1439 | @Override
|
---|
1440 | public int compare(Bid key1, Bid key2) {
|
---|
1441 | // value ‚ðŽæ“¾
|
---|
1442 | double value1 = map.get(key1);
|
---|
1443 | double value2 = map.get(key2);
|
---|
1444 | // value ‚Ì�~�‡, value‚ª“™‚µ‚¢‚Æ‚«‚Í key
|
---|
1445 | // ‚ÌŽ«�‘�‡
|
---|
1446 | if (value1 == value2)
|
---|
1447 | return 1;
|
---|
1448 | else if (value1 < value2)
|
---|
1449 | return 1;
|
---|
1450 | else
|
---|
1451 | return -1;
|
---|
1452 | }
|
---|
1453 | }
|
---|