1 | package agents.anac.y2018.seto;
|
---|
2 | import java.util.List;
|
---|
3 |
|
---|
4 | import agents.anac.y2018.seto.etc.BidSearch;
|
---|
5 | import agents.anac.y2018.seto.etc.NegoHistory;
|
---|
6 | import agents.anac.y2018.seto.etc.NegoStats;
|
---|
7 | import agents.anac.y2018.seto.etc.NegoStrategy;
|
---|
8 | import genius.core.AgentID;
|
---|
9 | import genius.core.Bid;
|
---|
10 | import genius.core.actions.Accept;
|
---|
11 | import genius.core.actions.Action;
|
---|
12 | import genius.core.actions.EndNegotiation;
|
---|
13 | import genius.core.actions.Inform;
|
---|
14 | import genius.core.actions.Offer;
|
---|
15 | import genius.core.parties.AbstractNegotiationParty;
|
---|
16 | import genius.core.parties.NegotiationInfo;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * This is your negotiation party.
|
---|
20 | */
|
---|
21 | public class Seto extends AbstractNegotiationParty {
|
---|
22 | private NegotiationInfo info;
|
---|
23 | private Bid lastReceivedBid = null;
|
---|
24 | private Bid previousBid = null;
|
---|
25 | private Bid farstBid = null;
|
---|
26 |
|
---|
27 | private boolean isPrinting = false; // デバッグ用
|
---|
28 | private boolean isPrinting_Main = false;
|
---|
29 |
|
---|
30 | private NegoStrategy negoStrategy;
|
---|
31 | private NegoStats negoStats;
|
---|
32 | private NegoHistory negoHistory;
|
---|
33 | private BidSearch bidSearch;
|
---|
34 |
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public void init(NegotiationInfo info) {
|
---|
38 | super.init(info);
|
---|
39 | this.info = info;
|
---|
40 | negoHistory = new NegoHistory(info, isPrinting, getData());
|
---|
41 | negoStats = new NegoStats(info, isPrinting);
|
---|
42 | negoStrategy = new NegoStrategy(info, isPrinting, negoStats, negoHistory);
|
---|
43 |
|
---|
44 | try {
|
---|
45 | bidSearch = new BidSearch(info, isPrinting, negoStats, negoHistory);
|
---|
46 | } catch (Exception e) {
|
---|
47 | e.printStackTrace();
|
---|
48 | }
|
---|
49 |
|
---|
50 | if(isPrinting) {
|
---|
51 | System.out.println("[isPrint] ** isPrinting == True **");
|
---|
52 | System.out.println("[isPrint] Discount Factor is " + info.getUtilitySpace().getDiscountFactor());
|
---|
53 | System.out.println("[isPrint] Reservation Value is " + info.getUtilitySpace().getReservationValueUndiscounted());
|
---|
54 | }
|
---|
55 |
|
---|
56 | // if you need to initialize some variables, please initialize them
|
---|
57 | // below
|
---|
58 |
|
---|
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 | @Override
|
---|
71 | public Action chooseAction(List<Class<? extends Action>> validActions) {
|
---|
72 | double time = info.getTimeline().getTime();
|
---|
73 |
|
---|
74 | if(farstBid == null) {
|
---|
75 | if(lastReceivedBid != null) {
|
---|
76 | farstBid = lastReceivedBid;
|
---|
77 | negoStrategy.alpha = 4*Math.pow(info.getUtilitySpace().getUtility(farstBid),0.5)+0.5;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | if(validActions.contains(Accept.class) && negoStrategy.selectAccept(lastReceivedBid, time)){
|
---|
82 | return new Accept(getPartyId(), lastReceivedBid);
|
---|
83 | } else if (negoStrategy.selectEndNegotiation(time)){
|
---|
84 | return new EndNegotiation(getPartyId());
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 | Bid offerBid = bidSearch.getBid(generateRandomBid(), negoStrategy.getThreshold(time));
|
---|
89 | negoStats.updateMyBidHist(offerBid);
|
---|
90 | return new Offer(getPartyId(), offerBid);
|
---|
91 | }
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * All offers proposed by the other parties will be received as a message.
|
---|
95 | * You can use this information to your advantage, for example to predict
|
---|
96 | * their utility.
|
---|
97 | *
|
---|
98 | * @param sender
|
---|
99 | * The party that did the action. Can be null.
|
---|
100 | * @param action
|
---|
101 | * 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){ System.out.println("NumberofNegotiator:" + negoStats.getNegotiatorNum());}
|
---|
116 | }
|
---|
117 |
|
---|
118 | if (action instanceof Offer) {
|
---|
119 | if(!negoStats.getRivals().contains(sender)) {
|
---|
120 | negoStats.initRivals(sender);
|
---|
121 | }
|
---|
122 |
|
---|
123 | // RejectしたValueの頻度を更新
|
---|
124 | previousBid = lastReceivedBid;
|
---|
125 | if(previousBid != null){
|
---|
126 | negoStats.updateRejectedValues(sender, previousBid);
|
---|
127 | }
|
---|
128 |
|
---|
129 | // 今回Offerされた lastReceivedBid に関する更新
|
---|
130 | lastReceivedBid = ((Offer) action).getBid();
|
---|
131 | try {
|
---|
132 | negoStats.updateInfo(sender, lastReceivedBid);
|
---|
133 | } catch (Exception e) {
|
---|
134 | System.out.println("[Exception] 交渉情報の更新に失敗しました");
|
---|
135 | e.printStackTrace();
|
---|
136 | }
|
---|
137 | } else if (action instanceof Accept){
|
---|
138 | if(!negoStats.getRivals().contains(sender)) {
|
---|
139 | negoStats.initRivals(sender);
|
---|
140 | }
|
---|
141 |
|
---|
142 | // AcceptしたものもAgreeとし,AgreeしたValueの頻度を更新
|
---|
143 | negoStats.updateAgreedValues(sender, lastReceivedBid);
|
---|
144 | } else if (action instanceof EndNegotiation){
|
---|
145 |
|
---|
146 | }
|
---|
147 | }
|
---|
148 |
|
---|
149 | }
|
---|
150 |
|
---|
151 | @Override
|
---|
152 | public String getDescription() {
|
---|
153 | return "ANAC2018";
|
---|
154 | }
|
---|
155 |
|
---|
156 | }
|
---|