[127] | 1 | package negotiator.parties;
|
---|
| 2 |
|
---|
| 3 | import java.util.List;
|
---|
| 4 |
|
---|
| 5 | import genius.core.AgentID;
|
---|
| 6 | import genius.core.Bid;
|
---|
| 7 | import genius.core.DeadlineType;
|
---|
| 8 | import genius.core.Feedback;
|
---|
| 9 | import genius.core.Vote;
|
---|
| 10 | import genius.core.actions.Action;
|
---|
| 11 | import genius.core.actions.DefaultAction;
|
---|
| 12 | import genius.core.actions.GiveFeedback;
|
---|
| 13 | import genius.core.actions.InformVotingResult;
|
---|
| 14 | import genius.core.actions.OfferForFeedback;
|
---|
| 15 | import genius.core.actions.OfferForVoting;
|
---|
| 16 | import genius.core.actions.VoteForOfferAcceptance;
|
---|
| 17 | import genius.core.parties.AbstractNegotiationParty;
|
---|
| 18 | import genius.core.parties.NegotiationInfo;
|
---|
| 19 | import genius.core.parties.NegotiationParty;
|
---|
| 20 | import genius.core.protocol.MediatorFeedbackBasedProtocol;
|
---|
| 21 | import 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 | */
|
---|
| 36 | public 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 | }
|
---|