First we import all necessary files.
In [ ]:
from indra.agent import Agent
from indra.agent import prob_state_trans
from indra.composite import Composite
from indra.display_methods import RED, GREEN, BLACK
from indra.display_methods import SPRINGGREEN, TOMATO, TREE
from indra.env import Env
from indra.registry import get_env, get_prop
from indra.utils import init_props
from models.forestfire import set_up
We then initialize global variables.
In [ ]:
MODEL_NAME = "forestfire"
DEBUG = False # turns debugging code on or off
DEBUG2 = False # turns deeper debugging code on or off
NEARBY = 1.8
DEF_DIM = 30
DEF_DENSITY = .44
TREE_PREFIX = "Tree"
# tree condition strings
HEALTHY = "Healthy"
NEW_FIRE = "New Fire"
ON_FIRE = "On Fire"
BURNED_OUT = "Burned Out"
NEW_GROWTH = "New Growth"
# state numbers
HE = 0
NF = 1
OF = 2
BO = 3
NG = 4
NUM_STATES = 5
STATE_MAP = {HE: HEALTHY, NF: NEW_FIRE,
OF: ON_FIRE, BO: BURNED_OUT, NG: NEW_GROWTH}
STATE_TRANS = [
[.985, .015, 0.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, .99, .01],
[1.0, 0.0, 0.0, 0.0, 0.0],
]
group_map = {HE: None, NF: None, OF: None, BO: None, NG: None}
Next we call the set_up function to set up the environment, groups, and agents of the model.
In [ ]:
set_up()
You can run the model N periods by typing the number you want in the following function and then running it.
In [ ]:
Env("Forest", height=forest_height, width=forest_width, members=groups)
.runN()
You can view the position of all of the agents in space with the following command:
In [ ]:
Env("Forest", height=forest_height, width=forest_width, members=groups)
.scatter_graph()
You can view the line graph through the following command:
In [ ]:
Env("Forest", height=forest_height, width=forest_width, members=groups)
.line_graph()