source: src/main/java/agents/anac/y2016/myagent/MyAgent.java@ 93

Last change on this file since 93 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
Line 
1package agents.anac.y2016.myagent;
2
3import java.util.List;
4
5import agents.anac.y2016.myagent.etc.bidSearch;
6import agents.anac.y2016.myagent.etc.negotiationInfo;
7import agents.anac.y2016.myagent.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 MyAgent extends AbstractNegotiationParty {
25 private TimeLineInfo timeLineInfo; // タイムライン
26 private AbstractUtilitySpace utilitySpace;
27 private negotiationInfo negotiationInfo; // 交渉情報
28 private agents.anac.y2016.myagent.etc.bidSearch bidSearch; // 合意案候補の探索
29 private agents.anac.y2016.myagent.etc.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
38 if (isPrinting)
39 System.out.println("*** SampleAgent2016 v1.0 ***");
40
41 this.timeLineInfo = timeline;
42 this.utilitySpace = getUtilitySpace();
43 negotiationInfo = new negotiationInfo(utilitySpace, isPrinting);
44 negotiationStrategy = new negotiationStrategy(utilitySpace,
45 negotiationInfo, isPrinting);
46
47 try {
48 bidSearch = new bidSearch(utilitySpace, negotiationInfo,
49 isPrinting);
50 } catch (Exception e) {
51 // TODO Auto-generated catch block
52 e.printStackTrace();
53 }
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 @Override
66 public Action chooseAction(List<Class<? extends Action>> validActions) {
67 double time = timeLineInfo.getTime(); // 現在の時刻
68
69 // Acceptの判定
70 if (validActions.contains(Accept.class)
71 && negotiationStrategy.selectAccept(offeredBid, time)) {
72 return new Accept(getPartyId(), offeredBid);
73 }
74
75 negotiationInfo.updateLast(false);
76
77 // EndNegotiationの判定
78 if (negotiationStrategy.selectEndNegotiation(time)) {
79 return new EndNegotiation(getPartyId());
80 }
81
82 // 他のプレイヤーに新たなBidをOffer
83 Bid offerBid = bidSearch.getBid(
84 utilitySpace.getDomain().getRandomBid(null),
85 negotiationStrategy.getThreshold(timeLineInfo.getTime()));
86
87 // offeredBidの更新
88 offeredBid = offerBid;
89
90 negotiationInfo.updateMyBidHistory(offerBid);
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 @Override
105 public void receiveMessage(AgentID sender, Action action) {
106 // プレイヤーのアクションを受信
107 super.receiveMessage(sender, action);
108
109 // System.out.println("Sender:"+sender+", Action:"+action);
110
111 if (action != null) {
112 if (action instanceof Inform
113 && ((Inform) action).getName() == "NumberOfAgents"
114 && ((Inform) action).getValue() instanceof Integer) {
115 Integer opponentsNum = (Integer) ((Inform) action).getValue();
116 negotiationInfo.updateOpponentsNum(opponentsNum);
117 if (isPrinting) {
118 System.out.println("NumberofNegotiator:"
119 + negotiationInfo.getNegotiatorNum());
120 }
121 }
122 if (action instanceof Accept) {
123 if (!negotiationInfo.getOpponents().contains(sender)) {
124 negotiationInfo.initOpponent(sender);
125 } // 初出の交渉者は初期化
126 negotiationInfo.updateLast(true);
127 // Accept数の更新
128 negotiationInfo.updateAcceptList(sender, offeredBid);
129 }
130 if (action instanceof Offer) {
131
132 if (!negotiationInfo.getOpponents().contains(sender)) {
133 negotiationInfo.initOpponent(sender);
134 } // 初出の交渉者は初期化
135 offeredBid = ((Offer) action).getBid(); // 提案された合意案候補
136 try {
137 negotiationInfo.updateInfo(sender, offeredBid);
138 } // 交渉情報を更新
139 catch (Exception e) {
140 System.out.println(
141 "交渉情報の更新に失敗しました");
142 e.printStackTrace();
143 }
144
145 negotiationInfo.updateOpponentIssueWeight(sender, offeredBid); // 相手の論点重みを更新
146 // System.out.println("---------" + sender + "---------");
147 // System.out.println(negotiationInfo.getOpponentMaxValues(sender));
148 // System.out.println(negotiationInfo.getRecentWeight(sender,
149 // 20));
150 // System.out.println(negotiationInfo.getRecentMaxWeight(sender,
151 // 20));
152 // System.out.println(negotiationInfo.getSlant(sender));
153 // System.out.println("--------------------------------");
154 }
155 if (action instanceof EndNegotiation) {
156 }
157 }
158 }
159
160 @Override
161 public String getDescription() {
162 return "ANAC2016";
163 }
164
165}
Note: See TracBrowser for help on using the repository browser.