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.InformVotingResult;
|
---|
11 | import genius.core.actions.OfferForVoting;
|
---|
12 | import genius.core.actions.Reject;
|
---|
13 | import genius.core.parties.AbstractNegotiationParty;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Implementation of a party that uses hill climbing strategy to get to an
|
---|
17 | * agreement.
|
---|
18 | * <p/>
|
---|
19 | * This party should be run with {@link genius.core.protocol.MediatorProtocol}
|
---|
20 | *
|
---|
21 | * @author David Festen
|
---|
22 | * @author Reyhan
|
---|
23 | */
|
---|
24 | public class HillClimberMajorityVoting extends AbstractNegotiationParty {
|
---|
25 |
|
---|
26 | private boolean lastOfferIsAcceptable = false;
|
---|
27 |
|
---|
28 | @Override
|
---|
29 | public Action chooseAction(List<Class<? extends Action>> possibleActions) {
|
---|
30 | if (possibleActions.contains(OfferForVoting.class)) {
|
---|
31 | return new OfferForVoting(getPartyId(), this.generateRandomBid());
|
---|
32 | } else {
|
---|
33 | if (lastOfferIsAcceptable) {
|
---|
34 | return new Accept(getPartyId(), ((ActionWithBid) getLastReceivedAction()).getBid());
|
---|
35 | }
|
---|
36 | return new Reject(getPartyId(), ((ActionWithBid) getLastReceivedAction()).getBid());
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | public void receiveMessage(AgentID sender, Action action) {
|
---|
41 | super.receiveMessage(sender, action);
|
---|
42 | if (action instanceof OfferForVoting) {
|
---|
43 | if (isAcceptable(((OfferForVoting) action).getBid())) {
|
---|
44 | lastOfferIsAcceptable = true;
|
---|
45 | }
|
---|
46 | lastOfferIsAcceptable = false;
|
---|
47 | } else if (action instanceof InformVotingResult) {
|
---|
48 | // WHATEVER.
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | protected boolean isAcceptable(Bid bid) {
|
---|
53 | double lastReceivedBidUtility = getUtility(bid);
|
---|
54 | double reservationValue = (timeline == null) ? utilitySpace.getReservationValue()
|
---|
55 | : utilitySpace.getReservationValueWithDiscount(timeline);
|
---|
56 |
|
---|
57 | if (lastReceivedBidUtility >= reservationValue) {
|
---|
58 | return true;
|
---|
59 | }
|
---|
60 | return false;
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public String getDescription() {
|
---|
65 | return "Hill Climber Majority Voting";
|
---|
66 | }
|
---|
67 |
|
---|
68 | }
|
---|