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

Last change on this file since 127 was 50, checked in by Tim Baarslag, 6 years ago

EvaluatorDiscrete clean-up
agent API calls to util space

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