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.actions.Accept;
|
---|
8 | import genius.core.actions.Action;
|
---|
9 | import genius.core.actions.ActionWithBid;
|
---|
10 | import genius.core.actions.OfferForVoting;
|
---|
11 | import genius.core.actions.Reject;
|
---|
12 | import genius.core.parties.AbstractNegotiationParty;
|
---|
13 | import genius.core.protocol.AlternatingMajorityConsensusProtocol;
|
---|
14 | import 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 | */
|
---|
23 | public 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 | }
|
---|