1 | package agents.anac.y2018.libra;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import java.util.HashMap;
|
---|
7 |
|
---|
8 | import negotiator.parties.BoulwareNegotiationParty;
|
---|
9 | import negotiator.parties.ConcederNegotiationParty;
|
---|
10 |
|
---|
11 | import agents.anac.y2015.Atlas3.Atlas3;
|
---|
12 | //
|
---|
13 | import agents.anac.y2015.ParsAgent.ParsAgent;
|
---|
14 | import agents.anac.y2015.RandomDance.RandomDance;
|
---|
15 | import agents.anac.y2016.caduceus.Caduceus;
|
---|
16 | import agents.anac.y2016.farma.Farma;
|
---|
17 | import agents.anac.y2016.myagent.MyAgent;
|
---|
18 | import agents.anac.y2016.parscat.ParsCat;
|
---|
19 | //
|
---|
20 | import agents.anac.y2016.terra.Terra;
|
---|
21 | //
|
---|
22 | import agents.anac.y2016.yxagent.YXAgent;
|
---|
23 | //
|
---|
24 | import agents.anac.y2017.agentf.AgentF;
|
---|
25 | import agents.anac.y2017.agentkn.AgentKN;
|
---|
26 | import agents.anac.y2017.caduceusdc16.CaduceusDC16;
|
---|
27 | import agents.anac.y2017.mamenchis.Mamenchis;
|
---|
28 | //
|
---|
29 | import agents.anac.y2017.parsagent3.ShahAgent;
|
---|
30 | import agents.anac.y2017.parscat2.ParsCat2;
|
---|
31 | import agents.anac.y2017.ponpokoagent.PonPokoAgent;
|
---|
32 | import agents.anac.y2017.rubick.Rubick;
|
---|
33 | //
|
---|
34 | import genius.core.AgentID;
|
---|
35 | import genius.core.Bid;
|
---|
36 | import genius.core.actions.Accept;
|
---|
37 | import genius.core.actions.Action;
|
---|
38 | import genius.core.actions.EndNegotiation;
|
---|
39 | import genius.core.actions.Offer;
|
---|
40 | //
|
---|
41 | import genius.core.issue.Value;
|
---|
42 | import genius.core.parties.AbstractNegotiationParty;
|
---|
43 | import genius.core.parties.NegotiationInfo;
|
---|
44 | import genius.core.parties.NegotiationParty;
|
---|
45 | //
|
---|
46 | /**
|
---|
47 | * This is your negotiation party.
|
---|
48 | */
|
---|
49 | public class Libra extends AbstractNegotiationParty {
|
---|
50 |
|
---|
51 | HashMap<AgentID,Bid> lastReceivedBidMap = new HashMap<AgentID, Bid>();
|
---|
52 | private Bid lastReceivedBid = null;
|
---|
53 | private Bid lastOfferedBid = null;
|
---|
54 | public int agentNum = 19;
|
---|
55 | public NegotiationParty[] agents = new NegotiationParty[agentNum];
|
---|
56 | public double[] weightS = new double[agentNum];
|
---|
57 | private double def_weight =10.0;
|
---|
58 | private double weightSum = (double)agentNum*def_weight;
|
---|
59 | private double chg_weight = 2.0;
|
---|
60 | private double min_weight = 1.0;
|
---|
61 | private Action[] lastActionS = new Action[agentNum];
|
---|
62 | @Override
|
---|
63 | public void init(NegotiationInfo info) {
|
---|
64 | super.init(info);
|
---|
65 | System.out.println("Discount Factor is " + info.getUtilitySpace().getDiscountFactor());
|
---|
66 | System.out.println("Reservation Value is " + info.getUtilitySpace().getReservationValueUndiscounted());
|
---|
67 |
|
---|
68 | // if you need to initialize some variables, please initialize them
|
---|
69 | // below
|
---|
70 | agents[0] = new BoulwareNegotiationParty();
|
---|
71 | agents[1] = new ConcederNegotiationParty();
|
---|
72 | //
|
---|
73 | agents[2] = new ParsAgent();
|
---|
74 | agents[3] = new RandomDance();
|
---|
75 | agents[4] = new Atlas3();
|
---|
76 | //
|
---|
77 | agents[5] = new YXAgent();
|
---|
78 | agents[6] = new Farma();
|
---|
79 | agents[7] = new ParsCat();
|
---|
80 | //
|
---|
81 | agents[8] = new ShahAgent();
|
---|
82 | agents[9] = new PonPokoAgent();
|
---|
83 | agents[10] = new Mamenchis();
|
---|
84 | //
|
---|
85 | agents[11] = new Rubick();
|
---|
86 | agents[12] = new AgentKN();
|
---|
87 | agents[13] = new ParsCat2();
|
---|
88 | //
|
---|
89 | agents[14] = new Terra();
|
---|
90 | agents[15] = new Caduceus();
|
---|
91 | agents[16] = new MyAgent();
|
---|
92 | //
|
---|
93 | agents[17] = new AgentF();
|
---|
94 | agents[18] = new CaduceusDC16();
|
---|
95 | //
|
---|
96 | int index = 0;
|
---|
97 | for(NegotiationParty agent : agents){
|
---|
98 | agent.init(info);
|
---|
99 | weightS[index] = def_weight;
|
---|
100 | index+=1;
|
---|
101 | }
|
---|
102 | //weightS[16] = 20;
|
---|
103 | System.out.println("Init has finished");
|
---|
104 | }
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * Each round this method gets called and ask you to accept or offer. The
|
---|
108 | * first party in the first round is a bit different, it can only propose an
|
---|
109 | * offer.
|
---|
110 | *
|
---|
111 | * @param validActions
|
---|
112 | * Either a list containing both accept and offer or only offer.
|
---|
113 | * @return The chosen action.
|
---|
114 | */
|
---|
115 | public Action chooseAction(List<Class<? extends Action>> validActions) {
|
---|
116 | System.out.println("ChooseAction has started");
|
---|
117 | double offerVote = 0;
|
---|
118 | double acceptVote = 0;
|
---|
119 | double endVote = 0;
|
---|
120 | int index = 0;
|
---|
121 | ArrayList<Bid> offeredList = new ArrayList<Bid>();
|
---|
122 | ArrayList<Double> weightList = new ArrayList<Double>();
|
---|
123 | for(NegotiationParty agent : agents){
|
---|
124 | Action act = agent.chooseAction(validActions);
|
---|
125 | lastActionS[index] = act;
|
---|
126 | if (act instanceof Offer){
|
---|
127 | offerVote+=weightS[index];
|
---|
128 | Bid b =((Offer) act).getBid();
|
---|
129 | //Offer proposed = new Offer(getPartyId(),b);
|
---|
130 | offeredList.add(b);
|
---|
131 | weightList.add(weightS[index]);
|
---|
132 | }
|
---|
133 | else if (act instanceof Accept){
|
---|
134 | acceptVote+=weightS[index];
|
---|
135 | }
|
---|
136 | else {
|
---|
137 | endVote+=weightS[index];
|
---|
138 | }
|
---|
139 | index+=1;
|
---|
140 | }
|
---|
141 | System.out.println("offerVote="+offerVote);
|
---|
142 | System.out.println("acceptVote="+acceptVote);
|
---|
143 | System.out.println("endVote="+endVote);
|
---|
144 | //
|
---|
145 | if(offerVote>acceptVote && offerVote>endVote){
|
---|
146 | //System.out.println("Offer is chosen");
|
---|
147 | Bid newBid = generateRandomBid();
|
---|
148 | System.out.println("Before="+newBid);
|
---|
149 | HashMap<Integer,Value>valueMap = newBid.getValues();
|
---|
150 | double receivedAve = 0;
|
---|
151 | if(lastReceivedBidMap.isEmpty()){
|
---|
152 | receivedAve = 0.5;
|
---|
153 | }
|
---|
154 | else {
|
---|
155 | for (AgentID sender : lastReceivedBidMap.keySet()) {
|
---|
156 | receivedAve += getUtilityWithDiscount(lastReceivedBidMap.get(sender));
|
---|
157 | }
|
---|
158 | receivedAve/=lastReceivedBidMap.size();
|
---|
159 | }
|
---|
160 |
|
---|
161 | for(Integer issueKey : valueMap.keySet()){
|
---|
162 | //HashMap<Value,Integer> valueCount = new HashMap<Value, Integer>();
|
---|
163 | HashMap<Value,Double> valueCount = new HashMap<Value, Double>();
|
---|
164 | index = 0;
|
---|
165 | //System.out.println("Index is reset");
|
---|
166 | //System.out.println(offeredList.size());
|
---|
167 | for(Bid proposed : offeredList){
|
---|
168 | Value proposedValue = proposed.getValue(issueKey);
|
---|
169 | //System.out.println("Value is picked");
|
---|
170 | if(valueCount.containsKey(proposedValue)){
|
---|
171 | //Integer count = valueCount.get(issueKey);
|
---|
172 | //valueCount.put(proposedValue,count+1);
|
---|
173 | //System.out.println("Value is editing");
|
---|
174 | double current = valueCount.get(proposedValue);
|
---|
175 | valueCount.put(proposedValue,current+weightList.get(index)*(getUtilityWithDiscount(proposed)-receivedAve)*100);
|
---|
176 | //System.out.println("Value is edited");
|
---|
177 | }
|
---|
178 | else{
|
---|
179 | //valueCount.put(proposedValue,1);
|
---|
180 | valueCount.put(proposedValue,weightList.get(index)*(getUtilityWithDiscount(proposed)-receivedAve)*100);
|
---|
181 | //System.out.println("Value is set");
|
---|
182 | }
|
---|
183 | //System.out.println("Value is picked2");
|
---|
184 | index+=1;
|
---|
185 | }
|
---|
186 | //System.out.println("Count has finished");
|
---|
187 | double maxCount = 0;
|
---|
188 | Value bestValue = null;
|
---|
189 | for(Value valueKey : valueCount.keySet()){
|
---|
190 | //int count = valueCount.get(valueKey);
|
---|
191 | double count = valueCount.get(valueKey);
|
---|
192 | if(count>maxCount){
|
---|
193 | bestValue = valueKey;
|
---|
194 | maxCount = count;
|
---|
195 | }
|
---|
196 | }
|
---|
197 | newBid = newBid.putValue(issueKey,bestValue);
|
---|
198 | //System.out.println("Choice has finished");
|
---|
199 | }
|
---|
200 | System.out.println("Offer is Decided");
|
---|
201 | lastOfferedBid = newBid;
|
---|
202 | System.out.println("After="+newBid);
|
---|
203 | return new Offer(getPartyId(),newBid);
|
---|
204 | }
|
---|
205 | else if(acceptVote>offerVote && acceptVote>endVote){
|
---|
206 | System.out.println("Accept is Decided");
|
---|
207 | return new Accept(getPartyId(), lastReceivedBid);
|
---|
208 | }
|
---|
209 | else{
|
---|
210 | System.out.println("EndNegotiation is Decided");
|
---|
211 | return new EndNegotiation(getPartyId());
|
---|
212 | }
|
---|
213 | /*
|
---|
214 | // with 50% chance, counter offer
|
---|
215 | // if we are the first party, also offer.
|
---|
216 | if (lastReceivedBid == null || !validActions.contains(Accept.class) || Math.random() > 0.5) {
|
---|
217 | return new Offer(getPartyId(), generateRandomBid());
|
---|
218 | } else {
|
---|
219 | return new Accept(getPartyId(), lastReceivedBid);
|
---|
220 | }
|
---|
221 | //*/
|
---|
222 | }
|
---|
223 |
|
---|
224 | /**
|
---|
225 | * All offers proposed by the other parties will be received as a message.
|
---|
226 | * You can use this information to your advantage, for example to predict
|
---|
227 | * their utility.
|
---|
228 | *
|
---|
229 | * @param sender
|
---|
230 | * The party that did the action. Can be null.
|
---|
231 | * @param action
|
---|
232 | * The action that party did.
|
---|
233 | */
|
---|
234 | @Override
|
---|
235 | public void receiveMessage(AgentID sender, Action action) {
|
---|
236 | super.receiveMessage(sender, action);
|
---|
237 | if (action instanceof Offer) {
|
---|
238 | lastReceivedBid = ((Offer) action).getBid();
|
---|
239 | lastReceivedBidMap.put(sender,((Offer) action).getBid());
|
---|
240 | }
|
---|
241 | for(NegotiationParty agent : agents){
|
---|
242 | agent.receiveMessage(sender, action);
|
---|
243 | }
|
---|
244 | if(lastOfferedBid==null){
|
---|
245 | System.out.println("ReceiveMessage has finished with return");
|
---|
246 | return;
|
---|
247 | }
|
---|
248 | //
|
---|
249 | System.out.println("ReceiveMessage has started");
|
---|
250 | if (action instanceof Offer){//相手が別の提案をしてきた場合
|
---|
251 | //System.out.println("Received Action is Offer");
|
---|
252 | int index = 0;
|
---|
253 | Bid b =((Offer) action).getBid();
|
---|
254 | double receive_util = getUtilityWithDiscount(b);
|
---|
255 | double offered_util = getUtilityWithDiscount(lastOfferedBid);
|
---|
256 | System.out.println(lastActionS.length);
|
---|
257 | for(Action lastAct:lastActionS){
|
---|
258 | if(lastAct instanceof Offer){
|
---|
259 | //System.out.println("Last Action is offer");
|
---|
260 | if(receive_util>offered_util*1.1){//自分以上の提案をもらえた場合
|
---|
261 | weightS[index]-=chg_weight;
|
---|
262 | }
|
---|
263 | else{//自分以下の場合
|
---|
264 | weightS[index]+=chg_weight;
|
---|
265 | }
|
---|
266 | }
|
---|
267 | else if(lastAct instanceof Accept){
|
---|
268 | //System.out.println("Last Action is Accept");
|
---|
269 | if(receive_util>offered_util*1.1){//自分以上の提案をもらえた場合
|
---|
270 | weightS[index]+=chg_weight;
|
---|
271 | }
|
---|
272 | else{//自分以下の場合
|
---|
273 | weightS[index]-=chg_weight;
|
---|
274 | if(weightS[index]<min_weight){
|
---|
275 | weightS[index] = min_weight;
|
---|
276 | }
|
---|
277 | }
|
---|
278 | }
|
---|
279 | else{
|
---|
280 | //System.out.println("Last Action is EndNegotiation");
|
---|
281 | //double reserve_util = getUtilitySpace().getReservationValue();
|
---|
282 | double reserve_util = getUtilitySpace().getReservationValueWithDiscount(getTimeLine());
|
---|
283 | if(receive_util>=reserve_util){//留保価格以上の提案をもらえた場合
|
---|
284 | weightS[index]-=chg_weight;
|
---|
285 | if(weightS[index]<min_weight){
|
---|
286 | weightS[index] = min_weight;
|
---|
287 | }
|
---|
288 | }
|
---|
289 | else{//留保価格以下の場合
|
---|
290 | weightS[index]+=chg_weight;
|
---|
291 | }
|
---|
292 | }
|
---|
293 | index+=1;
|
---|
294 | }
|
---|
295 | }
|
---|
296 | else if(action instanceof Accept){//相手が受け入れた場合
|
---|
297 | //System.out.println("Received Action is Accept");
|
---|
298 | int index = 0;
|
---|
299 | for(Action lastAct:lastActionS){
|
---|
300 | if(lastAct instanceof Offer){
|
---|
301 | weightS[index]+=chg_weight;
|
---|
302 | }
|
---|
303 | else{
|
---|
304 | weightS[index]-=chg_weight;
|
---|
305 | if(weightS[index]<min_weight){
|
---|
306 | weightS[index] = min_weight;
|
---|
307 | }
|
---|
308 | }
|
---|
309 | index+=1;
|
---|
310 | }
|
---|
311 | }
|
---|
312 | //
|
---|
313 | //System.out.println("Normalization has started");
|
---|
314 | normalizeWeightS();
|
---|
315 | System.out.println("ReceiveMessage has finished");
|
---|
316 | return;
|
---|
317 | }
|
---|
318 |
|
---|
319 | public void normalizeWeightS(){
|
---|
320 | //System.out.println("Summation has started");
|
---|
321 | double weightSum2 = 0;
|
---|
322 | for(int index3=0;index3<weightS.length;index3++){
|
---|
323 | //System.out.println(weightS[index3]);
|
---|
324 | weightSum2+=weightS[index3];
|
---|
325 | //System.out.println(weightSum2);
|
---|
326 | //System.out.println(index3);
|
---|
327 | }
|
---|
328 | //System.out.println("Summation has finished");
|
---|
329 | for(int index3=0;index3<weightS.length;index3++){
|
---|
330 | weightS[index3] = weightS[index3]*(weightSum/weightSum2);
|
---|
331 | }
|
---|
332 | //System.out.println("Normalization has started");
|
---|
333 | return;
|
---|
334 | }
|
---|
335 |
|
---|
336 | public String getDescription() {
|
---|
337 | return "This is Libra";
|
---|
338 | }
|
---|
339 |
|
---|
340 | }
|
---|