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