source: src/main/java/negotiator/parties/HillClimberMajorityVoting.java@ 48

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

Initial import : Genius 9.0.0

File size: 2.0 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.InformVotingResult;
11import genius.core.actions.OfferForVoting;
12import genius.core.actions.Reject;
13import 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 */
24public 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}
Note: See TracBrowser for help on using the repository browser.