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

Last change on this file since 343 was 343, checked in by Tim Baarslag, 4 years ago

Fixed all errors in all 2018 agents

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