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

Last change on this file since 3 was 1, checked in by Wouter Pasman, 7 years ago

Initial import : Genius 9.0.0

File size: 3.6 KB
Line 
1package parties.in4010.q12015.group17;
2
3import java.util.HashMap;
4import java.util.List;
5
6import genius.core.AgentID;
7import genius.core.Bid;
8import genius.core.actions.Accept;
9import genius.core.actions.Action;
10import genius.core.actions.Offer;
11import genius.core.bidding.BidDetails;
12import genius.core.boaframework.NegotiationSession;
13import genius.core.boaframework.SessionData;
14import genius.core.boaframework.SortedOutcomeSpace;
15import genius.core.parties.AbstractNegotiationParty;
16import 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 */
26public 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, info.getUtilitySpace(), info.getTimeline());
45 os = new OfferStrat();
46 }
47
48 /**
49 * Each round this method gets called and ask you to accept or offer. The
50 * first party in the first round is a bit different, it can only propose an
51 * offer.
52 *
53 * @param validActions
54 * A list containing both {@link Accept} and {@link Offer} or
55 * only {@link Offer}
56 * @return The chosen {@link Action}.
57 */
58 @Override
59 public Action chooseAction(List<Class<? extends Action>> validActions) {
60 if (initOS) { // Verify if the init function has run.
61 os.init(negotiationSession, sos, om);
62 initOS = false;
63 }
64
65 if (acceptOffer) {
66 return new Accept(getPartyId(), lastOffer);
67 } else {
68 BidDetails bd = os.determineNextBid();
69 negotiationSession.getOwnBidHistory().add(bd);
70 return new Offer(getPartyId(), bd.getBid());
71 }
72 }
73
74 /**
75 * All {@link Action}s performed by the other parties will be received as a
76 * message. You can use this information to your advantage, for example to
77 * predict their utility.
78 *
79 * @param sender
80 * The party that performed the {@link Action}.
81 * @param action
82 * The {@link Action} that the sending party performed.
83 */
84 @Override
85 public void receiveMessage(AgentID sender, Action action) {
86 super.receiveMessage(sender, action);
87 if (initOM) { // Verify if the init function has run.
88 om.init(negotiationSession, new HashMap<String, Double>());
89 initOM = false;
90 }
91
92 if (action instanceof Offer) {
93 lastOffer = ((Offer) action).getBid();
94 try { // Update the model according to the offer presented to us.
95 om.updateModel(lastOffer, sender.toString());
96 } catch (Exception e) {
97 e.printStackTrace();
98 } // Determine if we want to accept this offer.
99 acceptOffer = acceptStrategy.determineAcceptability(lastOffer);
100 }
101 }
102
103 @Override
104 public String getDescription() {
105 return "IN4010 Group 17's agent party";
106 }
107}
Note: See TracBrowser for help on using the repository browser.