|
| 1 | +TYPE_COST_MAPPING = {"gasfired": "gas(euro/MWh)", "turbojet": "kerosine(euro/MWh)"} |
| 2 | + |
| 3 | + |
| 4 | +class PowerPlant: |
| 5 | + |
| 6 | + def __init__(self, values): |
| 7 | + for key, value in values.items(): |
| 8 | + setattr(self, key, value) |
| 9 | + |
| 10 | + def get_producted_load(self, required_load): |
| 11 | + # To extend method, depending powerplant type |
| 12 | + pass |
| 13 | + |
| 14 | + |
| 15 | +class WindPowerPlant(PowerPlant): |
| 16 | + |
| 17 | + def __init__(self, values): |
| 18 | + super().__init__(values) |
| 19 | + self.wind_rate = values.get("wind") |
| 20 | + |
| 21 | + def get_producted_load(self, required_load): |
| 22 | + if required_load <= 0: |
| 23 | + return 0 |
| 24 | + load_to_product = required_load if self.pmax > required_load else self.pmax |
| 25 | + return round(load_to_product * self.wind_rate, 1) |
| 26 | + |
| 27 | + |
| 28 | +class FossilePowerPlant(PowerPlant): |
| 29 | + |
| 30 | + def __init__(self, values): |
| 31 | + super().__init__(values) |
| 32 | + theorical_cost = values.get("cost") |
| 33 | + self.cost = round(theorical_cost * (1 / (self.efficiency)), 1) |
| 34 | + |
| 35 | + def get_producted_load(self, required_load): |
| 36 | + if required_load <= 0: |
| 37 | + return 0 |
| 38 | + elif self.pmin < required_load < self.pmax: |
| 39 | + return required_load |
| 40 | + return self.pmin if required_load < self.pmin else self.pmax |
| 41 | + |
| 42 | + |
| 43 | +def init_all_powerplant_units(powerplant_values, productivity_settings): |
| 44 | + powerplants = [] |
| 45 | + breakpoint() |
| 46 | + for values in powerplant_values: |
| 47 | + type = values.get("type") |
| 48 | + cost_type = TYPE_COST_MAPPING.get(type, "wind") |
| 49 | + values.update( |
| 50 | + { |
| 51 | + "cost": productivity_settings.get(cost_type, 0.0), |
| 52 | + "wind": productivity_settings.get("wind(%)", 0.0) / 100, |
| 53 | + } |
| 54 | + ) |
| 55 | + ToInstanceClass = WindPowerPlant if type == "windturbine" else FossilePowerPlant |
| 56 | + powerplant = ToInstanceClass(values) |
| 57 | + powerplants.append(powerplant) |
| 58 | + return powerplants |
| 59 | + |
| 60 | + |
| 61 | +def get_merit_order_production_plan(required_load, powerplants): |
| 62 | + production_plan = [] |
| 63 | + ordered_powerplants = sorted(powerplants, key=lambda powerplant: powerplant.cost) |
| 64 | + for powerplant in ordered_powerplants: |
| 65 | + producted_load = powerplant.get_producted_load(required_load) |
| 66 | + production_plan.append({"name": powerplant.name, "p": producted_load}) |
| 67 | + required_load = round(required_load - producted_load, 1) |
| 68 | + return production_plan |
0 commit comments