Rev | Line | |
---|
[75] | 1 | from decimal import Decimal
|
---|
| 2 | from geniusweb.bidspace.BidsWithUtility import BidsWithUtility
|
---|
| 3 | from geniusweb.bidspace.Interval import Interval
|
---|
| 4 | from geniusweb.issuevalue.Bid import Bid
|
---|
| 5 | from geniusweb.profile.utilityspace.LinearAdditive import LinearAdditive
|
---|
| 6 | from tudelft.utilities.immutablelist.ImmutableList import ImmutableList
|
---|
| 7 | from typing import List
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 | class ExtendedUtilSpace:
|
---|
| 11 | def __init__(self, space: LinearAdditive):
|
---|
| 12 | self.util_space = space
|
---|
| 13 | self.bid_utils = BidsWithUtility.create(self.util_space)
|
---|
| 14 | self.tolerance = self.compute_tolerance()
|
---|
| 15 |
|
---|
| 16 | def compute_tolerance(self) -> Decimal:
|
---|
| 17 | tolerance = Decimal(1)
|
---|
| 18 | for iss in self.bid_utils.getInfo():
|
---|
| 19 | if iss.getValues().size() > 1:
|
---|
| 20 | # we have at least 2 values.
|
---|
| 21 | values: List[Decimal] = []
|
---|
| 22 | for val in iss.getValues():
|
---|
| 23 | values.append(iss.getWeightedUtil(val))
|
---|
| 24 | values.sort()
|
---|
| 25 | values.reverse()
|
---|
| 26 | tolerance = min(tolerance, values[0] - values[1])
|
---|
| 27 | return tolerance
|
---|
| 28 |
|
---|
| 29 | def getBids(self, utilityGoal: Decimal, time: float) -> ImmutableList[Bid]:
|
---|
| 30 | return self.bid_utils.getBids(
|
---|
| 31 | Interval(utilityGoal - (Decimal(time)*3 + 1)*self.tolerance, utilityGoal + (Decimal(time)*3 + 1)*self.tolerance)
|
---|
| 32 | )
|
---|
Note:
See
TracBrowser
for help on using the repository browser.