Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbailey committed Dec 9, 2019
1 parent 5de7040 commit 72c2dfc
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions rail/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,37 @@
import numpy as np
from scipy.stats import lognorm


class Control(UserDict):
"""
A class to represent Controls
"""
def __init__(self, name: str, cost: float, reduction: float, implemented: bool=True) -> None:

def __init__(
self, name: str, cost: float, reduction: float, implemented: bool = True
) -> None:
self.data = {}
self.data['name'] = name
self.data['cost'] = cost
self.data['reduction'] = reduction
self.data['implemented'] = implemented
self.data["name"] = name
self.data["cost"] = cost
self.data["reduction"] = reduction
self.data["implemented"] = implemented

def evaluate_lognormal(self, iterations=1):
return Control(
name = self.data['name'],
cost = lognorm.ppf(np.random.rand(iterations), s=np.log(self.data['cost'])),
reduction = lognorm.ppf(np.random.rand(iterations), s=np.log(self.data['reduction'])),
implemented = self.data['implemented']
name=self.data["name"],
cost=lognorm.ppf(np.random.rand(iterations), s=np.log(self.data["cost"])),
reduction=lognorm.ppf(
np.random.rand(iterations), s=np.log(self.data["reduction"])
),
implemented=self.data["implemented"],
)


class Controls(UserDict):
"""
A class to hold multiple Controls
"""

def __init__(self) -> None:
self.data = {}

Expand All @@ -45,11 +52,26 @@ def costs(self):
"""
A method to compute the deterministic costs of implemented controls in a Controls class
"""
return np.sum(list(map(lambda x: x['cost'] if x['implemented'] is True else 0, self.data.values())))
return np.sum(
list(
map(
lambda x: x["cost"] if x["implemented"] is True else 0,
self.data.values(),
)
)
)

def costs_lognormal(self):
"""
A method to compute the stochastic costs of implemented controls in a Controls class
"""
return np.sum(list(map(lambda x: x.evaluate_lognormal().data['cost'] if x.data['implemented'] is True else 0, self)))

return np.sum(
list(
map(
lambda x: x.evaluate_lognormal().data["cost"]
if x.data["implemented"] is True
else 0,
self,
)
)
)

0 comments on commit 72c2dfc

Please sign in to comment.