Loading pyehub/multi_run_period.py +11 −14 Original line number Diff line number Diff line Loading @@ -26,14 +26,11 @@ def same_converter_constraint(converter, hubs): """ Constraint to ensure the capacities are kept constant across all the subproblems. """ first = True for i in enumerate(hubs): if not first: yield hubs[i-1].capacities[converter] == hubs[i].capacities[converter] first = False for i in range(len(hubs)-1): yield hubs[i].capacities[converter] == hubs[i+1].capacities[converter] def split_hubs(excel=None, request=None, max_carbon=None, num_periods=1, len_periods=24): def split_hubs(excel=None, request=None, max_carbon=None, num_periods=1, len_periods=24, num_skipped_periods=0): """ Splits a PyEHub into a series of smaller hubs with a given period. """ Loading @@ -43,17 +40,17 @@ def split_hubs(excel=None, request=None, max_carbon=None, num_periods=1, len_per if request: _data = InputData(request) else: raise RuntimeError("Can't create a hub with no data.") raise RuntimeError("Can't create hubs with no data.") hubs = [] if ((num_periods*len_periods) > len(request['time_series'][0]['data'])): if ((num_periods*len_periods*(num_skipped_periods+1)) > len(request['time_series'][0]['data'])): raise IndexError("Not enough data to cover all the periods.") 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] stream['data'] = stream['data'][(i*len_periods) + (i*num_skipped_periods) : ((i+1)*len_periods) + (i*num_skipped_periods)] hub = EHubModel(request=temp_request, max_carbon=max_carbon) hubs.append(hub) return hubs Loading @@ -74,11 +71,11 @@ def merge_hubs(hubs): return constraints def run_split_period(excel=None, request=None, output_filename=None, max_carbon=None, num_periods=1, len_periods=24, solver='glpk'): def run_split_period(excel=None, request=None, output_filename=None, max_carbon=None, num_periods=1, len_periods=24, num_skipped_periods=0, solver='glpk'): """ Core function for splitting a PyEHub model into smaller problems to solve together. """ hubs = split_hubs(excel, request, max_carbon, num_periods, len_periods) hubs = split_hubs(excel, request, max_carbon, num_periods, len_periods, num_skipped_periods) constraints = merge_hubs(hubs) #TODO: Make sure storage looping is working for each sub_hub Loading @@ -86,9 +83,9 @@ def run_split_period(excel=None, request=None, output_filename=None, max_carbon= #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 objective = hubs[0].investment_cost for hub in hubs: objective += hub.operating_cost*(num_skipped_periods+1) + hub.maintenance_cost*(num_skipped_periods+1) Loading Loading
pyehub/multi_run_period.py +11 −14 Original line number Diff line number Diff line Loading @@ -26,14 +26,11 @@ def same_converter_constraint(converter, hubs): """ Constraint to ensure the capacities are kept constant across all the subproblems. """ first = True for i in enumerate(hubs): if not first: yield hubs[i-1].capacities[converter] == hubs[i].capacities[converter] first = False for i in range(len(hubs)-1): yield hubs[i].capacities[converter] == hubs[i+1].capacities[converter] def split_hubs(excel=None, request=None, max_carbon=None, num_periods=1, len_periods=24): def split_hubs(excel=None, request=None, max_carbon=None, num_periods=1, len_periods=24, num_skipped_periods=0): """ Splits a PyEHub into a series of smaller hubs with a given period. """ Loading @@ -43,17 +40,17 @@ def split_hubs(excel=None, request=None, max_carbon=None, num_periods=1, len_per if request: _data = InputData(request) else: raise RuntimeError("Can't create a hub with no data.") raise RuntimeError("Can't create hubs with no data.") hubs = [] if ((num_periods*len_periods) > len(request['time_series'][0]['data'])): if ((num_periods*len_periods*(num_skipped_periods+1)) > len(request['time_series'][0]['data'])): raise IndexError("Not enough data to cover all the periods.") 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] stream['data'] = stream['data'][(i*len_periods) + (i*num_skipped_periods) : ((i+1)*len_periods) + (i*num_skipped_periods)] hub = EHubModel(request=temp_request, max_carbon=max_carbon) hubs.append(hub) return hubs Loading @@ -74,11 +71,11 @@ def merge_hubs(hubs): return constraints def run_split_period(excel=None, request=None, output_filename=None, max_carbon=None, num_periods=1, len_periods=24, solver='glpk'): def run_split_period(excel=None, request=None, output_filename=None, max_carbon=None, num_periods=1, len_periods=24, num_skipped_periods=0, solver='glpk'): """ Core function for splitting a PyEHub model into smaller problems to solve together. """ hubs = split_hubs(excel, request, max_carbon, num_periods, len_periods) hubs = split_hubs(excel, request, max_carbon, num_periods, len_periods, num_skipped_periods) constraints = merge_hubs(hubs) #TODO: Make sure storage looping is working for each sub_hub Loading @@ -86,9 +83,9 @@ def run_split_period(excel=None, request=None, output_filename=None, max_carbon= #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 objective = hubs[0].investment_cost for hub in hubs: objective += hub.operating_cost*(num_skipped_periods+1) + hub.maintenance_cost*(num_skipped_periods+1) Loading