[127] | 1 | package parties.simplemediator;
|
---|
| 2 |
|
---|
| 3 | import java.util.List;
|
---|
| 4 |
|
---|
| 5 | import genius.core.AgentID;
|
---|
| 6 | import genius.core.Bid;
|
---|
| 7 | import genius.core.Feedback;
|
---|
| 8 | import genius.core.Vote;
|
---|
| 9 | import genius.core.actions.Action;
|
---|
| 10 | import genius.core.actions.DefaultAction;
|
---|
| 11 | import genius.core.actions.GiveFeedback;
|
---|
| 12 | import genius.core.actions.InformVotingResult;
|
---|
| 13 | import genius.core.actions.OfferForFeedback;
|
---|
| 14 | import genius.core.actions.OfferForVoting;
|
---|
| 15 | import genius.core.actions.VoteForOfferAcceptance;
|
---|
| 16 | import genius.core.parties.AbstractNegotiationParty;
|
---|
| 17 | import genius.core.protocol.DefaultMultilateralProtocol;
|
---|
| 18 | import genius.core.protocol.SimpleMediatorBasedProtocol;
|
---|
| 19 | import genius.core.timeline.Timeline.Type;
|
---|
| 20 |
|
---|
| 21 | public class FeedbackParty extends AbstractNegotiationParty {
|
---|
| 22 |
|
---|
| 23 | private double lastBidUtility;
|
---|
| 24 | private double lastAcceptedUtility;
|
---|
| 25 | private double currentBidUtility;
|
---|
| 26 | private Feedback currentFeedback;
|
---|
| 27 | private Vote currentVote;
|
---|
| 28 | private boolean voteTime;
|
---|
| 29 |
|
---|
| 30 | public FeedbackParty() {
|
---|
| 31 | super();
|
---|
| 32 | lastBidUtility = 0.0;
|
---|
| 33 | lastAcceptedUtility = 0.0;
|
---|
| 34 | currentBidUtility = 0.0;
|
---|
| 35 | currentFeedback = Feedback.SAME;
|
---|
| 36 | voteTime = false;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | @Override
|
---|
| 40 | public void receiveMessage(AgentID sender, Action opponentAction) {
|
---|
| 41 |
|
---|
| 42 | if (opponentAction instanceof InformVotingResult) {
|
---|
| 43 |
|
---|
| 44 | if (((InformVotingResult) opponentAction).getVotingResult() == Vote.ACCEPT) // update
|
---|
| 45 | // the
|
---|
| 46 | // utility
|
---|
| 47 | // of
|
---|
| 48 | // last
|
---|
| 49 | // accepted
|
---|
| 50 | // bid
|
---|
| 51 | // by
|
---|
| 52 | // all
|
---|
| 53 | lastAcceptedUtility = currentBidUtility;
|
---|
| 54 | return;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | Bid receivedBid = DefaultAction.getBidFromAction(opponentAction);
|
---|
| 58 | if (receivedBid == null)
|
---|
| 59 | return;
|
---|
| 60 |
|
---|
| 61 | if (getTimeLine().getType() == Type.Time)
|
---|
| 62 | currentBidUtility = getUtilityWithDiscount(receivedBid);
|
---|
| 63 | else
|
---|
| 64 | currentBidUtility = getUtility(receivedBid);
|
---|
| 65 |
|
---|
| 66 | if (opponentAction instanceof OfferForFeedback) {
|
---|
| 67 | currentFeedback = Feedback.madeupFeedback(lastBidUtility, currentBidUtility);
|
---|
| 68 | voteTime = false;
|
---|
| 69 | }
|
---|
| 70 | if (opponentAction instanceof OfferForVoting) {
|
---|
| 71 | voteTime = true;
|
---|
| 72 | if (lastAcceptedUtility <= currentBidUtility)
|
---|
| 73 | currentVote = Vote.ACCEPT;
|
---|
| 74 | else
|
---|
| 75 | currentVote = Vote.REJECT;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | lastBidUtility = currentBidUtility;
|
---|
| 79 |
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | @Override
|
---|
| 83 | public Action chooseAction(List<Class<? extends Action>> validActions) {
|
---|
| 84 |
|
---|
| 85 | if (voteTime)
|
---|
| 86 | return (new VoteForOfferAcceptance(getPartyId(), currentVote));
|
---|
| 87 | else
|
---|
| 88 | return (new GiveFeedback(getPartyId(), currentFeedback));
|
---|
| 89 |
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | @Override
|
---|
| 93 | public Class<? extends DefaultMultilateralProtocol> getProtocol() {
|
---|
| 94 | return SimpleMediatorBasedProtocol.class;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | @Override
|
---|
| 98 | public String getDescription() {
|
---|
| 99 | return "Feedback Negotiator";
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | }
|
---|