source: src/main/java/agents/anac/y2017/farma/Farma17.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
Line 
1package agents.anac.y2017.farma;
2
3import java.util.List;
4
5import agents.anac.y2017.farma.etc.BidSearch;
6import agents.anac.y2017.farma.etc.NegoHistory;
7import agents.anac.y2017.farma.etc.NegoStats;
8import agents.anac.y2017.farma.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 Farma17 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 @Override
35 public void init(NegotiationInfo info) {
36 super.init(info);
37 this.info = info;
38 negoHistory = new NegoHistory(info, isPrinting, getData());
39 negoStats = new NegoStats(info, isPrinting);
40 negoStrategy = new NegoStrategy(info, isPrinting, negoStats,
41 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 "
52 + info.getUtilitySpace().getDiscountFactor());
53 System.out.println("[isPrint] Reservation Value is "
54 + info.getUtilitySpace().getReservationValueUndiscounted());
55 }
56
57 // if you need to initialize some variables, please initialize them
58 // below
59
60 }
61
62 /**
63 * Each round this method gets called and ask you to accept or offer. The
64 * first party in the first round is a bit different, it can only propose an
65 * offer.
66 *
67 * @param validActions
68 * Either a list containing both accept and offer or only offer.
69 * @return The chosen action.
70 */
71 @Override
72 public Action chooseAction(List<Class<? extends Action>> validActions) {
73 double time = info.getTimeline().getTime();
74
75 if (validActions.contains(Accept.class)
76 && negoStrategy.selectAccept(lastReceivedBid, time)) {
77 return new Accept(getPartyId(), lastReceivedBid);
78 } else if (negoStrategy.selectEndNegotiation(time)) {
79 return new EndNegotiation(getPartyId());
80 }
81
82 Bid offerBid = bidSearch.getBid(generateRandomBid(),
83 negoStrategy.getThreshold(time));
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 super.receiveMessage(sender, action);
101
102 if (isPrinting_Main) {
103 System.out.println("[isPrinting_Main] Sender:" + sender
104 + ", Action:" + action);
105 }
106
107 if (action != null) {
108 if (action instanceof Inform
109 && ((Inform) action).getName() == "NumberOfAgents"
110 && ((Inform) action).getValue() instanceof Integer) {
111 Integer opponentsNum = (Integer) ((Inform) action).getValue();
112 negoStats.updateNegotiatorsNum(opponentsNum);
113 if (isPrinting) {
114 System.out.println("NumberofNegotiator:"
115 + negoStats.getNegotiatorNum());
116 }
117 }
118
119 if (action instanceof Offer) {
120 if (!negoStats.getRivals().contains(sender)) {
121 negoStats.initRivals(sender);
122 }
123
124 // RejectしたValueの頻度を更新
125 previousBid = lastReceivedBid;
126 if (previousBid != null) {
127 negoStats.updateRejectedValues(sender, previousBid);
128 }
129
130 // 今回Offerされた lastReceivedBid に関する更新
131 lastReceivedBid = ((Offer) action).getBid();
132 try {
133 negoStats.updateInfo(sender, lastReceivedBid);
134 } catch (Exception e) {
135 System.out.println(
136 "[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 "ANAC2017";
156 }
157
158}
Note: See TracBrowser for help on using the repository browser.