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

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

Initial import : Genius 9.0.0

File size: 6.6 KB
Line 
1package agents.anac.y2015.Atlas3;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import agents.anac.y2015.Atlas3.etc.bidSearch;
7import agents.anac.y2015.Atlas3.etc.negotiatingInfo;
8import agents.anac.y2015.Atlas3.etc.strategy;
9import genius.core.AgentID;
10import genius.core.Bid;
11import genius.core.actions.Accept;
12import genius.core.actions.Action;
13import genius.core.actions.EndNegotiation;
14import genius.core.actions.Inform;
15import genius.core.actions.Offer;
16import genius.core.parties.AbstractNegotiationParty;
17import genius.core.parties.NegotiationInfo;
18import genius.core.utility.AdditiveUtilitySpace;
19
20/**
21 * This is your negotiation party.
22 */
23public class Atlas3 extends AbstractNegotiationParty {
24 private negotiatingInfo negotiatingInfo; // 交渉情報
25 private bidSearch bidSearch; // Bid探索
26 private strategy strategy; // 交渉戦略
27 private double rv; // 留保価格
28 private Bid offeredBid = null; // 提案された合意案候補
29 private int supporter_num = 0; // 支持者数
30 private int CList_index = 0; // CListのインデックス:最終提案フェーズにおける遡行を行うために利用(ConcessionList)
31
32 // デバッグ用
33 public static boolean isPrinting = false; // メッセージを表示する
34
35 @Override
36 public void init(NegotiationInfo info) {
37 super.init(info);
38
39 if (isPrinting) {
40 System.out.println("*** Atlas3 v1.0 ***");
41 }
42
43 negotiatingInfo = new negotiatingInfo(
44 (AdditiveUtilitySpace) utilitySpace);
45 try {
46 bidSearch = new bidSearch((AdditiveUtilitySpace) utilitySpace,
47 negotiatingInfo);
48 } catch (Exception e) {
49 throw new RuntimeException("init failed:" + e, e);
50 }
51 strategy = new strategy((AdditiveUtilitySpace) utilitySpace,
52 negotiatingInfo);
53 rv = utilitySpace.getReservationValue();
54 }
55
56 /**
57 * Each round this method gets called and ask you to accept or offer. The
58 * first party in the first round is a bit different, it can only propose an
59 * offer.
60 *
61 * @param validActions
62 * Either a list containing both accept and offer or only offer.
63 * @return The chosen action.
64 */
65 @SuppressWarnings("rawtypes")
66 @Override
67 // Actionの選択
68 public Action chooseAction(List<Class<? extends Action>> validActions) {
69 double time = timeline.getTime(); // 現在の交渉時刻を取得
70 negotiatingInfo.updateTimeScale(time); // 自身の手番が回ってくる時間間隔を記録
71
72 // 最終提案フェーズにおけるアクション
73 ArrayList<Bid> CList;
74 CList = negotiatingInfo.getPBList();
75 if (time > 1.0 - negotiatingInfo.getTimeScale() * (CList.size() + 1)) {
76 try {
77 return chooseFinalAction(offeredBid, CList);
78 } catch (Exception e) {
79 System.out.println(
80 "最終提案フェーズにおけるActionの選択に失敗しました");
81 e.printStackTrace();
82 }
83 }
84
85 // Accept
86 if (validActions.contains(Accept.class)
87 && strategy.selectAccept(offeredBid, time)) {
88 return new Accept(getPartyId(), offeredBid);
89 }
90
91 // EndNegotiation
92 if (strategy.selectEndNegotiation(time)) {
93 return new EndNegotiation(getPartyId());
94 }
95
96 // Offer
97 return OfferAction();
98 }
99
100 public Action chooseFinalAction(Bid offeredBid, ArrayList<Bid> CList)
101 throws Exception {
102 double offeredBid_util = 0;
103 if (offeredBid != null) {
104 offeredBid_util = utilitySpace.getUtility(offeredBid);
105 }
106 if (CList_index >= CList.size()) {
107 if (offeredBid_util >= rv) {
108 return new Accept(getPartyId(), offeredBid);
109 } // 遡行を行っても合意が失敗する場合,Acceptする
110 else {
111 return OfferAction();
112 }
113 }
114
115 // CListの遡行
116 Bid CBid = CList.get(CList_index);
117 double CBid_util = utilitySpace.getUtility(CBid);
118 if (CBid_util > offeredBid_util && CBid_util > rv) {
119 CList_index++;
120 negotiatingInfo.updateMyBidHistory(CBid);
121 return new Offer(getPartyId(), CBid);
122 } else if (offeredBid_util > rv) {
123 return new Accept(getPartyId(), offeredBid);
124 }
125
126 return OfferAction();
127 }
128
129 public Action OfferAction() {
130 Bid offerBid = bidSearch.getBid(generateRandomBid(),
131 strategy.getThreshold(timeline.getTime()));
132 negotiatingInfo.updateMyBidHistory(offerBid);
133 return new Offer(getPartyId(), offerBid);
134 }
135
136 /**
137 * All offers proposed by the other parties will be received as a message.
138 * You can use this information to your advantage, for example to predict
139 * their utility.
140 *
141 * @param sender
142 * The party that did the action.
143 * @param action
144 * The action that party did.
145 */
146 @Override
147 // 自身以外の交渉参加者のActionを受信
148 public void receiveMessage(AgentID sender, Action action) {
149 super.receiveMessage(sender, action);
150 // Here you can listen to other parties' messages
151 if (isPrinting) {
152 System.out.println("Sender:" + sender + ", Action:" + action);
153 }
154
155 if (action != null) {
156 if (action instanceof Inform
157 && ((Inform) action).getName() == "NumberOfAgents"
158 && ((Inform) action).getValue() instanceof Integer) {
159 Integer opponentsNum = (Integer) ((Inform) action).getValue();
160 negotiatingInfo.updateOpponentsNum(opponentsNum);
161 if (isPrinting) {
162 System.out.println("NumberofNegotiator:"
163 + negotiatingInfo.getNegotiatorNum());
164 }
165 } else if (action instanceof Accept) {
166 if (!negotiatingInfo.getOpponents().contains(sender)) {
167 negotiatingInfo.initOpponent(sender);
168 } // 初出の交渉者は初期化
169 supporter_num++;
170 } else if (action instanceof Offer) {
171 if (!negotiatingInfo.getOpponents().contains(sender)) {
172 negotiatingInfo.initOpponent(sender);
173 } // 初出の交渉者は初期化
174 supporter_num = 1; // supporterをリセット
175 offeredBid = ((Offer) action).getBid(); // 提案された合意案候補
176 try {
177 negotiatingInfo.updateInfo(sender, offeredBid);
178 } // 交渉情報を更新
179 catch (Exception e) {
180 System.out.println(
181 "交渉情報の更新に失敗しました");
182 e.printStackTrace();
183 }
184 } else if (action instanceof EndNegotiation) {
185 }
186
187 // 自身以外が賛成している合意案候補を記録(自身以外のエージェントを1つの交渉者とみなす.そもそも自身以外のエージェントが二人以上非協力であれば,自身の選択に関わらず合意は不可能である)
188 if (supporter_num == negotiatingInfo.getNegotiatorNum() - 1) {
189 if (offeredBid != null) {
190 try {
191 negotiatingInfo.updatePBList(offeredBid);
192 } catch (Exception e) {
193 System.out.println(
194 "PBListの更新に失敗しました"); // PopularBidHistoryを更新
195 e.printStackTrace();
196 }
197 }
198 }
199 }
200 }
201
202 @Override
203 public String getDescription() {
204 return "ANAC2015";
205 }
206
207}
Note: See TracBrowser for help on using the repository browser.