1 | package parties.in4010.q12015.group9;
|
---|
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.BidHistory;
|
---|
9 | import genius.core.actions.Accept;
|
---|
10 | import genius.core.actions.Action;
|
---|
11 | import genius.core.actions.DefaultAction;
|
---|
12 | import genius.core.actions.Offer;
|
---|
13 | import genius.core.bidding.BidDetails;
|
---|
14 | import genius.core.parties.AbstractNegotiationParty;
|
---|
15 | import genius.core.parties.NegotiationInfo;
|
---|
16 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * This is your negotiation party.
|
---|
20 | */
|
---|
21 | public class Group9 extends AbstractNegotiationParty {
|
---|
22 | private Bid prevReceivedBid;
|
---|
23 | private Bid currentConsideredBid;
|
---|
24 | private int acceptCount;
|
---|
25 | private OpponentModeling opponentModels;
|
---|
26 | private AcceptStrat acceptStrat;
|
---|
27 | private BiddingStrat biddingStrat;
|
---|
28 | private HashMap<Object, BidHistory> previousBidsMap;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Each round this method gets called and ask you to accept or offer. The
|
---|
32 | * first party in the first round is a bit different, it can only propose an
|
---|
33 | * offer.
|
---|
34 | *
|
---|
35 | * @param validActions
|
---|
36 | * Either a list containing both accept and offer or only offer.
|
---|
37 | * @return The chosen action.
|
---|
38 | */
|
---|
39 | @Override
|
---|
40 | public Action chooseAction(List<Class<? extends Action>> validActions) {
|
---|
41 | Bid ourBid = biddingStrat.createBid(previousBidsMap, opponentModels.getOpponentUtilities(), this.getTimeLine());
|
---|
42 |
|
---|
43 | if (!validActions.contains(Accept.class)) {
|
---|
44 | currentConsideredBid = ourBid;
|
---|
45 | return new Offer(getPartyId(), ourBid);
|
---|
46 | } else {
|
---|
47 | if (acceptStrat.determineAcceptance(prevReceivedBid, previousBidsMap, ourBid,
|
---|
48 | opponentModels.getOpponentUtilities(), this.getTimeLine())) {
|
---|
49 | return new Accept(getPartyId(), prevReceivedBid);
|
---|
50 | } else {
|
---|
51 | currentConsideredBid = ourBid;
|
---|
52 | return new Offer(getPartyId(), ourBid);
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * All offers proposed by the other parties will be received as a message.
|
---|
59 | * You can use this information to your advantage, for example to predict
|
---|
60 | * their utility.
|
---|
61 | *
|
---|
62 | * @param sender
|
---|
63 | * The party that did the action.
|
---|
64 | * @param action
|
---|
65 | * The action that party did.
|
---|
66 | */
|
---|
67 | @Override
|
---|
68 | public void receiveMessage(AgentID sender, Action action) {
|
---|
69 | if (action instanceof Accept) { // .getClass().isInstance(new
|
---|
70 | // Accept(getPartyId()))) {
|
---|
71 | acceptCount = acceptCount + 1;
|
---|
72 | updateBidhistory(sender, currentConsideredBid);
|
---|
73 | opponentModels.updateModel(sender, action, previousBidsMap);
|
---|
74 | } else if (DefaultAction.getBidFromAction(action) != null) {
|
---|
75 | acceptCount = 0;
|
---|
76 | prevReceivedBid = DefaultAction.getBidFromAction(action);
|
---|
77 | updateBidhistory(sender, prevReceivedBid);
|
---|
78 | opponentModels.updateModel(sender, action, previousBidsMap);
|
---|
79 | }
|
---|
80 | super.receiveMessage(sender, action);
|
---|
81 | // Here you hear other parties' messages
|
---|
82 | }
|
---|
83 |
|
---|
84 | // Simple helper for putting a newly received bid into the history
|
---|
85 | private void updateBidhistory(AgentID sender, Bid sendBid) {
|
---|
86 |
|
---|
87 | if (!previousBidsMap.containsKey(sender)) {
|
---|
88 | previousBidsMap.put(sender, new BidHistory());
|
---|
89 | }
|
---|
90 | BidDetails tempBidDetails = new BidDetails(sendBid, this.getUtility(sendBid),
|
---|
91 | this.getTimeLine().getCurrentTime());
|
---|
92 | previousBidsMap.get(sender).add(tempBidDetails);
|
---|
93 | }
|
---|
94 |
|
---|
95 | @Override
|
---|
96 | public String getDescription() {
|
---|
97 | return "example party group 9";
|
---|
98 | }
|
---|
99 |
|
---|
100 | // Mostly initiate the super, besides that create the BOA components
|
---|
101 | @Override
|
---|
102 | public void init(NegotiationInfo info) {
|
---|
103 | super.init(info);
|
---|
104 | acceptCount = 0;
|
---|
105 | opponentModels = new OpponentModeling((AdditiveUtilitySpace) info.getUtilitySpace());
|
---|
106 | acceptStrat = new AcceptStrat((AdditiveUtilitySpace) info.getUtilitySpace());
|
---|
107 | biddingStrat = new BiddingStrat((AdditiveUtilitySpace) info.getUtilitySpace());
|
---|
108 | previousBidsMap = new HashMap<Object, BidHistory>();
|
---|
109 | }
|
---|
110 |
|
---|
111 | }
|
---|