Ejemplo n.º 1
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
Ejemplo n.º 2
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
 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
 MINIMIZE = ScalarOutcome.MINIMIZE  # @UndefinedVariable
 robustnes_functions = [ScalarOutcome('mean p', kind=MINIMIZE, 
                          variable_name='max_P', function=np.mean),
                        ScalarOutcome('std p', kind=MINIMIZE, 
                          variable_name='max_P', function=np.std),
Ejemplo n.º 7
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('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)
    y = pd.DataFrame(outcomes['density'], columns=['density'])
    print(y)
Ejemplo n.º 8
0
                             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 sa single default no release policy
 policy = Policy('no release', **{str(i):0.1 for i in range(100)})
 
 n_scenarios = 1000
  
 with MultiprocessingEvaluator(lake_model) as evaluator:
     results = evaluator.perform_experiments(n_scenarios, policy, 
                                             uncertainty_sampling=SOBOL)
     
 sobol_stats, s2, s2_conf = analyze(results, 'max_P')
 print(sobol_stats)
 print(s2)
 print(s2_conf)
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
 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)]
     
 # generate some random policies by sampling over levers
 n_scenarios = 100
 n_policies = 4
  
 with MultiprocessingEvaluator(lake_model) as evaluator:
     res = evaluator.perform_experiments(n_scenarios, n_policies,
                                         levers_sampling=MC)
    #                          ]

    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':
        #             solutions = pd.DataFrame.from_csv(r'../results/Results_EpsNsgaII_nfe10000_scRef_v3.csv')
        #         else:
        #             solutions = pd.DataFrame.from_csv(r'../results/Results_EpsNsgaII_nfe10000_sc{}_v5.csv'.format(s))

        #checked if there are duplicates: No.
        solutions = pd.DataFrame.from_csv(
Ejemplo n.º 12
0
# input domain name from command line
domain = sys.argv[1]

ema_logging.LOG_FORMAT = '[%(name)s/%(levelname)s/%(processName)s] %(message)s'
ema_logging.log_to_stderr(ema_logging.INFO)
    
model = Model('grsystem', function=gr_system)

# set levers
model.uncertainties = [IntegerParameter("phi", 0,100),
                RealParameter("delta", 0, 5),
                RealParameter("lamb", 1, 5),
                RealParameter("threshold", 0.6, 1.0)]

# model.levers = [CategoricalParameter("domain", ["sokoban", "blocks-world"])]
model.constants = [Constant("domain", domain)]

#specify outcomes
model.outcomes = [ScalarOutcome('p_10'),
                  ScalarOutcome('r_10'),
                  ScalarOutcome('a_10'),
                  ScalarOutcome('p_30'),
                  ScalarOutcome('r_30'),
                  ScalarOutcome('a_30'),
                  ScalarOutcome('p_50'),
                  ScalarOutcome('r_50'),
                  ScalarOutcome('a_50'),
                  ScalarOutcome('p_70'),
                  ScalarOutcome('r_70'),
                  ScalarOutcome('a_70'),
                  ScalarOutcome('p_100'),
Ejemplo n.º 13
0
    RealParameter('prey_birth_rate', 0.015, 0.35),
    RealParameter('predation_rate', 0.0005, 0.003),
    RealParameter('predator_efficiency', 0.001, 0.004),
    RealParameter('predator_loss_rate', 0.04, 0.08),
]

# specify outcomes
model.outcomes = [
    TimeSeriesOutcome('prey'),  # amount of prey
    TimeSeriesOutcome('predators'),  # amount of predators
]

# model constants
model.constants = [
    Constant('dt', 0.25),
    Constant('final_time', 365),
    Constant('reps', 1)
]

###
# Perform experiments
from ema_workbench import (SequentialEvaluator)

with SequentialEvaluator(model) as evaluator:
    results = perform_experiments(model,
                                  100,
                                  reporting_interval=1,
                                  evaluator=evaluator)

experiments, outcomes = results
print(experiments.shape)
Ejemplo n.º 14
0
    # specify outcomes
    model.outcomes = [
        ScalarOutcome('y'),
        ScalarOutcome('y1'),
        ArrayOutcome('y3'),
        ScalarOutcome('y4'),
        ScalarOutcome('y5'),
        ScalarOutcome('y6'),
        ScalarOutcome('y7')
    ]

    # override some of the defaults of the model
    model.constants = [
        Constant("X4rSnow", 0.7),
        Constant("xCostDay", 6),
        Constant("xRevenueDay", 10)
    ]

    #results = perform_experiments(model, 1500, 5)
    results = perform_experiments(model, 200, 20)

    #with MultiprocessingEvaluator(model, n_processes=4) as evaluator:
    #    results = evaluator.perform_experiments(scenarios=4, policies=5)

print('end!')
training_time = time.time() - start_time

print("--- %s seconds ---" % (training_time))
print('training time : {} mins and {} seconds'.format(
    (training_time // 60), round((training_time % 60), 1)))
Ejemplo n.º 15
0
# set levers
model.levers = [RealParameter("solarVSwind", 0, 1)]

# specify outcomes
model.outcomes = [ScalarOutcome(metric) for metric in metrics]
# model.outcomes = [ScalarOutcome("hv_net_capacity_delta_present_future")]

# initiate ETM connection
ref_scenario = 769771
ETM = init_ETM(ref_scenario, metrics)

# override some of the defaults of the model
model.constants = [
    # standard = 1920 hours / year
    Constant("ETM_instance", ETM),
    Constant("flh_of_energy_power_wind_turbine_inland", 3000),
    Constant("flh_of_solar_pv_solar_radiation", 1000),  # standard = 867 / year
    Constant("costs_co2", 100),  # standard = 8 €/tonne
    Constant("total_supply", 55e6),  # MWh 35e6 minimum, RES 1.0 55e6
]

results = perform_experiments(model, policies=25)

experiments, outcomes = results

policies = experiments["policy"]
for i, policy in enumerate(np.unique(policies)):
    experiments.loc[policies == policy, "policy"] = str(i)

data = pd.DataFrame(outcomes)
data["solarVSwind"] = experiments["solarVSwind"]
Ejemplo n.º 16
0
    RealParameter("r2", 0, 2),
    RealParameter("w1", 0, 1)
]

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

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

from ema_workbench import (SequentialEvaluator, ema_logging,
                           perform_experiments)
ema_logging.log_to_stderr(ema_logging.INFO)

from SALib.analyze import sobol
from ema_workbench.em_framework.salib_samplers import get_SALib_problem

with SequentialEvaluator(model) as evaluator:
    sa_results = evaluator.perform_experiments(scenarios=1,
                                               uncertainty_sampling='sobol')

experiments, outcomes = sa_results
# 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
# generate experiments
n_scenarios = 1000
n_policies = 4
policy = Policy("no release", **{l.name: 0 for l in model.levers})

from ema_workbench import (MultiprocessingEvaluator, ema_logging,
                           perform_experiments)

ema_logging.log_to_stderr(ema_logging.INFO)

if __name__ == '__main__':
Ejemplo n.º 18
0
        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
    MINIMIZE = ScalarOutcome.MINIMIZE  # @UndefinedVariable
    robustnes_functions = [
        ScalarOutcome('mean p',
                      kind=MINIMIZE,