source: src/main/java/agents/anac/y2016/syagent/SYAgent.java@ 316

Last change on this file since 316 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.0 KB
Line 
1package agents.anac.y2016.syagent;
2
3import java.util.List;
4
5import genius.core.AgentID;
6import genius.core.Bid;
7import genius.core.actions.Accept;
8import genius.core.actions.Action;
9import genius.core.actions.DefaultAction;
10import genius.core.actions.EndNegotiation;
11import genius.core.actions.Inform;
12import genius.core.actions.Offer;
13import genius.core.parties.AbstractNegotiationParty;
14import genius.core.parties.NegotiationInfo;
15import genius.core.timeline.TimeLineInfo;
16import genius.core.utility.AbstractUtilitySpace;
17
18/**
19 * This is your negotiation party.
20 */
21
22public class SYAgent extends AbstractNegotiationParty {
23 private TimeLineInfo timeLineInfo; // タイムライン
24 private AbstractUtilitySpace utilitySpace;
25 private negotiationInfo negotiationInfo; // 交渉情報
26 private bidSearch bidSearch; // 合意案候補の探索
27 private negotiationStrategy negotiationStrategy; // 交渉戦略
28 private Bid offeredBid = null; // 最近提案された合意案候補
29 private boolean isPrinting = false; // 本番用
30
31 // private boolean isPrinting = true; // デバッグ用
32
33 @Override
34 public void init(NegotiationInfo info) {
35 super.init(info);
36 if (isPrinting)
37 System.out.println("*** SYAgent2016 v1.0 ***");
38
39 this.timeLineInfo = timeline;
40 this.utilitySpace = getUtilitySpace();
41
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.countRound();
68 // double discountedUtility =
69 // utilitySpace.discount(utilitySpace.getUtility(offeredBid), time);
70 // discount の計算方法 = (Bid の Utility) * Math.pow(df,time);
71
72 // Acceptの判定
73 if (validActions.contains(Accept.class)
74 && negotiationStrategy.selectAccept(offeredBid, time)) {
75 return new Accept(getPartyId(), offeredBid);
76 }
77
78 // EndNegotiationの判定
79 if (negotiationStrategy.selectEndNegotiation(time)) {
80 return new EndNegotiation(getPartyId());
81 }
82
83 // Accept でも EndNegotiation でない時
84 // 他のプレイヤーに新たなBidをOffer
85 Bid offerBid = bidSearch.getBid(
86 utilitySpace.getDomain().getRandomBid(null),
87 negotiationStrategy.getThreshold(timeLineInfo.getTime()));
88 // 自分の提案履歴を更新
89 negotiationInfo.updateMyBidHistory(offerBid);
90
91 return new Offer(getPartyId(), offerBid);
92 }
93
94 /**
95 * All offers proposed by the other parties will be received as a message.
96 * You can use this information to your advantage, for example to predict
97 * their utility.
98 *
99 * @param sender
100 * The party that did the action. Can be null.
101 * @param action
102 * The action that party did.
103 */
104 // 自分以外のエージェントのActionを受信するメソッド
105 @Override
106 public void receiveMessage(AgentID sender, Action action) {
107 // sender(送り主)のActionを受信
108 super.receiveMessage(sender, action);
109
110 // Action がある時
111 if (action != null) {
112 // 交渉者数 の更新
113 if (action instanceof Inform
114 && ((Inform) action).getName() == "NumberOfAgents"
115 && ((Inform) action).getValue() instanceof Integer) {
116 Integer opponentsNum = (Integer) ((Inform) action).getValue();
117 negotiationInfo.updateOpponentsNum(opponentsNum);
118 if (isPrinting) {
119 System.out.println("Number of Negotiator: "
120 + negotiationInfo.getNegotiatorNum());
121 }
122 }
123 // Accept の時
124 if (action instanceof Accept) {
125 if (!negotiationInfo.getOpponents().contains(sender)) {
126 negotiationInfo.initOpponent(sender);
127 } // 初出の交渉者は初期化
128 negotiationInfo.updateAcceptedBid(sender,
129 DefaultAction.getBidFromAction(action)); // accept
130 // された
131 // bid
132 // を記録
133 }
134 // Offer の時
135 if (action instanceof Offer) {
136 if (!negotiationInfo.getOpponents().contains(sender)) {
137 negotiationInfo.initOpponent(sender);
138 } // 初出の交渉者は初期化
139 offeredBid = ((Offer) action).getBid(); // senderによって提案された合意案候補
140 try {
141 negotiationInfo.updateInfo(sender, offeredBid);
142
143 } // 交渉情報を更新
144 catch (Exception e) {
145 System.out.println(
146 "交渉情報の更新に失敗しました");
147 e.printStackTrace();
148 }
149 }
150 if (action instanceof EndNegotiation) {
151 }
152 }
153 }
154
155 @Override
156 public String getDescription() {
157 return "ANAC2016";
158 }
159
160}
Note: See TracBrowser for help on using the repository browser.