1 | package parties.in4010.q12015.group17;
|
---|
2 |
|
---|
3 | import java.util.HashMap;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import genius.core.AgentID;
|
---|
7 | import genius.core.Bid;
|
---|
8 | import genius.core.actions.Accept;
|
---|
9 | import genius.core.actions.Action;
|
---|
10 | import genius.core.actions.Offer;
|
---|
11 | import genius.core.bidding.BidDetails;
|
---|
12 | import genius.core.boaframework.NegotiationSession;
|
---|
13 | import genius.core.boaframework.SessionData;
|
---|
14 | import genius.core.boaframework.SortedOutcomeSpace;
|
---|
15 | import genius.core.parties.AbstractNegotiationParty;
|
---|
16 | import genius.core.parties.NegotiationInfo;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Group 17's negotiation party. It is inspired by the BOA framework and has
|
---|
20 | * split up its offer strategy, opponent modelling and accept strategy. These
|
---|
21 | * classes are {@link OfferStrat}, {@link OpMod} and {@link AcceptStrategy}.
|
---|
22 | * Essentially, the only function this class has is to correctly forward the
|
---|
23 | * data and requests it receives to the former three classes and then return
|
---|
24 | * their responses.
|
---|
25 | */
|
---|
26 | public class Group17 extends AbstractNegotiationParty {
|
---|
27 | private boolean initOM = true;
|
---|
28 | private boolean initOS = true;
|
---|
29 | private OpMod om;
|
---|
30 | private NegotiationSession negotiationSession;
|
---|
31 | private OfferStrat os;
|
---|
32 | private AcceptStrategy acceptStrategy;
|
---|
33 | private SortedOutcomeSpace sos;
|
---|
34 | private boolean acceptOffer = false;
|
---|
35 | private Bid lastOffer;
|
---|
36 |
|
---|
37 | @Override
|
---|
38 | public void init(NegotiationInfo info) {
|
---|
39 | super.init(info);
|
---|
40 | sos = new SortedOutcomeSpace(utilitySpace);
|
---|
41 | SessionData sessionData = new SessionData();
|
---|
42 | acceptStrategy = new AcceptStrategy(utilitySpace, timeline);
|
---|
43 | om = new OpMod();
|
---|
44 | negotiationSession = new NegotiationSession(sessionData,
|
---|
45 | getUtilitySpace(), timeline, null, info.getUserModel());
|
---|
46 | os = new OfferStrat();
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Each round this method gets called and ask you to accept or offer. The
|
---|
51 | * first party in the first round is a bit different, it can only propose an
|
---|
52 | * offer.
|
---|
53 | *
|
---|
54 | * @param validActions
|
---|
55 | * A list containing both {@link Accept} and {@link Offer} or
|
---|
56 | * only {@link Offer}
|
---|
57 | * @return The chosen {@link Action}.
|
---|
58 | */
|
---|
59 | @Override
|
---|
60 | public Action chooseAction(List<Class<? extends Action>> validActions) {
|
---|
61 | if (initOS) { // Verify if the init function has run.
|
---|
62 | os.init(negotiationSession, sos, om);
|
---|
63 | initOS = false;
|
---|
64 | }
|
---|
65 |
|
---|
66 | if (acceptOffer) {
|
---|
67 | return new Accept(getPartyId(), lastOffer);
|
---|
68 | } else {
|
---|
69 | BidDetails bd = os.determineNextBid();
|
---|
70 | negotiationSession.getOwnBidHistory().add(bd);
|
---|
71 | return new Offer(getPartyId(), bd.getBid());
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * All {@link Action}s performed by the other parties will be received as a
|
---|
77 | * message. You can use this information to your advantage, for example to
|
---|
78 | * predict their utility.
|
---|
79 | *
|
---|
80 | * @param sender
|
---|
81 | * The party that performed the {@link Action}.
|
---|
82 | * @param action
|
---|
83 | * The {@link Action} that the sending party performed.
|
---|
84 | */
|
---|
85 | @Override
|
---|
86 | public void receiveMessage(AgentID sender, Action action) {
|
---|
87 | super.receiveMessage(sender, action);
|
---|
88 | if (initOM) { // Verify if the init function has run.
|
---|
89 | om.init(negotiationSession, new HashMap<String, Double>());
|
---|
90 | initOM = false;
|
---|
91 | }
|
---|
92 |
|
---|
93 | if (action instanceof Offer) {
|
---|
94 | lastOffer = ((Offer) action).getBid();
|
---|
95 | try { // Update the model according to the offer presented to us.
|
---|
96 | om.updateModel(lastOffer, sender.toString());
|
---|
97 | } catch (Exception e) {
|
---|
98 | e.printStackTrace();
|
---|
99 | } // Determine if we want to accept this offer.
|
---|
100 | acceptOffer = acceptStrategy.determineAcceptability(lastOffer);
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | @Override
|
---|
105 | public String getDescription() {
|
---|
106 | return "IN4010 Group 17's agent party";
|
---|
107 | }
|
---|
108 | }
|
---|