source: src/main/java/agents/anac/y2015/DrageKnight/DrageKnight.java@ 346

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

Initial import : Genius 9.0.0

File size: 5.9 KB
Line 
1package agents.anac.y2015.DrageKnight;
2
3import java.util.List;
4
5import agents.anac.y2015.DrageKnight.etc.bidSearch;
6import agents.anac.y2015.DrageKnight.etc.negotiatingInfo;
7import agents.anac.y2015.DrageKnight.etc.strategy;
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.utility.AdditiveUtilitySpace;
18
19/**
20 * This is your negotiation party.
21 */
22public class DrageKnight extends AbstractNegotiationParty {
23 private negotiatingInfo negotiatingInfo; // 交渉情報
24 private bidSearch bidSearch; // Bid探索
25 private strategy strategy; // 交渉戦略
26 private Bid offeredBid = null; // 提案された合意案候補
27
28 // デバッグ用
29 public static boolean isPrinting = false; // メッセージを表示する
30
31 /**
32 * Please keep this constructor. This is called by genius.
33 *
34 * @param utilitySpace
35 * Your utility space.
36 * @param deadlines
37 * The deadlines set for this negotiation.
38 * @param timeline
39 * Value counting from 0 (start) to 1 (end).
40 * @param randomSeed
41 * If you use any randomization, use this seed for it.
42 * @throws Exception
43 */
44 @Override
45 public void init(NegotiationInfo info) {
46 // Make sure that this constructor calls it's parent.
47 super.init(info);
48
49 if (isPrinting) {
50 System.out.println("*** DrageKnight ***");
51 }
52
53 negotiatingInfo = new negotiatingInfo(
54 (AdditiveUtilitySpace) utilitySpace);
55 try {
56 bidSearch = new bidSearch((AdditiveUtilitySpace) utilitySpace,
57 negotiatingInfo);
58 } catch (Exception e) {
59 throw new RuntimeException("init failed:" + e, e);
60 }
61 strategy = new strategy((AdditiveUtilitySpace) utilitySpace,
62 negotiatingInfo);
63 }
64
65 /**
66 * Each round this method gets called and ask you to accept or offer. The
67 * first party in the first round is a bit different, it can only propose an
68 * offer.
69 *
70 * @param validActions
71 * Either a list containing both accept and offer or only offer.
72 * @return The chosen action.
73 */
74 @SuppressWarnings("rawtypes")
75 @Override
76 // Actionの選択
77 public Action chooseAction(List<Class<? extends Action>> validActions) {
78 double time = timeline.getTime(); // 現在の交渉時刻を取得
79
80 // Accept
81 if (validActions.contains(Accept.class)
82 && strategy.selectAccept(offeredBid, time)) {
83 return new Accept(getPartyId(), offeredBid);
84 }
85
86 // EndNegotiation
87 if (strategy.selectEndNegotiation(time)) {
88 return new EndNegotiation(getPartyId());
89 }
90
91 // Offer
92 return OfferAction();
93 }
94
95 // こっちの提案
96 public Action OfferAction() {
97 Bid offerBid = bidSearch.getBid(generateRandomBid(),
98 strategy.getThreshold2(timeline.getTime()));
99 negotiatingInfo.updateMyBidHistory(offerBid);
100 return new Offer(getPartyId(), offerBid);
101 }
102
103 /**
104 * All offers proposed by the other parties will be received as a message.
105 * You can use this information to your advantage, for example to predict
106 * their utility.
107 *
108 * @param sender
109 * The party that did the action.
110 * @param action
111 * The action that party did.
112 */
113 @Override
114 // 自身以外の交渉参加者のActionを受信
115 public void receiveMessage(AgentID sender, Action action) {
116 super.receiveMessage(sender, action);
117 // Here you can listen to other parties' messages
118 if (isPrinting) {
119 System.out.println("Sender:" + sender + ", Action:" + action);
120 }
121
122 if (action != null) {
123 if (action instanceof Inform
124 && ((Inform) action).getName() == "NumberOfAgents"
125 && ((Inform) action).getValue() instanceof Integer) {
126 Integer opponentsNum = (Integer) ((Inform) action).getValue();
127 negotiatingInfo.updateOpponentsNum(opponentsNum);
128 if (isPrinting) {
129 System.out.println("NumberofNegotiator:"
130 + negotiatingInfo.getNegotiatorNum());
131 }
132 } else if (action instanceof Accept) {
133 if (!negotiatingInfo.getOpponents().contains(sender)) {
134 negotiatingInfo.initOpponent(sender);
135 } // 初出の交渉者は初期化
136 } else if (action instanceof Offer) {
137 if (!negotiatingInfo.getOpponents().contains(sender)) {
138 negotiatingInfo.initOpponent(sender);
139 } // 初出の交渉者は初期化
140 offeredBid = ((Offer) action).getBid(); // 提案された合意案候補
141 try {
142 negotiatingInfo.updateInfo(sender, offeredBid);
143 } // 交渉情報を更新
144 catch (Exception e) {
145 System.out.println(
146 "交渉情報の更新に失敗しました");
147 e.printStackTrace();
148 }
149 } else if (action instanceof EndNegotiation) {
150 }
151 }
152 }
153 /*
154 * public void receiveMessage(Object sender, Action action) {
155 * super.receiveMessage(sender, action); // Here you can listen to other
156 * parties' messages if(isPrinting){
157 * System.out.println("Sender:"+sender+", Action:"+action); }
158 *
159 * if (action != null ) { if(action instanceof Accept){
160 * if(!negotiatingInfo.getOpponents().contains(sender)){
161 * negotiatingInfo.initOpponent(sender); } // 初出の交渉者は初期化
162 * } else if(action instanceof Offer) {
163 * if(!negotiatingInfo.getOpponents().contains(sender)){
164 * negotiatingInfo.initOpponent(sender); } // 初出の交渉者は初期化
165 * offeredBid = ((Offer) action).getBid(); // 提案された合意案候補
166 * try { negotiatingInfo.updateInfo(sender, offeredBid); } //
167 * 交渉情報を更新 catch (Exception e) {
168 * System.out.println("交渉情報の更新に失敗しました");
169 * e.printStackTrace(); } } else { Object obj = ((Object)action); int
170 * opponentsNum = Integer.parseInt(obj.toString().replaceAll("[^0-9]",""));
171 * negotiatingInfo.updateOpponentsNum(opponentsNum); if(isPrinting){
172 * System.out.println("NumberofNegotiator:" +
173 * negotiatingInfo.getNegotiatorNum());} } } }
174 */
175
176 @Override
177 public String getDescription() {
178 return "ANAC2015";
179 }
180
181}
Note: See TracBrowser for help on using the repository browser.