1 | package storageexample;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import java.util.HashMap;
|
---|
6 | import java.util.Map;
|
---|
7 |
|
---|
8 | import genius.core.AgentID;
|
---|
9 | import genius.core.Bid;
|
---|
10 | import genius.core.actions.Accept;
|
---|
11 | import genius.core.actions.Action;
|
---|
12 | import genius.core.actions.Offer;
|
---|
13 | import genius.core.list.Tuple;
|
---|
14 | import genius.core.parties.AbstractNegotiationParty;
|
---|
15 | import genius.core.parties.NegotiationInfo;
|
---|
16 | import genius.core.persistent.PersistentDataType;
|
---|
17 | import genius.core.persistent.StandardInfo;
|
---|
18 | import 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 | */
|
---|
24 | public 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 | }
|
---|