source: src/main/java/negotiator/parties/RandomMajorityVoting.java@ 256

Last change on this file since 256 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.1 KB
Line 
1package negotiator.parties;
2
3import java.util.List;
4
5import genius.core.AgentID;
6import genius.core.Bid;
7import genius.core.actions.Accept;
8import genius.core.actions.Action;
9import genius.core.actions.ActionWithBid;
10import genius.core.actions.OfferForVoting;
11import genius.core.actions.Reject;
12import genius.core.parties.AbstractNegotiationParty;
13import genius.core.protocol.AlternatingMajorityConsensusProtocol;
14import genius.core.protocol.DefaultMultilateralProtocol;
15
16/**
17 * Random agent suited for AlternatingOfferMajorityVotingProtocol
18 * <p/>
19 * This party should be run with {@link genius.core.protocol.MediatorProtocol}
20 *
21 * @author W.Pasman
22 */
23public class RandomMajorityVoting extends AbstractNegotiationParty {
24
25 private boolean lastOfferIsAcceptable = false;
26
27 @Override
28 public Action chooseAction(List<Class<? extends Action>> possibleActions) {
29 if (possibleActions.contains(OfferForVoting.class)) {
30 return new OfferForVoting(getPartyId(), this.generateRandomBid());
31 } else {
32 if (lastOfferIsAcceptable) {
33 return new Accept(getPartyId(), ((ActionWithBid) getLastReceivedAction()).getBid());
34 }
35 return new Reject(getPartyId(), ((ActionWithBid) getLastReceivedAction()).getBid());
36 }
37 }
38
39 @Override
40 public void receiveMessage(AgentID sender, Action arguments) {
41 super.receiveMessage(sender, arguments);
42 if (arguments instanceof OfferForVoting) {
43 if (isAcceptable(((OfferForVoting) arguments).getBid())) {
44 lastOfferIsAcceptable = true;
45 }
46 lastOfferIsAcceptable = false;
47 }
48 }
49
50 protected boolean isAcceptable(Bid bid) {
51 double lastReceivedBidUtility = getUtility(bid);
52 double reservationValue = (timeline == null) ? utilitySpace.getReservationValue()
53 : utilitySpace.getReservationValueWithDiscount(timeline);
54
55 if (lastReceivedBidUtility >= reservationValue) {
56 return true;
57 }
58 return false;
59 }
60
61 @Override
62 public Class<? extends DefaultMultilateralProtocol> getProtocol() {
63 return AlternatingMajorityConsensusProtocol.class;
64 }
65
66 @Override
67 public String getDescription() {
68 return "Random Majority Voting Party";
69 }
70
71}
Note: See TracBrowser for help on using the repository browser.