source: src/main/java/negotiator/parties/FeedbackHillClimber.java@ 61

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

Initial import : Genius 9.0.0

File size: 3.9 KB
RevLine 
[1]1package negotiator.parties;
2
3import java.util.List;
4
5import genius.core.AgentID;
6import genius.core.Bid;
7import genius.core.DeadlineType;
8import genius.core.Feedback;
9import genius.core.Vote;
10import genius.core.actions.Action;
11import genius.core.actions.DefaultAction;
12import genius.core.actions.GiveFeedback;
13import genius.core.actions.InformVotingResult;
14import genius.core.actions.OfferForFeedback;
15import genius.core.actions.OfferForVoting;
16import genius.core.actions.VoteForOfferAcceptance;
17import genius.core.parties.AbstractNegotiationParty;
18import genius.core.parties.NegotiationInfo;
19import genius.core.parties.NegotiationParty;
20import genius.core.protocol.MediatorFeedbackBasedProtocol;
21import genius.core.protocol.MultilateralProtocol;
22
23/**
24 * Hill climber implementation for the mediator protocol with feedback.
25 * <p/>
26 * This implementation was adapted from Reyhan's original code and refitted in
27 * the new framework
28 * <p/>
29 * <u>Possible bug:</u><br>
30 * Possibly, there is a small bug in this code, which you will encounter when
31 * running this agent for an extended period of time (i.e. minutes)
32 *
33 * @author David Festen
34 * @author Reyhan (Orignal code)
35 */
36public class FeedbackHillClimber extends AbstractNegotiationParty {
37 private double lastBidUtility;
38 private double lastAcceptedUtility;
39 private double currentBidUtility;
40 private Feedback currentFeedback;
41 private Vote currentVote;
42 private boolean voteTime;
43
44 @Override
45 public void init(NegotiationInfo info) {
46 super.init(info);
47 lastBidUtility = 0.0;
48 lastAcceptedUtility = 0.0;
49 currentBidUtility = 0.0;
50 currentFeedback = Feedback.SAME;
51 voteTime = false;
52 }
53
54 /**
55 * When this class is called, it is expected that the Party chooses one of
56 * the actions from the possible action list and returns an instance of the
57 * chosen action. This class is only called if this {@link NegotiationParty}
58 * is in the
59 * {@link negotiator.protocol .DefaultProtocol#getRoundStructure(java.util.List, negotiator.session.Session)}
60 * .
61 *
62 * @param possibleActions
63 * List of all actions possible.
64 * @return The chosen action
65 */
66 @Override
67 public Action chooseAction(List<Class<? extends Action>> possibleActions) {
68 if (voteTime) {
69 return (new VoteForOfferAcceptance(getPartyId(), currentVote));
70 } else {
71 return (new GiveFeedback(getPartyId(), currentFeedback));
72 }
73 }
74
75 /**
76 * This method is called when an observable action is performed. Observable
77 * actions are defined in
78 * {@link MultilateralProtocol#getActionListeners(java.util.List)}
79 *
80 * @param sender
81 * The initiator of the action
82 * @param arguments
83 * The action performed
84 */
85 @Override
86 public void receiveMessage(AgentID sender, Action arguments) {
87
88 if (arguments instanceof InformVotingResult) {
89 // update the utility of last accepted bid by all
90 if (((InformVotingResult) arguments).getVotingResult() == Vote.ACCEPT) {
91 lastAcceptedUtility = currentBidUtility;
92 }
93 return;
94 }
95
96 Bid receivedBid = DefaultAction.getBidFromAction(arguments);
97 if (receivedBid == null) {
98 return;
99 }
100
101 if (getDeadlines().getType() == DeadlineType.TIME) {
102 currentBidUtility = getUtilityWithDiscount(receivedBid);
103 } else {
104 currentBidUtility = getUtility(receivedBid);
105 }
106
107 if (arguments instanceof OfferForFeedback) {
108 currentFeedback = Feedback.madeupFeedback(lastBidUtility, currentBidUtility);
109 voteTime = false;
110 }
111 if (arguments instanceof OfferForVoting) {
112 voteTime = true;
113 if (lastAcceptedUtility <= currentBidUtility) {
114 currentVote = Vote.ACCEPT;
115 } else {
116 currentVote = Vote.REJECT;
117 }
118 }
119
120 lastBidUtility = currentBidUtility;
121 }
122
123 @Override
124 public Class<? extends MultilateralProtocol> getProtocol() {
125 return MediatorFeedbackBasedProtocol.class;
126 }
127
128 @Override
129 public String getDescription() {
130 return "Feedback Hillclimber";
131 }
132
133}
Note: See TracBrowser for help on using the repository browser.