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