def set_model(func=recycle_model):
    experiment_model = EMA_Model('plastic', function=func)

    uncertainties = [
        RealParameter('target_mean', 0.05, 0.20),
        RealParameter('amb_mean', 0.1, 0.5),
        RealParameter('percep_range', 0.1, 0.5),
        RealParameter('know_range', 0.1, 0.5),
        RealParameter('technology', 0.1, 0.5),
        RealParameter('tech_std', 0.05, 0.20),
        IntegerParameter('cap_mean', 400, 800),
        IntegerParameter('cap_std', 100, 400),
    ]

    levers = [
        RealParameter("campaign_bud_prop", 0.05, 0.5),
        RealParameter("final_target", 0.1, 0.4)
    ]

    outcomes = [
        ScalarOutcome('target_met_frac', ),
        ScalarOutcome('no_budget_frac', ),
        ScalarOutcome('avg_fine_period'),
        ScalarOutcome('fine_per_house'),
        ScalarOutcome('time_conv'),
        ScalarOutcome('profit_std'),
    ]
    experiment_model.uncertainties = uncertainties
    experiment_model.levers = levers
    experiment_model.outcomes = outcomes
    return experiment_model
Exemplo n.º 2
0
def get_lake_model():
    """Returns a fully formulated model of the lake problem."""
    # instantiate the model
    lake_model = Model('lakeproblem', function=lake_problem)
    lake_model.time_horizon = 100

    # 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, one for each time step
    lake_model.levers = [
        RealParameter(str(i), 0, 0.1) for i in range(lake_model.time_horizon)
    ]

    # specify outcomes
    lake_model.outcomes = [
        ScalarOutcome('max_P', ),
        ScalarOutcome('utility'),
        ScalarOutcome('inertia'),
        ScalarOutcome('reliability')
    ]

    # override some of the defaults of the model
    lake_model.constants = [Constant('alpha', 0.41), Constant('nsamples', 150)]
    return lake_model
Exemplo n.º 3
0
def performExperiments():

    ema_logging.LOG_FORMAT = '[%(name)s/%(levelname)s/%(processName)s] %(message)s'
    ema_logging.log_to_stderr(ema_logging.INFO)

    model = Model('SimulateER', function=simulate_ER)  # instantiate the model
    # specify uncertainties
    model.uncertainties = [RealParameter("p", 0.1, 1.0)]
    model.uncertainties = [RealParameter("f", 0.1, 0.9)]

    model.levers = [IntegerParameter("n", 10, 100)]

    # specify outcomes
    model.outcomes = [ScalarOutcome('cc')]

    model.constants = [Constant('replications', 10)]

    n_scenarios = 10
    n_policies = 10

    res = perform_experiments(model, n_scenarios, n_policies)

    experiments, outcomes = res
    data = experiments[['n', 'p', 'f']]
    data.to_csv('out.csv', index=False)
    return data
def intertemporal_model(params):
    intertemporal = Model('intertemporal',
                          function=modelData.intertemporal.lake_model)
    intertemporal.timeHorizon = params.timeHorizon
    intertemporal.uncertainties = params.uncertainties
    intertemporal.levers = [
            RealParameter('l{}'.format(i), 0, 0.1) for i in range(100)
    ]
    intertemporal.outcomes = params.outcomes
    intertemporal.constants = params.constants
    intertemporal.constraints = params.constraints

    return intertemporal
def dps_model(params):
    dps = Model('dps', function=modelData.dps.lake_model)
    dps.timeHorizon = params.timeHorizon
    dps.uncertainties = params.uncertainties
    dps.levers = [RealParameter("c1", -2, 2),
                  RealParameter("c2", -2, 2),
                  RealParameter("r1", 0, 2),
                  RealParameter("r2", 0, 2),
                  RealParameter("w1", 0, 1)]
    dps.outcomes = params.outcomes
    dps.constants = params.constants
    dps.constraints = params.constraints

    return dps
def planned_adaptive_model(params):
    adaptive = Model('plannedadaptive',
                     function=modelData.planned_adaptive.lake_model)
    adaptive.timeHorizon = params.timeHorizon
    adaptive.uncertainties = params.uncertainties
    adaptive.levers = [RealParameter("c1", -2, 2),
                       RealParameter("c2", -2, 2),
                       RealParameter("r1", 0, 2),
                       RealParameter("r2", 0, 2),
                       RealParameter("w1", 0, 1)]
    adaptive.outcomes = params.outcomes
    adaptive.constants = params.constants
    adaptive.constraints = params.constraints

    return adaptive
        IntegerParameter('scenario_sigma', 0, 2),
        IntegerParameter('scenario_cback', 0, 1),
        IntegerParameter('scenario_elasticity_of_damages', 0, 2),
        IntegerParameter('scenario_limmiu', 0, 1)
    ]

    RICE.levers = [
        RealParameter('sr', 0.1, 0.5),
        RealParameter('irstp', 0.001, 0.015),
        IntegerParameter('miu_period', 5, 30),
        IntegerParameter('egalitarian_discounting', 0, 1)
    ]  #0 = no discouting , 1 = normal discounting,

    RICE.outcomes = [
        ScalarOutcome('Utility 2055', ScalarOutcome.MAXIMIZE),
        ScalarOutcome('Utility 2105', ScalarOutcome.MAXIMIZE),
        ScalarOutcome('Total Aggregated Utility', ScalarOutcome.MAXIMIZE)
    ]

    convergence_metrics = [EpsilonProgress()]
    minimize = ScalarOutcome.MINIMIZE
    maximize = ScalarOutcome.MAXIMIZE

    for outcome in RICE.outcomes:
        if outcome.kind == minimize:
            outcome.kind = maximize
        else:
            outcome.kind = minimize

    ema_logging.log_to_stderr(ema_logging.INFO)
    #only needed on IPython console within Anaconda
Exemplo n.º 8
0
        IntegerParameter('scenario_cback', 0, 1),
        IntegerParameter('scenario_elasticity_of_damages', 0, 2),
        IntegerParameter('scenario_limmiu', 0, 1)
    ]

    RICE.levers = [
        RealParameter('sr', 0.1, 0.5),
        RealParameter('irstp', 0.001, 0.015),
        IntegerParameter('miu_period', 5, 30),
        IntegerParameter('egalitarian_discounting', 0, 1)
    ]  #0 = no discouting , 1 = normal discounting,

    RICE.outcomes = [
        ScalarOutcome('Lowest income per capita 2055', ScalarOutcome.MAXIMIZE),
        ScalarOutcome('Highest climate impact per capita 2055',
                      ScalarOutcome.MINIMIZE),
        ScalarOutcome('Lowest income per capita 2105', ScalarOutcome.MAXIMIZE),
        ScalarOutcome('Highest climate impact per capita 2105',
                      ScalarOutcome.MINIMIZE)
    ]

    convergence_metrics = [EpsilonProgress()]
    minimize = ScalarOutcome.MINIMIZE
    maximize = ScalarOutcome.MAXIMIZE

    for outcome in RICE.outcomes:
        if outcome.kind == minimize:
            outcome.kind = maximize
        else:
            outcome.kind = minimize

    epsilon_list = [0.1, 0.001, 0.1, 0.001, 0.1, 0.001, 0.1, 0.001, 0.1, 0.001]
    ]

    #     lake_model.levers = [RealParameter("c1", -2, 2),
    #                          RealParameter("c2", -2, 2),
    #                          RealParameter("r1", 0, 2), #[0,2]
    #                          RealParameter("r2", 0, 2), #
    #                          RealParameter("w1", 0, 1)
    #                          ]

    lake_model.levers = [
        RealParameter(str(i), 0, 0.1) for i in range(lake_model.time_horizon)
    ]

    lake_model.outcomes = [
        ScalarOutcome('max_P', kind=ScalarOutcome.MINIMIZE),
        ScalarOutcome('utility', kind=ScalarOutcome.MAXIMIZE),
        ScalarOutcome('inertia', kind=ScalarOutcome.MINIMIZE),
        ScalarOutcome('reliability', kind=ScalarOutcome.MAXIMIZE)
    ]

    lake_model.constants = [
        Constant('alpha', 0.41),
        Constant('nsamples', 100),
        Constant('timehorizon', lake_model.time_horizon)
    ]

    scenarios = ['Ref', 77, 96, 130, 181]
    random_scenarios = [81, 289, 391, 257]
    policies = []

    for s in random_scenarios:
        #         if s == 'Ref':
Exemplo n.º 10
0
    model = Model('omegaDriver', function=omegaDriver)  # instantiate the model
    # specify uncertainties

    model.uncertainties = [
        RealParameter("SCUDB.targetRange", 100000.0, 200000.0),
        RealParameter("SCUDB.targetAltitude", 15000.0, 20000.0)
    ]

    model.levers = [
        RealParameter("SCUDB.MassProperties.initialMass", 5000.0, 6000.0)
    ]

    model.outcomes = [
        ScalarOutcome('burnout'),
        ScalarOutcome('impact'),
        ScalarOutcome('apogeeAlt'),
        ScalarOutcome('apogeeTime')
    ]

    #model.constants = [Constant('replications', 10)]

    n_contextScenarios = 10
    n_designPolicies = 10

    res = perform_experiments(model,
                              n_contextScenarios,
                              n_designPolicies,
                              levers_sampling=LHS)

    experiments, outcomes = res
                             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), 
                      RealParameter("w1", 0, 1)
                      ]
 
 #specify outcomes 
 lake_model.outcomes = [ScalarOutcome('max_P'),
                        ScalarOutcome('utility'), 
                        ScalarOutcome('inertia'), 
                        ScalarOutcome('reliability')]  
 
 # override some of the defaults of the model
 lake_model.constants = [Constant('alpha', 0.41),
                         Constant('nsamples', 100),
                         Constant('myears', 100)]
 
 # setup and execute the robust optimization
 def signal_to_noise(data):
     mean = np.mean(data)
     std = np.std(data)
     sn = mean/std
     return sn
 
 MAXIMIZE = ScalarOutcome.MAXIMIZE  # @UndefinedVariable
Exemplo n.º 12
0
    RealParameter('limmiu', 0.8, 1.2)
]

RICE.levers = [
    RealParameter('sr', 0.1, 0.5),
    RealParameter('irstp', 0.001, 0.015),
    IntegerParameter('miu_period', 5, 30)
]

RICE.outcomes = [
    ScalarOutcome('Damages 2055', ScalarOutcome.MINIMIZE),
    ScalarOutcome('Utility 2055', ScalarOutcome.MAXIMIZE),
    ScalarOutcome('Damages 2105', ScalarOutcome.MINIMIZE),
    ScalarOutcome('Utility 2105', ScalarOutcome.MAXIMIZE),
    ScalarOutcome('Damages 2155', ScalarOutcome.MINIMIZE),
    ScalarOutcome('Utility 2155', ScalarOutcome.MAXIMIZE),
    ScalarOutcome('Damages 2205', ScalarOutcome.MINIMIZE),
    ScalarOutcome('Utility 2205', ScalarOutcome.MAXIMIZE),
    ScalarOutcome('Damages 2305', ScalarOutcome.MINIMIZE),
    ScalarOutcome('Utility 2305', ScalarOutcome.MAXIMIZE),
    ScalarOutcome('Total Aggregated Utility', ScalarOutcome.MAXIMIZE)
]

epsilon_list = [0.01]
eps = []

for i in epsilon_list:
    k = np.ones((len(RICE.outcomes))) * i
    eps.append(k)

nfe = 200
Exemplo n.º 13
0
    model = Model('omegaDriver', function=omegaDriver)  # instantiate the model
    # specify uncertainties

    model.uncertainties = [
        RealParameter("SCUDB.targetRange", 100000.0, 200000.0),
        RealParameter("SCUDB.targetAltitude", 15000.0, 20000.0)
    ]

    model.levers = [
        RealParameter("SCUDB.MassProperties.initialMass", 5000.0, 6000.0)
    ]

    model.outcomes = [
        ArrayOutcome('burnout'),
        ArrayOutcome('impact'),
        ArrayOutcome('apogeeAlt'),
        ArrayOutcome('apogeeTime')
    ]

    #model.constants = [Constant('replications', 10)]

    n_contextScenarios = 3
    n_designPolicies = 3

    res = perform_experiments(model,
                              n_contextScenarios,
                              n_designPolicies,
                              levers_sampling=LHS)

    experiments, outcomes = res
Exemplo n.º 14
0
.. codeauthor:: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>
'''
from __future__ import (absolute_import, print_function, division,
                        unicode_literals)

from ema_workbench import (Model, RealParameter, ScalarOutcome, ema_logging,
                           perform_experiments)


def some_model(x1=None, x2=None, x3=None):
    return {'y': x1 * x2 + x3}


if __name__ == '__main__':
    ema_logging.LOG_FORMAT = '[%(name)s/%(levelname)s/%(processName)s] %(message)s'
    ema_logging.log_to_stderr(ema_logging.INFO)

    model = Model('simpleModel', function=some_model)  # instantiate the model

    # specify uncertainties
    model.uncertainties = [
        RealParameter("x1", 0.1, 10),
        RealParameter("x2", -0.01, 0.01),
        RealParameter("x3", -0.01, 0.01)
    ]
    # specify outcomes
    model.outcomes = [ScalarOutcome('y')]

    results = perform_experiments(model, 100)
Exemplo n.º 15
0
    density = cum / replications
    return {'density': density}


if __name__ == '__main__':
    ema_logging.LOG_FORMAT = '[%(name)s/%(levelname)s/%(processName)s] %(message)s'
    ema_logging.log_to_stderr(ema_logging.INFO)

    model = Model('SimulateER', function=simulate_ER)  # instantiate the model
    # specify uncertainties
    model.uncertainties = [RealParameter("p", 0.1, 1.0)]

    model.levers = [IntegerParameter("n", 10, 100)]

    # specify outcomes
    model.outcomes = [ScalarOutcome('density')]

    model.constants = [Constant('replications', 10)]

    n_scenarios = 10
    n_policies = 10

    res = perform_experiments(model, n_scenarios, n_policies)
    """ 
        with MultiprocessingEvaluator(model) as evaluator:
            res = evaluator.perform_experiments(n_scenarios, n_policies,
                                             levers_sampling=MC)
    """
    experiments, outcomes = res
    data = experiments[['n', 'p']]
    data.to_csv('outExperiment.csv', index=False)
Exemplo n.º 16
0
                          0.4, ax1)
    tree_generate_heatmap(x, prey_final_np, prey_mean_np, prey_std_np, 100,
                          0.6, ax2)
    tree_generate_heatmap(x, prey_final_np, prey_mean_np, prey_std_np, 100,
                          0.8, ax3)

    plt.show()


model = Model('PredPreyGSA', function=pred_prey)

model.uncertainties = [
    RealParameter('prey_birth_rate', 0.015, 0.035),
    RealParameter('predation_rate', 0.0005, 0.003),
    RealParameter('predator_efficiency', 0.001, 0.004),
    RealParameter('predator_loss_rate', 0.04, 0.08)
]

model.outcomes = [
    TimeSeriesOutcome('TIME', function=np.squeeze),
    TimeSeriesOutcome('predators', function=np.squeeze),
    TimeSeriesOutcome('prey', function=np.squeeze)
]

run_full_tree_experiment(50)
run_full_tree_experiment(250)
run_full_tree_experiment(1000)

# We can see that the sample size has a significant impact on the relative sobol indices. Most noticably, the tree model predicts a lower importance of the predator efficiency on the prey_mean value.
#
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
Exemplo n.º 18
0

if __name__ == '__main__':
    ema_logging.LOG_FORMAT = '[%(name)s/%(levelname)s/%(processName)s] %(message)s'
    ema_logging.log_to_stderr(ema_logging.INFO)

    model = Model('SimulateCM', function=simulate_CM)  # instantiate the model
    # specify uncertainties
    model.uncertainties = [RealParameter("a", 0.1, 1.0)]

    model.levers = [RealParameter("b", 0.0, 0.01)]

    # specify outcomes
    model.outcomes = [
        ScalarOutcome('c'),
        ScalarOutcome('d'),
        ScalarOutcome('e')
    ]

    #model.constants = [Constant('replications', 10)]

    n_scenarios = 10
    n_policies = 10

    res = perform_experiments(model, n_scenarios, n_policies)

    experiments, outcomes = res

    print(experiments)
    print(outcomes)
''' 
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]
Exemplo n.º 20
0
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
Exemplo n.º 21
0
        RealParameter('x32', 0, 0.5),
        RealParameter('x41', 0, 0.9),
        RealParameter('x51', 0, 0.5),
        RealParameter('x52', 0, 0.5),
        RealParameter('x61', 0, 0.8),
        RealParameter('x62', 0, 0.8),
        RealParameter('x81', 1, 10),
        RealParameter('x82', 1, 10),
        RealParameter('x91', 0, 0.1),
        RealParameter('x92', 0, 0.1),
        RealParameter('x101', 0, 200),
        RealParameter('x102', 0, 200)
    ]

    model.outcomes = [
        TimeSeriesOutcome("TIME"),
        TimeSeriesOutcome("deceased_population_region_1")
    ]

    nr_experiments = 500

    results = perform_experiments(model, 10)

    #     with MultiprocessingPoolEvaluator(model) as evaluator:
    #         results = perform_experiments(model, nr_experiments,
    #                                       evaluator=evaluator)

    lines(results,
          outcomes_to_show="deceased_population_region_1",
          show_envelope=True,
          density=KDE,
          titles=None,
Exemplo n.º 22
0
    #k=0
    #l=0
    #m=[]
    #n=1
    #for k in range(len(dams)):
    #for i in range(12):
    #a=Constraint("Constraint_"+str(n),parameter_names=[dams[k][0][i],dams[k][1][i]],function=lambda x,y:max(0,-x+y))
    #m.append(a)
    #n=n+1
    #a=Constraint("Constraint_"+str(n),parameter_names=[dams[k][1][i],dams[k][2][i]],function=lambda x,y:max(0,-x+y))
    #m.append(a)
    #n=n+1

    basin_model.outcomes = [
        ScalarOutcome('pwsshortageavg', kind=ScalarOutcome.MINIMIZE),
        ScalarOutcome('energyaverage', kind=ScalarOutcome.MAXIMIZE),
        ScalarOutcome('pwssum', kind=ScalarOutcome.MINIMIZE)
    ]

    convergence_metrics = [EpsilonProgress()]

    #with SequentialEvaluator(basin_model) as evaluator:
    #experiments, outcomes=evaluator.perform_experiments(policies=10)#constraints=constraints)
    with SequentialEvaluator(basin_model) as evaluator:
        #experiments, outcomes=evaluator.perform_experiments(scenarios=100)
        results, convergence = evaluator.optimize(
            nfe=100,
            searchover='levers',
            epsilons=[1, 1, 1],
            convergence=convergence_metrics,
            reference=None)  #constraints=m)
Exemplo n.º 23
0
RICE.levers = [RealParameter('sr', 0.1, 0.5),
               RealParameter('irstp',  0.001, 0.015),
               IntegerParameter('miu_period', 5, 30),
               
               IntegerParameter('sufficitarian_discounting', 0,1), 
               RealParameter('growth_factor_suf',1,1.04),
               RealParameter('ini_suf_treshold',0.7,2.4)]

RICE.outcomes =[ScalarOutcome('Distance to treshold 2055', ScalarOutcome.MINIMIZE),
                ScalarOutcome('Population under treshold 2055', ScalarOutcome.MINIMIZE),
                
                ScalarOutcome('Distance to treshold 2105', ScalarOutcome.MINIMIZE),
                ScalarOutcome('Population under treshold 2105', ScalarOutcome.MINIMIZE),
                
                ScalarOutcome('Distance to treshold 2155', ScalarOutcome.MINIMIZE),
                ScalarOutcome('Population under treshold 2155', ScalarOutcome.MINIMIZE),
                
                ScalarOutcome('Distance to treshold 2205', ScalarOutcome.MINIMIZE),
                ScalarOutcome('Population under treshold 2205', ScalarOutcome.MINIMIZE),
                
                ScalarOutcome('Distance to treshold 2305', ScalarOutcome.MINIMIZE),
                ScalarOutcome('Population under treshold 2305', ScalarOutcome.MINIMIZE),
                ScalarOutcome('Total Aggregated Utility',ScalarOutcome.MAXIMIZE)
               ]

epsilon_list = [0.01]
eps = []

for i in epsilon_list:
    k = np.ones((len(RICE.outcomes))) * i
    eps.append(k)
    
Exemplo n.º 24
0
    # 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, one for each time step
    lake_model.levers = [RealParameter(str(i), 0, 0.1) for i in range(lake_model.time_horizon)]

    # specify outcomes
    lake_model.outcomes = [
        ScalarOutcome("max_P"),
        ScalarOutcome("utility"),
        ScalarOutcome("inertia"),
        ScalarOutcome("reliability"),
    ]

    # override some of the defaults of the model
    lake_model.constants = [Constant("alpha", 0.41), Constant("nsamples", 150)]

    # generate some random policies by sampling over levers
    policies = samplers.sample_levers(lake_model, 4, sampler=samplers.MonteCarloSampler(), name=util.counter)

    # perform experiments
    nr_experiments = 100

    results = perform_experiments(lake_model, nr_experiments, policies, parallel=True)
Exemplo n.º 25
0
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
# initiate model
model = Model(name='taxidriver', function=ema_experiment)

# levers
model.levers = [
    RealParameter("startup_fee", 2, 5),
    RealParameter("km_fee", 0.2, 0.5),
    RealParameter("speed", 90, 130),
]

# uncertainties
model.uncertainties = [
    RealParameter("distance", 3, 60),
    RealParameter("fuel_price", 1.1, 1.8),
    RealParameter("driver_salary_rate", 10, 20),
]

# specify outcomes
model.outcomes = [
    ScalarOutcome("profit"),
    ScalarOutcome("fuel_use"),
    ScalarOutcome("time_spent"),
]

# run experiments
results = perform_experiments(model, scenarios=10, policies=3)

# # save results
# results_file_name = os.path.join(RESULT_FOLDER, f"cabelpooling_ema_results_{RUNID}.tar.gz")
# save_results(results, file_name=results_file_name)
        IntegerParameter('scenario_limmiu', 0, 1)
    ]

    RICE.levers = [
        RealParameter('sr', 0.1, 0.5),
        RealParameter('irstp', 0.001, 0.015),
        IntegerParameter('miu_period', 5, 30),
        IntegerParameter('egalitarian_discounting', 0, 1)
    ]  #0 = no discouting , 1 = normal discounting,

    RICE.outcomes = [
        ScalarOutcome('Intratemporal utility GINI 2055',
                      ScalarOutcome.MINIMIZE),
        ScalarOutcome('Intratemporal impact GINI 2055',
                      ScalarOutcome.MINIMIZE),
        ScalarOutcome('Intratemporal utility GINI 2105',
                      ScalarOutcome.MINIMIZE),
        ScalarOutcome('Intratemporal impact GINI 2105',
                      ScalarOutcome.MINIMIZE),
        ScalarOutcome('Intertemporal utility GINI', ScalarOutcome.MINIMIZE),
        ScalarOutcome('Intertemporal impact GINI', ScalarOutcome.MINIMIZE)
    ]

    convergence_metrics = [EpsilonProgress()]
    minimize = ScalarOutcome.MINIMIZE
    maximize = ScalarOutcome.MAXIMIZE

    for outcome in RICE.outcomes:
        if outcome.kind == minimize:
            outcome.kind = maximize
        else:
            outcome.kind = minimize
Exemplo n.º 28
0
'''
from __future__ import (absolute_import, print_function, division,
                        unicode_literals)

from ema_workbench import (Model, RealParameter, ScalarOutcome, ema_logging,
                           perform_experiments)

def some_model(x1=None, x2=None, x3=None):
    return {'y':x1*x2+x3}

if __name__ == '__main__':
    ema_logging.LOG_FORMAT = '[%(name)s/%(levelname)s/%(processName)s] %(message)s'
    ema_logging.log_to_stderr(ema_logging.INFO)
    
    model = Model('simpleModel', function=some_model) #instantiate the model

    #specify uncertainties
    model.uncertainties = [RealParameter("x1", 0.1, 10),
                           RealParameter("x2", -0.01,0.01),
                           RealParameter("x3", -0.01,0.01)]
    #specify outcomes 
    model.outcomes = [ScalarOutcome('y')]

    results = perform_experiments(model, 100)

#     ensemble = ModelEnsemble() #instantiate an ensemble
#     ensemble.model_structure = model #set the model on the ensemble
#     results = ensemble.perform_experiments(100, reporting_interval=1) #run 1000 experiments
    

Exemplo n.º 29
0
        RealParameter("x22", 0.0001, 0.1),
        RealParameter("x31", 0, 0.5),
        RealParameter("x32", 0, 0.5),
        RealParameter("x41", 0, 0.9),
        RealParameter("x51", 0, 0.5),
        RealParameter("x52", 0, 0.5),
        RealParameter("x61", 0, 0.8),
        RealParameter("x62", 0, 0.8),
        RealParameter("x81", 1, 10),
        RealParameter("x82", 1, 10),
        RealParameter("x91", 0, 0.1),
        RealParameter("x92", 0, 0.1),
        RealParameter("x101", 0, 200),
        RealParameter("x102", 0, 200),
    ]

    model.outcomes = [TimeSeriesOutcome("TIME"), TimeSeriesOutcome("deceased_population_region_1")]

    nr_experiments = 500
    results = perform_experiments(model, nr_experiments, parallel=True)

    lines(
        results,
        outcomes_to_show="deceased_population_region_1",
        show_envelope=True,
        density=KDE,
        titles=None,
        experiments_to_show=np.arange(0, nr_experiments, 10),
    )
    plt.show()
Exemplo n.º 30
0
dice_sm.levers = [RealParameter('sr', 0.1, 0.5),
                      RealParameter('prtp_con',  0.001, 0.015),
                    #   RealParameter('prtp_dam',  0.001, 0.015),
                      RealParameter('emuc', 1.01, 2.00),
                      IntegerParameter('vd_switch', 0, 1),
                      IntegerParameter('periodfullpart', 10, 58),
                      IntegerParameter('miu_period', 10, 58)
                      ]

dice_sm.outcomes = [
            ScalarOutcome('Atmospheric Temperature 2300', kind=ScalarOutcome.MINIMIZE),
            ScalarOutcome('Total Output 2300', kind=ScalarOutcome.MAXIMIZE),
            # ScalarOutcome('Per Capita Consumption 2300', kind=ScalarOutcome.INFO),
            # ScalarOutcome('Consumption Growth 2300', kind=ScalarOutcome.INFO),
            ScalarOutcome('Utility of Consumption 2300', kind=ScalarOutcome.MAXIMIZE),
            # ScalarOutcome('Per Capita Damage 2300', kind=ScalarOutcome.INFO),
            # ScalarOutcome('Damage Growth 2300', kind=ScalarOutcome.INFO),
            ScalarOutcome('Disutility of Damage 2300', kind=ScalarOutcome.MINIMIZE),
            ScalarOutcome('Welfare 2300', kind=ScalarOutcome.MAXIMIZE),
            # ScalarOutcome('Undiscounted Period Welfare 2300', kind=ScalarOutcome.INFO),
            ScalarOutcome('Consumption SDR 2300', kind=ScalarOutcome.INFO),
            ScalarOutcome('Damage SDR 2300', kind=ScalarOutcome.INFO)
            ]


# %%
n_scenarios = 1000
n_policies = 25
run = 10
#%%

# %%
Exemplo n.º 31
0
    RICE = Model('RICE', function=model)

    RICE.uncertainties = [
        IntegerParameter('fdamage', 0, 2),
        IntegerParameter('t2xco2_index', 0, 999),
        IntegerParameter('t2xco2_dist', 0, 2),
        RealParameter('fosslim', 4000, 13649),
        IntegerParameter('scenario_pop_gdp', 0, 5),
        IntegerParameter('scenario_sigma', 0, 2),
        IntegerParameter('scenario_cback', 0, 1),
        IntegerParameter('scenario_elasticity_of_damages', 0, 2),
        IntegerParameter('scenario_limmiu', 0, 1)
    ]

    #same for all formulations
    RICE.outcomes = get_all_model_outcomes_uncertainty_search(
        optimization_formulation="utilitarian")

    ema_logging.log_to_stderr(ema_logging.INFO)
    #only needed on IPython console within Anaconda
    __spec__ = "ModuleSpec(name='builtins', loader=<class '_frozen_importlib.BuiltinImporter'>)"

    with MultiprocessingEvaluator(RICE) as evaluator:
        results = evaluator.perform_experiments(
            scenarios=nfe, policies=total_policy_list[principle_index])

        file_name = "//root//util_gen//server//output//uncertainty_analsysis_" + principles_list[
            principle_index] + "_runs_" + str(nfe) + ".tar.gz"
        save_results(results, file_name)

    print("uncertainty cycle " + principles_list[principle_index] +
          " completed")
Exemplo n.º 32
0
def main():

    hybridmodel = Model('hybridmodel', function=hybridloop)

    hybridmodel.uncertainties = [
        IntegerParameter("inputpowerfactor", 15, 25),  #7 13
        IntegerParameter("inputLNGprice", 200, 1000),
        IntegerParameter("inputtransferprice", 50, 300),
        IntegerParameter("inputCapincrease", 1000, 3000),
        IntegerParameter("inputCapincreasetime", 1, 2),
        IntegerParameter("inputLNGCapincrease", 1000, 3000),
        IntegerParameter("inputLNGCapincreasetime", 1, 2),
        #                             RealParameter("DemandBalanceSupplyEnergyPrice", 0.4, 0.7),
        RealParameter("MaximumChangeinDemand", 0.4, 0.7),
        RealParameter("SupplyElasticityGas", 0.06, 0.07),
        RealParameter("SupplyElasticityOil", 0.1, 0.2),
        RealParameter("SupplyElasticityCoal", 0.1, 0.2),
        RealParameter("SupplyElasticityNuclear", 0.007, 0.017),
        RealParameter("SupplyElasticityBiofuel", 0.1, 0.2),
        RealParameter("SupplyElasticityOR", 0.15, 0.3),
        IntegerParameter("EconomicGrowthScenario", 1, 3),
        IntegerParameter("EnergyIntensityScenario", 1, 3),
        RealParameter("CO2coal", 93.46, 113.67),
        RealParameter("CO2oil", 59.58, 102.12),
        RealParameter("Variancepower", -5.0, -0.1),
        IntegerParameter("POil", 8900, 9100),
        IntegerParameter("PCoal", 2800, 3100),
        IntegerParameter("PBio", 29000, 32000),
        IntegerParameter("PNuc", 16000, 17000),
        IntegerParameter("POR", 19000, 22000),
        IntegerParameter("PGasE", 6500, 7000),
        IntegerParameter("PGasNA", 2500, 2700),
        IntegerParameter("PGasSCA", 2500, 2700),
        IntegerParameter("PGasCIS", 6500, 7000),
        IntegerParameter("PGasME", 7000, 8000),
        IntegerParameter("PGasAF", 7000, 8000),
        IntegerParameter("PGasAP", 7000, 8000)
    ]

    hybridmodel.outcomes = [
        TimeSeriesOutcome("EU_GasSup"),
        TimeSeriesOutcome("EU_GasDem"),
        TimeSeriesOutcome("EU_GasCon"),
        TimeSeriesOutcome("EU_OilSup"),
        TimeSeriesOutcome("EU_OilDem"),
        TimeSeriesOutcome("EU_OilCon"),
        TimeSeriesOutcome("EU_CoalSup"),
        TimeSeriesOutcome("EU_CoalDem"),
        TimeSeriesOutcome("EU_CoalCon"),
        TimeSeriesOutcome("EU_NucSup"),
        TimeSeriesOutcome("EU_NucDem"),
        #                         TimeSeriesOutcome("EU_NucCon"),
        TimeSeriesOutcome("EU_BioSup"),
        TimeSeriesOutcome("EU_BioDem"),
        TimeSeriesOutcome("EU_BioCon"),
        TimeSeriesOutcome("EU_ORSup"),
        TimeSeriesOutcome("EU_ORDem"),
        #                         TimeSeriesOutcome("EU_ORCon"),
        TimeSeriesOutcome("EU_EDem"),
        TimeSeriesOutcome("EU_ESup"),
        TimeSeriesOutcome("EU_GDP"),
        TimeSeriesOutcome("EU_CO2"),
        TimeSeriesOutcome("EU_RusGas"),
        TimeSeriesOutcome("EU_EUGI"),
        TimeSeriesOutcome("EU_GIC"),
        TimeSeriesOutcome("EU_RGperAG"),
        TimeSeriesOutcome("EU_RGperTES"),
        TimeSeriesOutcome("EU_RGperGC"),
        TimeSeriesOutcome("EU_GICperBBTU"),
        TimeSeriesOutcome("Oil_Price"),
        TimeSeriesOutcome("Coal_Price"),
        TimeSeriesOutcome("Bio_Price"),
        TimeSeriesOutcome("Gas_PriceE"),
        TimeSeriesOutcome("Nuc_PriceE"),
        TimeSeriesOutcome("OR_PriceE"),
        TimeSeriesOutcome("FuncpriceGas"),
        TimeSeriesOutcome("FuncpriceOil"),
        TimeSeriesOutcome("FuncpriceCoal")
    ]

    hybridmodel.levers = [
        IntegerParameter("EnergyUnion", 0, 1),
        IntegerParameter("CO2Cost", 0, 1)
    ]

    # In[ ]:

    ema_logging.log_to_stderr(ema_logging.INFO)
    with MultiprocessingEvaluator(hybridmodel) as evaluator:
        results = evaluator.perform_experiments(scenarios=1,
                                                policies=4,
                                                levers_sampling='ff')

# In[1]:

    save_results(results, r'./1000 runs V30.tar.gz')
model = Model('lakeproblem', function=lake_model_actual)
model.time_horizon = 100

# specify uncertainties
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)
]

# specify outcomes
model.outcomes = [
    ScalarOutcome('max_P'),
    ScalarOutcome('utility'),
    ScalarOutcome('inertia'),
    ScalarOutcome('reliability')
]

# set levers
#model.levers = [RealParameter('decisions', 0, 0.1)]
model.levers = [
    RealParameter(f"l{i}", 0, 0.1) for i in range(model.time_horizon)
]

# model constants
model.constants = [Constant('alpha', 0.4), Constant('nsamples', 100)]

#####################################################################################################
from ema_workbench import Policy
# performing experiments
Exemplo n.º 34
0
                                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)]

    # reference is optional, but can be used to implement search for
    # various user specified scenarios along the lines suggested by
    # Watson and Kasprzyk (2017)
    reference = Scenario('reference', b=0.4, q=2, mean=0.02, stdev=0.01)

    with MultiprocessingEvaluator(lake_model) as evaluator: