How to use the indra.composite.Composite 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))
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 / fashion.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)
    groups = []

    groups.append(Composite(BLUE_TSETTERS, {"color": NAVY}))
    groups.append(Composite(RED_TSETTERS, {"color": DARKRED},
                            member_creator=create_tsetter,
                            num_members=get_prop('num_tsetters',
                                                 NUM_TSETTERS)))

    groups.append(Composite(RED_FOLLOWERS, {"color": RED}))
    groups.append(Composite(BLUE_FOLLOWERS, {"color": BLUE},
                            member_creator=create_follower,
                            num_members=get_prop('num_followers',
                                                 NUM_FOLLOWERS)))

    Env(MODEL_NAME, members=groups, attrs={OPP_GROUP: opp_group})
github gcallah / indras_net / epidemics / epidemic.py View on Github external
# Replace state trans values with updated values
    set_trans(STATE_TRANS, EX, IN, infec, HE)
    set_trans(STATE_TRANS, CN, DE, death_rate, IM)
    set_trans(STATE_TRANS, IM, HE, immune_rate, IM)

    pop_cnt = int(city_height * city_width * city_density)
    groups = []
    groups.append(Composite(HEALTHY, {"color": GREEN},
                            member_creator=create_person,
                            num_members=int(pop_cnt * (1 - initial_infected)),
                            state=HE))
    groups.append(Composite(EXPOSED, {"color": YELLOW},
                            member_creator=create_person,
                            num_members=1,
                            state=EX))
    groups.append(Composite(INFECTED, {"color": TOMATO},
                            member_creator=create_person,
                            num_members=int(pop_cnt * initial_infected),
                            state=IN))
    groups.append(Composite(CONTAGIOUS, {"color": RED},
                            member_creator=create_person,
                            num_members=1,
                            state=CN))
    groups.append(Composite(DEAD, {"color": BLACK},
                            member_creator=create_person,
                            num_members=1,
                            state=DE))
    groups.append(Composite(IMMUNE, {"color": BLUE},
                            member_creator=create_person,
                            num_members=1,
                            state=IM))
    Env(MODEL_NAME, height=city_height, width=city_width, members=groups)
github gcallah / indras_net / models / segregation.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)
    blue_agents = Composite(group_names[BLUE_GRP_IDX],
                            {"color": BLUE},
                            member_creator=create_resident,
                            num_members=get_prop('num_blue',
                                                 NUM_BLUE),
                            group=BLUE)
    red_agents = Composite(group_names[RED_GRP_IDX],
                           {"color": RED},
                           member_creator=create_resident,
                           num_members=get_prop('num_red', NUM_RED),
                           group=RED)
    city = Env(MODEL_NAME, members=[blue_agents, red_agents],
               height=get_prop('grid_height', DEF_CITY_DIM),
               width=get_prop('grid_width', DEF_CITY_DIM))
    city.exclude_menu_item("line_graph")
github gcallah / indras_net / models / scheduler.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 = props
    ds_file = get_prop_path(MODEL_NAME)
    if pa is None:
        pa = PropArgs.create_props(MODEL_NAME, ds_file=ds_file)
    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))

    # add our agents to the groups
    course_assignments = CourseRoomProfAssigner()
    for c, a in course_assignments.items():
        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)
github gcallah / indras_net / models / coop.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)

    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": []})
github gcallah / indras_net / models / fashion.py View on Github external
def set_up():
    """
    A func to set up run that can also be used by test code.
    """
    blue_tsetters = Composite(BLUE_TSETTERS)
    red_tsetters = Composite(RED_TSETTERS)
    for i in range(NUM_TSETTERS):
        red_tsetters += create_tsetter(i)

    if DEBUG2:
        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)
github gcallah / indras_net / models / models_to_rewrite / bigbox.py View on Github external
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)
github gcallah / indras_net / models / fashion.py View on Github external
def set_up():
    """
    A func to set up run that can also be used by test code.
    """
    blue_tsetters = Composite(BLUE_TSETTERS)
    red_tsetters = Composite(RED_TSETTERS)
    for i in range(NUM_TSETTERS):
        red_tsetters += create_tsetter(i)

    if DEBUG2:
        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}