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

Last change on this file since 330 was 330, checked in by Tim Baarslag, 6 years ago

BasicAgent

File size: 4.3 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.outcomes.Outcome;
15import bargainingchips.utilityfunctions.UtilityFunction;
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 @Override
37 protected Offer sendOffer()
38 {
39 // Nothing received yet
40 if (lastReceivedOffer == null)
41 return new Bid(getNextBid());
42
43 // Our last bid got accepted. We are also accepting (and we should notify the coordinator).
44 if (lastReceivedOffer.isAccept())
45 return new Accept(lastReceivedOffer);
46
47 Bundle lastReceivedBid = lastReceivedOffer.getBundle();
48 Bundle nextBid = getNextBid();
49
50 double lastUtil = lastReceivedBid != null ? u.getUtility(lastReceivedBid) : 0;
51 double nextUtil = nextBid != null ? u.getUtility(nextBid) : 0;
52
53 // Accept
54 if (nextUtil <= lastUtil)
55 return new Accept(lastReceivedOffer);
56 // Counter offer based actions
57 else
58 return new Bid(nextBid);
59 }
60
61 /**
62 * Get the next bid we should do
63 */
64 protected Bundle getNextBid()
65 {
66 OutcomeSpace outcomeSpace = negotiationContext.getOutcomeSpace();
67 return outcomeSpace.getBidNearUtility(getTargetUtility(), u, this);
68 }
69
70 @Override
71 protected void receiveOffer(Offer o)
72 {
73 lastReceivedOffer = o;
74 }
75
76 @Override
77 protected void receiveOutcome(Outcome outcome)
78 {
79 System.out.println(this + " is done with outcome " + outcome + ". Should clean up now.");
80 }
81
82 /**
83 * Gets the target utility for the next bid
84 *
85 * @return The target utility for the given time
86 */
87 private double getTargetUtility()
88 {
89 // timeline runs from 0.0 to 1.0
90 int totalrounds = NegotiationContext.DEADLINE;
91 double time = (double) k / totalrounds;
92 double target = 1d - f(time);
93// System.out.println(this + ": t = " + time + ". Target util: " + target);
94 return target;
95 }
96
97 /**
98 * From [1]:
99 *
100 * A wide range of time dependent functions can be defined by varying the
101 * way in which f(t) is computed. However, functions must ensure that 0 <=
102 * f(t) <= 1, f(0) = k, and f(1) = 1.
103 *
104 * That is, the offer will always be between the value range, at the
105 * beginning it will give the initial constant and when the deadline is
106 * reached, it will offer the reservation value.
107 *
108 * For e = 0 (special case), it will behave as a Hardliner.
109 */
110 private double f(double t) {
111 if (getE() == 0) {
112 return 0;
113 }
114 return pow(t, 1 / getE());
115 }
116
117 /**
118 * Depending on the value of e, extreme sets show clearly different patterns
119 * of behaviour [1]:
120 *
121 * 1. Boulware: For this strategy e < 1 and the initial offer is maintained
122 * till time is almost exhausted, when the agent concedes up to its
123 * reservation value.
124 *
125 * 2. Conceder: For this strategy e > 1 and the agent goes to its
126 * reservation value very quickly.
127 *
128 * 3. When e = 1, the price is increased linearly.
129 *
130 * 4. When e = 0, the agent plays hardball.
131 */
132 public abstract double getE();
133
134 @Override
135 protected Offer sendOpeningOffer()
136 {
137 return sendOffer();
138 }
139
140 /**
141 * Messaging with the coordinator can happen below
142 */
143
144 @Override
145 protected void receiveCoordinationMessage(CoordinationMessage cpoll)
146 {
147 // Update the utility function
148 u = cpoll.getUtilityFunction();
149 }
150
151 @Override
152 protected StatusMessage sendStatusMessage()
153 {
154 return null;
155 }
156}
Note: See TracBrowser for help on using the repository browser.