source: src/main/java/bargainingchips/players/TimeDependentNegotiationAgent.java@ 319

Last change on this file since 319 was 319, checked in by Tim Baarslag, 5 years ago

validate gives a ValidationResult

File size: 4.5 KB
RevLine 
[316]1package bargainingchips.players;
[315]2
3import static java.lang.Math.pow;
4
5import java.util.concurrent.BlockingQueue;
6
[316]7import bargainingchips.Bundle;
8import bargainingchips.NegotiationContext;
9import bargainingchips.OutcomeSpace;
10import bargainingchips.actions.Accept;
[319]11import bargainingchips.actions.Bid;
[316]12import bargainingchips.actions.Offer;
13import bargainingchips.utilityfunctions.UtilityFunction;
[315]14import genius.core.protocol.MultilateralProtocol;
15
16/**
17 * Boulware/Conceder tactics, by Tim Baarslag, adapted from [1].
18 *
19 * [1] S. Shaheen Fatima Michael Wooldridge Nicholas R. Jennings Optimal
20 * Negotiation Strategies for Agents with Incomplete Information
21 * http://eprints.ecs.soton.ac.uk/6151/1/atal01.pdf
22 */
23public abstract class TimeDependentNegotiationAgent extends Agent
24{
25 private Offer lastReceivedOffer = null;
26
27 public TimeDependentNegotiationAgent(String name, UtilityFunction u, NegotiationContext nc,
[316]28 BlockingQueue<Offer> in,
29 BlockingQueue<Offer> out,
[315]30 BlockingQueue<CoordinationMessage> cin,
31 BlockingQueue<StatusMessage> cout) {
32 super(name, u, nc, in, out, cin, cout);
33 }
34
35 /**
36 * When this class is called, it is expected that the Party chooses one of
37 * the actions from the possible action list and returns an instance of the
38 * chosen action. This class is only called if this
39 * {@link genius.core.parties.NegotiationParty} is in the
40 * {@link MultilateralProtocol#getRoundStructure(java.util.List, negotiator.session.Session)}
41 * .
42 *
43 * @param possibleActions
44 * List of all actions possible.
45 * @return The chosen action
46 */
47 @Override
48 protected Offer sendOffer()
49 {
50 // Nothing received yet
51 if (lastReceivedOffer == null)
[319]52 return new Bid(getNextBid());
[315]53
54 // Our last bid got accepted. We are also accepting (and we should notify the coordinator).
55 if (lastReceivedOffer.isAccept())
56 return new Accept(lastReceivedOffer);
57
58 Bundle lastReceivedBid = lastReceivedOffer.getBundle();
59 Bundle nextBid = getNextBid();
60
61 double lastUtil = lastReceivedBid != null ? u.getUtility(lastReceivedBid) : 0;
62 double nextUtil = nextBid != null ? u.getUtility(nextBid) : 0;
63
64 // Accept
65 if (nextUtil <= lastUtil)
66 return new Accept(lastReceivedOffer);
67 // Counter offer based actions
68 else
[319]69 return new Bid(nextBid);
[315]70 }
71
72 /**
73 * Get the next bid we should do
74 */
75 protected Bundle getNextBid()
76 {
77 OutcomeSpace outcomeSpace = negotiationContext.getOutcomeSpace();
78 return outcomeSpace.getBidNearUtility(getTargetUtility(), u, this);
79 }
80
81 @Override
82 protected void receiveOffer(Offer o)
83 {
84 lastReceivedOffer = o;
85 }
86
87 /**
88 * Gets the target utility for the next bid
89 *
90 * @return The target utility for the given time
91 */
92 private double getTargetUtility()
93 {
94 // timeline runs from 0.0 to 1.0
95 int totalrounds = NegotiationContext.DEADLINE;
96 double time = (double) k / totalrounds;
97 double target = 1d - f(time);
98// System.out.println(this + ": t = " + time + ". Target util: " + target);
99 return target;
100 }
101
102 /**
103 * From [1]:
104 *
105 * A wide range of time dependent functions can be defined by varying the
106 * way in which f(t) is computed. However, functions must ensure that 0 <=
107 * f(t) <= 1, f(0) = k, and f(1) = 1.
108 *
109 * That is, the offer will always be between the value range, at the
110 * beginning it will give the initial constant and when the deadline is
111 * reached, it will offer the reservation value.
112 *
113 * For e = 0 (special case), it will behave as a Hardliner.
114 */
115 private double f(double t) {
116 if (getE() == 0) {
117 return 0;
118 }
119 return pow(t, 1 / getE());
120 }
121
122 /**
123 * Depending on the value of e, extreme sets show clearly different patterns
124 * of behaviour [1]:
125 *
126 * 1. Boulware: For this strategy e < 1 and the initial offer is maintained
127 * till time is almost exhausted, when the agent concedes up to its
128 * reservation value.
129 *
130 * 2. Conceder: For this strategy e > 1 and the agent goes to its
131 * reservation value very quickly.
132 *
133 * 3. When e = 1, the price is increased linearly.
134 *
135 * 4. When e = 0, the agent plays hardball.
136 */
137 public abstract double getE();
138
139 @Override
140 protected Offer sendOpeningOffer()
141 {
142 return sendOffer();
143 }
144
145 /**
146 * Messaging with the coordinator can happen below
147 */
148
149 @Override
150 protected void receiveCoordinationMessage(CoordinationMessage cpoll)
151 {
152 // Update the utility function
153 u = cpoll.getUtilityFunction();
154 }
155
156 @Override
157 protected StatusMessage sendStatusMessage()
158 {
159 return null;
160 }
161}
Note: See TracBrowser for help on using the repository browser.