source: src/main/java/negotiator/parties/Annealer.java@ 126

Last change on this file since 126 was 126, checked in by Aron Hammond, 6 years ago

Added function to calculate opposition to MultiLateralAnalysis.java

Moved code to add RLBOA listeners to RLBOAUtils is misc package

Added input for strategyParameters to SessionPanel (gui)

!! close SessionInfo after tournament; this caused /tmp/ to fill up with GeniusData files

Our own package:

  • Added opponents and strategies that are mentioned in the report
  • Change class hierarchy, agents can now extend from RLBOAagentBilateral to inherit RL functionality.
  • States extend from AbstractState
File size: 4.1 KB
RevLine 
[126]1package negotiator.parties;
2
3import static java.lang.Math.E;
4import static java.lang.Math.max;
5import static java.lang.Math.pow;
6
7import java.util.List;
8
9import genius.core.AgentID;
10import genius.core.DeadlineType;
11import genius.core.Vote;
12import genius.core.actions.Action;
13import genius.core.actions.InformVotingResult;
14import genius.core.actions.OfferForVoting;
15import genius.core.actions.VoteForOfferAcceptance;
16import genius.core.parties.AbstractNegotiationParty;
17import genius.core.parties.NegotiationInfo;
18import genius.core.parties.NegotiationParty;
19import genius.core.protocol.MultilateralProtocol;
20
21/**
22 * Implementation of a party that uses simulated annealing strategy to get to an
23 * agreement.
24 * <p/>
25 * This party should be run with {@link genius.core.protocol.MediatorProtocol}
26 *
27 * @author David Festen
28 * @author Reyhan
29 */
30public class Annealer extends AbstractNegotiationParty {
31
32 /**
33 * Holds the utility value for the most recently accepted offer.
34 */
35 private double lastAcceptedBidUtility;
36
37 /**
38 * Holds the utility value for the most recently received offer.
39 */
40 private double lastReceivedBidUtility;
41
42 /**
43 * Holds the vote that will be done when asked for voting.
44 */
45 private Vote currentVote;
46
47 /**
48 * Holds the current round number (used for cooling down the annealing).
49 */
50 private int currentRound;
51
52 @Override
53 public void init(NegotiationInfo info) {
54 super.init(info);
55 lastAcceptedBidUtility = 0;
56 lastReceivedBidUtility = 0;
57 currentVote = Vote.REJECT;
58 currentRound = 0;
59 }
60
61 /**
62 * When this class is called, it is expected that the Party chooses one of
63 * the actions from the possible action list and returns an instance of the
64 * chosen action. This class is only called if this {@link NegotiationParty}
65 * is in the
66 * {@link negotiator.protocol .DefaultProtocol#getRoundStructure(java.util.List, negotiator.session.Session)}
67 * .
68 *
69 * @param possibleActions
70 * List of all actions possible.
71 * @return The chosen action
72 */
73 @Override
74 public Action chooseAction(List<Class<? extends Action>> possibleActions) {
75 return new VoteForOfferAcceptance(getPartyId(), currentVote);
76 }
77
78 /**
79 * This method is called when an observable action is performed. Observable
80 * actions are defined in
81 * {@link MultilateralProtocol#getActionListeners(java.util.List)}
82 *
83 * @param sender
84 * The initiator of the action
85 * @param arguments
86 * The action performed
87 */
88 @Override
89 public void receiveMessage(AgentID sender, Action arguments) {
90 if (arguments instanceof OfferForVoting) {
91 lastReceivedBidUtility = getUtility(((OfferForVoting) arguments).getBid());
92 if (lastReceivedBidUtility >= lastAcceptedBidUtility) {
93 currentVote = Vote.ACCEPT;
94 } else {
95 double temperature = getNormalizedRoundOrTimeValue();
96
97 double probability = pow(E, ((lastReceivedBidUtility - lastAcceptedBidUtility) / temperature));
98 currentVote = probability > rand.nextDouble() ? Vote.ACCEPT : Vote.REJECT;
99 }
100 } else if (arguments instanceof InformVotingResult) {
101 if (((InformVotingResult) arguments).getVotingResult() == Vote.ACCEPT) {
102 lastAcceptedBidUtility = lastReceivedBidUtility;
103 }
104 currentRound++;
105 }
106 }
107
108 /**
109 * returns the highest of normalized time and round values
110 *
111 * @return a value between 0.0 and 1.0
112 */
113 private double getNormalizedRoundOrTimeValue() {
114 // return the most urgent value
115 return max(getNormalizedRoundValue(), getNormalizedTimeValue());
116 }
117
118 /**
119 * Gets the normalized current round between 0.0 and 1.0
120 *
121 * @return A value between 0.0 and 1.0 or 0.0 if no round deadline given
122 */
123 private double getNormalizedRoundValue() {
124 if (getDeadlines().getType() == DeadlineType.ROUND) {
125 return ((double) currentRound / (double) getDeadlines().getValue());
126 } else {
127 return 0d;
128 }
129 }
130
131 /**
132 * Gets the normalized current time, which runs from 0.0 to 1.0
133 *
134 * @return A value between 0.0 and 1.0 which defaults to 0.0 if no time
135 * deadline set
136 */
137 private double getNormalizedTimeValue() {
138 return timeline == null ? 0d : timeline.getTime();
139 }
140
141 @Override
142 public String getDescription() {
143 return "Annealer Party";
144 }
145
146}
Note: See TracBrowser for help on using the repository browser.