1 | package multipartyexample;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import genius.core.AgentID;
|
---|
6 | import genius.core.Bid;
|
---|
7 | import genius.core.actions.Accept;
|
---|
8 | import genius.core.actions.Action;
|
---|
9 | import genius.core.actions.Offer;
|
---|
10 | import genius.core.parties.AbstractNegotiationParty;
|
---|
11 | import genius.core.parties.NegotiationInfo;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * This is your negotiation party.
|
---|
15 | */
|
---|
16 | public class Groupn extends AbstractNegotiationParty {
|
---|
17 |
|
---|
18 | private Bid lastReceivedBid = null;
|
---|
19 |
|
---|
20 | @Override
|
---|
21 | public void init(NegotiationInfo info) {
|
---|
22 |
|
---|
23 | super.init(info);
|
---|
24 |
|
---|
25 | System.out.println("Discount Factor is " + getUtilitySpace().getDiscountFactor());
|
---|
26 | System.out.println("Reservation Value is " + getUtilitySpace().getReservationValueUndiscounted());
|
---|
27 |
|
---|
28 | // if you need to initialize some variables, please initialize them
|
---|
29 | // below
|
---|
30 |
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public Action chooseAction(List<Class<? extends Action>> validActions) {
|
---|
35 |
|
---|
36 | // with 50% chance, counter offer
|
---|
37 | // if we are the first party, also offer.
|
---|
38 | if (lastReceivedBid == null || !validActions.contains(Accept.class) || Math.random() > 0.5) {
|
---|
39 | return new Offer(getPartyId(), generateRandomBid());
|
---|
40 | } else {
|
---|
41 | return new Accept(getPartyId(), lastReceivedBid);
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public void receiveMessage(AgentID sender, Action action) {
|
---|
47 | super.receiveMessage(sender, action);
|
---|
48 | if (action instanceof Offer) {
|
---|
49 | lastReceivedBid = ((Offer) action).getBid();
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Override
|
---|
54 | public String getDescription() {
|
---|
55 | return "example party group N";
|
---|
56 | }
|
---|
57 |
|
---|
58 | }
|
---|