source: src/main/java/parties/simplemediator/FeedbackParty.java@ 203

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

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 2.8 KB
RevLine 
[127]1package parties.simplemediator;
2
3import java.util.List;
4
5import genius.core.AgentID;
6import genius.core.Bid;
7import genius.core.Feedback;
8import genius.core.Vote;
9import genius.core.actions.Action;
10import genius.core.actions.DefaultAction;
11import genius.core.actions.GiveFeedback;
12import genius.core.actions.InformVotingResult;
13import genius.core.actions.OfferForFeedback;
14import genius.core.actions.OfferForVoting;
15import genius.core.actions.VoteForOfferAcceptance;
16import genius.core.parties.AbstractNegotiationParty;
17import genius.core.protocol.DefaultMultilateralProtocol;
18import genius.core.protocol.SimpleMediatorBasedProtocol;
19import genius.core.timeline.Timeline.Type;
20
21public 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}
Note: See TracBrowser for help on using the repository browser.