source: src/test/java/storageexample/GroupX.java@ 15

Last change on this file since 15 was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 2.4 KB
Line 
1package storageexample;
2
3import java.util.HashMap;
4import java.util.List;
5import java.util.Map;
6
7import genius.core.AgentID;
8import genius.core.Bid;
9import genius.core.actions.Accept;
10import genius.core.actions.Action;
11import genius.core.actions.Offer;
12import genius.core.list.Tuple;
13import genius.core.parties.AbstractNegotiationParty;
14import genius.core.parties.NegotiationInfo;
15import genius.core.persistent.PersistentDataType;
16import genius.core.persistent.StandardInfo;
17import genius.core.persistent.StandardInfoList;
18
19/**
20 * Sample party that accepts the Nth offer, where N is the number of sessions
21 * this [agent-profile] already did.
22 */
23public class GroupX extends AbstractNegotiationParty {
24
25 private Bid lastReceivedBid = null;
26 private int nrChosenActions = 0; // number of times chosenAction was called.
27 private StandardInfoList history;
28
29 @Override
30 public void init(NegotiationInfo info) {
31
32 super.init(info);
33
34 System.out.println("Discount Factor is " + info.getUtilitySpace().getDiscountFactor());
35 System.out.println("Reservation Value is " + info.getUtilitySpace().getReservationValueUndiscounted());
36
37 if (getData().getPersistentDataType() != PersistentDataType.STANDARD) {
38 throw new IllegalStateException("need standard persistent data");
39 }
40 history = (StandardInfoList) getData().get();
41
42 if (!history.isEmpty()) {
43 // example of using the history. Compute for each party the maximum
44 // utility of the bids in last session.
45 Map<String, Double> maxutils = new HashMap<String, Double>();
46 StandardInfo lastinfo = history.get(history.size() - 1);
47 for (Tuple<String, Double> offered : lastinfo.getUtilities()) {
48 String party = offered.get1();
49 Double util = offered.get2();
50 maxutils.put(party, maxutils.containsKey(party) ? Math.max(maxutils.get(party), util) : util);
51 }
52 System.out.println(maxutils); // notice tournament suppresses all
53 // output.
54 }
55 }
56
57 public Action chooseAction(List<Class<? extends Action>> validActions) {
58 nrChosenActions++;
59 if (nrChosenActions > history.size() & lastReceivedBid != null) {
60 return new Accept(getPartyId(), lastReceivedBid);
61 } else {
62 return new Offer(getPartyId(), generateRandomBid());
63 }
64 }
65
66 @Override
67 public void receiveMessage(AgentID sender, Action action) {
68 super.receiveMessage(sender, action);
69 if (action instanceof Offer) {
70 lastReceivedBid = ((Offer) action).getBid();
71 }
72 }
73
74 public String getDescription() {
75 return "accept Nth offer";
76 }
77
78}
Note: See TracBrowser for help on using the repository browser.