コード例 #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)

    num_members = get_prop('num_babysitter', DEF_BABYSITTER)
    co_op_members = Composite(CO_OP_MEMBERS,
                              num_members=num_members,
                              member_creator=create_babysitter)
    central_bank = Composite("central_bank",
                             num_members=1,
                             member_creator=create_central_bank)

    Env('coop_env',
        members=[co_op_members, central_bank],
        action=coop_action,
        width=UNLIMITED,
        height=UNLIMITED,
        census=coop_report,
        pop_hist_setup=initial_exchanges,
        pop_hist_func=record_exchanges,
        attrs={
            "show_special_points": CB_intervention_points,
            "special_points_name": "CB intervention points"
        })
コード例 #2
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)
    exec_key = init_exec_key(props)
    members = []
    members.append(
        Composite(WOLF_GROUP,
                  attrs={"color": TAN},
                  member_creator=create_wolf,
                  num_members=get_prop('num_wolves',
                                       NUM_WOLVES,
                                       execution_key=exec_key),
                  execution_key=exec_key))

    members.append(
        Composite(SHEEP_GROUP,
                  attrs={"color": GRAY},
                  member_creator=create_sheep,
                  num_members=get_prop('num_sheep',
                                       NUM_SHEEP,
                                       execution_key=exec_key),
                  execution_key=exec_key))

    Env(MODEL_NAME,
        members=members,
        attrs={
            "prey_dist": get_prop("prey_dist",
                                  PREY_DIST,
                                  execution_key=exec_key)
        },
        height=get_prop('grid_height', MEADOW_HEIGHT, execution_key=exec_key),
        width=get_prop('grid_width', MEADOW_WIDTH, execution_key=exec_key),
        execution_key=exec_key)
コード例 #3
0
ファイル: fashion.py プロジェクト: gcallah/Indra
def set_up():
    """
    A func to set up run that can also be used by test code.
    """
    blue_tsetters = Composite(BLUE_TSETTERS, {"color": NAVY})
    red_tsetters = Composite(RED_TSETTERS, {"color": DARKRED})
    for i in range(NUM_TSETTERS):
        red_tsetters += create_tsetter(i)

    if DEBUG2:
        print(red_tsetters.__repr__())

    red_followers = Composite(RED_FOLLOWERS, {"color": SPRINGGREEN})
    blue_followers = Composite(BLUE_FOLLOWERS, {"color": GRAY})
    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)
コード例 #4
0
ファイル: bacteria.py プロジェクト: gupta-arpit/indras_net
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
    toxins = Composite(TOXINS, {"color": RED},
                       member_creator=create_toxin,
                       num_members=get_prop('num_toxins',
                                            NUM_TOXINS,
                                            execution_key=execution_key),
                       execution_key=execution_key)

    nutrients = Composite(NUTRIENTS, {"color": GREEN},
                          member_creator=create_nutrient,
                          num_members=get_prop('num_nutrients',
                                               NUM_TOXINS,
                                               execution_key=execution_key),
                          execution_key=execution_key)

    bacteria = Composite(BACTERIA, {"color": BLUE},
                         member_creator=create_bacterium,
                         num_members=get_prop('num_toxins',
                                              DEF_NUM_BACT,
                                              execution_key=execution_key),
                         execution_key=execution_key)

    Env(MODEL_NAME,
        height=get_prop('grid_height', DEF_HEIGHT,
                        execution_key=execution_key),
        width=get_prop('grid_width', DEF_WIDTH, execution_key=execution_key),
        members=[toxins, nutrients, bacteria],
        execution_key=execution_key)
コード例 #5
0
ファイル: panic.py プロジェクト: gupta-arpit/indras_net
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
    calm = Composite(CALM, {"color": BLUE},
                     member_creator=create_resident,
                     num_members=get_prop('num_people',
                                          NUM_CALM_AGENTS,
                                          execution_key=execution_key),
                     group=BLUE, execution_key=execution_key)
    panic = Composite(PANIC, {"color": RED},
                      member_creator=create_resident,
                      num_members=NUM_PANIC_AGENTS,
                      group=RED, execution_key=execution_key)
    city = Env(MODEL_NAME, members=[calm, panic],
               height=get_prop('grid_height', DEF_CITY_DIM,
                               execution_key=execution_key),
               width=get_prop('grid_width', DEF_CITY_DIM,
                              execution_key=execution_key),
               execution_key=execution_key)
    set_env_attr(STATES, [CALM, PANIC], execution_key=execution_key)
    city.exclude_menu_item("line_graph")
コード例 #6
0
ファイル: coop.py プロジェクト: gupta-arpit/indras_net
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

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

    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": []
        },
        execution_key=execution_key)
    set_env_attrs(execution_key=execution_key)
コード例 #7
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)
    groups = []

    groups.append(
        Composite("value_investors", {"color": BLUE},
                  member_creator=create_value_investor,
                  num_members=get_prop("value_investors",
                                       DEF_NUM_VALUE_INVESTOR)))
    groups.append(
        Composite("trend_followers", {"color": RED},
                  member_creator=create_trend_follower,
                  num_members=get_prop("trend_followers",
                                       DEF_NUM_TREND_FOLLOWER)))
    groups.append(create_market_maker("market_maker"))
    Env("fmarket",
        members=groups,
        width=UNLIMITED,
        height=UNLIMITED,
        census=market_report,
        line_data_func=plot_asset_price)
    get_env().exclude_menu_item("scatter_plot")
コード例 #8
0
ファイル: el_farol.py プロジェクト: Abhilash1993/indras_net
def set_up(props=None):
    """
    A func to set up run that can also be used by test code.
    """
    global population
    global optimal_occupancy
    global agents_decided

    init_props(MODEL_NAME, props)
    agents_decided = 0

    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)

    population = len(drinkers) + len(non_drinkers)
    optimal_occupancy = int(population * 0.6)

    Env("bar",
        height=get_prop('grid_height', DEF_HEIGHT),
        width=get_prop('grid_width', DEF_WIDTH),
        members=[drinkers, non_drinkers])
コード例 #9
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

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

    non_drinkers = Composite(NON_DRINKERS, {"color": BLUE},
                             member_creator=create_non_drinker,
                             num_members=population_prop // 2,
                             execution_key=execution_key)
    Env(MODEL_NAME,
        height=get_prop('grid_height', DEF_HEIGHT,
                        execution_key=execution_key),
        width=get_prop('grid_width', DEF_WIDTH,
                       execution_key=execution_key),
        members=[drinkers, non_drinkers],
        pop_hist_setup=setup_attendance,
        execution_key=execution_key)

    population = len(drinkers) + len(non_drinkers)
    set_env_attr(POPULATION, population, execution_key=execution_key)
    set_env_attr(OPT_OCCUPANCY, int(population * DEF_MOTIV),
                 execution_key=execution_key)
    set_env_attr(AGENTS_DECIDED, 0, execution_key=execution_key)
    set_env_attr(ATTENDANCE, 0, execution_key=execution_key)
    set_env_attrs(execution_key=execution_key)
コード例 #10
0
ファイル: used_cars.py プロジェクト: gupta-arpit/indras_net
def set_up(props=None):  # testcase???
    """
    A func to set up run that can also be used by test code.
    """
    init_props(MODEL_NAME, props, model_dir="ml")
    group = []
    group.append(
        Composite(DEALER_GRP, {"color": BLUE},
                  member_creator=generate_dealer,
                  num_members=get_prop('num_dealers', DEF_NUM_DEALER)))
    # can we put the testing period in to composite too?
    group.append(
        Composite(AVA_BUYER_GRP, {"color": RED},
                  member_creator=ava_cb,
                  num_members=get_prop('num_buyers', DEF_NUM_BUYER)))

    group.append(
        Composite(SELINA_BUYER_GRP, {"color": RED},
                  member_creator=selina_cb,
                  num_members=get_prop('num_buyers', DEF_NUM_BUYER)))

    Env(MODEL_NAME,
        height=get_prop('grid_height', DEF_HEIGHT),
        width=get_prop('grid_width', DEF_WIDTH),
        members=group)
コード例 #11
0
ファイル: fmarket.py プロジェクト: gupta-arpit/indras_net
def set_up(props=None):
    """
    A func to set up run that can also be used by test code.
    """
    init_props(MODEL_NAME, props)
    exec_key = init_exec_key(props)
    groups = []

    groups.append(
        Composite("value_investors", {"color": BLUE},
                  member_creator=create_value_investor,
                  num_members=get_prop("value_investors",
                                       DEF_NUM_VALUE_INVESTOR,
                                       execution_key=exec_key),
                  execution_key=exec_key))
    groups.append(
        Composite("trend_followers", {"color": RED},
                  member_creator=create_trend_follower,
                  num_members=get_prop("trend_followers",
                                       DEF_NUM_TREND_FOLLOWER,
                                       execution_key=exec_key),
                  execution_key=exec_key), )
    groups.append(create_market_maker(MARKET_MAKER))
    Env(MODEL_NAME,
        members=groups,
        width=UNLIMITED,
        height=UNLIMITED,
        pop_hist_setup=initial_price,
        execution_key=exec_key)
    get_env(execution_key=exec_key).exclude_menu_item("scatter_plot")
    set_env_attrs(execution_key=exec_key)
コード例 #12
0
ファイル: fashion.py プロジェクト: gupta-arpit/indras_net
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
    groups = []

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

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

    Env(MODEL_NAME, members=groups, attrs={OPP_GROUP: opp_group},
        execution_key=execution_key)
コード例 #13
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

    blue_group = Composite("Blues", {"color": BLUE},
                           member_creator=create_agent,
                           num_members=get_prop('num_blue',
                                                DEF_NUM_BLUE,
                                                execution_key=execution_key),
                           execution_key=execution_key)
    red_group = Composite("Reds", {"color": RED},
                          member_creator=create_agent,
                          num_members=get_prop('num_red',
                                               DEF_NUM_RED,
                                               execution_key=execution_key),
                          execution_key=execution_key)

    Env(MODEL_NAME,
        height=get_prop('grid_height', DEF_HEIGHT,
                        execution_key=execution_key),
        width=get_prop('grid_width', DEF_WIDTH, execution_key=execution_key),
        members=[blue_group, red_group],
        execution_key=execution_key)
コード例 #14
0
def set_up(props=None):
    """
    A func to set up run that can also be used by test code.
    """
    global max_util
    pa = init_props(MODEL_NAME, props, model_dir="capital")
    cheese_group = Composite("Cheese holders", {"color": BLUE},
                             member_creator=create_cagent,
                             props=pa,
                             num_members=get_prop('num_cagents',
                                                  DEF_NUM_CAGENTS))
    wine_group = Composite("Wine holders", {"color": RED},
                           member_creator=create_wagent,
                           props=pa,
                           num_members=get_prop('num_wagents',
                                                DEF_NUM_WAGENTS))

    Env("EdgeworthBox",
        height=get_prop('grid_height', DEF_HEIGHT),
        width=get_prop('grid_width', DEF_WIDTH),
        members=[cheese_group, wine_group])

    start_cheese = 0
    start_wine = 0
    if pa is not None:
        start_cheese = get_prop('start_cheese', DEF_NUM_CHEESE)
        start_wine = get_prop('start_wine', DEF_NUM_WINE)
        max_util = max(start_cheese, start_wine)
    else:
        props_max_util = max(start_cheese, start_wine)
        max_util = max(props_max_util, DEF_MAX_UTIL)

    return (cheese_group, wine_group, max_util)
コード例 #15
0
def set_up(props=None):
    """
    A func to set up run that can also be used by test code.
    """

    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
コード例 #16
0
ファイル: forestfire.py プロジェクト: KhaingSuYin/indras_net
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)
コード例 #17
0
ファイル: segregation.py プロジェクト: gupta-arpit/indras_net
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
    blue_agents = Composite(group_names[BLUE_GRP_IDX], {"color": BLUE},
                            member_creator=create_resident,
                            num_members=get_prop('num_blue',
                                                 NUM_BLUE,
                                                 execution_key=execution_key),
                            group=BLUE,
                            execution_key=execution_key)
    red_agents = Composite(group_names[RED_GRP_IDX], {"color": RED},
                           member_creator=create_resident,
                           num_members=get_prop('num_red',
                                                NUM_RED,
                                                execution_key=execution_key),
                           group=RED,
                           execution_key=execution_key)
    city = Env(MODEL_NAME,
               members=[blue_agents, red_agents],
               height=get_prop('grid_height',
                               DEF_CITY_DIM,
                               execution_key=execution_key),
               width=get_prop('grid_width',
                              DEF_CITY_DIM,
                              execution_key=execution_key),
               execution_key=execution_key)
    city.exclude_menu_item("line_graph")
コード例 #18
0
def set_up():
    """
    A func to set up run that can also be used by test code.
    """
    global on_fire
    global healthy

    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 * 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)
コード例 #19
0
ファイル: forestfire.py プロジェクト: gupta-arpit/indras_net
def set_up(props=None):
    """
    A func to set up a  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

    forest_height = get_prop('grid_height',
                             DEF_DIM,
                             execution_key=execution_key)
    forest_width = get_prop('grid_width', DEF_DIM, execution_key=execution_key)
    new_fire = get_prop('new_fire', DEF_NEW_FIRE, execution_key=execution_key)
    set_trans(state_trans, HE, NF, float(new_fire), HE)
    forest_density = get_prop('density',
                              DEF_DENSITY,
                              execution_key=execution_key)
    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,
                  execution_key=execution_key))
    groups.append(
        Composite(NEW_FIRE, {
            "color": TOMATO,
            "marker": TREE
        },
                  execution_key=execution_key))
    groups.append(
        Composite(ON_FIRE, {
            "color": RED,
            "marker": TREE
        },
                  execution_key=execution_key))
    groups.append(
        Composite(BURNED_OUT, {
            "color": BLACK,
            "marker": TREE
        },
                  execution_key=execution_key))
    groups \
        .append(Composite(NEW_GROWTH, {"color": SPRINGGREEN, "marker": TREE},
                          execution_key=execution_key))

    Env(MODEL_NAME,
        height=forest_height,
        width=forest_width,
        members=groups,
        execution_key=execution_key)
    # the next set should just be done once:
    set_env_attr(TRANS_TABLE, state_trans, execution_key=execution_key)
    # whereas these settings must be re-done every API re-load:
    set_env_attrs(execution_key=execution_key)
コード例 #20
0
 def test_market_report(self):
     new_market_maker = create_market_maker("market_maker")
     value_investors = Composite("value_investors")
     trend_followers = Composite("trend_followers")
     market = Env(
         "env",
         members=[value_investors, trend_followers, new_market_maker],
         census=market_report)
     self.assertEqual(market_report(market),
                      "Asset price on the market: " + str(DEF_PRICE) + "\n")
コード例 #21
0
 def test_get_color(self):
     """
     Based on a passed in group return the appropriate color.
     """
     white = Composite("white")
     black = Composite("black")
     wolf.groups = []
     wolf.groups.append(white)
     wolf.groups.append(black)
     self.assertEqual(get_color(wolf.groups[W]), W)
コード例 #22
0
 def test_add_grain(self):
     """
     Creates an agent, assign it to Group0,
     and checks if add_grain changed the agent to Group1.
     """
     a = create_grain(TEST_X, TEST_Y)
     sp.groups = []
     sp.groups.append(Composite("Group" + str(0)))
     sp.groups.append(Composite("Group" + str(1)))
     sp.groups[0] += a
     add_grain(a)
     self.assertEqual(a.primary_group(), sp.groups[1])
コード例 #23
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)
コード例 #24
0
ファイル: basic.py プロジェクト: crosstuck/indras_net
def set_up():
    """
    A func to set up run that can also be used by test code.
    """
    blue_group = Composite("Blues", {"color": BLUE},
                           member_creator=create_agent,
                           num_members=NUM_BLUE)
    red_group = Composite("Reds", {"color": RED},
                          member_creator=create_agent,
                          num_members=NUM_RED)

    env = Env("env", members=[blue_group, red_group])
    return (blue_group, red_group, env)
コード例 #25
0
    def agent_in_little_city(self, with_blue=False):
        red_agents = Composite("My reds")
        test_agent = create_resident(RED_AGENTS, TEST_ANUM)
        red_agents += test_agent
        blue_agents = Composite("My blues")
        if with_blue:
            for i in range(0, SMALL_GRID * SMALL_GRID - 1):
                blue_agents += create_resident(BLUE_AGENTS, TEST_ANUM + 1)

        my_city = Env("Small city for test",
                      width=SMALL_GRID,
                      height=SMALL_GRID,
                      members=[red_agents, blue_agents])
        return (test_agent, my_city)
コード例 #26
0
ファイル: fashion.py プロジェクト: KhaingSuYin/indras_net
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)
コード例 #27
0
ファイル: fashion.py プロジェクト: crosstuck/indras_net
def set_up():
    """
    A func to set up run that can also be used by test code.
    """
    blue_tsetters = Composite(BLUE_TSETTERS, {"color": NAVY})
    red_tsetters = Composite(RED_TSETTERS, {"color": DARKRED})
    for i in range(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(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)
コード例 #28
0
ファイル: basic.py プロジェクト: Abhilash1993/indras_net
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_group = Composite("Blues", {"color": BLUE},
                           member_creator=create_agent,
                           num_members=get_prop('num_blue', DEF_NUM_BLUE))
    red_group = Composite("Reds", {"color": RED},
                          member_creator=create_agent,
                          num_members=get_prop('num_red', DEF_NUM_RED))

    Env("env",
        height=get_prop('grid_height', DEF_HEIGHT),
        width=get_prop('grid_width', DEF_WIDTH),
        members=[blue_group, red_group])
コード例 #29
0
def tree_action(agent):
    """
    This is what trees do each turn in the forest.
    """
    global on_fire

    old_state = agent["state"]
    if is_healthy(agent):
        nearby_fires = Composite(agent.name + "'s nearby fires")
        neighbors = agent.locator.get_moore_hood(agent)
        if neighbors is not None:
            nearby_fires = neighbors.subset(is_on_fire, agent)
        if len(nearby_fires) > 0:
            if DEBUG2:
                print("Setting nearby tree on fire!")
            agent["state"] = NF

    # if we didn't catch on fire above, do probabilistic transition:
    if old_state == agent["state"]:
        agent["state"] = prob_state_trans(old_state, STATE_TRANS)

    if old_state != agent["state"]:
        agent.has_acted = True
        agent.locator.add_switch(agent, group_map[old_state],
                                 group_map[agent["state"]])
    return True
コード例 #30
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
コード例 #31
0
ファイル: sandpile.py プロジェクト: gupta-arpit/indras_net
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 = get_prop('grid_height', DEF_HEIGHT, execution_key=execution_key)
    groups = []

    for i in range(NUM_GROUPS):
        groups.append(
            Composite(str(i), {"marker": CIRCLE}, execution_key=execution_key))
    for y in range(height):
        for x in range(width):
            groups[0] += create_grain(x, y, execution_key=execution_key)
    sandpile_env = Env(MODEL_NAME,
                       action=sandpile_action,
                       height=height,
                       width=width,
                       members=groups,
                       attrs={
                           "size": 65,
                           "hide_axes": True,
                           "hide_legend": True
                       },
                       random_placing=False,
                       execution_key=execution_key)
    # these settings must be re-done every API re-load:
    set_env_attrs(execution_key)
    return sandpile_env, groups
コード例 #32
0
ファイル: segregation.py プロジェクト: gcallah/Indra
def set_up():
    """
    A func to set up run that can also be used by test code.
    """
    blue_agents = Composite(group_names[BLUE_TEAM] + " group", {"color": BLUE})
    red_agents = Composite(group_names[RED_TEAM] + " group", {"color": RED})
    for i in range(NUM_AGENTS):
        red_agents += create_agent(i, color=RED_TEAM)

    if DEBUG2:
        print(red_agents.__repr__())

    for i in range(NUM_AGENTS):
        blue_agents += create_agent(i, color=BLUE_TEAM)

    if DEBUG2:
        print(blue_agents.__repr__())

    city = Env("A city", members=[blue_agents, red_agents],
               height=DEF_CITY_DIM, width=DEF_CITY_DIM)
    return (blue_agents, red_agents, city)
コード例 #33
0
ファイル: test_composite.py プロジェクト: gcallah/Indra
 def test_rand_member(self):
     rand_guy = self.calc.rand_member()
     self.assertIsNotNone(rand_guy)
     empty_set = Composite("Empty")
     rand_guy = empty_set.rand_member()
     self.assertIsNone(rand_guy)