source: src/main/java/agents/anac/y2015/SENGOKU/SENGOKU.java

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

Initial import : Genius 9.0.0

File size: 10.2 KB
Line 
1package agents.anac.y2015.SENGOKU;
2
3import java.util.List;
4
5import agents.anac.y2015.SENGOKU.etc.bidSearch;
6import agents.anac.y2015.SENGOKU.etc.negotiatingInfo;
7import agents.anac.y2015.SENGOKU.etc.strategy;
8import genius.core.AgentID;
9import genius.core.Bid;
10import genius.core.actions.Accept;
11import genius.core.actions.Action;
12import genius.core.actions.EndNegotiation;
13import genius.core.actions.Inform;
14import genius.core.actions.Offer;
15import genius.core.parties.AbstractNegotiationParty;
16import genius.core.parties.NegotiationInfo;
17import genius.core.utility.AdditiveUtilitySpace;
18
19/**
20 * This is your negotiation party.
21 */
22public class SENGOKU extends AbstractNegotiationParty {
23 private negotiatingInfo negotiatingInfo; // 交渉情報
24 private bidSearch bidSearch; // Bid探索
25 private strategy strategy; // 交渉戦略
26 private Bid offeredBid = null; // 提案された合意案候補
27
28 // デバッグ用
29 public static boolean isPrinting = false; // メッセージを表示する
30
31 // コンストラクター 初期化
32 @Override
33 public void init(NegotiationInfo info) {
34 super.init(info);
35
36 if (isPrinting) {
37 System.out.println("*** SAOPMN_SampleAgent ***");
38 }
39
40 negotiatingInfo = new negotiatingInfo(
41 (AdditiveUtilitySpace) utilitySpace);
42 try {
43 bidSearch = new bidSearch((AdditiveUtilitySpace) utilitySpace,
44 negotiatingInfo);
45 } catch (Exception e) {
46 throw new RuntimeException("init failed:" + e, e);
47 }
48 strategy = new strategy((AdditiveUtilitySpace) utilitySpace,
49 negotiatingInfo, bidSearch);
50 }
51
52 /**
53 * Each round this method gets called and ask you to accept or offer. The
54 * first party in the first round is a bit different, it can only propose an
55 * offer.
56 *
57 * @param validActions
58 * Either a list containing both accept and offer or only offer.
59 * @return The chosen action.
60 */
61
62 // validActions 自分に行動圏があるか!
63 // その行動がAcceptのとき!
64 @SuppressWarnings("rawtypes")
65 @Override
66 // Actionの選択
67 public Action chooseAction(List<Class<? extends Action>> validActions) {
68 if (isPrinting) {
69 System.out.println("-----------------MyTern----------------------"
70 + timeline.getTime() * 180);
71 }
72 double time = timeline.getTime(); // 現在の交渉時刻を取得
73 negotiatingInfo.resetAcceptRate(); // アクセプト率の更新
74 negotiatingInfo.laststrategy(time); // 最後に妥協するとき
75 negotiatingInfo.myActionAccept(); // 自分の行動をアクセプトにする
76 // Acceptのアクションを要求されているとき
77
78 // 一度最大の閾値を保存しておく
79 negotiatingInfo.updateMaxThreshold(strategy.maxthreshold(0));
80 if (time > 0.05) {
81 try {
82 if (isPrinting) {
83 System.out.println("有効値:"
84 + utilitySpace.getUtility(offeredBid));
85 }
86 } catch (Exception e) {
87 // TODO Auto-generated catch block
88 e.printStackTrace();
89 }
90 }
91
92 // 最後の妥協処理
93 if (negotiatingInfo.lastFlag) {
94 if (isPrinting) {
95 System.out.println(
96 "last-------------------------------------------");
97 }
98 return lastAction();
99 }
100
101 // アクセプトの処理
102 if (validActions.contains(Accept.class)
103 && strategy.selectAccept(offeredBid, time)) {
104 if (isPrinting) {
105 System.out.println("MyAction:Accept");
106 }
107 return new Accept(getPartyId(), offeredBid);
108 }
109
110 // EndNegotiation
111 // selectEndNegotiation 時間切れ!
112 if (strategy.selectEndNegotiation(time)
113 || strategy.endNegotieitionFlag) {
114 // System.out.println("flag:"+strategy.endNegotieitionFlag
115 // +"タイム"+strategy.selectEndNegotiation(time));
116 // System.out.println("MyAction:EndNegociation");
117 return new EndNegotiation(getPartyId());
118 }
119
120 // Offer
121 // System.out.println("MyAction:Offer");
122 negotiatingInfo.myActionOffer();
123 return OfferAction();
124 }
125
126 // 自分でオファーするときの選択!
127 public Action OfferAction() {
128 Bid offerBid = bidSearch.shiftBidSerch(generateRandomBid(),
129 strategy.getThreshold(timeline.getTime()));
130 negotiatingInfo.updateMyBidHistory(offerBid);
131 return new Offer(getPartyId(), offerBid);
132 }
133
134 // 最後の処理のメソッド
135 public Action lastAction() {
136 if (isPrinting) {
137 System.out.println("ラストリストの数"
138 + negotiatingInfo.getLastOfferBidNum());
139 }
140
141 if (negotiatingInfo.getLastOfferBidNum() == 0) { // 最後のオファー用リストがなくなったとき
142 if (isPrinting) {
143 System.out.println("カラリストでアクセプト");
144 }
145 return new Accept(getPartyId(), offeredBid);
146 } else { //
147 Bid lastBid = negotiatingInfo.getLastOfferBidHistry();
148 double offerUtil = 0.0;
149 double lastUtil = 0.0;
150 try {
151 offerUtil = utilitySpace.getUtility(offeredBid);
152 } catch (Exception e) {
153 // TODO Auto-generated catch block
154 e.printStackTrace();
155 }
156
157 try {
158 lastUtil = utilitySpace.getUtility(lastBid);
159 } catch (Exception e) {
160 // TODO Auto-generated catch block
161 e.printStackTrace();
162 }
163
164 negotiatingInfo.removeLastOfferBidHistry();
165
166 if (isPrinting) {
167 // System.out.println("自分のオファー"+ lastUtil);
168 // System.out.println("相手オファー" + offerUtil);
169 }
170
171 if (offerUtil > lastUtil) {
172 if (isPrinting) {
173 System.out.println("lastAccept");
174 }
175 return new Accept(getPartyId(), offeredBid);
176 } else {
177 if (isPrinting) {
178 System.out.println("lastOffer");
179 }
180 return new Offer(getPartyId(), lastBid);
181 }
182
183 }
184 }
185
186 // 非協力状態でのオファーのときに閾値調節してからオファーに行く
187 /*
188 * private Bid noCooperateOffer(){ ArrayList<Bid> MyBidHistory =
189 * negotiatingInfo.getMyBidHistory(); while(true){ int flag = 0; Bid
190 * offerBid = bidSearch.getBid(generateRandomBid(), strategy.myThreshold);
191 * for (Bid mybid:MyBidHistory){ if(offerBid.equals(mybid) ){ flag = 1;
192 * continue; } } if(flag == 1){ strategy.myThreshold = strategy.myThreshold
193 * -0.0005; }else{ negotiatingInfo.updateMyBidHistory(offerBid); return
194 * offerBid; } } }
195 */
196
197 /***
198 ** All offers proposed by the other parties will be received as a message.
199 * You can use this information to your advantage, for example to predict
200 * their utility.
201 **
202 ** @param sender
203 * The party that did the action.
204 ** @param action
205 * The action that party did.
206 ***/
207
208 /*
209 * @Override // 自身以外の交渉参加者のActionを受信 //
210 * senderが相手 相手名 //
211 * Actionはどんなアクションでオファーのときは中身
212 * もわかる! // 絶えず相手の情報がわかる
213 * なにもしているのか! public void receiveMessage(Object sender,
214 * Action action) {
215 * //System.out.println("Sender:"+sender+", Action:"+action);
216 *
217 * // 親クラスのメッソドを実行する いじらなくてよし!
218 * super.receiveMessage(sender, action);
219 *
220 * // Here you can listen to other parties' messages //
221 * 表示するのみ! if(isPrinting){
222 * System.out.println("Sender:"+sender+", Action:"+action); }
223 *
224 * //System.out.println("Sender:"+sender+", Action:"+action);
225 *
226 * //アクションがあるとき if (action != null ) {
227 *
228 * //アクセプトをとき! actionの中にAcceptがある if(action
229 * instanceof Accept){ negotiatingInfo.updateAccept(sender);
230 * //System.out.println("アクセプト数"+negotiatingInfo.getAccept());
231 * //System.out.println("アクセプト率"+negotiatingInfo.getAcceptRate()
232 * ); if(!negotiatingInfo.getOpponents().contains(sender)){//
233 * 初出の交渉者は初期化
234 * 相手のリストにないから最初いれていく!
235 * negotiatingInfo.initOpponent(sender);
236 * //negotiatingInfoのopperatersインスタンスに保存している } }
237 *
238 * //相手がオファーを出した時 else if(action instanceof Offer) {
239 * if(!negotiatingInfo.getOpponents().contains(sender)){
240 * negotiatingInfo.initOpponent(sender); } // 初出の交渉者は初期化
241 * offeredBid = ((Offer) action).getBid(); // 提案された合意案候補
242 * try { negotiatingInfo.updateInfo(sender, offeredBid); } //
243 * 交渉情報を更新 catch (Exception e) {
244 * System.out.println("交渉情報の更新に失敗しました");
245 * e.printStackTrace(); } } else {//最初に参加人数の情報を出す
246 * Object obj = ((Object)action); int opponentsNum =
247 * Integer.parseInt(obj.toString().replaceAll("[^0-9]",""));
248 * //相手のナンバーを取る
249 * negotiatingInfo.updateOpponentsNum(opponentsNum); if(isPrinting){
250 * System.out.println("NumberofNegotiator:" +
251 * negotiatingInfo.getNegotiatorNum());} } } }
252 */
253
254 /**
255 * All offers proposed by the other parties will be received as a message.
256 * You can use this information to your advantage, for example to predict
257 * their utility.
258 *
259 * @param sender
260 * The party that did the action.
261 * @param action
262 * The action that party did.
263 */
264 @Override
265 // 自身以外の交渉参加者のActionを受信
266 public void receiveMessage(AgentID sender, Action action) {
267 super.receiveMessage(sender, action);
268 // Here you can listen to other parties' messages
269 if (isPrinting) {
270 System.out.println("Sender:" + sender + ", Action:" + action);
271 }
272
273 if (action != null) {
274 if (action instanceof Inform
275 && ((Inform) action).getName() == "NumberOfAgents"
276 && ((Inform) action).getValue() instanceof Integer) {
277 Integer opponentsNum = (Integer) ((Inform) action).getValue();
278 negotiatingInfo.updateOpponentsNum(opponentsNum);
279 if (isPrinting) {
280 System.out.println("NumberofNegotiator:"
281 + negotiatingInfo.getNegotiatorNum());
282 }
283 } else if (action instanceof Accept) {
284 if (!negotiatingInfo.getOpponents().contains(sender)) {
285 negotiatingInfo.initOpponent(sender);
286 } // 初出の交渉者は初期化
287 } else if (action instanceof Offer) {
288 if (!negotiatingInfo.getOpponents().contains(sender)) {
289 negotiatingInfo.initOpponent(sender);
290 } // 初出の交渉者は初期化
291 offeredBid = ((Offer) action).getBid(); // 提案された合意案候補
292 try {
293 negotiatingInfo.updateInfo(sender, offeredBid);
294 } // 交渉情報を更新
295 catch (Exception e) {
296 System.out.println(
297 "交渉情報の更新に失敗しました");
298 e.printStackTrace();
299 }
300 } else if (action instanceof EndNegotiation) {
301 }
302 }
303 }
304
305 @Override
306 public String getDescription() {
307 return "ANAC2015";
308 }
309
310}
Note: See TracBrowser for help on using the repository browser.