def test_run_model(self): wd = r"../models" model_file = r"/Wolf Sheep Predation.nlogo" model = NetLogoModel("predPreyNetlogo", wd=wd, model_file=model_file) model.run_length = 1000 model.uncertainties = [ RealParameter("grass-regrowth-time", 10, 100), CategoricalParameter("grass?", ("true", "false")) ] model.outcomes = [ TimeSeriesOutcome('sheep'), TimeSeriesOutcome('wolves') ] model.model_init(Policy('no policy')) case = {"grass-regrowth-time": 35, "grass?": "true"} model.run_model(case) _ = model.retrieve_output() model.cleanup()
def _build_executable_model(mediator, context): # set the name of the EMAModel name = mediator.name # set the dir path for the model model_dir_path = mediator.model['dir'] # set the name of the model model_file = mediator.model['name'] # set the dir path where NetLogo is located netlogo_home = mediator.netlogo['dir'] # set the NetLogo version netlogo_version = mediator.netlogo['version'] # create the NetLogoModel object ema_model = NetLogoModel(name=name, wd=model_dir_path, model_file=model_file, netlogo_home=netlogo_home, netlogo_version=netlogo_version, gui=False) # set the max run length of this model ema_model.run_length = context.max_run_length # set the number of replications ema_model.replications = context.num_replications uncertainties, outcomes, constants = _determine_parameters( mediator, context) ema_model.uncertainties = uncertainties ema_model.outcomes = outcomes ema_model.constants = constants return ema_model
def test_run_model(self): wd = r"../models" model_file = r"/Wolf Sheep Predation.nlogo" model = NetLogoModel("predPreyNetlogo", wd=wd, model_file=model_file) model.run_length = 1000 model.uncertainties = [RealParameter("grass-regrowth-time", 10, 100), CategoricalParameter("grass?", ("true", "false")) ] model.outcomes = [TimeSeriesOutcome('sheep'), TimeSeriesOutcome('wolves')] model.model_init(Policy('no policy')) case = {"grass-regrowth-time": 35, "grass?": "true"} model.run_model(case) _ = model.retrieve_output() model.cleanup()
#model.outcomes = [ScalarOutcome('lastvalue-co2-emitted-to-air-global', ScalarOutcome.MINIMIZE), # ScalarOutcome('sum-co2-emitted-to-air-global', ScalarOutcome.MAXIMIZE), # ScalarOutcome('sum-subsidy-to-por-global', ScalarOutcome.MINIMIZE), # ScalarOutcome('sum-subsidy-to-industries-global', ScalarOutcome.MINIMIZE)] #np.max is used as the outcome is a list of one value #-> it doesn't matter which function is used to extract it, np.max was chosen arbitrarily model.outcomes = [ ScalarOutcome('2050 yearly CO2 emitted', ScalarOutcome.MINIMIZE, variable_name='lastvalue-co2-emitted-to-air-global', function=np.max), ScalarOutcome('sum-co2-emitted-to-air-global', ScalarOutcome.MAXIMIZE, variable_name='sum-co2-emitted-to-air-global', function=np.max), ScalarOutcome('sum-subsidy-to-por-global', ScalarOutcome.MINIMIZE, variable_name='sum-subsidy-to-por-global', function=np.max), ScalarOutcome('sum-subsidy-to-industries-global', ScalarOutcome.MINIMIZE, variable_name='sum-subsidy-to-industries-global', function=np.max) ] convergence = [ HyperVolume(minimum=[0, 0, 0, 0], maximum=[1e9, 1e9, 1e8, 1e8]), EpsilonProgress() ] with SequentialEvaluator(model) as evaluator:
model = NetLogoModel('predprey', wd="./models/predatorPreyNetlogo", model_file="Wolf Sheep Predation.nlogo") model.run_length = 100 model.replications = 1 model.uncertainties = [ RealParameter("grass-regrowth-time", 1, 99), RealParameter("initial-number-sheep", 1, 200), RealParameter("initial-number-wolves", 1, 200), RealParameter("sheep-reproduce", 1, 20), RealParameter("wolf-reproduce", 1, 20), ] model.outcomes = [ TimeSeriesOutcome('sheep'), TimeSeriesOutcome('wolves'), TimeSeriesOutcome('grass'), TimeSeriesOutcome('TIME') ] #perform experiments n = 10 with MultiprocessingEvaluator(model) as evaluator: results = perform_experiments(model, n, evaluator=evaluator) fn = r'./data/{} runs.tar.gz'.format(n) save_results(results, fn) print "finish"
from ema_workbench.connectors.netlogo import NetLogoModel from ema_workbench.em_framework import (TimeSeriesOutcome, RealParameter, perform_experiments) from ema_workbench.util import ema_logging from ema_workbench.analysis import plotting, plotting_util if __name__ == '__main__': #turn on logging ema_logging.log_to_stderr(ema_logging.DEBUG) model = NetLogoModel('predprey', wd="./models/predatorPreyNetlogo", model_file="Wolf Sheep Predation.nlogo") model.run_length = 100 model.uncertainties = [RealParameter("grass-regrowth-time", 1, 99), RealParameter("initial-number-sheep", 1, 200), RealParameter("initial-number-wolves", 1, 200), RealParameter("sheep-reproduce", 1, 20), RealParameter("wolf-reproduce", 1, 20), ] model.outcomes = [TimeSeriesOutcome('sheep'), TimeSeriesOutcome('wolves'), TimeSeriesOutcome('grass') ] #perform experiments n = 100 results = perform_experiments(model, n, parallel=True)
model.uncertainties = [RealParameter('clustering-resources', 0, 1), RealParameter('clustering-PCFs', 0, 1), RealParameter('clustering-SCFs', 0, 1), RealParameter('clustering-ECFs', 0, 1), RealParameter('width-distributions-resources', 0, 1), #RealParameter('width-distributions-PCFs', 0, 1), RealParameter('width-distributions-SCFs', 0, 1), RealParameter('width-distributions-ECFs', 0, 1), RealParameter('social-network-size', 2, 8), RealParameter('network-ratio', 0, 1) ] model.outcomes = [TimeSeriesOutcome('level-of-achievability'), TimeSeriesOutcome('personal-conversion-factor-shortage'), TimeSeriesOutcome('social-conversion-factor-shortage'), TimeSeriesOutcome('environmental-conversion-factor-shortage'), TimeSeriesOutcome('TIME')] #perform experiments n = 100 with MultiprocessingEvaluator(model) as evaluator: #results = evaluator.perform_experiments(scenarios=500) results = perform_experiments(model, n, evaluator=evaluator) fn = r'./data/{}_runs_cap_approach.tar.gz'.format(n) save_results(results, fn)
RealParameter('clustering-resources', 0, 1), RealParameter('clustering-PCFs', 0, 1), RealParameter('clustering-SCFs', 0, 1), RealParameter('clustering-ECFs', 0, 1), RealParameter('width-distributions-resources', 0, 1), #RealParameter('width-distributions-PCFs', 0, 1), RealParameter('width-distributions-SCFs', 0, 1), RealParameter('width-distributions-ECFs', 0, 1), RealParameter('social-network-size', 2, 8), RealParameter('network-ratio', 0, 1) ] model.outcomes = [ TimeSeriesOutcome('level-of-achievability'), TimeSeriesOutcome('personal-conversion-factor-shortage'), TimeSeriesOutcome('social-conversion-factor-shortage'), TimeSeriesOutcome('environmental-conversion-factor-shortage'), TimeSeriesOutcome('TIME') ] #perform experiments n = 100 with MultiprocessingEvaluator(model) as evaluator: #results = evaluator.perform_experiments(scenarios=500) results = perform_experiments(model, n, evaluator=evaluator) fn = r'./data/{}_runs_cap_approach.tar.gz'.format(n) save_results(results, fn) print "finish"