1 | package agents.anac.y2018.agent33;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import agents.anac.y2018.agent33.etc.BidSearch;
|
---|
6 | import agents.anac.y2018.agent33.etc.NegoHistory;
|
---|
7 | import agents.anac.y2018.agent33.etc.NegoStats;
|
---|
8 | import agents.anac.y2018.agent33.etc.NegoStrategy;
|
---|
9 | import genius.core.AgentID;
|
---|
10 | import genius.core.Bid;
|
---|
11 | import genius.core.actions.Accept;
|
---|
12 | import genius.core.actions.Action;
|
---|
13 | import genius.core.actions.EndNegotiation;
|
---|
14 | import genius.core.actions.Inform;
|
---|
15 | import genius.core.actions.Offer;
|
---|
16 | import genius.core.parties.AbstractNegotiationParty;
|
---|
17 | import genius.core.parties.NegotiationInfo;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * This is your negotiation party.
|
---|
21 | */
|
---|
22 | public class Agent33 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
|
---|
66 | * Either a list containing both accept and offer or only offer.
|
---|
67 | * @return The chosen action.
|
---|
68 | */
|
---|
69 | @Override
|
---|
70 | public Action chooseAction(List<Class<? extends Action>> validActions) {
|
---|
71 | double time = info.getTimeline().getTime();
|
---|
72 |
|
---|
73 | if(validActions.contains(Accept.class) && negoStrategy.selectAccept(lastReceivedBid, time)){
|
---|
74 | System.out.println("Choose the Accept!!");
|
---|
75 | return new Accept(getPartyId(), lastReceivedBid);
|
---|
76 | } else if (negoStrategy.selectEndNegotiation(time)){
|
---|
77 | System.out.println("Choose the End!!");
|
---|
78 | return new EndNegotiation(getPartyId());
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|
82 | Bid offerBid = bidSearch.getBid(generateRandomBid(), negoStrategy.getThreshold(time));
|
---|
83 | System.out.println("offerBid:" + offerBid);
|
---|
84 | negoStats.updateMyBidHist(offerBid);
|
---|
85 | return new Offer(getPartyId(), offerBid);
|
---|
86 | }
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * All offers proposed by the other parties will be received as a message.
|
---|
90 | * You can use this information to your advantage, for example to predict
|
---|
91 | * their utility.
|
---|
92 | *
|
---|
93 | * @param sender
|
---|
94 | * The party that did the action. Can be null.
|
---|
95 | * @param action
|
---|
96 | * The action that party did.
|
---|
97 | */
|
---|
98 | @Override
|
---|
99 | public void receiveMessage(AgentID sender, Action action) {
|
---|
100 | System.out.println("receiveMessageが始まる");
|
---|
101 | super.receiveMessage(sender, action);
|
---|
102 |
|
---|
103 | System.out.println("isPrinting_Main:" + isPrinting_Main);
|
---|
104 | //if(isPrinting_Main){
|
---|
105 | System.out.println("[isPrinting_Main] Sender:" + sender + ", Action:"+action);
|
---|
106 | //}
|
---|
107 |
|
---|
108 | if(action != null){
|
---|
109 | if(action instanceof Inform && ((Inform) action).getName() == "NumberOfAgents" && ((Inform) action).getValue() instanceof Integer) {
|
---|
110 | Integer opponentsNum = (Integer) ((Inform) action).getValue();
|
---|
111 | negoStats.updateNegotiatorsNum(opponentsNum);
|
---|
112 | //if(isPrinting){
|
---|
113 | //System.out.println("NumberofNegotiator:" + negoStats.getNegotiatorNum());
|
---|
114 | // }
|
---|
115 | }
|
---|
116 | System.out.println("NumberofNegotiator:" + negoStats.getNegotiatorNum());
|
---|
117 | //System.out.println("rivals:" + negoStats.getRivals());
|
---|
118 |
|
---|
119 | if (action instanceof Offer) {
|
---|
120 | if(!negoStats.getRivals().contains(sender)) {
|
---|
121 | System.out.println("rivals:" + negoStats.getRivals());
|
---|
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 | System.out.println("lastReceivedBid:" + lastReceivedBid);
|
---|
134 | try {
|
---|
135 | negoStats.updateInfo(sender, lastReceivedBid);
|
---|
136 | } catch (Exception e) {
|
---|
137 | System.out.println("[Exception] 交渉情報の更新に失敗しました");
|
---|
138 | e.printStackTrace();
|
---|
139 | }
|
---|
140 | } else if (action instanceof Accept){
|
---|
141 | if(!negoStats.getRivals().contains(sender)) {
|
---|
142 | negoStats.initRivals(sender);
|
---|
143 | }
|
---|
144 |
|
---|
145 | // AcceptしたものもAgreeとし,AgreeしたValueの頻度を更新
|
---|
146 | negoStats.updateAgreedValues(sender, lastReceivedBid);
|
---|
147 | } else if (action instanceof EndNegotiation){
|
---|
148 | // System.out.print("I want to end.");
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | }
|
---|
153 |
|
---|
154 | @Override
|
---|
155 | public String getDescription() {
|
---|
156 | return "ANAC2018";
|
---|
157 | }
|
---|
158 |
|
---|
159 | }
|
---|