source: src/main/java/agents/anac/y2018/shiboy/Shiboy.java@ 341

Last change on this file since 341 was 341, checked in by Katsuhide Fujita, 5 years ago

Katsuhide Fujita added ANAC2018 agents.

File size: 5.7 KB
Line 
1package agents.anac.y2018.shiboy;
2
3import java.util.HashMap;
4import java.util.List;
5import java.util.Map;
6import java.util.Random;
7
8import anac2018.shiboy.etc.BidSearch;
9import anac2018.shiboy.etc.NegoHistory;
10import anac2018.shiboy.etc.NegoStats;
11import anac2018.shiboy.etc.NegoStrategy;
12import list.Tuple;
13
14import negotiator.AgentID;
15import negotiator.Bid;
16import negotiator.Deadline;
17import negotiator.actions.Action;
18import negotiator.actions.Accept;
19import negotiator.actions.Offer;
20import negotiator.actions.EndNegotiation;
21import negotiator.actions.Inform;
22import negotiator.parties.AbstractNegotiationParty;
23import negotiator.parties.NegotiationInfo;
24import negotiator.persistent.PersistentDataContainer;
25import negotiator.persistent.PersistentDataType;
26import negotiator.persistent.StandardInfo;
27import negotiator.persistent.StandardInfoList;
28
29/**
30 * This is your negotiation party.
31 */
32public class Shiboy extends AbstractNegotiationParty {
33 private NegotiationInfo info;
34 private Bid lastReceivedBid = null;
35 private Bid previousBid = null;
36 private boolean isPrinting = false; // デバッグ用
37 private boolean isPrinting_Main = false;
38
39 private NegoStrategy negoStrategy;
40 private NegoStats negoStats;
41 private NegoHistory negoHistory;
42 private BidSearch bidSearch;
43
44
45 @Override
46 public void init(NegotiationInfo info) {
47 super.init(info);
48 this.info = info;
49 negoHistory = new NegoHistory(info, isPrinting, getData());
50 negoStats = new NegoStats(info, isPrinting);
51 negoStrategy = new NegoStrategy(info, isPrinting, negoStats, negoHistory);
52
53 try {
54 bidSearch = new BidSearch(info, isPrinting, negoStats, negoHistory);
55 } catch (Exception e) {
56 e.printStackTrace();
57 }
58
59 if (isPrinting) {
60 System.out.println("[isPrint] ** isPrinting == True **");
61 System.out.println("[isPrint] Discount Factor is " + info.getUtilitySpace().getDiscountFactor());
62 System.out.println("[isPrint] Reservation Value is " + info.getUtilitySpace().getReservationValueUndiscounted());
63 }
64
65 // if you need to initialize some variables, please initialize them
66 // below
67
68 }
69
70 /**
71 * Each round this method gets called and ask you to accept or offer. The
72 * first party in the first round is a bit different, it can only propose an
73 * offer.
74 *
75 * @param validActions Either a list containing both accept and offer or only offer.
76 * @return The chosen action.
77 */
78 @Override
79 public Action chooseAction(List<Class<? extends Action>> validActions) {
80 double time = info.getTimeline().getTime();
81 /*
82 try {
83 System.out.println("停止");
84 Random rand = new Random();
85 int stopTime = rand.nextInt(1000);
86 Thread.sleep(stopTime);
87 System.out.println("起動");
88 } catch (InterruptedException e) {
89 e.printStackTrace();
90 }
91 */
92
93 if (validActions.contains(Accept.class) && negoStrategy.selectAccept(lastReceivedBid, time)) {
94 return new Accept(getPartyId(), lastReceivedBid);
95 } else if (negoStrategy.selectEndNegotiation(time)) {
96 return new EndNegotiation(getPartyId());
97 }
98
99
100 Bid offerBid = bidSearch.getBid(generateRandomBid(), negoStrategy.getThreshold(time));
101 negoStats.updateMyBidHist(offerBid);
102 return new Offer(getPartyId(), offerBid);
103 }
104
105 /**
106 * All offers proposed by the other parties will be received as a message.
107 * You can use this information to your advantage, for example to predict
108 * their utility.
109 *
110 * @param sender The party that did the action. Can be null.
111 * @param action The action that party did.
112 */
113 @Override
114 public void receiveMessage(AgentID sender, Action action) {
115 super.receiveMessage(sender, action);
116
117 if (isPrinting_Main) {
118 System.out.println("[isPrinting_Main] Sender:" + sender + ", Action:" + action);
119 }
120
121 if (action != null) {
122 if (action instanceof Inform && ((Inform) action).getName() == "NumberOfAgents" && ((Inform) action).getValue() instanceof Integer) {
123 Integer opponentsNum = (Integer) ((Inform) action).getValue();
124 negoStats.updateNegotiatorsNum(opponentsNum);
125 if (isPrinting) {
126 System.out.println("NumberofNegotiator:" + negoStats.getNegotiatorNum());
127 }
128 }
129
130 if (action instanceof Offer) {
131 if (!negoStats.getRivals().contains(sender)) {
132 negoStats.initRivals(sender);
133 }
134
135 // RejectしたValueの頻度を更新
136 previousBid = lastReceivedBid;
137 if (previousBid != null) {
138 negoStats.updateRejectedValues(sender, previousBid);
139 }
140
141 // 今回Offerされた lastReceivedBid に関する更新
142 lastReceivedBid = ((Offer) action).getBid();
143 try {
144 negoStats.updateInfo(sender, lastReceivedBid);
145 } catch (Exception e) {
146 System.out.println("[Exception] 交渉情報の更新に失敗しました");
147 e.printStackTrace();
148 }
149 } else if (action instanceof Accept) {
150 if (!negoStats.getRivals().contains(sender)) {
151 negoStats.initRivals(sender);
152 }
153
154 // AcceptしたものもAgreeとし,AgreeしたValueの頻度を更新
155 negoStats.updateAgreedValues(sender, lastReceivedBid);
156 } else if (action instanceof EndNegotiation) {
157
158 }
159 }
160
161 }
162
163 @Override
164 public String getDescription() {
165 return "AAAgent for ANAC2018";
166 }
167
168}
Note: See TracBrowser for help on using the repository browser.