Loading pyehub/multi_run_period.py 0 → 100644 +68 −0 Original line number Diff line number Diff line import argparse import os import numpy as np import copy from energy_hub.param_var import ConstantOrVar from energy_hub import EHubModel from energy_hub.utils import constraint from energy_hub.input_data import InputData from outputter import print_section, output_excel import excel_to_request_format import pylp from pylp import RealVariable, BinaryVariable, IntegerVariable import pdb DOMAIN_TO_VARIABLE = { 'Continuous': RealVariable, 'Integer': IntegerVariable, 'Binary': BinaryVariable, } @constraint() def same_converter_constraint(hubs): pass def periodic_subproblem(excel=None, request=None, output_filename=None, max_carbon=None, num_periods=1, len_periods=24, solver='glpk'): """ Core function for splitting a PyEHub model into smaller problems to solve together. :param: excel """ if excel: request = excel_to_request_format.convert(excel) if request: _data = InputData(request) else: raise RuntimeError("Can't create a hub with no data.") hubs = [] for i in range(0, num_periods): temp_request = copy.deepcopy(request) for stream in temp_request['time_series']: stream['data'] = stream['data'][i*len_periods:(i+1)*len_periods] hub = EHubModel(request=temp_request, max_carbon=max_carbon) hubs.append(hub) constraints = [] for hub in hubs: hub.recompile() for constr in hub.constraints: constraints.append(constr) #TODO: Make sure storage looping is working for each sub_hub #FIXME: Ralph had specific instructions for how to handle the objective (wanting a single one or something) # "Make the objective function only one of the investment consts (since they're all the same) # plus the operating cost for each sub-hub scaled by an appropriate factor to represent the whole year."" objective = hubs[0].objective for hub in hubs[1:]: objective += hub.objective status = pylp.solve(objective=objective, constraints=constraints, minimize=True, solver=solver) #TODO: Figure out setting up the output No newline at end of file pyehub/multiple_hubs.py +1 −0 Original line number Diff line number Diff line Loading @@ -421,6 +421,7 @@ def multiple_hubs(minimize_carbon=False, output_filename=None, input_files=None, "capacity_tech", ] #TODO: clean up the use of this input variable to just checking the objective of the hubs instead. #: Used to output files with names according to their job. if minimize_carbon: ext = "_minimized_carbon" Loading Loading
pyehub/multi_run_period.py 0 → 100644 +68 −0 Original line number Diff line number Diff line import argparse import os import numpy as np import copy from energy_hub.param_var import ConstantOrVar from energy_hub import EHubModel from energy_hub.utils import constraint from energy_hub.input_data import InputData from outputter import print_section, output_excel import excel_to_request_format import pylp from pylp import RealVariable, BinaryVariable, IntegerVariable import pdb DOMAIN_TO_VARIABLE = { 'Continuous': RealVariable, 'Integer': IntegerVariable, 'Binary': BinaryVariable, } @constraint() def same_converter_constraint(hubs): pass def periodic_subproblem(excel=None, request=None, output_filename=None, max_carbon=None, num_periods=1, len_periods=24, solver='glpk'): """ Core function for splitting a PyEHub model into smaller problems to solve together. :param: excel """ if excel: request = excel_to_request_format.convert(excel) if request: _data = InputData(request) else: raise RuntimeError("Can't create a hub with no data.") hubs = [] for i in range(0, num_periods): temp_request = copy.deepcopy(request) for stream in temp_request['time_series']: stream['data'] = stream['data'][i*len_periods:(i+1)*len_periods] hub = EHubModel(request=temp_request, max_carbon=max_carbon) hubs.append(hub) constraints = [] for hub in hubs: hub.recompile() for constr in hub.constraints: constraints.append(constr) #TODO: Make sure storage looping is working for each sub_hub #FIXME: Ralph had specific instructions for how to handle the objective (wanting a single one or something) # "Make the objective function only one of the investment consts (since they're all the same) # plus the operating cost for each sub-hub scaled by an appropriate factor to represent the whole year."" objective = hubs[0].objective for hub in hubs[1:]: objective += hub.objective status = pylp.solve(objective=objective, constraints=constraints, minimize=True, solver=solver) #TODO: Figure out setting up the output No newline at end of file
pyehub/multiple_hubs.py +1 −0 Original line number Diff line number Diff line Loading @@ -421,6 +421,7 @@ def multiple_hubs(minimize_carbon=False, output_filename=None, input_files=None, "capacity_tech", ] #TODO: clean up the use of this input variable to just checking the objective of the hubs instead. #: Used to output files with names according to their job. if minimize_carbon: ext = "_minimized_carbon" Loading