1 | package geniusweb.boa.biddingstrategy;
|
---|
2 |
|
---|
3 | import java.math.BigDecimal;
|
---|
4 | import java.math.BigInteger;
|
---|
5 | import java.util.Collections;
|
---|
6 | import java.util.LinkedList;
|
---|
7 |
|
---|
8 | import geniusweb.bidspace.BidsWithUtility;
|
---|
9 | import geniusweb.bidspace.Interval;
|
---|
10 | import geniusweb.bidspace.IssueInfo;
|
---|
11 | import geniusweb.issuevalue.Bid;
|
---|
12 | import geniusweb.issuevalue.Value;
|
---|
13 | import geniusweb.profile.utilityspace.LinearAdditive;
|
---|
14 | import tudelft.utilities.immutablelist.ImmutableList;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Inner class for TimeDependentParty, made public for testing purposes. This
|
---|
18 | * class may change in the future, use at your own risk. Copy of
|
---|
19 | * geniusweb.exampleparties.timedependentparty
|
---|
20 | *
|
---|
21 | */
|
---|
22 | public class ExtendedUtilSpace {
|
---|
23 | private LinearAdditive utilspace;
|
---|
24 | private BigDecimal tolerance; // utility tolerance for a bid.
|
---|
25 | private BidsWithUtility bidutils;
|
---|
26 | // min and max achievable utility
|
---|
27 | private BigDecimal minUtil;
|
---|
28 | private BigDecimal maxUtil;
|
---|
29 |
|
---|
30 | public ExtendedUtilSpace(LinearAdditive space) {
|
---|
31 | this.utilspace = space;
|
---|
32 | bidutils = new BidsWithUtility(utilspace);
|
---|
33 | computeMinMax();
|
---|
34 | this.tolerance = computeTolerance();
|
---|
35 |
|
---|
36 | }
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Computes the fields minutil and maxUtil.
|
---|
40 | * <p>
|
---|
41 | * TODO this is simplistic, very expensive method and may cause us to run
|
---|
42 | * out of time on large domains.
|
---|
43 | * <p>
|
---|
44 | * Assumes that utilspace and bidutils have been set properly.
|
---|
45 | */
|
---|
46 | private void computeMinMax() {
|
---|
47 | Interval range = bidutils.getRange();
|
---|
48 | this.minUtil = range.getMin();
|
---|
49 | this.maxUtil = range.getMax();
|
---|
50 |
|
---|
51 | Bid rvbid = utilspace.getReservationBid();
|
---|
52 | if (rvbid != null) {
|
---|
53 | BigDecimal rv = utilspace.getUtility(rvbid);
|
---|
54 | if (rv.compareTo(minUtil) > 0)
|
---|
55 | minUtil = rv;
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Tolerance is the Interval we need when searching bids. When we are close
|
---|
61 | * to the maximum utility, this value has to be the distance between the
|
---|
62 | * best and one-but-best utility.
|
---|
63 | *
|
---|
64 | * @return the minimum tolerance required, which is the minimum difference
|
---|
65 | * between the weighted utility of the best and one-but-best issue
|
---|
66 | * value.
|
---|
67 | */
|
---|
68 | protected BigDecimal computeTolerance() {
|
---|
69 | BigDecimal tolerance = BigDecimal.ONE;
|
---|
70 | for (IssueInfo iss : bidutils.getInfo()) {
|
---|
71 | if (iss.getValues().size().compareTo(BigInteger.ONE) > 0) {
|
---|
72 | // we have at least 2 values.
|
---|
73 | LinkedList<BigDecimal> values = new LinkedList<BigDecimal>();
|
---|
74 | for (Value val : iss.getValues()) {
|
---|
75 | values.add(iss.getWeightedUtil(val));
|
---|
76 | }
|
---|
77 | Collections.sort(values);
|
---|
78 | Collections.reverse(values);
|
---|
79 | tolerance = tolerance
|
---|
80 | .min(values.get(0).subtract(values.get(1)));
|
---|
81 | }
|
---|
82 | }
|
---|
83 | return tolerance;
|
---|
84 | }
|
---|
85 |
|
---|
86 | public BigDecimal getMin() {
|
---|
87 | return minUtil;
|
---|
88 | }
|
---|
89 |
|
---|
90 | public BigDecimal getMax() {
|
---|
91 | return maxUtil;
|
---|
92 | }
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * @param utilityGoal the intended utilty
|
---|
96 | * @return bids with utility inside [utilitygoal-tolerance, utilitygoal]
|
---|
97 | */
|
---|
98 | public ImmutableList<Bid> getBids(BigDecimal utilityGoal) {
|
---|
99 | return bidutils.getBids(
|
---|
100 | new Interval(utilityGoal.subtract(tolerance), utilityGoal));
|
---|
101 | }
|
---|
102 |
|
---|
103 | }
|
---|