source: boa/src/main/java/geniusweb/boa/acceptancestrategy/TimeDependentAcceptanceStrategy.java

Last change on this file was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 5.3 KB
Line 
1package geniusweb.boa.acceptancestrategy;
2
3import geniusweb.actions.Accept;
4import geniusweb.actions.Action;
5import geniusweb.actions.Offer;
6import geniusweb.bidspace.BidsWithUtility;
7import geniusweb.boa.BoaState;
8import geniusweb.boa.biddingstrategy.TimeDependentBiddingStrategy;
9import geniusweb.inform.Settings;
10import geniusweb.issuevalue.Bid;
11import geniusweb.profile.Profile;
12import geniusweb.profile.utilityspace.LinearAdditive;
13import geniusweb.profile.utilityspace.UtilitySpace;
14
15/**
16 * Simple implementation similar to the {@link TimeDependentBiddingStrategy}.
17 * Accepts if the last placed offer is ≥ {@link #p(double)}. Uses 4
18 * parameters:
19 * <ul>
20 * <li>e: the exponent for the target-utility function. See {@link #f(double)}
21 * <li>k: the constant for the target-utility function. See {@link #f(double)}
22 * <li>max: the maximum utility target used at t=0.
23 * <li>min: the minimum utility target used at t=1
24 * </ul>
25 */
26public class TimeDependentAcceptanceStrategy implements AcceptanceStrategy {
27
28 private transient Double min = null, max = null, e = null, k = null; // cache
29
30 @Override
31 public Action filter(Action action, BoaState state) {
32 Offer lastOffer = state.getLastReceivedOffer();
33 if (lastOffer == null || !(action instanceof Offer))
34 return action;
35 Bid bid = lastOffer.getBid();
36 if (min == null || max == null || e == null || k == null) {
37 min = getMin(state);
38 max = getMax(state);
39 e = getE(state);
40 k = getK(state);
41 }
42 double targetUtil = p(
43 state.getProgress().get(System.currentTimeMillis()));
44 // we subtract epsilon because of rounding errors in computation.
45 if (((UtilitySpace) state.getProfile()).getUtility(bid)
46 .doubleValue() >= targetUtil - 0.0000001)
47 return new Accept(state.getSettings().getID(), bid);
48 return action;
49 }
50
51 /**
52 * Overrideable for hard configuring this component.
53 *
54 * @param state the {@link BoaState}
55 * @return the parameter e for the time depemdency function
56 * {@link #f(double)}. The parameter is 1 by default, or the value
57 * for the "e" parameter in the {@link Settings} if available.
58 */
59 protected Double getE(BoaState state) {
60 return state.getSettings().getParameters().getDouble("e", 1d, 0d, 1d);
61 }
62
63 /**
64 * Overrideable for hard configuring this component.
65 *
66 * @param state the {@link BoaState}
67 * @return the parameter k for the time depemdency function
68 * {@link #f(double)}. The parameter is 0 by default, or the value
69 * for the "k" parameter in the {@link Settings} if available.
70 */
71 protected Double getK(BoaState state) {
72 return state.getSettings().getParameters().getDouble("k", 0d, 0d, 1d);
73 }
74
75 /**
76 * Overrideable for hard configuring this component.
77 *
78 * @param state the {@link BoaState}
79 * @return the min value for {@link #p(double)}. We use the "min" parameter
80 * in the {@link Settings} if available. If not available, the
81 * parameter is computed as the utility of the reservation bid. If
82 * there is no reservation bid, we use the minimum utility of the
83 * available profile.
84 */
85 protected Double getMin(BoaState state) {
86 Double val = state.getSettings().getParameters().getDouble("min", null,
87 0d, 1d);
88 if (val != null)
89 return val;
90 // val=null, try the reservation bid
91 LinearAdditive profile = (LinearAdditive) state.getProfile();
92 if (profile.getReservationBid() != null) {
93 return profile.getUtility(profile.getReservationBid())
94 .doubleValue();
95 }
96
97 return getBidspace(profile).getRange().getMin().doubleValue();
98 }
99
100 /**
101 * Overrideable for hard configuring this component.
102 *
103 * @param state the {@link BoaState}
104 * @return the max value for {@link #p(double)}. We use the "max" parameter
105 * in the {@link Settings} if available. If not available, we use
106 * the maximum utility of the available profile.
107 */
108 protected Double getMax(BoaState state) {
109 Double val = state.getSettings().getParameters().getDouble("max", null,
110 0d, 1d);
111 if (val != null)
112 return val;
113 UtilitySpace profile = (UtilitySpace) state.getProfile();
114 return getBidspace(profile).getRange().getMax().doubleValue();
115
116 }
117
118 /**
119 * factory method. Overridable for testing
120 *
121 * @param profile the profile to get a bidspace for
122 * @return {@link BidsWithUtility}
123 */
124 protected BidsWithUtility getBidspace(Profile profile) {
125 return new BidsWithUtility((LinearAdditive) profile);
126 }
127
128 /**
129 * Makes sure the target utility with in the acceptable range according to
130 * the domain
131 *
132 * @param t the normalized current time in the negotiation, where t=9 at
133 * start of negotiation and t=1 at end of negotiation.
134 * @return double
135 */
136 private double p(double t) {
137 return this.min + (this.max - this.min) * (1.0 - f(t));
138 }
139
140 /**
141 * From the paper:
142 *
143 * A wide range of time dependent functions can be defined by varying the
144 * way in which f(t) is computed. However, functions must ensure that 0 <=
145 * f(t) <= 1, f(0) = k, and f(1) = 1.
146 *
147 * That is, the offer will always be between the value range, at the
148 * beginning it will give the initial constant and when the deadline is
149 * reached, it will offer the reservation value.
150 *
151 * @param t the normalized current time in the negotiation, where t=9 at
152 * start of negotiation and t=1 at end of negotiation.
153 * @return
154 */
155 private double f(double t) {
156 return k + (1.0 - k) * Math.pow(t, 1.0 / e);
157 }
158
159}
Note: See TracBrowser for help on using the repository browser.