source: src/main/java/agents/anac/y2016/farma/Farma.java

Last change on this file was 46, checked in by Tim Baarslag, 6 years ago

agents get their getUtilitySpace() from the API, not the info object anymore

File size: 5.2 KB
RevLine 
[1]1package agents.anac.y2016.farma;
2
3import java.util.List;
4
5import agents.anac.y2016.farma.etc.bidSearch;
6import agents.anac.y2016.farma.etc.negotiationInfo;
7import agents.anac.y2016.farma.etc.negotiationStrategy;
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.timeline.TimeLineInfo;
18import genius.core.utility.AbstractUtilitySpace;
19
20/**
21 * This is your negotiation party.
22 */
23
24public class Farma extends AbstractNegotiationParty {
25 private TimeLineInfo timeLineInfo; // タイムライン
26 private AbstractUtilitySpace utilitySpace;
27 private negotiationInfo negotiationInfo; // 交渉情報
28 private bidSearch bidSearch; // 合意案候補の探索
29 private negotiationStrategy negotiationStrategy; // 交渉戦略
30 private Bid offeredBid = null; // 最近提案された合意案候補
31
32 private boolean isPrinting = false; // デバッグ用
33
34 @Override
35 public void init(NegotiationInfo info) {
36 super.init(info);
37 if (isPrinting)
38 System.out.println("*** Farma2016 v1.0 ***");
39
[46]40 this.timeLineInfo = timeline;
41 this.utilitySpace = getUtilitySpace();
[1]42 negotiationInfo = new negotiationInfo(utilitySpace, isPrinting);
43 negotiationStrategy = new negotiationStrategy(utilitySpace,
44 negotiationInfo, isPrinting);
45
46 try {
47 bidSearch = new bidSearch(utilitySpace, negotiationInfo,
48 isPrinting);
49 } catch (Exception e) {
50 // TODO Auto-generated catch block
51 e.printStackTrace();
52 }
53 }
54
55 /**
56 * Each round this method gets called and ask you to accept or offer. The
57 * first party in the first round is a bit different, it can only propose an
58 * offer.
59 *
60 * @param validActions
61 * Either a list containing both accept and offer or only offer.
62 * @return The chosen action.
63 */
64 @Override
65 public Action chooseAction(List<Class<? extends Action>> validActions) {
66 double time = timeLineInfo.getTime(); // 現在の時刻
67 negotiationInfo.updateRound();
68
69 // Acceptの判定
70 if (validActions.contains(Accept.class)
71 && negotiationStrategy.selectAccept(offeredBid, time)) {
72 return new Accept(getPartyId(), offeredBid);
73 }
74
75 // EndNegotiationの判定
76 if (negotiationStrategy.selectEndNegotiation(time)) {
77 return new EndNegotiation(getPartyId());
78 }
79
80 // 他のプレイヤーに新たなBidをOffer
81 Bid offerBid = bidSearch.getBid(
82 utilitySpace.getDomain().getRandomBid(null),
83 negotiationStrategy.getThreshold(timeLineInfo.getTime()));
84
85 negotiationInfo.updateMyOfferedBids(offerBid);
86 negotiationInfo.updateMyBidHistory(offerBid);
87 // 自分の統計情報の更新
88 try {
89 negotiationInfo.updateMyNegotiatingInfo(offerBid);
90 } catch (Exception e) {
91 e.printStackTrace();
92 }
93 return new Offer(getPartyId(), offerBid);
94 }
95
96 /**
97 * All offers proposed by the other parties will be received as a message.
98 * You can use this information to your advantage, for example to predict
99 * their utility.
100 *
101 * @param sender
102 * The party that did the action. Can be null.
103 * @param action
104 * The action that party did.
105 */
106 @Override
107 public void receiveMessage(AgentID sender, Action action) {
108 // プレイヤーのアクションを受信
109 super.receiveMessage(sender, action);
110
111 double time = timeLineInfo.getTime(); // 現在の時刻
112
113 if (isPrinting) {
114 System.out.println("Sender:" + sender + ", Action:" + action);
115 }
116
117 if (action != null) {
118 if (action instanceof Inform
119 && ((Inform) action).getName() == "NumberOfAgents"
120 && ((Inform) action).getValue() instanceof Integer) {
121 Integer opponentsNum = (Integer) ((Inform) action).getValue();
122 negotiationInfo.updateOpponentsNum(opponentsNum);
123
124 if (isPrinting) {
125 System.out.println("NumberofNegotiator:"
126 + negotiationInfo.getNegotiatorNum());
127 }
128 }
129
130 if (action instanceof Accept) {
131 // 初出の交渉者は初期化
132 if (!negotiationInfo.getOpponents().contains(sender)) {
133 negotiationInfo.initOpponent(sender);
134 }
135 // Bid別のAccept数の更新
136 negotiationInfo.updateBidAcceptNum(sender, offeredBid, time);
137 // SenderごとのAccept数(Offerを除く)の更新
138 negotiationInfo.updateOpponentsAcceptNum(sender, time);
139 }
140
141 if (action instanceof Offer) {
142 // 初出の交渉者は初期化
143 if (!negotiationInfo.getOpponents().contains(sender)) {
144 negotiationInfo.initOpponent(sender);
145 }
146 offeredBid = ((Offer) action).getBid(); // 提案された合意案候補
147
148 // 交渉情報を更新
149 try {
150 negotiationInfo.updateOfferedValueNum(sender, offeredBid,
151 time);
152 negotiationInfo.updateBidAcceptNum(sender, offeredBid,
153 time);
154 negotiationInfo.updateInfo(sender, offeredBid);
155
156 bidSearch.shiftBidSearch(offeredBid);
157 } catch (Exception e) {
158 System.out.println(
159 "交渉情報の更新に失敗しました");
160 e.printStackTrace();
161 }
162 }
163 if (action instanceof EndNegotiation) {
164 }
165 }
166 }
167
168 @Override
169 public String getDescription() {
170 return "ANAC2016";
171 }
172
173}
Note: See TracBrowser for help on using the repository browser.