source: ANL2022/charging_boul/extended_util_space.py

Last change on this file was 75, checked in by wouter, 21 months ago

#6 added ANAC2022 parties

File size: 1.3 KB
Line 
1from decimal import Decimal
2from geniusweb.bidspace.BidsWithUtility import BidsWithUtility
3from geniusweb.bidspace.Interval import Interval
4from geniusweb.issuevalue.Bid import Bid
5from geniusweb.profile.utilityspace.LinearAdditive import LinearAdditive
6from tudelft.utilities.immutablelist.ImmutableList import ImmutableList
7from typing import List
8
9
10class 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.