[88] | 1 | from decimal import Decimal
|
---|
| 2 | from typing import List, Dict
|
---|
| 3 |
|
---|
| 4 | from geniusweb.issuevalue.Bid import Bid
|
---|
| 5 | from geniusweb.issuevalue.Value import Value
|
---|
| 6 | from geniusweb.profile.utilityspace.LinearAdditive import LinearAdditive
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 | class ParetoPoint:
|
---|
| 10 | '''
|
---|
| 11 | A Paretopoint is a Bid together with an N-dimensional utility vector. This is
|
---|
| 12 | also a caching mechanism to avoid repeated utility computation of good bids.
|
---|
| 13 | This is a internal utility class to streamline pareto computations.
|
---|
| 14 | '''
|
---|
| 15 |
|
---|
| 16 | def __init__(self, utils:List[Decimal] , bid:Bid):
|
---|
| 17 | '''
|
---|
| 18 | @param bid a (possibly partial) {@link Bid}
|
---|
| 19 | @param utils the utilities of the bid in all spaces, in order
|
---|
| 20 | '''
|
---|
| 21 | self._bid = bid;
|
---|
| 22 | self._utilities = list(utils)
|
---|
| 23 |
|
---|
| 24 | @staticmethod
|
---|
| 25 | def create(bid:Bid , spaces:List[LinearAdditive]) -> "ParetoPoint":
|
---|
| 26 | '''
|
---|
| 27 | @param bid a (possibly partial) {@link Bid}
|
---|
| 28 | @param spaces the {@link LinearAdditive}s to consider
|
---|
| 29 | '''
|
---|
| 30 | utilities:List[Decimal] = []
|
---|
| 31 | for space in spaces:
|
---|
| 32 | utilities.append(space.getUtility(bid))
|
---|
| 33 | return ParetoPoint(utilities, bid)
|
---|
| 34 |
|
---|
| 35 | def merge(self, otherpoint:"ParetoPoint") -> "ParetoPoint":
|
---|
| 36 | '''
|
---|
| 37 | Merges the issues from both bids and adds the utilities. This only works
|
---|
| 38 | correctly if the issues in other point are completely disjoint from our
|
---|
| 39 | bid issues.
|
---|
| 40 |
|
---|
| 41 | @param otherpoint with the utils summed and the issue values merged
|
---|
| 42 | '''
|
---|
| 43 | summedutils:List[Decimal] = []
|
---|
| 44 | for n in range(len(self._utilities)):
|
---|
| 45 | summedutils.append(self._utilities[n] + otherpoint._utilities[n])
|
---|
| 46 |
|
---|
| 47 | return ParetoPoint(summedutils, self._bid.merge(otherpoint.getBid()))
|
---|
| 48 |
|
---|
| 49 | def isDominatedBy(self, other:"ParetoPoint") -> bool:
|
---|
| 50 | '''
|
---|
| 51 | @param other
|
---|
| 52 | @return true if this ParetoPoint is dominated by the other. That means
|
---|
| 53 | other has better or equal utilities in ALL dimensions.
|
---|
| 54 | '''
|
---|
| 55 | otherutils:List[Decimal] = other.getUtilities()
|
---|
| 56 | for i in range(len(self._utilities)):
|
---|
| 57 | if otherutils[i] < self._utilities[i]:
|
---|
| 58 | return False
|
---|
| 59 | return True
|
---|
| 60 |
|
---|
| 61 | def getUtilities(self) -> List[Decimal]:
|
---|
| 62 | return self._utilities
|
---|
| 63 |
|
---|
| 64 | def getBid(self) -> Bid:
|
---|
| 65 | return self._bid
|
---|