Пример #1
0
def set_up(props=None):
    """
    A func to set up run that can also be used by test code.
    """
    init_props(MODEL_NAME, props)
    execution_key = int(props[EXEC_KEY].val) \
        if props is not None else CLI_EXEC_KEY

    width = get_prop('grid_width', DEF_WIDTH, execution_key=execution_key)
    height = (width // 2) + (width % 2)

    groups = [
        Composite(WHITE, {"color": WHITE}, execution_key=execution_key),
        Composite(BLACK, {
            "color": BLACK,
            "marker": SQUARE
        },
                  execution_key=execution_key)
    ]

    for y in range(height):
        for x in range(width):
            groups[W] += create_wolf_cell(x, y, execution_key)
    wolfram_env = Env(MODEL_NAME,
                      action=wolfram_action,
                      height=height,
                      width=width,
                      members=groups,
                      attrs={
                          "size": 50,
                          "hide_grid_lines": True,
                          "hide_legend": True
                      },
                      random_placing=False,
                      execution_key=execution_key)

    rule_num = get_prop('rule_number', DEF_RULE, execution_key=execution_key)
    wolfram_env.set_attr("rule_num", rule_num)
    wolfram_env.set_attr("rule_dict", get_rule(rule_num))
    wolfram_env.exclude_menu_item("line_graph")
    '''
    This switch needs to happen before the environment is executed.
    Using add switch doesn't process the switch until after
    the environment is executed which breaks the model.
    '''
    top_center_agent = \
        wolfram_env.get_agent_at(width // 2, top_row(execution_key))
    switch(top_center_agent.name, WHITE, BLACK, execution_key=execution_key)

    # top row is the "previous" because we just processed it
    set_env_attr("prev_row_idx",
                 top_row(execution_key),
                 execution_key=execution_key)
Пример #2
0
def set_up(props=None):
    """
    Create an Env for Big box.
    """

    init_props(MODEL_NAME, props)

    width = get_prop("grid_width", DEF_WIDTH)
    height = get_prop("grid_height", DEF_HEIGHT)
    num_consumers = get_prop("consumer_num", NUM_OF_CONSUMERS)
    num_mp = get_prop("mp_num", NUM_OF_MP)
    mp_pref = get_prop("mp_pref", MP_PREF)
    hood_size = get_prop("hood_size", HOOD_SIZE)
    multiplier = get_prop("multiple", MULTIPLIER)
    bb_capital = multiplier * STANDARD
    period = get_prop("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]
    # add mom and pop stores to groups:
    groups.extend(mp_stores)

    # loop over m&p store types and add stores:
    for i in range(num_mp):
        store_num = i % len(mp_stores)  # keep store_num in range
        mp_stores[store_num] += create_mp(mp_stores[store_num], i)

    box = Env(MODEL_NAME,
              action=town_action,
              members=groups,
              height=height,
              width=width)
    box.set_attr("consumer_group", consumer_group)
    box.set_attr("bb_group", bb_group)
    box.set_attr("hood_size", hood_size)
    box.set_attr("mp_pref", mp_pref)
    box.set_attr("period", period)
    box.set_attr("bb_capital", bb_capital)
Пример #3
0
def set_up(props=None):
    """
    Create an Env for Big box.
    """

    init_props(MODEL_NAME, props)

    width = get_prop("grid_width", DEF_WIDTH)
    height = get_prop("grid_height", DEF_HEIGHT)
    num_consumers = get_prop("consumer_num", NUM_OF_CONSUMERS)
    num_mp = get_prop("mp_num", NUM_OF_MP)
    mp_pref = get_prop("mp_pref", MP_PREF)
    hood_size = get_prop("hood_size", HOOD_SIZE)
    multiplier = get_prop("multiple", MULTIPLIER)
    bb_capital = multiplier * STANDARD
    period = get_prop("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 kind in range(0, len(mp_stores)):
        groups[kind+2] += create_mp(groups[kind+2], kind)
    if num_mp > len(mp_stores):
        for mp in range(len(mp_stores), num_mp):
            rand = random.randint(2, len(groups) - 1)
            groups[rand] += create_mp(groups[rand], mp)
    box = Env(MODEL_NAME,
              action=town_action,
              members=groups,
              height=height,
              width=width)
    box.set_attr("consumer_group", consumer_group)
    box.set_attr("bb_group", bb_group)
    box.set_attr("hood_size", hood_size)
    box.set_attr("mp_pref", mp_pref)
    box.set_attr("period", period)
    box.set_attr("bb_capital", bb_capital)