How to use the indra.utils 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 / wolfsheep_markov_run.py View on Github external
import indra.utils as utils
import indra.prop_args as props
import wolfsheep_markov_model as wsmm

# set up some file names:
MODEL_NM = "wolfsheep_model"
(prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)

# We store basic parameters in a "property" file; this allows us to save
#  multiple parameter sets, which is important in simulation work.
#  We can read these in from file or set them here.
pa = utils.read_props(MODEL_NM)
if pa is None:
    pa = props.PropArgs(MODEL_NM, logfile=log_file, props=None)
    utils.get_grid_dims(pa, 16)
    utils.get_agent_num(pa, "num_wolves", "wolves", 5)
    utils.get_agent_num(pa, "num_sheep", "sheep", 16)
    pa.ask("wolf_repro", "What is the wolf reproduction age?", int, default=16)
    pa.ask("wolf_lforce", "What is the wolf life force?", int, default=7)
    pa.ask("sheep_repro", "What is the sheep reproduction age?", int,
           default=3)
    pa.ask("sheep_lforce", "What is the sheep life force?", int, default=6)

# Now we create a meadow for our agents to act within:
env = wsmm.Meadow("Meadow",
                 pa.get("grid_width"),
                 pa.get("grid_height"),
                 model_nm=MODEL_NM,
                 preact=True,
                 postact=True)

# Now we loop creating multiple agents with numbered names
github gcallah / indras_net / models / old_models / menger_run.py View on Github external
#!/usr/bin/env python3
"""
A script to run our Menger model.
"""

import indra.utils as utils
import indra.prop_args as props
import indra.node as node
import barter_model as bm
import menger_model as mm

# set up some file names:
MODEL_NM = "menger_model"
(prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)
CSV_FILE = MODEL_NM + "02.csv"

# We store basic parameters in a
# "property" file; this allows us to save
#  multiple parameter sets, which is important in simulation work.
#  We can read these in from file or set them here.
pa = utils.read_props(MODEL_NM)
if pa is None:
    pa = props.PropArgs(MODEL_NM, logfile=log_file, props=None)
    pa.set("prod_amt", 1)

# Now we create an environment for our agents to act within:
env = mm.MengerEnv("Menger's money model", 50, 50,
                   model_nm=MODEL_NM)
env.fetch_agents_from_file(CSV_FILE, mm.MengerAgent)
env.add_prod_goods()
github gcallah / indras_net / models / party_run.py View on Github external
# Now we loop creating multiple agents with numbered names
    # based on the loop variable:
    for i in range(pa["num_men"]):
        env.add_agent(pm.Man(name="Man" + str(i),
                      goal="A good party.",
                      tol=0.5,
                      max_detect=pa['max_detect']))
        
    for i in range(pa["num_women"]):
        env.add_agent(pm.Woman(name="Woman" + str(i),
                      goal="A good party.",
                      tol=0.5,
                      max_detect=pa['max_detect']))
        
    return utils.run_model(env, prog_file, results_file)
github gcallah / indras_net / models / forestfire_run.py View on Github external
def run(prop_dict=None):
    (prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)
    
    global pa

    if pa["user_type"] == props.WEB:
        pa["base_dir"] = os.environ["base_dir"]
    
    grid_x = pa["grid_width"]
    grid_y = pa["grid_height"]
    density = pa["density"]

    # Now we create a forest environment for our agents to act within:
    env = fm.ForestEnv(grid_x,
                       grid_y,
                       density,
                       pa["strike_freq"],
                       pa["regen_period"],
github gcallah / indras_net / schelling / segregation_run.py View on Github external
# based on the loop variable:
    for i in range(pa["num_B_agents"]):
        env.add_agent(sm.BlueAgent(name="Blue agent" + str(i),
                      goal="A good neighborhood.",
                      min_tol=pa['min_tolerance'],
                      max_tol=pa['max_tolerance'],
                      max_detect=pa['max_detect']))
        
    for i in range(pa["num_R_agents"]):
        env.add_agent(sm.RedAgent(name="Red agent" + str(i),
                      goal="A good neighborhood.",
                      min_tol=pa['min_tolerance'],
                      max_tol=pa['max_tolerance'],
                      max_detect=pa['max_detect']))
        
    return utils.run_model(env, prog_file, results_file)
github gcallah / indras_net / models / fashion_run.py View on Github external
import indra.utils as utils
import indra.prop_args as props
import fashion_model as fm

# set up some file names:
MODEL_NM = "fashion_model"
(prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)

# We store basic parameters in a "property" file; this allows us to save
#  multiple parameter sets, which is important in simulation work.
#  We can read these in from file or set them here.
pa = utils.read_props(MODEL_NM)
if pa is None:
    pa = props.PropArgs(MODEL_NM, logfile=log_file, props=None)
    utils.get_grid_dims(pa, 16)
    utils.get_agent_num(pa, "num_followers", "followers", 48)
    utils.get_agent_num(pa, "num_hipsters", "hipsters", 16)
    utils.get_max_move(pa, "fmax_move", "follower", 4)
    utils.get_max_move(pa, "hmax_move", "hipster", 4)
    pa.ask("min_adv_periods", "What are the minimum adverse periods?", int,
           default=6, limits=(1, 100))


# Now we create a minimal environment for our agents to act within:
env = fm.Society("Society",
                 pa.get("grid_height"),
                 pa.get("grid_width"),
                 torus=False,
                 model_nm=MODEL_NM)

# Now we loop creating multiple agents with numbered names
# based on the loop variable:
github gcallah / indras_net / models / plane_run.py View on Github external
pa = utils.read_props(MODEL_NM)
if pa is None:
    pa = props.PropArgs(MODEL_NM, logfile=log_file, props=None)
    pa.set("num_agents", 2)

# Now we create a minimal environment for our agents to act within:
env = pe.PlaneEnv("Test plane env", 100.0, 100.0, model_nm=MODEL_NM)

# Now we loop creating multiple agents with numbered names
# based on the loop variable:
for i in range(pa.get("num_agents")):
    env.add_agent(
        pm.TestPlaneAgent(name="agent" + str(i),
                          goal="moving around aimlessly!"))

utils.run_model(env, prog_file, results_file)
github gcallah / indras_net / models / standing_ovation_run.py View on Github external
import indra.utils as utils
    import models.standing_ovation as wsm
    (prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)

    env = wsm.Auditorium("Auditorium",
                     pa["grid_width"],
                     pa["grid_height"],
                     model_nm=MODEL_NM,
                     preact=True,
                     props=pa)

    num_agents = int(pa["grid_width"] * pa["grid_height"])
    for i in range(num_agents):
        env.add_agent(wsm.Member("member" + str(i), "Enjoying the show", pa["noise_level"]))

    return utils.run_model(env, prog_file, results_file)
github gcallah / indras_net / models / old_models / emp_run.py View on Github external
demonstrating heirarchical graphing.
"""

import indra.utils as utils
import indra.prop_args as props
import emp_model as em

# set up some file names:
MODEL_NM = "emp_model"
(prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)

# We store basic parameters in a
# "property" file; this allows us to save
#  multiple parameter sets, which is important in simulation work.
#  We can read these in from file or set them here.
pa = utils.read_props(MODEL_NM)
if pa is None:
    pa = props.PropArgs(MODEL_NM, logfile=log_file, props=None)

# Now we create a minimal environment for our agents to act within:
env = em.EmpEnv(model_nm=MODEL_NM)

linda = em.EmpAgent("Linda")
suzanne = em.EmpAgent("Suzanne")
sandy = em.EmpAgent("Sandy")
connie = em.EmpAgent("Connie")
rich = em.EmpAgent("Rich")
gene = em.EmpAgent("Gene")
shruti = em.EmpAgent("Shruti")
cedric = em.EmpAgent("Cedric")

em.employs(sandy, gene)
github gcallah / indras_net / models / markov_attempts / fashion_markov_run.py View on Github external
#!/usr/bin/env python3
"""
Runs a fashion model with hipsters and followers.
"""

import indra.utils as utils
import indra.prop_args as props
import fashion_markov_model as fmm

# set up some file names:
MODEL_NM = "fashion_markov_model"
(prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)

# We store basic parameters in a "property" file; this allows us to save
#  multiple parameter sets, which is important in simulation work.
#  We can read these in from file or set them here.
pa = utils.read_props(MODEL_NM)
if pa is None:
    pa = props.PropArgs(MODEL_NM, logfile=log_file, props=None)
    utils.get_grid_dims(pa, 16)
    utils.get_agent_num(pa, "num_followers", "followers", 48)
    utils.get_agent_num(pa, "num_hipsters", "hipsters", 16)
    utils.get_max_move(pa, "fmax_move", "follower", 4)
    utils.get_max_move(pa, "hmax_move", "hipster", 4)

# Now we create a minimal environment for our agents to act within:
env = fmm.Society("Society",
                 pa.get("grid_height"),