RealParameter('SD_Grey electricity cost ramp', -0.001, 0.001), #minimum is -0.001 RealParameter('SD_Renewable Electricity cost multiplier', 0.5, 2), RealParameter('SD_Foreign renewable multiplier', 0.5, 2), # Economy Scenarios RealParameter('SD_Expected Period', 4, 10), RealParameter('SD_Expected Amplitude', 0.01, 0.05), # People uncertainties RealParameter('ABM_group-behaviour', 0, 1), RealParameter('ABM_Heat-company-ROI', 0.03, 0.15), RealParameter('ABM_Max-income-inv-share', 0.01, 0.15), RealParameter('ABM_Max-capital-inv-share', 0.01, 0.15), # Low level system uncertainties RealParameter('ABM_Relative-construction-capacity', 0.01, 0.1), CategoricalParameter( 'ABM_heating-grid-cost-scenario', ['"High"', '"Low"']) # Double quotes needed for netlogo ] multi_model.levers = [ RealParameter('ABM_insulation-subsidy', 0, 0.5), RealParameter('ABM_LT-production-subsidy', 0, 0.5), RealParameter('ABM_LT-investment-subsidy', 0, 0.5), RealParameter('ABM_MT-production-subsidy', 0, 0.5), RealParameter('ABM_MT-investment-subsidy', 0, 0.5), RealParameter('SD_NMTU factor', 1, 2), RealParameter('SD_Tax multiplier', 0, 3), CategoricalParameter('SD_CO2 tax scheme', [0, 1, 2]), CategoricalParameter('SD_Green gas transition scheme', [0, 1, 2]) ]
df_supply = db_file.parse('Supply') df_supply_units = db_file.parse('SupplyUnits') df_time_periods = db_file.parse('TimePeriods') #model = Model('simpleModel', function=optim_model) ############################################################################### #ema_logging.LOG_FORMAT = '[%(name)s/%(levelname)s/%(processName)s] %(message)s' ema_logging.log_to_stderr(ema_logging.DEBUG) ############################################################################## model = PyomoModel('simpleModel', wd='./data') # instantiate the model ############################################################################## # specify uncertainties model.uncertainties = [ CategoricalParameter('demand_index', (3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)), RealParameter('dev_rate_wind', 0.011, 0.033), #0.022 is estimated base value RealParameter('dev_rate_solar', 0.025, 0.075), #0.05 is estimated base value RealParameter("dev_rate_storage_elec", 0.025, 0.075), #0.05 is estimated base value #RealParameter("dev_rate_storage_heat",0.0125,0.0375),#0.016 is estimated base value RealParameter("dev_rate_conv_P2G", 0.0395, 0.1185), #0.079 is estimated base value #RealParameter("dev_rate_conv_HP",0.0125,0.0375),#0.01 is estimated base value RealParameter("discount_rate", 0.01, 0.15) ] #'base value' is 0.04. # specify outcomes model.outcomes = [
# instantiate the model lake_model = Model('lakeproblem', function=lake_problem) # specify uncertainties lake_model.uncertainties = [RealParameter('b', 0.1, 0.45), RealParameter('q', 2.0, 4.5), RealParameter('mean', 0.01, 0.05), RealParameter('stdev', 0.001, 0.005), RealParameter('delta', 0.93, 0.99)] # set levers lake_model.levers = [RealParameter("c1", -2, 2), RealParameter("c2", -2, 2), RealParameter("r1", 0, 2), RealParameter("r2", 0, 2), CategoricalParameter("w1", np.linspace(0, 1, 10)) ] # specify outcomes lake_model.outcomes = [ScalarOutcome('max_P', kind=ScalarOutcome.MINIMIZE), # @UndefinedVariable ScalarOutcome('utility', kind=ScalarOutcome.MAXIMIZE), # @UndefinedVariable ScalarOutcome('inertia', kind=ScalarOutcome.MAXIMIZE), # @UndefinedVariable ScalarOutcome('reliability', kind=ScalarOutcome.MAXIMIZE)] # @UndefinedVariable # override some of the defaults of the model lake_model.constants = [Constant('alpha', 0.41), Constant('nsamples', 100), Constant('myears', 100)]
'low': [0.1, 0.15], 'high': [0.15, 0.5], 'all': [0.1, 0.5] } infection_bucket = infection_buckets[infection.lower()] dying_bucket = dying_buckets[dying.lower()] #We can define common uncertainties and outcomes for each model: uncertainties = [ RealParameter('Average incubation time', 0.5, 14), RealParameter('Average infectious period', 7, 21), RealParameter('Basic reproduction number', infection_bucket[0], infection_bucket[1]), RealParameter('Case fatality rate', dying_bucket[0], dying_bucket[1]), CategoricalParameter('Switch SEIR or SIR', [1, 0]), RealParameter('Base Transmission Coefficient Social Distance III', 0.7, 0.8), RealParameter('Base Societal Stress Coefficient Social Distance III', 0.5, 0.9), RealParameter('Base Effort Coefficient Social Distance III', 4, 8), RealParameter('Implementation Time Social Distance III', 2, 4), RealParameter('Duration Social Distance III', 5, 21), RealParameter('Base Transmission Coefficient Social Distance II', 0.89, 0.96), RealParameter('Base Societal Stress Coefficient Social Distance II', 0.3, 0.8), RealParameter('Base Effort Coefficient Social Distance II', 3, 6), RealParameter('Implementation Time Social Distance II', 1, 3), RealParameter('Duration Social Distance II', 5, 21), RealParameter('Base Transmission Coefficient Social Distance I', 0.92,
def get_model_for_problem_formulation(problem_formulation_id): ''' Prepare DikeNetwork in a way it can be input in the EMA-workbench. Specify uncertainties, levers and problem formulation. ''' # Load the model: function = DikeNetwork() # workbench model: dike_model = Model('dikesnet', function=function) # Uncertainties and Levers: # Specify uncertainties range: Real_uncert = {'Bmax': [30, 350], 'pfail': [0, 1]} # m and [.] # breach growth rate [m/day] cat_uncert_loc = {'Brate': (1., 1.5, 10)} cat_uncert = { 'discount rate {}'.format(n): (1.5, 2.5, 3.5, 4.5) for n in function.planning_steps } Int_uncert = {'A.0_ID flood wave shape': [0, 132]} # Range of dike heightening: dike_lev = {'DikeIncrease': [0, 10]} # dm # Series of five Room for the River projects: rfr_lev = ['{}_RfR'.format(project_id) for project_id in range(0, 5)] # Time of warning: 0, 1, 2, 3, 4 days ahead from the flood EWS_lev = {'EWS_DaysToThreat': [0, 4]} # days uncertainties = [] levers = [] for uncert_name in cat_uncert.keys(): categories = cat_uncert[uncert_name] uncertainties.append(CategoricalParameter(uncert_name, categories)) for uncert_name in Int_uncert.keys(): uncertainties.append( IntegerParameter(uncert_name, Int_uncert[uncert_name][0], Int_uncert[uncert_name][1])) # RfR levers can be either 0 (not implemented) or 1 (implemented) for lev_name in rfr_lev: for n in function.planning_steps: lev_name_ = '{} {}'.format(lev_name, n) levers.append(IntegerParameter(lev_name_, 0, 1)) # Early Warning System lever for lev_name in EWS_lev.keys(): levers.append( IntegerParameter(lev_name, EWS_lev[lev_name][0], EWS_lev[lev_name][1])) for dike in function.dikelist: # uncertainties in the form: locationName_uncertaintyName for uncert_name in Real_uncert.keys(): name = "{}_{}".format(dike, uncert_name) lower, upper = Real_uncert[uncert_name] uncertainties.append(RealParameter(name, lower, upper)) for uncert_name in cat_uncert_loc.keys(): name = "{}_{}".format(dike, uncert_name) categories = cat_uncert_loc[uncert_name] uncertainties.append(CategoricalParameter(name, categories)) # location-related levers in the form: locationName_leversName for lev_name in dike_lev.keys(): for n in function.planning_steps: name = "{}_{} {}".format(dike, lev_name, n) levers.append( IntegerParameter(name, dike_lev[lev_name][0], dike_lev[lev_name][1])) # load uncertainties and levers in dike_model: dike_model.uncertainties = uncertainties dike_model.levers = levers # Problem formulations: # Outcomes are all costs, thus they have to minimized: direction = ScalarOutcome.MINIMIZE # 2-objective PF: if problem_formulation_id == 0: variable_names = [] variable_names_ = [] for n in function.planning_steps: variable_names.extend([ '{}_{} {}'.format(dike, e, n) for e in ['Expected Annual Damage', 'Dike Investment Costs'] for dike in function.dikelist ]) variable_names_.extend([ '{}_{} {}'.format(dike, e, n) for e in ['Expected Number of Deaths'] for dike in function.dikelist ]) variable_names.extend(['RfR Total Costs {}'.format(n)]) variable_names.extend(['Expected Evacuation Costs {}'.format(n)]) dike_model.outcomes = [ ScalarOutcome('All Costs', variable_name=[var for var in variable_names], function=sum_over, kind=direction), ScalarOutcome('Expected Number of Deaths', variable_name=[var for var in variable_names_], function=sum_over, kind=direction) ] # 3-objectives PF: elif problem_formulation_id == 1: variable_names = [] variable_names_ = [] variable_names__ = [] for n in function.planning_steps: variable_names.extend([ '{}_Expected Annual Damage {}'.format(dike, n) for dike in function.dikelist ]) variable_names_.extend([ '{}_Dike Investment Costs {}'.format(dike, n) for dike in function.dikelist ] + ['RfR Total Costs {}'.format(n)] + ['Expected Evacuation Costs {}'.format(n)]) variable_names__.extend([ '{}_Expected Number of Deaths {}'.format(dike, n) for dike in function.dikelist ]) dike_model.outcomes = [ ScalarOutcome('Expected Annual Damage', variable_name=[var for var in variable_names], function=sum_over, kind=direction), ScalarOutcome('Total Investment Costs', variable_name=[var for var in variable_names_], function=sum_over, kind=direction), ScalarOutcome('Expected Number of Deaths', variable_name=[var for var in variable_names__], function=sum_over, kind=direction) ] # 5-objectives PF: elif problem_formulation_id == 2: variable_names = [] variable_names_ = [] variable_names__ = [] variable_names___ = [] variable_names____ = [] for n in function.planning_steps: variable_names.extend([ '{}_Expected Annual Damage {}'.format(dike, n) for dike in function.dikelist ]) variable_names_.extend([ '{}_Dike Investment Costs {}'.format(dike, n) for dike in function.dikelist ]) variable_names__.extend(['RfR Total Costs {}'.format(n)]) variable_names___.extend( ['Expected Evacuation Costs {}'.format(n)]) variable_names____.extend([ '{}_Expected Number of Deaths {}'.format(dike, n) for dike in function.dikelist ]) dike_model.outcomes = [ ScalarOutcome('Expected Annual Damage', variable_name=[var for var in variable_names], function=sum_over, kind=direction), ScalarOutcome('Dike Investment Costs', variable_name=[var for var in variable_names_], function=sum_over, kind=direction), ScalarOutcome('RfR Investment Costs', variable_name=[var for var in variable_names__], function=sum_over, kind=direction), ScalarOutcome('Evacuation Costs', variable_name=[var for var in variable_names___], function=sum_over, kind=direction), ScalarOutcome('Expected Number of Deaths', variable_name=[var for var in variable_names____], function=sum_over, kind=direction) ] # Disaggregate over locations: elif problem_formulation_id == 3: outcomes = [] for dike in function.dikelist: variable_name = [] for e in ['Expected Annual Damage', 'Dike Investment Costs']: variable_name.extend([ '{}_{} {}'.format(dike, e, n) for n in function.planning_steps ]) outcomes.append( ScalarOutcome('{} Total Costs'.format(dike), variable_name=[var for var in variable_name], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('{}_Expected Number of Deaths'.format(dike), variable_name=[ '{}_Expected Number of Deaths {}'.format( dike, n) for n in function.planning_steps ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('RfR Total Costs', variable_name=[ 'RfR Total Costs {}'.format(n) for n in function.planning_steps ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('Expected Evacuation Costs', variable_name=[ 'Expected Evacuation Costs {}'.format(n) for n in function.planning_steps ], function=sum_over, kind=direction)) dike_model.outcomes = outcomes # Disaggregate over time: elif problem_formulation_id == 4: outcomes = [] for n in function.planning_steps: for dike in function.dikelist: outcomes.append( ScalarOutcome('Expected Annual Damage {}'.format(n), variable_name=[ '{}_Expected Annual Damage {}'.format( dike, n) for dike in function.dikelist ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('Dike Investment Costs {}'.format(n), variable_name=[ '{}_Dike Investment Costs {}'.format( dike, n) for dike in function.dikelist ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('Expected Number of Deaths {}'.format(n), variable_name=[ '{}_Expected Number of Deaths {}'.format( dike, n) for dike in function.dikelist ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('RfR Total Costs {}'.format(n), kind=direction)) outcomes.append( ScalarOutcome('Expected Evacuation Costs {}'.format(n), kind=direction)) dike_model.outcomes = outcomes # Fully disaggregated: elif problem_formulation_id == 5: outcomes = [] for n in function.planning_steps: for dike in function.dikelist: for entry in [ 'Expected Annual Damage', 'Dike Investment Costs', 'Expected Number of Deaths' ]: o = ScalarOutcome('{}_{} {}'.format(dike, entry, n), kind=direction) outcomes.append(o) outcomes.append( ScalarOutcome('RfR Total Costs {}'.format(n), kind=direction)) outcomes.append( ScalarOutcome('Expected Evacuation Costs {}'.format(n), kind=direction)) dike_model.outcomes = outcomes # Specific to Gelderland Province elif problem_formulation_id == 6: damage_a1_a2 = [] damage_a3 = [] casualties_a1_a2 = [] casualties_a3 = [] dike_costs = [] rfr_costs = [] evacuation_costs = [] outcomes = [] for n in function.planning_steps: #Damage damage_a1_a2.extend([ 'A.1_Expected Annual Damage {}'.format(n), 'A.2_Expected Annual Damage {}'.format(n) ]) damage_a3.extend(['A.3_Expected Annual Damage {}'.format(n)]) #Casualties casualties_a1_a2.extend([ 'A.1_Expected Number of Deaths {}'.format(n), 'A.2_Expected Number of Deaths {}'.format(n) ]) casualties_a3.extend( ['A.3_Expected Number of Deaths {}'.format(n)]) #Costs for dike in function.dikelist: dike_costs.extend([ '{}_Dike Investment Costs {}'.format(dike, n) for dike in function.dikelist ]) rfr_costs.extend(['RfR Total Costs {}'.format(n)]) evacuation_costs.extend(['Expected Evacuation Costs {}'.format(n)]) dike_model.outcomes = [ ScalarOutcome('A1_2 Aggr Expected Annual Damage', variable_name=[var for var in damage_a1_a2], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome('A3 Expected Annual Damage', variable_name=[var for var in damage_a3], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome('A1_2 Aggr Expected Number of Deaths', variable_name=[var for var in casualties_a1_a2], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome('A3 Aggr Expected Number of Deaths', variable_name=[var for var in casualties_a3], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome('A1_5 Dike Investment Costs', variable_name=[var for var in dike_costs], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome('Room for River Investment Costs', variable_name=[var for var in rfr_costs], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome('Evacuation Costs', variable_name=[var for var in evacuation_costs], function=sum_over, kind=ScalarOutcome.MINIMIZE) ] #Specified for Overijssel elif problem_formulation_id == 7: damage_a4 = [] damage_a5 = [] casualties_a4 = [] casualties_a5 = [] dike_costs = [] rfr_costs = [] evacuation_costs = [] outcomes = [] for n in function.planning_steps: #Damage damage_a4.extend(['A.4_Expected Annual Damage {}'.format(n)]) damage_a5.extend(['A.5_Expected Annual Damage {}'.format(n)]) #Casualties casualties_a4.extend( ['A.4_Expected Number of Deaths {}'.format(n)]) casualties_a5.extend( ['A.5_Expected Number of Deaths {}'.format(n)]) #Costs for dike in function.dikelist: dike_costs.extend([ '{}_Dike Investment Costs {}'.format(dike, n) for dike in function.dikelist ]) rfr_costs.extend(['RfR Total Costs {}'.format(n)]) evacuation_costs.extend(['Expected Evacuation Costs {}'.format(n)]) dike_model.outcomes = [ ScalarOutcome('A4 Expected Annual Damage', variable_name=[var for var in damage_a4], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome('A5 Expected Annual Damage', variable_name=[var for var in damage_a5], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome('A4 Expected Number of Deaths', variable_name=[var for var in casualties_a4], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome('A5 Expected Number of Deaths', variable_name=[var for var in casualties_a5], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome('A1_5 Dike Investment Costs', variable_name=[var for var in dike_costs], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome('Room for River Investment Costs', variable_name=[var for var in rfr_costs], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome('Evacuation Costs', variable_name=[var for var in evacuation_costs], function=sum_over, kind=ScalarOutcome.MINIMIZE) ] # 7-Objectives PF Holistic View: elif problem_formulation_id == 8: casualties = [] rfr_costs = [] evacuation_costs = [] gelderland_dike_cost = [] overijssel_dike_cost = [] gelderland_expected_damage = [] overijssel_expected_damage = [] outcomes = [] for n in function.planning_steps: #Damage gelderland_expected_damage.extend([ 'A.1_Expected Annual Damage {}'.format(n), 'A.2_Expected Annual Damage {}'.format(n), 'A.3_Expected Annual Damage {}'.format(n) ]) overijssel_expected_damage.extend([ 'A.4_Expected Annual Damage {}'.format(n), 'A.5_Expected Annual Damage {}'.format(n) ]) #Casualties casualties.extend([ 'A.1_Expected Number of Deaths {}'.format(n), 'A.2_Expected Number of Deaths {}'.format(n), 'A.3_Expected Number of Deaths {}'.format(n), 'A.4_Expected Number of Deaths {}'.format(n), 'A.5_Expected Number of Deaths {}'.format(n) ]) #Costs for dike in function.dikelist: gelderland_dike_cost.extend([ '{}_Dike Investment Costs {}'.format(dike, n) for dike in function.dikelist[0:len(function.dikelist) - 1] ]) overijssel_dike_cost.extend([ '{}_Dike Investment Costs {}'.format(dike, n) for dike in function.dikelist[4:5] ]) rfr_costs.extend(['RfR Total Costs {}'.format(n)]) evacuation_costs.extend(['Expected Evacuation Costs {}'.format(n)]) dike_model.outcomes = [ ScalarOutcome( 'Gelderland Expected Annual Damage', variable_name=[var for var in gelderland_expected_damage], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome( 'Overijssel Expected Annual Damage', variable_name=[var for var in overijssel_expected_damage], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome('Expected Number of Deaths', variable_name=[var for var in casualties], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome('Gelderland Dike Cost', variable_name=[var for var in gelderland_dike_cost], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome('Overijssel Dike Cost', variable_name=[var for var in overijssel_dike_cost], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome('Room for River Investment Costs', variable_name=[var for var in rfr_costs], function=sum_over, kind=ScalarOutcome.MINIMIZE), ScalarOutcome('Evacuation Costs', variable_name=[var for var in evacuation_costs], function=sum_over, kind=ScalarOutcome.MINIMIZE) ] else: raise TypeError('unknownx identifier') return dike_model, function.planning_steps
netlogo_version="6.0" ) with open('delta_dicts_list.json') as f: delta_dicts_list = json.load(f) model.replications = delta_dicts_list model.nticks = 30 model.assets = assets model.yearofintroduction = get_introductionyear() model.paths = paths uncertainties = [] for assettype, paths in paths.items(): unc = CategoricalParameter(f"{assettype} paths", paths) uncertainties.append(unc) assettype = AssetTypes["Powergen_baseload".upper()] for assetid in assets[assettype.name]: uncertainties += [BooleanParameter(f"baseload biomass or closure {assetid}"), IntegerParameter(f"{assetid} year", 2020, 2030)] uncertainties += [IntegerParameter("yearGunvorPhaseout", 2025, 2030), IntegerParameter("yearKochPhaseout", 2025, 2030), IntegerParameter("yearBPOffline", 2035, 2040), BooleanParameter("yearHydrocrackerBP"), IntegerParameter("year of introduction ELECTROLYSIS_H20", 2028, 2050), # tov earliest H2 availability CategoricalParameter("location h2 production", ["maasvlakte", "botlek", "none"]), # asset ids
def problem_definition(problem_formulation_id): ''' Prepare DikeNetwork in a way it can be input in the EMA-workbench. Specify uncertainties, levers and problem formulation. ''' # Load the model: function = DikeNetwork() # workbench model: dike_model = Model('dikesnet', function=function) # Uncertainties and Levers: # Specify uncertainties range: Real_uncert = {'Bmax': [30, 350], 'pfail': [0, 1]} # m and [.] # breach growth rate [m/day] cat_uncert_loc = {'Brate': (1., 1.5, 10)} cat_uncert = { 'discount rate {}'.format(n): (1.5, 2.5, 3.5, 4.5) for n in function.planning_steps } Int_uncert = {'A.0_ID flood wave shape': [0, 132]} # Range of dike heightening: dike_lev = {'DikeIncrease': [0, 10]} # dm # Series of five Room for the River projects: rfr_lev = ['{}_RfR'.format(project_id) for project_id in range(0, 5)] # Time of warning: 0, 1, 2, 3, 4 days ahead from the flood EWS_lev = {'EWS_DaysToThreat': [0, 4]} # days uncertainties = [] levers = [] for uncert_name in cat_uncert.keys(): categories = cat_uncert[uncert_name] uncertainties.append(CategoricalParameter(uncert_name, categories)) for uncert_name in Int_uncert.keys(): uncertainties.append( IntegerParameter(uncert_name, Int_uncert[uncert_name][0], Int_uncert[uncert_name][1])) # RfR levers can be either 0 (not implemented) or 1 (implemented) for lev_name in rfr_lev: for n in function.planning_steps: lev_name_ = '{} {}'.format(lev_name, n) levers.append(IntegerParameter(lev_name_, 0, 1)) # Early Warning System lever for lev_name in EWS_lev.keys(): levers.append( IntegerParameter(lev_name, EWS_lev[lev_name][0], EWS_lev[lev_name][1])) for dike in function.dikelist: # uncertainties in the form: locationName_uncertaintyName for uncert_name in Real_uncert.keys(): name = "{}_{}".format(dike, uncert_name) lower, upper = Real_uncert[uncert_name] uncertainties.append(RealParameter(name, lower, upper)) for uncert_name in cat_uncert_loc.keys(): name = "{}_{}".format(dike, uncert_name) categories = cat_uncert_loc[uncert_name] uncertainties.append(CategoricalParameter(name, categories)) # location-related levers in the form: locationName_leversName for lev_name in dike_lev.keys(): for n in function.planning_steps: name = "{}_{} {}".format(dike, lev_name, n) levers.append( IntegerParameter(name, dike_lev[lev_name][0], dike_lev[lev_name][1])) # load uncertainties and levers in dike_model: dike_model.uncertainties = uncertainties dike_model.levers = levers # Problem formulations: # Outcomes are all costs, thus they have to minimized: direction = ScalarOutcome.MINIMIZE ## TODO implement own problem # 3-objectives PF: if problem_formulation_id.lower() == 'damage, cost, deaths': variable_names = [] variable_names_ = [] variable_names__ = [] for n in function.planning_steps: variable_names.extend([ '{}_Expected Annual Damage {}'.format(dike, n) for dike in function.dikelist ]) variable_names_.extend([ '{}_Dike Investment Costs {}'.format(dike, n) for dike in function.dikelist ] + ['RfR Total Costs {}'.format(n)] + ['Expected Evacuation Costs {}'.format(n)]) variable_names__.extend([ '{}_Expected Number of Deaths {}'.format(dike, n) for dike in function.dikelist ]) dike_model.outcomes = [ ScalarOutcome('Expected Annual Damage', variable_name=[var for var in variable_names], function=sum_over, kind=direction), ScalarOutcome('Total Investment Costs', variable_name=[var for var in variable_names_], function=sum_over, kind=direction), ScalarOutcome('Expected Number of Deaths', variable_name=[var for var in variable_names__], function=sum_over, kind=direction) ] # 5-objectives PF: elif problem_formulation_id.lower() == 'damage, investment, rfr, deaths': variable_names = [] variable_names_ = [] variable_names__ = [] variable_names___ = [] variable_names____ = [] for n in function.planning_steps: variable_names.extend([ '{}_Expected Annual Damage {}'.format(dike, n) for dike in function.dikelist ]) variable_names_.extend([ '{}_Dike Investment Costs {}'.format(dike, n) for dike in function.dikelist ]) variable_names__.extend(['RfR Total Costs {}'.format(n)]) variable_names___.extend( ['Expected Evacuation Costs {}'.format(n)]) variable_names____.extend([ '{}_Expected Number of Deaths {}'.format(dike, n) for dike in function.dikelist ]) dike_model.outcomes = [ ScalarOutcome('Expected Annual Damage', variable_name=[var for var in variable_names], function=sum_over, kind=direction), ScalarOutcome('Dike Investment Costs', variable_name=[var for var in variable_names_], function=sum_over, kind=direction), ScalarOutcome('RfR Investment Costs', variable_name=[var for var in variable_names__], function=sum_over, kind=direction), ScalarOutcome('Evacuation Costs', variable_name=[var for var in variable_names___], function=sum_over, kind=direction), ScalarOutcome('Expected Number of Deaths', variable_name=[var for var in variable_names____], function=sum_over, kind=direction) ] # Disaggregate over locations: elif problem_formulation_id.lower() == 'vars per location': outcomes = [] for dike in function.dikelist: variable_name = [] for e in ['Expected Annual Damage', 'Dike Investment Costs']: variable_name.extend([ '{}_{} {}'.format(dike, e, n) for n in function.planning_steps ]) outcomes.append( ScalarOutcome('{} Total Costs'.format(dike), variable_name=[var for var in variable_name], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('{}_Expected Number of Deaths'.format(dike), variable_name=[ '{}_Expected Number of Deaths {}'.format( dike, n) for n in function.planning_steps ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('RfR Total Costs', variable_name=[ 'RfR Total Costs {}'.format(n) for n in function.planning_steps ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('Expected Evacuation Costs', variable_name=[ 'Expected Evacuation Costs {}'.format(n) for n in function.planning_steps ], function=sum_over, kind=direction)) dike_model.outcomes = outcomes # Disaggregate over locations: elif problem_formulation_id.lower() == 'a4, a5 vars': outcomes = [] for dike in function.dikelist: if '4' in dike or '5' in dike: variable_name = [] for e in ['Expected Annual Damage', 'Dike Investment Costs']: variable_name.extend([ '{}_{} {}'.format(dike, e, n) for n in function.planning_steps ]) outcomes.append( ScalarOutcome('{} Total Costs'.format(dike), variable_name=[var for var in variable_name], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('{}_Expected Number of Deaths'.format(dike), variable_name=[ '{}_Expected Number of Deaths {}'.format( dike, n) for n in function.planning_steps ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('RfR Total Costs', variable_name=[ 'RfR Total Costs {}'.format(n) for n in function.planning_steps ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('Expected Evacuation Costs', variable_name=[ 'Expected Evacuation Costs {}'.format(n) for n in function.planning_steps ], function=sum_over, kind=direction)) dike_model.outcomes = outcomes # Disaggregate over time: elif problem_formulation_id.lower() == 'vars per planningstep': outcomes = [] for n in function.planning_steps: for dike in function.dikelist: outcomes.append( ScalarOutcome('Expected Annual Damage {}'.format(n), variable_name=[ '{}_Expected Annual Damage {}'.format( dike, n) for dike in function.dikelist ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('Dike Investment Costs {}'.format(n), variable_name=[ '{}_Dike Investment Costs {}'.format( dike, n) for dike in function.dikelist ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('Expected Number of Deaths {}'.format(n), variable_name=[ '{}_Expected Number of Deaths {}'.format( dike, n) for dike in function.dikelist ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('RfR Total Costs {}'.format(n), kind=direction)) outcomes.append( ScalarOutcome('Expected Evacuation Costs {}'.format(n), kind=direction)) dike_model.outcomes = outcomes # Fully disaggregated: elif problem_formulation_id.lower() == 'all vars': outcomes = [] for n in function.planning_steps: for dike in function.dikelist: for entry in [ 'Expected Annual Damage', 'Dike Investment Costs', 'Expected Number of Deaths' ]: o = ScalarOutcome('{}_{} {}'.format(dike, entry, n), kind=direction) outcomes.append(o) outcomes.append( ScalarOutcome('RfR Total Costs {}'.format(n), kind=direction)) outcomes.append( ScalarOutcome('Expected Evacuation Costs {}'.format(n), kind=direction)) dike_model.outcomes = outcomes else: raise TypeError('unknownx identifier') return dike_model, function.planning_steps
x_min) assert isinstance(x_distributed, tuple), "is not tuple" return x_distributed non_uniform_sampling = False # set uncertainties n_eval_per_var = 12 sampling = distributed_sampling if non_uniform_sampling == True else lambda x, y: ( np.linspace(x, y, num=n_eval_per_var)) model.uncertainties = [ #CategoricalParameter('wind_multiplier', sampling(1.0, 2.0) ), # up to 100% increase in wind speed CategoricalParameter('sea_level_shift', sampling(0.0, 1)), # up to 1.5 meter shift water level CategoricalParameter('peak_inflow_multiplier', sampling(1, 2)), # up to 100% increase in inflow CategoricalParameter('low_flow_shift', sampling( 0., 100.)), # up to a reduction of low flow of 100 m^3/s #CategoricalParameter('evaporation_multiplier', sampling(1, 2)), # Increase of potential evaporation #CategoricalParameter('precipitation_multiplier', sampling(1,3) ) ] # set levers policies = [ CategoricalParameter('summer_target', (-0.2, 0.2)), CategoricalParameter('pump_capacity', (0, 500)), #CategoricalParameter('winter_target', (-0.4, -0.1) ), CategoricalParameter('sluices_widening', (1, 2))
def generate_params(prefix: str, dataset: Dict, override: Optional[Dict] = None): """Generate EMA Workbench compatible parameter definitions. Parameters ---------- prefix : str dataset : dict, of parameters for given component override : Dict[str, object], values to override nominals with keys based on prefix + name Returns ---------- * Dict matching structure of dataset """ prefix += '__' if override is None: override = {} for n, vals in dataset.items(): var_id = prefix + n if isinstance(vals, dict): dataset[n] = generate_params(prefix, vals, override) continue # Replace nominal value with override value if specified if var_id in override: vals = override.pop(var_id) dataset[n] = Constant(var_id, vals) continue param = None try: val_type, *param_vals = vals if len(set(param_vals)) == 1: dataset[n] = Constant(var_id, param_vals[0]) continue ptype = getattr(ema_mod, val_type) param = ptype(var_id, *param_vals[1:], default=param_vals[0]) dataset[n] = param continue except (ValueError, TypeError) as e: dataset[n] = Constant(var_id, vals) continue except AttributeError: warnings.warn( "Old data parsing method used - this wil be deprecated in the future." ) # Unknown param type, revert to old behaviour # To be removed nom, lb, ub = vals same_value = False if not isinstance(nom, str): try: param = RealParameter(name=var_id, default=nom, lower_bound=lb, upper_bound=ub) except ValueError: same_value = True else: if (nom == lb) and (ub == lb): same_value = True else: if len(set(vals)) > 1: param = CategoricalParameter(name=var_id, default=nom, categories=vals) else: same_value = True # End if # End if if same_value: param = Constant(var_id, nom) if param is None: raise ValueError("Could not determine parameter type!") dataset[n] = param # End try # End for return dataset
from evhub_leso_handshake import METRICS, EVHub from ema_workbench import ( RealParameter, CategoricalParameter, ScalarOutcome, Model, ) # initiate model model = Model(name='EVHub', function=EVHub) # levers / policies model.levers = [ CategoricalParameter("grid_capacity", [0, 0.5, 1, 1.5]), ] # uncertainties / scenarios model.uncertainties = [ RealParameter("pv_cost_factor", 0.38, 0.85), RealParameter("wind_cost_factor", 0.77, 0.98), RealParameter("battery_cost_factor", 0.41, 0.70), ] # specify outcomes model.outcomes = [ScalarOutcome(metric) for metric in METRICS]
def get_model_for_problem_formulation(problem_formulation_id): ''' Prepare DikeNetwork in a way it can be input in the EMA-workbench. Specify uncertainties, levers and problem formulation. ''' # Load the model: function = DikeNetwork() # workbench model: dike_model = Model('dikesnet', function=function) # Uncertainties and Levers: # Specify uncertainties range: Real_uncert = {'Bmax': [30, 350], 'pfail': [0, 1]} # m and [.] # breach growth rate [m/day] cat_uncert_loc = {'Brate': (1, 1.5, 10)} cat_uncert = { 'discount rate {}'.format(n): (1.5, 2.5, 3.5, 4.5) for n in function.planning_steps } Int_uncert = {'A.0_ID flood wave shape': [0, 132]} # Range of dike heightening: dike_lev = {'DikeIncrease': [0, 10]} # dm # Series of five Room for the River projects: rfr_lev = ['{}_RfR'.format(project_id) for project_id in range(0, 5)] # Time of warning: 0, 1, 2, 3, 4 days ahead from the flood EWS_lev = {'EWS_DaysToThreat': [0, 4]} # days uncertainties = [] levers = [] for uncert_name in cat_uncert.keys(): categories = cat_uncert[uncert_name] uncertainties.append(CategoricalParameter(uncert_name, categories)) for uncert_name in Int_uncert.keys(): uncertainties.append( IntegerParameter(uncert_name, Int_uncert[uncert_name][0], Int_uncert[uncert_name][1])) # RfR levers can be either 0 (not implemented) or 1 (implemented) for lev_name in rfr_lev: for n in function.planning_steps: lev_name_ = '{} {}'.format(lev_name, n) levers.append(IntegerParameter(lev_name_, 0, 1)) # Early Warning System lever for lev_name in EWS_lev.keys(): levers.append( IntegerParameter(lev_name, EWS_lev[lev_name][0], EWS_lev[lev_name][1])) for dike in function.dikelist: # uncertainties in the form: locationName_uncertaintyName for uncert_name in Real_uncert.keys(): name = "{}_{}".format(dike, uncert_name) lower, upper = Real_uncert[uncert_name] uncertainties.append(RealParameter(name, lower, upper)) for uncert_name in cat_uncert_loc.keys(): name = "{}_{}".format(dike, uncert_name) categories = cat_uncert_loc[uncert_name] uncertainties.append(CategoricalParameter(name, categories)) # location-related levers in the form: locationName_leversName for lev_name in dike_lev.keys(): for n in function.planning_steps: name = "{}_{} {}".format(dike, lev_name, n) levers.append( IntegerParameter(name, dike_lev[lev_name][0], dike_lev[lev_name][1])) # load uncertainties and levers in dike_model: dike_model.uncertainties = uncertainties dike_model.levers = levers # Problem formulations: # Outcomes are all costs, thus they have to minimized: direction = ScalarOutcome.MINIMIZE # 2-objective PF: if problem_formulation_id == 0: variable_names = [] variable_names_ = [] for n in function.planning_steps: variable_names.extend([ '{}_{} {}'.format(dike, e, n) for e in ['Expected Annual Damage', 'Dike Investment Costs'] for dike in function.dikelist ]) variable_names_.extend([ '{}_{} {}'.format(dike, e, n) for e in ['Expected Number of Deaths'] for dike in function.dikelist ]) variable_names.extend(['RfR Total Costs {}'.format(n)]) variable_names.extend(['Expected Evacuation Costs {}'.format(n)]) dike_model.outcomes = [ ScalarOutcome('All Costs', variable_name=[var for var in variable_names], function=sum_over, kind=direction), ScalarOutcome('Expected Number of Deaths', variable_name=[var for var in variable_names_], function=sum_over, kind=direction) ] # 3-objectives PF: elif problem_formulation_id == 1: variable_names = [] variable_names_ = [] variable_names__ = [] for n in function.planning_steps: variable_names.extend([ '{}_Expected Annual Damage {}'.format(dike, n) for dike in function.dikelist ]) variable_names_.extend([ '{}_Dike Investment Costs {}'.format(dike, n) for dike in function.dikelist ] + ['RfR Total Costs {}'.format(n)] + ['Expected Evacuation Costs {}'.format(n)]) variable_names__.extend([ '{}_Expected Number of Deaths {}'.format(dike, n) for dike in function.dikelist ]) dike_model.outcomes = [ ScalarOutcome('Expected Annual Damage', variable_name=[var for var in variable_names], function=sum_over, kind=direction), ScalarOutcome('Total Investment Costs', variable_name=[var for var in variable_names_], function=sum_over, kind=direction), ScalarOutcome('Expected Number of Deaths', variable_name=[var for var in variable_names__], function=sum_over, kind=direction) ] # 5-objectives PF: elif problem_formulation_id == 2: variable_names = [] variable_names_ = [] variable_names__ = [] variable_names___ = [] variable_names____ = [] for n in function.planning_steps: variable_names.extend([ '{}_Expected Annual Damage {}'.format(dike, n) for dike in function.dikelist ]) variable_names_.extend([ '{}_Dike Investment Costs {}'.format(dike, n) for dike in function.dikelist ]) variable_names__.extend(['RfR Total Costs {}'.format(n)]) variable_names___.extend( ['Expected Evacuation Costs {}'.format(n)]) variable_names____.extend([ '{}_Expected Number of Deaths {}'.format(dike, n) for dike in function.dikelist ]) dike_model.outcomes = [ ScalarOutcome('Expected Annual Damage', variable_name=[var for var in variable_names], function=sum_over, kind=direction), ScalarOutcome('Dike Investment Costs', variable_name=[var for var in variable_names_], function=sum_over, kind=direction), ScalarOutcome('RfR Investment Costs', variable_name=[var for var in variable_names__], function=sum_over, kind=direction), ScalarOutcome('Evacuation Costs', variable_name=[var for var in variable_names___], function=sum_over, kind=direction), ScalarOutcome('Expected Number of Deaths', variable_name=[var for var in variable_names____], function=sum_over, kind=direction) ] # Disaggregate over locations: elif problem_formulation_id == 3: outcomes = [] for dike in function.dikelist: variable_name = [] for e in ['Expected Annual Damage', 'Dike Investment Costs']: variable_name.extend([ '{}_{} {}'.format(dike, e, n) for n in function.planning_steps ]) outcomes.append( ScalarOutcome('{} Total Costs'.format(dike), variable_name=[var for var in variable_name], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('{}_Expected Number of Deaths'.format(dike), variable_name=[ '{}_Expected Number of Deaths {}'.format( dike, n) for n in function.planning_steps ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('RfR Total Costs', variable_name=[ 'RfR Total Costs {}'.format(n) for n in function.planning_steps ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('Expected Evacuation Costs', variable_name=[ 'Expected Evacuation Costs {}'.format(n) for n in function.planning_steps ], function=sum_over, kind=direction)) dike_model.outcomes = outcomes # Disaggregate over time: elif problem_formulation_id == 4: outcomes = [] for n in function.planning_steps: for dike in function.dikelist: outcomes.append( ScalarOutcome('Expected Annual Damage {}'.format(n), variable_name=[ '{}_Expected Annual Damage {}'.format( dike, n) for dike in function.dikelist ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('Dike Investment Costs {}'.format(n), variable_name=[ '{}_Dike Investment Costs {}'.format( dike, n) for dike in function.dikelist ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('Expected Number of Deaths {}'.format(n), variable_name=[ '{}_Expected Number of Deaths {}'.format( dike, n) for dike in function.dikelist ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('RfR Total Costs {}'.format(n), kind=direction)) outcomes.append( ScalarOutcome('Expected Evacuation Costs {}'.format(n), kind=direction)) dike_model.outcomes = outcomes # Fully disaggregated: elif problem_formulation_id == 5: outcomes = [] for n in function.planning_steps: for dike in function.dikelist: for entry in [ 'Expected Annual Damage', 'Dike Investment Costs', 'Expected Number of Deaths' ]: o = ScalarOutcome('{}_{} {}'.format(dike, entry, n), kind=direction) outcomes.append(o) outcomes.append( ScalarOutcome('RfR Total Costs {}'.format(n), kind=direction)) outcomes.append( ScalarOutcome('Expected Evacuation Costs {}'.format(n), kind=direction)) dike_model.outcomes = outcomes # OWN PROBLEM FORMULATION: elif problem_formulation_id == 6: outcomes = [] function.gelderland_dikelist = function.dikelist[: -2] #Cut the dikelist by removing the last two dike rings function.ring12_dikelist = function.dikelist[:-3] function.ring3_dikelist = function.dikelist[2:-2] variable_names_1 = [] variable_names_2 = [] variable_names_3 = [] variable_names_4 = [] variable_names_5 = [] for n in function.planning_steps: for dike in function.ring12_dikelist: variable_names_1.extend( ['{}_Expected Annual Damage {}'.format(dike, n)]) variable_names_2.extend( ['{}_Expected Number of Deaths {}'.format(dike, n)]) for dike in function.ring3_dikelist: variable_names_3.extend( ['{}_Expected Annual Damage {}'.format(dike, n)]) variable_names_4.extend( ['{}_Expected Number of Deaths {}'.format(dike, n)]) for dike in function.gelderland_dikelist: variable_names_5.extend( ['{}_Dike Investment Costs {}'.format(dike, n)]) variable_names_5.extend(['RfR Total Costs {}'.format(n)]) outcomes.append( ScalarOutcome( 'A1/2_EAD', #Expected Annual Cost variable_name=[var for var in variable_names_1], function=sum_over, kind=ScalarOutcome.MINIMIZE)) outcomes.append( ScalarOutcome( 'A1/2_END', #Expected Number of Deaths variable_name=[var for var in variable_names_2], function=sum_over, kind=ScalarOutcome.MINIMIZE)) outcomes.append( ScalarOutcome( 'A3_EAD', #Expected Annual Cost variable_name=[var for var in variable_names_3], function=sum_over, kind=ScalarOutcome.MINIMIZE)) outcomes.append( ScalarOutcome( 'A3_END', #Expected Number of Deaths variable_name=[var for var in variable_names_4], function=sum_over, kind=ScalarOutcome.MINIMIZE)) outcomes.append( ScalarOutcome( 'G_TIC', #Gelderland Total Investment Cost variable_name=[var for var in variable_names_5], function=sum_over, kind=ScalarOutcome.MINIMIZE)) outcomes.append( ScalarOutcome( 'EEC', #Expected Evacuation Cost variable_name=[ 'Expected Evacuation Costs {}'.format(n) for n in function.planning_steps ], function=sum_over, kind=ScalarOutcome.MINIMIZE)) dike_model.outcomes = outcomes elif problem_formulation_id == 7: outcomes = [] variable_names_1 = [] variable_names_2 = [] variable_names_3 = [] variable_names_4 = [] for n in function.planning_steps: for dike in function.dikelist: variable_names_1.extend( ['{}_Expected Annual Damage {}'.format(dike, n)]) variable_names_2.extend( ['{}_Expected Number of Deaths {}'.format(dike, n)]) variable_names_4.extend( ['{}_Dike Investment Costs {}'.format(dike, n)]) # variable_names_3.extend(['Expected Evacuation Costs {}'.format(n)]) variable_names_4.extend(['RfR Total Costs {}'.format(n)]) outcomes.append( ScalarOutcome( 'EAD', #Expected Annual Cost variable_name=[var for var in variable_names_1], function=sum_over, kind=ScalarOutcome.MINIMIZE)) outcomes.append( ScalarOutcome( 'END', #Expected Number of Deaths variable_name=[var for var in variable_names_2], function=sum_over, kind=ScalarOutcome.MINIMIZE)) outcomes.append( ScalarOutcome( 'TIC', #Expected Number of Deaths variable_name=[var for var in variable_names_4], function=sum_over, kind=ScalarOutcome.MINIMIZE)) outcomes.append( ScalarOutcome( 'EEC', #Expected Evacuation Cost variable_name=[ 'Expected Evacuation Costs {}'.format(n) for n in function.planning_steps ], function=sum_over, kind=ScalarOutcome.MINIMIZE)) dike_model.outcomes = outcomes else: raise TypeError('unknownx identifier') return dike_model, function.planning_steps
upper_bound=20.0), RealParameter( name='E-boiler OPEX', # per quarter variable_name='OPEX E-BOILER:Price', lower_bound=5.0, upper_bound=20.0), RealParameter(name='Steam Pipe CAPEX', variable_name='CAPEX Steam Pipe:Price', lower_bound=5.0, upper_bound=20.0) ] # define the levers (Power-to-X alternatives) model.levers = [ CategoricalParameter( name='Steam Pipe to Nouryon', variable_name='Option: transport to Nouryon (Steam pipe owner):UB', categories=[0, 7.5]), CategoricalParameter( name='Steam Pipe to Air Liquide and Huntsman', variable_name='FUTURE: transport 5210 site (Steam pipe owner):UB', categories=[0, 30]), CategoricalParameter( name='E-boiler 1', variable_name='Electrode boiler 50 bar 2/7 aFRR (Air Liquide):UB', categories=[0, 5]), CategoricalParameter( name='E-boiler 2', variable_name= 'electrode boiler 50 bar 5/7 inzetbaar (Air Liquide):UB', categories=[0, 17.5]), CategoricalParameter(name='E-boiler 3',
waas_model = WaasModel("waasmodel", wd='./model') waas_model.uncertainties = [ IntegerParameter("climate scenarios", 1, 30, pff=True, resolution=[x for x in range(1, 31)]), RealParameter("fragility dikes", -0.1, 0.1), RealParameter("DamFunctTbl", -0.1, 0.1), RealParameter("ShipTbl1", -0.1, 0.1), RealParameter("ShipTbl2", -0.1, 0.1), RealParameter("ShipTbl3", -0.1, 0.1), RealParameter("collaboration", 1, 1.6), CategoricalParameter("land use scenarios", [ "NoChange", "moreNature", "Deurbanization", "sustainableGrowth", "urbanizationDeurbanization", "urbanizationLargeAndFast", "urbanizationLargeSteady" ], pff=True) ] waas_model.outcomes = [ ScalarOutcome("Flood damage (Milj. Euro)"), ScalarOutcome("Number of casualties"), ScalarOutcome("Costs"), ScalarOutcome("Timing") ] n_scenarios = 500 policies = [ Policy(kwargs['name'], **kwargs['params']) for kwargs in policies ]
) with open('delta_dicts_list_rep_id.json') as f: delta_dicts_list = json.load(f) model.replications = delta_dicts_list model.nticks = 30 model.assets = assets model.yearofintroduction = get_introductionyear() model.paths = paths uncertainties = [] for assettype, paths in paths.items(): if assettype != "SMR": unc = CategoricalParameter(f"{assettype} paths", paths) uncertainties.append(unc) uncertainties += [IntegerParameter("timing CCS", 2022, 2030), BooleanParameter("offshore wind growth"), CategoricalParameter("decisionMakingModel", ["Reactive", "Current", "Proactive", "Collaborative"]), RealParameter("capex_factor", 0.7, 1.3), RealParameter("leadtime_factor", 0.7, 1.3), BooleanParameter("shuffle-needed-investments?"), IntegerParameter("random-seed", -2147483648, 2147483647) ] model.uncertainties = uncertainties
from cablepool_leso_handshake import METRICS, CablePooling from ema_workbench import ( RealParameter, CategoricalParameter, ScalarOutcome, Model, ) # initiate model model = Model(name='Cablepool', function=CablePooling) # levers / policies model.levers = [ CategoricalParameter("approach", [1, 0]), ] # uncertainties / scenarios model.uncertainties = [ RealParameter("pv_cost_factor", 0.38, 0.85), RealParameter("battery_cost_factor", 0.41, 0.70), RealParameter("wind_cost_factor", 0.77, 0.98) ] # specify outcomes model.outcomes = [ScalarOutcome(metric) for metric in METRICS]
def get_model_for_problem_formulation(problem_formulation_id): ''' Prepare DikeNetwork in a way it can be input in the EMA-workbench. Specify uncertainties, levers and problem formulation. ''' # Load the model: function = DikeNetwork() # workbench model: dike_model = Model('dikesnet', function=function) ## Uncertainties and Levers: # Specify uncertainties range: Real_uncert = {'Bmax': [30, 350], 'pfail': [0, 1]} # m and [.] cat_uncert_loc = {'Brate': (0.9, 1.5, 1000)} # breach growth rate [m/day] cat_uncert = {'discount rate': (1.5, 2.5, 3.5, 4.5)} Int_uncert = {'A.0_ID flood wave shape': [0, 133]} # Range of dike heightening: dike_lev = {'DikeIncrease': [0, 10]} # dm # Series of five Room for the River projects: rfr_lev = ['{}_RfR'.format(project_id) for project_id in range(0, 5)] # Time of warning: 0, 1, 2, 3, 4 days ahead from the flood EWS_lev = {'EWS_DaysToThreat': [0, 4]} # days uncertainties = [] levers = [] for dike in function.dikelist: # uncertainties in the form: locationName_uncertaintyName for uncert_name in Real_uncert.keys(): name = "{}_{}".format(dike, uncert_name) lower, upper = Real_uncert[uncert_name] uncertainties.append(RealParameter(name, lower, upper)) for uncert_name in cat_uncert_loc.keys(): name = "{}_{}".format(dike, uncert_name) categories = cat_uncert_loc[uncert_name] uncertainties.append(CategoricalParameter(name, categories)) # location-related levers in the form: locationName_leversName for lev_name in dike_lev.keys(): name = "{}_{}".format(dike, lev_name) levers.append( IntegerParameter(name, dike_lev[lev_name][0], dike_lev[lev_name][1])) for uncert_name in cat_uncert.keys(): categories = cat_uncert[uncert_name] uncertainties.append(CategoricalParameter(uncert_name, categories)) # project-related levers can be either 0 (not implemented) or 1 (implemented) for uncert_name in Int_uncert.keys(): uncertainties.append( IntegerParameter(uncert_name, Int_uncert[uncert_name][0], Int_uncert[uncert_name][1])) # RfR levers can be either 0 (not implemented) or 1 (implemented) for lev_name in rfr_lev: levers.append(IntegerParameter(lev_name, 0, 1)) # Early Warning System lever for lev_name in EWS_lev.keys(): levers.append( IntegerParameter(lev_name, EWS_lev[lev_name][0], EWS_lev[lev_name][1])) # load uncertainties and levers in dike_model: dike_model.uncertainties = uncertainties dike_model.levers = levers ## Problem formulations: # Outcomes are all costs, thus they have to minimized: direction = ScalarOutcome.MINIMIZE # 2-objective PF: if problem_formulation_id == 0: dikes_variable_names = [] for dike in function.dikelist: dikes_variable_names.extend([ '{}_{}'.format(dike, e) for e in ['Expected Annual Damage', 'Dike Investment Costs'] ]) dikes_variable_names.extend(['RfR Total Costs']) dikes_variable_names.extend(['Expected Evacuation Costs']) dike_model.outcomes = [ ScalarOutcome('All Costs', variable_name=[var for var in dikes_variable_names], function=sum_over, kind=direction), ScalarOutcome('Expected Number of Deaths', variable_name=[ '{}_Expected Number of Deaths'.format(dike) for dike in function.dikelist ], function=sum_over, kind=direction) ] # 3-objectives PF: elif problem_formulation_id == 1: dike_model.outcomes = [ ScalarOutcome('Expected Annual Damage', variable_name=[ '{}_Expected Annual Damage'.format(dike) for dike in function.dikelist ], function=sum_over, kind=direction), ScalarOutcome('Total Investment Costs', variable_name=[ '{}_Dike Investment Costs'.format(dike) for dike in function.dikelist ] + ['RfR Total Costs'] + ['Expected Evacuation Costs'], function=sum_over, kind=direction), ScalarOutcome('Expected Number of Deaths', variable_name=[ '{}_Expected Number of Deaths'.format(dike) for dike in function.dikelist ], function=sum_over, kind=direction) ] # 12-objectives PF: elif problem_formulation_id == 2: outcomes = [] for dike in function.dikelist: outcomes.append( ScalarOutcome( '{} Total Costs'.format(dike), variable_name=[ '{}_{}'.format(dike, e) for e in ['Expected Annual Damage', 'Dike Investment Costs'] ], function=sum_over, kind=direction)) outcomes.append( ScalarOutcome('{}_Expected Number of Deaths'.format(dike), kind=direction)) outcomes.append(ScalarOutcome('RfR Total Costs', kind=direction)) outcomes.append( ScalarOutcome('Expected Evacuation Costs', kind=direction)) dike_model.outcomes = outcomes # 17-objectives PF: elif problem_formulation_id == 3: outcomes = [] for dike in function.dikelist: for entry in [ 'Expected Annual Damage', 'Dike Investment Costs', 'Expected Number of Deaths' ]: o = ScalarOutcome('{}_{}'.format(dike, entry), kind=direction) outcomes.append(o) outcomes.append(ScalarOutcome('RfR Total Costs', kind=direction)) outcomes.append( ScalarOutcome('Expected Evacuation Costs', kind=direction)) dike_model.outcomes = outcomes else: raise TypeError('unknonw identifier') return dike_model
RealParameter('SD_Maximum cost reduction', 0.1, 0.5), RealParameter('ABM_group-behaviour', 0, 1), RealParameter('ABM_Heat-company-ROI', 0.04, 0.15), RealParameter('ABM_Max-income-inv-share', 0.05, 0.15), RealParameter('ABM_Max-capital-inv-share', 0.05, 0.15) ] model.levers = [ RealParameter('ABM_insulation-subsidy', 0, 0.5), RealParameter('ABM_LT-production-subsidy', 0, 0.5), RealParameter('ABM_LT-investment-subsidy', 0, 0.5), RealParameter('ABM_MT-production-subsidy', 0, 0.5), RealParameter('ABM_MT-investment-subsidy', 0, 0.5), RealParameter('SD_"NMTU-factor"', 1, 2), RealParameter('SD_Tax multiplier', 0, 3), CategoricalParameter('SD_"CO2-tax-scheme"', [0, 1, 2]) ] # FOR ABM: globals only model.outcomes = [ TimeSeriesOutcome( 'SD_National Energy System Distribution[Natural Gas]'), TimeSeriesOutcome('SD_Average Gas Price'), TimeSeriesOutcome('SD_Average Electricity Price'), TimeSeriesOutcome('SD_Average Heat Price'), TimeSeriesOutcome( 'SD_National Energy System Distribution[Natural Gas]'), TimeSeriesOutcome('SD_National Energy System Distribution[Green Gas]'), TimeSeriesOutcome( 'SD_National Energy System Distribution[LT Heating Grid]'), TimeSeriesOutcome(