source: src/main/java/agents/anac/y2018/libra/Libra.java@ 341

Last change on this file since 341 was 341, checked in by Katsuhide Fujita, 5 years ago

Katsuhide Fujita added ANAC2018 agents.

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