Exemplo n.º 1
0
def set_up(props=None):
    """
    A func to set up run that can also be used by test code.
    """
    global sandpile_env
    global groups
    global group_indices

    pa = get_props(MODEL_NAME, props)
    width = pa.get('grid_width', DEF_WIDTH)
    height = pa.get('grid_height', DEF_HEIGHT)
    groups = []
    group_indices = {}
    for i in range(NUM_GROUPS):
        groups.append(Composite("Group" + str(i), {"marker": CIRCLE}))
        group_indices[groups[i].name] = i
    for y in range(height):
        for x in range(width):
            groups[0] += create_grain(x, y)
    sandpile_env = Env("Sandpile",
                       action=sandpile_action,
                       height=height,
                       width=width,
                       members=groups,
                       attrs={"size": 65,
                              "hide_axes": True,
                              "hide_legend": True},
                       random_placing=False,
                       props=pa)
    sandpile_env.attrs["center_agent"] = sandpile_env.get_agent_at(height // 2,
                                                                   width // 2)
    return sandpile_env, groups, group_indices
Exemplo n.º 2
0
def set_up(props=None):
    """
    A func to set up run that can also be used by test code.
    """
    global groups

    pa = get_props(MODEL_NAME, props)

    height = pa.get("grid_height", DEF_HEIGHT)
    width = pa.get("grid_width", DEF_WIDTH)
    simulation = pa.get("simulation", 0)
    black = Composite("Black", {"color": BLACK, "marker": SQUARE})
    groups = [black]
    Env("Game of Life",
        action=gameoflife_action,
        height=height,
        width=width,
        members=groups,
        attrs={"size": 100,
               "change_grid_spacing": (0.5, 1),
               "hide_xy_ticks": True,
               "hide_legend": True},
        random_placing=False,
        props=pa)

    populate_board_dict[simulation](width, height)

    return groups
Exemplo n.º 3
0
def set_up(props=None):
    """
    A func to set up run that can also be used by test code.
    """
    pa = get_props(MODEL_NAME, props)

    flock = Composite(BIRD_GROUP, {
        "color": BLUE,
        "marker": TREE
    },
                      member_creator=create_bird,
                      num_members=pa.get('num_birds', DEF_NUM_BIRDS))

    Env("the_sky",
        height=pa.get('grid_height', DEF_HEIGHT),
        width=pa.get('grid_width', DEF_WIDTH),
        members=[flock])
Exemplo n.º 4
0
def set_up(props=None):
    """
    A func to set up run that can also be used by test code.
    """
    pa = get_props(MODEL_NAME, props)
    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],
              props=pa)

    return (env, blue_group, red_group)
Exemplo n.º 5
0
def set_up(props=None):
    """
    Create an Env for Big box.
    """
    global groups
    global mp_pref
    global hood_size
    global store_census
    global period
    global bb_capital

    pa = get_props(MODEL_NAME, props)

    width = pa.get("grid_width", DEF_WIDTH)
    height = pa.get("grid_height", DEF_HEIGHT)
    num_consumers = pa.get("consumer_num", NUM_OF_CONSUMERS)
    num_mp = pa.get("mp_num", NUM_OF_MP)
    mp_pref = pa.get("mp_pref", MP_PREF)
    hood_size = pa.get("hood_size", HOOD_SIZE)
    multiplier = pa.get("multiple", MULTIPLIER)
    bb_capital = multiplier * STANDARD
    period = pa.get("period", PERIOD)

    consumer_group = Composite("Consumer", {"color": GRAY},
                               member_creator=create_consumer,
                               num_members=num_consumers)
    bb_group = Composite("Big box", {"color": BLUE})
    groups = [consumer_group, bb_group]
    for stores in range(0, len(mp_stores)):
        store_name = list(mp_stores.keys())[stores]
        groups.append(
            Composite(store_name,
                      {"color": mp_stores[store_name][COLOR_INDX]}))
    for m in range(0, num_mp):
        rand = random.randint(2, len(groups) - 1)
        groups[rand] += create_mp(groups[rand], m)
    Env("Town",
        action=town_action,
        members=groups,
        height=height,
        width=width,
        props=pa)
    return (groups)
Exemplo n.º 6
0
def set_up(props=None):
    """
    A func to set up run that can also be used by test code.
    """
    global groups
    global curr_row
    global rule_dict
    global rule_num

    pa = get_props(MODEL_NAME, props)
    width = pa.get('grid_width', DEF_WIDTH)
    rule_num = pa.get('rule_number', DEF_RULE)
    rule_dict = get_rule(rule_num)
    height = 0
    height = (width // 2) + (width % 2)
    white = Composite("White", {"color": WHITE})
    black = Composite("Black", {"color": BLACK, "marker": SQUARE})
    groups = [white, black]
    for y in range(height):
        for x in range(width):
            groups[W] += create_wolf_cell(x, y)
    wolfram_env = Env("Wolfram Model",
                      action=wolfram_action,
                      height=height,
                      width=width,
                      members=groups,
                      attrs={
                          "size": 50,
                          "hide_grid_lines": True,
                          "hide_legend": True
                      },
                      random_placing=False,
                      props=pa)
    wolfram_env.exclude_menu_item("line_graph")
    wolfram_env.now_switch(wolfram_env.get_agent_at(width // 2, height - 1),
                           groups[W], groups[B])
    curr_row = wolfram_env.get_row_hood(wolfram_env.height - 1)
    return (wolfram_env, groups, rule_dict)
Exemplo n.º 7
0
"""
import os
import json
import random
from numpy import random as np_random
from indra.utils import get_props

MODEL_NAME = "dealer_car_generator"

MIN_CAR_LIFE = .2
POS_EMOJIS = ["smiley", "laughing", "relaxing", "wink"]
NEG_EMOJIS = ["unnatural", "ambiguous", "hesitate", "eye rolling"]
MEAN_SCORE = 3

dealers = {}
pa = get_props(MODEL_NAME, None, model_dir="ml")
dealer_num = pa.get("num_dealers", 10)
car_num = pa.get("num_cars", 50)
for i in range(dealer_num):
    center_score = np_random.uniform(1, 5)
    lst = [
        max(round(random.gauss(center_score, 0.7), 1), MIN_CAR_LIFE)
        for i in range(car_num)
    ]
    dealer = {}
    dealer_name = "dealer" + str(i)
    if center_score >= MEAN_SCORE:
        emoji = random.choice(POS_EMOJIS)
    else:
        emoji = random.choice(NEG_EMOJIS)
    dealers[dealer_name] = {'emoji': emoji, 'scores': lst}