How to use the indra.env.Env function in indra

To help you get started, we’ve selected a few indra examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gcallah / indras_net / models / el_farol.py View on Github external
def set_up(props=None):
    """
    A func to set up run that can also be used by test code.
    """
    init_props(MODEL_NAME, props)

    drinkers = Composite(DRINKERS, {"color": RED},
                         member_creator=create_drinker,
                         num_members=get_prop('population',
                                              DEF_POPULATION) // 2)

    non_drinkers = Composite(NON_DRINKERS, {"color": BLUE},
                             member_creator=create_non_drinker,
                             num_members=get_prop('population',
                                                  DEF_POPULATION) // 2)
    bar = Env(MODEL_NAME,
              height=get_prop('grid_height', DEF_HEIGHT),
              width=get_prop('grid_width', DEF_WIDTH),
              members=[drinkers, non_drinkers],
              pop_hist_setup=setup_attendance)
    population = len(drinkers) + len(non_drinkers)
    bar.set_attr("population", population)
    bar.set_attr(OPT_OCCUPANCY, int(population * DEF_MOTIV))
    bar.set_attr(AGENTS_DECIDED, 0)
    bar.set_attr(ATTENDANCE, 0)
    set_env_attrs()
github gcallah / indras_net / models / bigboxV2.py View on Github external
consumer_group = Composite("Consumer", {"color": GRAY},
                               member_creator=create_consumer,
                               num_members=num_consumers)
    bb_group = Composite("Big box", {"color": BLUE})
    groups = []
    groups.append(consumer_group)
    groups.append(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)
    town = Env("Town",
               action=town_action,
               members=groups,
               height=height,
               width=width,
               props=pa)
    return (town, groups)
github gcallah / indras_net / models / forestfire.py View on Github external
forest_width = get_prop('grid_width', DEF_DIM)
    new_fire = get_prop('new_fire', DEF_NEW_FIRE)
    set_trans(state_trans, HE, NF, float(new_fire), HE)
    forest_density = get_prop('density', DEF_DENSITY)
    tree_cnt = int(forest_height * forest_width * forest_density)
    groups = []
    groups.append(Composite(HEALTHY, {"color": GREEN, "marker": TREE},
                  member_creator=plant_tree,
                  num_members=tree_cnt))
    groups.append(Composite(NEW_FIRE, {"color": TOMATO, "marker": TREE}))
    groups.append(Composite(ON_FIRE, {"color": RED, "marker": TREE}))
    groups.append(Composite(BURNED_OUT, {"color": BLACK, "marker": TREE}))
    groups.append(Composite(NEW_GROWTH, {"color": SPRINGGREEN, "marker":
                                         TREE}))

    Env(MODEL_NAME, height=forest_height, width=forest_width, members=groups)
    # the next set should just be done once:
    set_env_attr(TRANS_TABLE, state_trans)
    # whereas these settings must be re-done every API re-load:
    set_env_attrs()
github gcallah / indras_net / models / scheduler.py View on Github external
course_agent = create_agent('Reds_', c)
        course_agent.attrs = a
        red_group += course_agent
        cprop = copy.deepcopy(a)
        prof = cprop['professor']
        room = cprop['room']
        blues_prof = 'Blues_' + str(prof)
        blues_room = 'Blues_' + str(room)
        if blues_prof not in blue_group.members:
            blue_group += create_agent('Blues_', prof)
        if blues_room not in blue_group.members:
            blue_group += create_agent('Blues_', room)
    print(red_group.members)
    print('```````')
    print(blue_group.members)
    env = Env("scheduler",
              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)
github gcallah / indras_net / models / models_to_rewrite / flocking.py View on Github external
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])
    return (flock)
github gcallah / indras_net / models / coop.py View on Github external
"""
    A func to set up run that can also be used by test code.
    """
    init_props(MODEL_NAME, props)

    num_members = get_prop('num_babysitter', DEF_BABYSITTER)
    co_op_members = Composite(CO_OP_MEMBERS,
                              {"color": RED},
                              num_members=num_members,
                              member_creator=create_babysitter)
    central_bank = Composite("central_bank",
                             {"color": GREEN},
                             num_members=1,
                             member_creator=create_central_bank)

    Env(MODEL_NAME, members=[co_op_members, central_bank],
        action=coop_action, width=UNLIMITED,
        height=UNLIMITED,
        pop_hist_setup=initial_exchanges,
        attrs={"last_per_exchg": 0,
               "last_per_unemp": 0,
               "num_rounds": 0,
               "CB_interven_pts": []})
    set_env_attrs()
github gcallah / indras_net / capital / cap_struct.py View on Github external
global resource_holders
    global entrepreneurs

    pa = init_props(MODEL_NAME, props, model_dir="capital")
    entrepreneurs = Composite("Entrepreneurs", {"color": BLUE},
                              member_creator=create_entr,
                              props=pa,
                              num_members=pa.get('num_entr',
                                                 DEF_NUM_ENTR))
    resource_holders = Composite("Resource_holders", {"color": RED},
                                 member_creator=create_rholder,
                                 props=pa,
                                 num_members=pa.get('num_rholder',
                                                    DEF_NUM_RHOLDER))

    Env("neighborhood",
        height=get_prop('grid_height', DEF_HEIGHT),
        width=get_prop('grid_width', DEF_WIDTH),
        members=[resource_holders, entrepreneurs])

    return resource_holders, entrepreneurs
github gcallah / indras_net / models / models_to_rewrite / bigbox.py View on Github external
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)
github gcallah / indras_net / models / fashion.py View on Github external
print(red_tsetters.__repr__())

    red_followers = Composite(RED_FOLLOWERS)
    blue_followers = Composite(BLUE_FOLLOWERS)
    for i in range(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)