source: src/main/java/parties/in4010/q12015/group9/Group9.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.8 KB
Line 
1package parties.in4010.q12015.group9;
2
3import java.util.HashMap;
4import java.util.List;
5
6import genius.core.AgentID;
7import genius.core.Bid;
8import genius.core.BidHistory;
9import genius.core.actions.Accept;
10import genius.core.actions.Action;
11import genius.core.actions.DefaultAction;
12import genius.core.actions.Offer;
13import genius.core.bidding.BidDetails;
14import genius.core.parties.AbstractNegotiationParty;
15import genius.core.parties.NegotiationInfo;
16import genius.core.utility.AdditiveUtilitySpace;
17
18/**
19 * This is your negotiation party.
20 */
21public 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}
Note: See TracBrowser for help on using the repository browser.