source: src/main/java/agents/anac/y2016/atlas3/Atlas32016.java@ 1

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

Initial import : Genius 9.0.0

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