source: src/main/java/onetomany/bargainingchipsgame/players/AbstractTimeDependentNegotiationParty.java@ 309

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

General NegotiationContext

File size: 4.6 KB
Line 
1package onetomany.bargainingchipsgame.players;
2
3import static java.lang.Math.pow;
4
5import java.util.concurrent.BlockingQueue;
6
7import genius.core.protocol.MultilateralProtocol;
8import onetomany.bargainingchipsgame.Bundle;
9import onetomany.bargainingchipsgame.NegotiationContext;
10import onetomany.bargainingchipsgame.OutcomeSpace;
11import onetomany.bargainingchipsgame.interactions.Accept;
12import onetomany.bargainingchipsgame.interactions.Offer;
13import onetomany.bargainingchipsgame.players.utilityfunction.UtilityFunction;
14
15/**
16 * Boulware/Conceder tactics, by Tim Baarslag, adapted from [1].
17 *
18 * [1] S. Shaheen Fatima Michael Wooldridge Nicholas R. Jennings Optimal
19 * Negotiation Strategies for Agents with Incomplete Information
20 * http://eprints.ecs.soton.ac.uk/6151/1/atal01.pdf
21 *
22 * @author Tim Baarslag, Mark Hendrikx
23 */
24public abstract class AbstractTimeDependentNegotiationParty extends Agent
25{
26 private Offer lastReceivedOffer = null;
27
28 public AbstractTimeDependentNegotiationParty(String name, UtilityFunction u, NegotiationContext nc,
29 BlockingQueue<onetomany.bargainingchipsgame.interactions.Offer> in,
30 BlockingQueue<onetomany.bargainingchipsgame.interactions.Offer> out,
31 BlockingQueue<CoordinationMessage> cin,
32 BlockingQueue<NegotiationStatusMessage> 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 Offer(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 Offer(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 @Override
147 protected void receiveCoordinationMessage(CoordinationMessage cpoll)
148 {
149 // Update the utility function
150 u = cpoll.f;
151 }
152}
Note: See TracBrowser for help on using the repository browser.