Exemple #1
0
def init_props(model_nm, props=None, model_dir=None,
               skip_user_questions=False):
    model_dir = get_model_dir(model_dir)
    props_file = get_prop_path(model_nm, model_dir=model_dir)
    if props is None:
        pa = PropArgs.create_props(model_nm,
                                   ds_file=props_file,
                                   skip_user_questions=skip_user_questions)
    else:
        pa = PropArgs.create_props(model_nm,
                                   prop_dict=props,
                                   skip_user_questions=skip_user_questions)

    return pa
Exemple #2
0
def init_props(model_nm, props=None, model_dir="models",
               skip_user_questions=False):
    props_file = get_prop_path(model_nm, model_dir=model_dir)
    if props is None:
        pa = PropArgs.create_props(model_nm,
                                   ds_file=props_file,
                                   skip_user_questions=skip_user_questions)
    else:
        pa = PropArgs.create_props(model_nm,
                                   prop_dict=props,
                                   skip_user_questions=skip_user_questions)

    # we keep props available in registry:
    set_propargs(pa)
    return pa
Exemple #3
0
def set_up():
    """
    A func to set up run that can also be used by test code.
    """
    global on_fire
    global healthy

    ds_file = 'props/forestfire.props.json'
    pa = PropArgs.create_props('forest_fire_props', ds_file=ds_file)
    forest_height = pa.get('grid_height', DEF_DIM)
    forest_width = pa.get('grid_width', DEF_DIM)
    forest_density = pa.get('density', DEF_DENSITY)

    healthy = Composite(HEALTHY, {"color": GREEN})
    new_fire = Composite(NEW_FIRE, {"color": TOMATO})
    on_fire = Composite(ON_FIRE, {"color": RED})
    burned_out = Composite(BURNED_OUT, {"color": BLACK})
    new_growth = Composite(NEW_GROWTH, {"color": SPRINGGREEN})
    for i in range(int(forest_height * forest_width * forest_density)):
        healthy += plant_tree(i)

    forest = Env("Forest", height=forest_height, width=forest_width,
                 members=[healthy, new_fire, on_fire, burned_out,
                          new_growth])

    global group_map
    group_map = {HE: healthy, NF: new_fire,
                 OF: on_fire, BO: burned_out, NG: new_growth}
    return (forest, group_map)
Exemple #4
0
def set_up():
    """
    A func to set up run that can also be used by test code.
    """
    global pa
    pa = PropArgs.create_props('wolfsheep_props',
                               ds_file='props/wolfsheep.props.json')
    wolves = Composite(COMP_WOLF_NAME, {"color": TAN})
    for i in range(pa.get('num_wolves', NUM_WOLVES)):
        wolves += create_wolf(i, pa)

    if DEBUG2:
        print(wolves.__repr__())

    sheep = Composite(COMP_SHEEP_NAME, {"color": GRAY})
    for i in range(pa.get('num_sheep', NUM_SHEEP)):
        sheep += create_sheep(i, pa)

    if DEBUG2:
        print(sheep.__repr__())

    meadow = Env("meadow", members=[wolves, sheep],
                 height=pa.get('meadow_height', MEADOW_HEIGHT),
                 width=pa.get('meadow_width', MEADOW_WIDTH))
    return (wolves, sheep, meadow)
Exemple #5
0
def set_up():
    """
    A func to set up run that can also be used by test code.
    """
    pa = PropArgs.create_props('basic_props',
                               ds_file='props/segregation.props.json')
    blue_agents = Composite(group_names[BLUE_TEAM] + " group", {"color": BLUE})
    red_agents = Composite(group_names[RED_TEAM] + " group", {"color": RED})
    for i in range(pa['num_red']):
        red_agents += create_agent(i,
                                   pa.get('mean_tol', DEF_TOLERANCE),
                                   pa.get('deviation', DEF_SIGMA),
                                   color=RED_TEAM)

    if DEBUG2:
        print(red_agents.__repr__())

    for i in range(pa['num_blue']):
        blue_agents += create_agent(i,
                                    pa.get('mean_tol', DEF_TOLERANCE),
                                    pa.get('deviation', DEF_SIGMA),
                                    color=BLUE_TEAM)
    if DEBUG2:
        print(blue_agents.__repr__())

    city = Env("A city",
               members=[blue_agents, red_agents],
               height=pa['grid_height'],
               width=pa['grid_width'])
    return (blue_agents, red_agents, city)
Exemple #6
0
def set_up():
    """
    A func to set up run that can also be used by test code.
    """
    pa = PropArgs.create_props('basic_props',
                               ds_file='props/fashion.props.json')
    blue_tsetters = Composite(BLUE_TSETTERS, {"color": NAVY})
    red_tsetters = Composite(RED_TSETTERS, {"color": DARKRED})
    for i in range(pa.get('num_tsetters', NUM_TSETTERS)):
        red_tsetters += create_tsetter(i)

    if DEBUG2:
        print(red_tsetters.__repr__())

    red_followers = Composite(RED_FOLLOWERS, {"color": RED})
    blue_followers = Composite(BLUE_FOLLOWERS, {"color": BLUE})
    for i in range(pa.get('num_followers', NUM_FOLLOWERS)):
        blue_followers += create_follower(i)

    opp_group = {str(red_tsetters): blue_tsetters,
                 str(blue_tsetters): red_tsetters,
                 str(red_followers): blue_followers,
                 str(blue_followers): red_followers}

    if DEBUG2:
        print(blue_followers.__repr__())

    society = Env("society", members=[blue_tsetters, red_tsetters,
                                      blue_followers, red_followers])
    return (blue_tsetters, red_tsetters, blue_followers, red_followers,
            opp_group, society)
 def get(self, model_id):
     """
     Get the list of properties (parameters) for a model.
     """
     props = PropArgs.create_props(str(model_id),
                                   prop_dict=get_props(model_id, indra_dir))
     exec_key = create_exec_env(save_on_register=True)
     props["exec_key"] = exec_key
     registry.save_reg(exec_key)
     return props.to_json()
Exemple #8
0
def init_props(model_nm,
               props=None,
               model_dir="models",
               skip_user_questions=False):
    props_file = get_prop_path(model_nm, model_dir=model_dir)
    execution_key = CLI_EXEC_KEY if props is None else int(
        props.get(EXEC_KEY).get("val"))
    if props is None:
        pa = PropArgs.create_props(model_nm,
                                   ds_file=props_file,
                                   skip_user_questions=skip_user_questions)
    else:
        pa = PropArgs.create_props(model_nm,
                                   prop_dict=props,
                                   skip_user_questions=skip_user_questions)

    # we keep props available in registry:
    execution_registry.set_propargs(execution_key, pa)
    return pa
Exemple #9
0
def set_up():
    """
    A func to set up run that can also be used by test code.
    """
    pa = PropArgs.create_props('basic_props', ds_file='props/basic.props.json')
    blue_group = Composite("Blues", {"color": BLUE},
                           member_creator=create_agent,
                           num_members=pa.get('num_blue', DEF_NUM_BLUE))
    red_group = Composite("Reds", {"color": RED},
                          member_creator=create_agent,
                          num_members=pa.get('num_red', DEF_NUM_RED))

    env = Env("env",
              height=pa.get('grid_height', DEF_HEIGHT),
              width=pa.get('grid_width', DEF_WIDTH),
              members=[blue_group, red_group])
    return (blue_group, red_group, env)
Exemple #10
0
"""
    This is wolf-sheep re-written in indra.
"""
from propargs.propargs import PropArgs
from indra.agent import Agent
from indra.composite import Composite
from indra.space import in_hood
from indra.env import Env
from indra.display_methods import TAN, GRAY

DEBUG = True  # turns debugging code on or off
DEBUG2 = False  # turns deeper debugging code on or off
pa = PropArgs.create_props('basic_props',
                           ds_file='props/wolfsheep.props.json')
NUM_WOLVES = 8
NUM_SHEEP = 20
HOOD_SIZE = 3
MEADOW_HEIGHT = 10
MEADOW_WIDTH = 10

WOLF_LIFESPAN = 5
WOLF_REPRO_PERIOD = 6

SHEEP_LIFESPAN = 8
SHEEP_REPRO_PERIOD = 3

AGT_WOLF_NAME = "wolf"
AGT_SHEEP_NAME = "sheep"

COMP_WOLF_NAME = "wolves"
COMP_SHEEP_NAME = "sheep"
Exemple #11
0
 def setUp(self):
     self.pa = PropArgs.create_props('flocking_props',
                                     ds_file='props/flocking.props.json')
     (self.flock) = set_up()
     self.bird_a = create_bird(TEST_BNAME, TEST_BNUM1, props=self.pa)
     self.bird_b = create_bird(TEST_BNAME, TEST_BNUM2, props=self.pa)
Exemple #12
0
from propargs.propargs import PropArgs
from indra.agent import Agent, X_VEC, Y_VEC, NEUTRAL
from indra.agent import ratio_to_sin
from indra.composite import Composite
from indra.space import in_hood
from indra.env import Env
from indra.display_methods import NAVY, DARKRED, RED, BLUE

import numpy as np

DEBUG = True  # turns debugging code on or off
DEBUG2 = False  # turns deeper debugging code on or off

NUM_TSETTERS = 5
NUM_FOLLOWERS = 55
pa = PropArgs.create_props('basic_props', ds_file='props/fashion.props.json')
"""
Adding weighted average for having a sine curve
"""
ENV_WEIGHT = 0.6
weightings = [1.0, pa.get('env_weight', ENV_WEIGHT)]

COLOR_PREF = "color_pref"
DISPLAY_COLOR = "display_color"

BLUE_SIN = 0.0
RED_SIN = 1.0

# for future use as we move to vector representation:
BLUE_VEC = X_VEC
RED_VEC = Y_VEC
Exemple #13
0
 def tearDown(self):
     pass
     self.pa = PropArgs.create_props('used_car_props',
                                     ds_file='props/used_cars.props.json')
     (self.car_market, self.dealers, self.buyers) = set_up(10)  # noqa: F405
 def setUp(self):
     self.pa = PropArgs.create_props('gameoflife_props',
                                     ds_file='props/gameoflife.props.json')
     (g.groups) = set_up()
     pass
Exemple #15
0
 def setUp(self):
     self.pa = PropArgs.create_props('wolfsheep_props',
                                     ds_file='props/wolfsheep.props.json')
     (ws.wolves, ws.sheep, ws.meadow) = set_up()
     self.wolf = create_wolf(TEST_WNUM, self.pa)
     self.sheep = create_sheep(TEST_SNUM, self.pa)