source: src/main/java/parties/in4010/q12015/group17/Group17.java@ 84

Last change on this file since 84 was 47, checked in by Tim Baarslag, 7 years ago

BOA agents get their getUtilitySpace() from the API, not the info object anymore

File size: 3.5 KB
Line 
1package parties.in4010.q12015.group17;
2
3import java.util.List;
4
5import java.util.HashMap;
6
7import genius.core.AgentID;
8import genius.core.Bid;
9import genius.core.actions.Accept;
10import genius.core.actions.Action;
11import genius.core.actions.Offer;
12import genius.core.bidding.BidDetails;
13import genius.core.boaframework.NegotiationSession;
14import genius.core.boaframework.SessionData;
15import genius.core.boaframework.SortedOutcomeSpace;
16import genius.core.parties.AbstractNegotiationParty;
17import genius.core.parties.NegotiationInfo;
18
19/**
20 * Group 17's negotiation party. It is inspired by the BOA framework and has
21 * split up its offer strategy, opponent modelling and accept strategy. These
22 * classes are {@link OfferStrat}, {@link OpMod} and {@link AcceptStrategy}.
23 * Essentially, the only function this class has is to correctly forward the
24 * data and requests it receives to the former three classes and then return
25 * their responses.
26 */
27public class Group17 extends AbstractNegotiationParty {
28 private boolean initOM = true;
29 private boolean initOS = true;
30 private OpMod om;
31 private NegotiationSession negotiationSession;
32 private OfferStrat os;
33 private AcceptStrategy acceptStrategy;
34 private SortedOutcomeSpace sos;
35 private boolean acceptOffer = false;
36 private Bid lastOffer;
37
38 @Override
39 public void init(NegotiationInfo info) {
40 super.init(info);
41 sos = new SortedOutcomeSpace(utilitySpace);
42 SessionData sessionData = new SessionData();
43 acceptStrategy = new AcceptStrategy(utilitySpace, timeline);
44 om = new OpMod();
45 negotiationSession = new NegotiationSession(sessionData, getUtilitySpace(), timeline);
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}
Note: See TracBrowser for help on using the repository browser.