1 | package negotiator.parties;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import genius.core.AgentID;
|
---|
6 | import genius.core.Vote;
|
---|
7 | import genius.core.actions.Action;
|
---|
8 | import genius.core.actions.InformVotingResult;
|
---|
9 | import genius.core.actions.OfferForVoting;
|
---|
10 | import genius.core.actions.VoteForOfferAcceptance;
|
---|
11 | import genius.core.parties.AbstractNegotiationParty;
|
---|
12 | import genius.core.parties.NegotiationInfo;
|
---|
13 | import genius.core.parties.NegotiationParty;
|
---|
14 | import genius.core.protocol.DefaultMultilateralProtocol;
|
---|
15 | import genius.core.protocol.MediatorProtocol;
|
---|
16 | import genius.core.protocol.MultilateralProtocol;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Implementation of a party that uses hill climbing strategy to get to an
|
---|
20 | * agreement.
|
---|
21 | * <p/>
|
---|
22 | * This party should be run with {@link genius.core.protocol.MediatorProtocol}
|
---|
23 | *
|
---|
24 | * @author David Festen
|
---|
25 | * @author Reyhan
|
---|
26 | */
|
---|
27 | public class HillClimber extends AbstractNegotiationParty {
|
---|
28 |
|
---|
29 | private double lastAcceptedBidUtility;
|
---|
30 |
|
---|
31 | private double lastReceivedBidUtility;
|
---|
32 |
|
---|
33 | private Vote currentVote;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Initializes a new instance of the {@link HillClimber} class.
|
---|
37 | *
|
---|
38 | * @param utilitySpace
|
---|
39 | * The utility space used by this class
|
---|
40 | * @param deadlines
|
---|
41 | * The deadlines for this session
|
---|
42 | * @param timeline
|
---|
43 | * The time line (if time deadline) for this session, can be null
|
---|
44 | * @param randomSeed
|
---|
45 | * The seed that should be used for all randomization (to be
|
---|
46 | * reproducible)
|
---|
47 | */
|
---|
48 | @Override
|
---|
49 | public void init(NegotiationInfo info) {
|
---|
50 | super.init(info);
|
---|
51 | lastAcceptedBidUtility = 0;
|
---|
52 | lastReceivedBidUtility = 0;
|
---|
53 | currentVote = Vote.REJECT;
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * When this class is called, it is expected that the Party chooses one of
|
---|
58 | * the actions from the possible action list and returns an instance of the
|
---|
59 | * chosen action. This class is only called if this {@link NegotiationParty}
|
---|
60 | * is in the
|
---|
61 | * {@link negotiator.protocol .DefaultProtocol#getRoundStructure(java.util.List, negotiator.session.Session)}
|
---|
62 | * .
|
---|
63 | *
|
---|
64 | * @param possibleActions
|
---|
65 | * List of all actions possible.
|
---|
66 | * @return The chosen action
|
---|
67 | */
|
---|
68 | @Override
|
---|
69 | public Action chooseAction(List<Class<? extends Action>> possibleActions) {
|
---|
70 | return new VoteForOfferAcceptance(getPartyId(), currentVote);
|
---|
71 | }
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * This method is called when an observable action is performed. Observable
|
---|
75 | * actions are defined in
|
---|
76 | * {@link MultilateralProtocol#getActionListeners(java.util.List)}
|
---|
77 | *
|
---|
78 | * @param sender
|
---|
79 | * The initiator of the action
|
---|
80 | * @param arguments
|
---|
81 | * The action performed
|
---|
82 | */
|
---|
83 | @Override
|
---|
84 | public void receiveMessage(AgentID sender, Action arguments) {
|
---|
85 | if (arguments instanceof OfferForVoting) {
|
---|
86 | lastReceivedBidUtility = getUtility(((OfferForVoting) arguments).getBid());
|
---|
87 | double reservationValue = (timeline == null) ? utilitySpace.getReservationValue()
|
---|
88 | : utilitySpace.getReservationValueWithDiscount(timeline);
|
---|
89 |
|
---|
90 | if (lastReceivedBidUtility < reservationValue) {
|
---|
91 | currentVote = Vote.REJECT;
|
---|
92 | } else {
|
---|
93 | currentVote = lastReceivedBidUtility >= lastAcceptedBidUtility ? Vote.ACCEPT : Vote.REJECT;
|
---|
94 | }
|
---|
95 | } else if (arguments instanceof InformVotingResult) {
|
---|
96 | if (((InformVotingResult) arguments).getVotingResult() == Vote.ACCEPT) {
|
---|
97 | lastAcceptedBidUtility = lastReceivedBidUtility;
|
---|
98 | }
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | @Override
|
---|
103 | public Class<? extends DefaultMultilateralProtocol> getProtocol() {
|
---|
104 | return MediatorProtocol.class;
|
---|
105 | }
|
---|
106 |
|
---|
107 | @Override
|
---|
108 | public String getDescription() {
|
---|
109 | return "Hill Climber Party";
|
---|
110 | }
|
---|
111 | }
|
---|