From 93324eb062f626f96139e4cd71f7bbc9ff4dbc67 Mon Sep 17 00:00:00 2001 From: "niehues.mark@gmail.com" <niehues.mark@gmail.com> Date: Fri, 20 Mar 2020 11:34:21 +0100 Subject: [PATCH] remove mental overhead by removing special functions --- evrouting/charge/T.py | 27 ++++++--------------------- evrouting/charge/utils.py | 6 +++--- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/evrouting/charge/T.py b/evrouting/charge/T.py index 82f4c5a..ff39183 100644 --- a/evrouting/charge/T.py +++ b/evrouting/charge/T.py @@ -134,14 +134,6 @@ class ChargingFunction: return cf_inverse - def __lt__(self, other) -> bool: - """Comparison for dominance check.""" - return self.c < other.c - - def __gt__(self, other): - """Comparison for dominance check.""" - return self.c > other.c - class Label(NamedTuple): """ @@ -238,7 +230,7 @@ class SoCFunction: t_charge = None - if cs > self.cf_cs: + if cs.c > self.cf_cs.c: # Faster charging station -> charge as soon as possible t_charge = self.breakpoints[0].t - self.t_trip elif self.breakpoints[-1].soc < capacity: @@ -249,20 +241,13 @@ class SoCFunction: return t_charge - def __lt__(self, other: 'SoCFunction') -> bool: - """Comparison for dominance check.""" - for t_i, soc_i in self.breakpoints: - if other(t_i) < soc_i: - return False - - for t_i, soc_i in other.breakpoints: - if soc_i < self(t_i): - return False + def dominates(self, other: 'SoCFunction') -> bool: + """ + Check if self dominates other function by evaluating all breakpoints. - return True + f dominates f' if f(t) >= f'(t) for all t - def __gt__(self, other: 'SoCFunction') -> bool: - """Comparison for dominance check.""" + """ for t_i, soc_i in self.breakpoints: if other(t_i) > soc_i: return False diff --git a/evrouting/charge/utils.py b/evrouting/charge/utils.py index 072eade..217ed4c 100644 --- a/evrouting/charge/utils.py +++ b/evrouting/charge/utils.py @@ -30,10 +30,10 @@ class LabelPriorityQueue(PriorityQueue): except KeyError: return - soc = self.f_soc_factory(label) + soc: SoCFunction = self.f_soc_factory(label) - # Remove item if it gets dominanted by any label in l_set - if any(self.f_soc_factory(label) > soc for label in self.l_set): + # Remove item if it gets dominated by any label in l_set + if any(self.f_soc_factory(label).dominates(soc) for label in self.l_set): self.remove_item(label) -- GitLab