package geniusweb.boa.acceptancestrategy;
import geniusweb.actions.Accept;
import geniusweb.actions.Action;
import geniusweb.actions.Offer;
import geniusweb.bidspace.BidsWithUtility;
import geniusweb.boa.BoaState;
import geniusweb.boa.biddingstrategy.TimeDependentBiddingStrategy;
import geniusweb.inform.Settings;
import geniusweb.issuevalue.Bid;
import geniusweb.profile.Profile;
import geniusweb.profile.utilityspace.LinearAdditive;
import geniusweb.profile.utilityspace.UtilitySpace;
/**
* Simple implementation similar to the {@link TimeDependentBiddingStrategy}.
* Accepts if the last placed offer is ≥ {@link #p(double)}. Uses 4
* parameters:
*
* - e: the exponent for the target-utility function. See {@link #f(double)}
*
- k: the constant for the target-utility function. See {@link #f(double)}
*
- max: the maximum utility target used at t=0.
*
- min: the minimum utility target used at t=1
*
*/
public class TimeDependentAcceptanceStrategy implements AcceptanceStrategy {
private transient Double min = null, max = null, e = null, k = null; // cache
@Override
public Action filter(Action action, BoaState state) {
Offer lastOffer = state.getLastReceivedOffer();
if (lastOffer == null || !(action instanceof Offer))
return action;
Bid bid = lastOffer.getBid();
if (min == null || max == null || e == null || k == null) {
min = getMin(state);
max = getMax(state);
e = getE(state);
k = getK(state);
}
double targetUtil = p(
state.getProgress().get(System.currentTimeMillis()));
// we subtract epsilon because of rounding errors in computation.
if (((UtilitySpace) state.getProfile()).getUtility(bid)
.doubleValue() >= targetUtil - 0.0000001)
return new Accept(state.getSettings().getID(), bid);
return action;
}
/**
* Overrideable for hard configuring this component.
*
* @param state the {@link BoaState}
* @return the parameter e for the time depemdency function
* {@link #f(double)}. The parameter is 1 by default, or the value
* for the "e" parameter in the {@link Settings} if available.
*/
protected Double getE(BoaState state) {
return state.getSettings().getParameters().getDouble("e", 1d, 0d, 1d);
}
/**
* Overrideable for hard configuring this component.
*
* @param state the {@link BoaState}
* @return the parameter k for the time depemdency function
* {@link #f(double)}. The parameter is 0 by default, or the value
* for the "k" parameter in the {@link Settings} if available.
*/
protected Double getK(BoaState state) {
return state.getSettings().getParameters().getDouble("k", 0d, 0d, 1d);
}
/**
* Overrideable for hard configuring this component.
*
* @param state the {@link BoaState}
* @return the min value for {@link #p(double)}. We use the "min" parameter
* in the {@link Settings} if available. If not available, the
* parameter is computed as the utility of the reservation bid. If
* there is no reservation bid, we use the minimum utility of the
* available profile.
*/
protected Double getMin(BoaState state) {
Double val = state.getSettings().getParameters().getDouble("min", null,
0d, 1d);
if (val != null)
return val;
// val=null, try the reservation bid
LinearAdditive profile = (LinearAdditive) state.getProfile();
if (profile.getReservationBid() != null) {
return profile.getUtility(profile.getReservationBid())
.doubleValue();
}
return getBidspace(profile).getRange().getMin().doubleValue();
}
/**
* Overrideable for hard configuring this component.
*
* @param state the {@link BoaState}
* @return the max value for {@link #p(double)}. We use the "max" parameter
* in the {@link Settings} if available. If not available, we use
* the maximum utility of the available profile.
*/
protected Double getMax(BoaState state) {
Double val = state.getSettings().getParameters().getDouble("max", null,
0d, 1d);
if (val != null)
return val;
UtilitySpace profile = (UtilitySpace) state.getProfile();
return getBidspace(profile).getRange().getMax().doubleValue();
}
/**
* factory method. Overridable for testing
*
* @param profile the profile to get a bidspace for
* @return {@link BidsWithUtility}
*/
protected BidsWithUtility getBidspace(Profile profile) {
return new BidsWithUtility((LinearAdditive) profile);
}
/**
* Makes sure the target utility with in the acceptable range according to
* the domain
*
* @param t the normalized current time in the negotiation, where t=9 at
* start of negotiation and t=1 at end of negotiation.
* @return double
*/
private double p(double t) {
return this.min + (this.max - this.min) * (1.0 - f(t));
}
/**
* From the paper:
*
* A wide range of time dependent functions can be defined by varying the
* way in which f(t) is computed. However, functions must ensure that 0 <=
* f(t) <= 1, f(0) = k, and f(1) = 1.
*
* That is, the offer will always be between the value range, at the
* beginning it will give the initial constant and when the deadline is
* reached, it will offer the reservation value.
*
* @param t the normalized current time in the negotiation, where t=9 at
* start of negotiation and t=1 at end of negotiation.
* @return
*/
private double f(double t) {
return k + (1.0 - k) * Math.pow(t, 1.0 / e);
}
}