source: src/main/java/agents/anac/y2015/AgentW/AgentW.java

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

Initial import : Genius 9.0.0

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