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