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

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

Connected AsynchronousOffersProtocol

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