source: src/main/java/agents/anac/y2016/agentsmith/AgentSmith2016.java@ 345

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

Initial import : Genius 9.0.0

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