Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#!/usr/bin/env python3
"""
Runs a model with leaders and followers.
"""
import indra.utils as utils
import indra.prop_args as props
import stance_model as sm
# set up some file names:
MODEL_NM = "stance_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_linvest", "leaders", 16)
utils.get_max_move(pa, "fmax_move", "follower", 4)
utils.get_max_move(pa, "lmax_move", "leader", 4)
# Now we create a minimal environment for our agents to act within:
env = sm.StanceEnv("Stance Environment",
pa.get("grid_height"),
def run():
(prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)
# We store menu 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 = mm.MenuEnv(model_nm=MODEL_NM, props=pa)
# 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(mm.MenuAgent(name="agent" + str(i),
def run(prop_dict=None):
(prog_file, log_file,
prop_file, results_file) = utils.gen_file_names(MODEL_NM)
global pa
# Now we create an environment for our agents to act within:
env = am.Auditorium("Auditorium",
height=pa["grid_height"],
width=pa["grid_width"],
torus=False,
model_nm=MODEL_NM,
num_agents=pa["num_agents"],
props=pa)
return utils.run_model(env, prog_file, results_file)
def run(prop_dict=None):
pa = props.PropArgs.create_props(MODEL_NM, prop_dict)
import indra.utils as utils
import indra.grid_env as ge
import models.grid as gm
(prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)
if pa["user_type"] == props.WEB:
pa["base_dir"] = os.environ["base_dir"]
# Now we create a minimal environment for our agents to act within:
env = ge.GridEnv("Test grid env",
pa["grid_width"],
pa["grid_height"],
torus=False,
model_nm=MODEL_NM,
preact=True,
postact=True,
props=pa)
# Now we loop creating multiple agents with numbered names
# based on the loop variable:
#!/usr/bin/env python3
"""
A script to run the bacterium model.
"""
import indra.utils as utils
import indra.prop_args as props
import indra.grid_env as ge
import models.bacterium_model as bm
# set up some file names:
MODEL_NM = "grid_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)
pa.set("num_agents", 1)
pa.set("grid_width", 4)
pa.set("grid_height", 4)
# Now we create a minimal environment for our agents to act within:
env = ge.GridEnv("Test grid env",
pa.get("grid_height"),
pa.get("grid_width"),
torus=False,
def run():
(prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)
# We store menu 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("num_agents", 10)
# Now we create a minimal environment for our agents to act within:
env = mm.MenuEnv(model_nm=MODEL_NM, props=pa)
# Now we loop creating multiple agents
# with numbered names based on the loop variable:
for i in range(pa.get("num_agents")):
def run(prop_dict=None):
pa = props.PropArgs.create_props(MODEL_NM, prop_dict)
import indra.utils as utils
import schelling.height as hm
(prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)
env = hm.HeightEnv(model_nm=MODEL_NM, props=pa)
for i in range(pa["num_agents"]):
env.add_agent(
hm.HeightAgentEng('Eng agent' + str(i),
START_HEIGHT, START_HEIGHT))
env.add_agent(
hm.HeightAgent('agent' + str(i), START_HEIGHT, START_HEIGHT))
return utils.run_model(env, prog_file, results_file)
def run(prop_dict=None):
# We need to create props before we import the basic model,
# as our choice of display_method is dependent on the user_type.
pa = props.PropArgs.create_props(MODEL_NM, prop_dict)
import models.basic as bm
import indra.utils as utils
(prog_file, log_file, prop_file,
results_file) = utils.gen_file_names(MODEL_NM)
# test prop_args as an iterable:
for prop, val in pa.items():
print(prop + ": " + str(val))
# test that props work as a dictionary:
if "num_agents" in pa:
print("In is working!")
# test what pa["num_agents"] is:
num_agents = pa["num_agents"]
print("num_agents = " + str(num_agents))
# make sure we can get props length:
print("Props length = " + str(len(pa)))
def run(prop_dict=None):
(prog_file, log_file,
prop_file, results_file) = utils.gen_file_names(MODEL_NM)
global pa
env = cm.CoopEnv(model_nm=MODEL_NM, props=pa)
for i in range(pa["num_agents"]):
env.add_agent(
cm.CoopAgent('agent' + str(i), 5, 0))
return utils.run_model(env, prog_file, results_file)
#!/usr/bin/env python3
"""
A fashion model with hipsters and followers.
"""
import indra.utils as utils
import indra.prop_args as props
import fashion2_model as fm
# set up some file names:
MODEL_NM = "fashion2_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)
pa.set("model", MODEL_NM)
pa.set("num_followers", 48)
pa.set("num_hipsters", 16)
pa.set("grid_width", 16)
pa.set("grid_height", 16)
pa.ask("fmax_move", "What is the follower's max move?", int)
pa.ask("hmax_move", "What is the hipster's max move?", int)
pa.ask("min_adv_periods", "What are the minimum adverse periods?", int)