Exemplo n.º 1
0
    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
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
from ema_workbench.analysis.plotting_util import BOXPLOT

if __name__ == '__main__':
    #turn on logging
    ema_logging.log_to_stderr(ema_logging.INFO)

    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:
Exemplo n.º 5
0
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)
if __name__ == '__main__':
    #turn on logging
    ema_logging.log_to_stderr(ema_logging.INFO)

    model = NetLogoModel('Netlogo', 
                          wd="./models/capabilityapproach", 
                          model_file="Model cap approach.nlogo")
    model.run_length = 100
    model.replications = 2
    
    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
    
if __name__ == '__main__':
    #turn on logging
    ema_logging.log_to_stderr(ema_logging.INFO)

    model = NetLogoModel('Netlogo',
                         wd="./models/capabilityapproach",
                         model_file="Model cap approach.nlogo")
    model.run_length = 100
    model.replications = 2

    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