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

Last change on this file since 339 was 339, checked in by Faria Nassiri Mofakham, 5 years ago

BargainingChips creates bob calling BargainingBuyer. OutcomeSpace is Iterable<Bundle>, also getAllBids, getRandom, getRandom(r), getAverageUtility(u), size(), checkReadyForNegotiation, getName(), getUtility(u, b), getReservationValue(u), and getDiscountFactor added. An update on Bid getSampleBid type. An update on Agent. A history' package of BidEvent, BidEventHistory, BidEventHisoryKeeper, BidEventSortedUtility, and BidEventStrictSortedUtility added. HistoryAgent added. An analysis' package of BundleUtilityPoint, BundleUtilitySpace, and ParetoFrontier added. BargainingAgent added. TitForTatNegotiationAgent. Now, Buyer extended to BargainingBuyer which is created using Boulware or TitForTatNegotiationAgent using one among 9 utility functions. Name of strategy added toDescription in BoulwareAgent. A few small updates on several utility function classes.

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