Here we are not going to look at any actual model of anything, but rather at the basic capabilities the Indra system provides to any modeling effort. The system consists of a heirarchy of classes that give the modeler a suite of capabilities useful in any agent-based model. To demonstrate the system and to give people new to it basic files to clone and begin work from, Indra includes two scripts that run a simple agent system: basic_model.py basic_run.py
All of our models follow this convention: one file implements the model (X_model.py), and another controls the parameters to the model and runs it (X_run.py). Let's have a look at basic_run.py and see what is in it. The comments are fairly complete as to what is going on, we hope!
In [2]:
!cat basic_run.py
OK, let us run the system and see what it does:
In [3]:
run basic_run.py
The first thing to notice in this aborted run is that the modeler gets an entire menuing system "for free": this is inherited from the base environment class. This menu is a simple text-based one, but it is organized to that it can be implemented in a GUI. Next, we look at what happens when we "step" through the simulation:
In [4]:
run basic_run.py
The basic environment operation is to loop through the contained agents and call each agent's act() function. In this case, the agents just announce their name and goal. One item to note: the agents appear in random order each time through the loop. This is built into the basic environment in an efficient fashion, as usually we don't want the fact an agent happens to be first in a list to affect the outcome. Of course, because this is an object-oriented system, this behavior can be over-ridden.
Let us look at a couple of other things the base environment automatically provides the modeler. For one thing, we can examine the state of any agent, and change its field values:
In [2]:
run basic_run.py
While the program is running, we have changed the name of agent0 to Eugene. Obviously, that change is trivial, but the modeler could, instead, do something like change the utility function of a trader or the ethnic preferences of an agent in a segregation model. Now, let us add an agent on the fly: we will add an agent of a new type: Gozer. If you remember Ghostbusters, that would be Gozer the Destructor. Let's see what Gozer does.
In [3]:
run basic_run.py
Gozer has entered the environment and turn by turn destroyed all of the other agents. Other capabilities already provided in our basic framework are listing all agents, examining log files, write properties (parameter sets) to disk, and launching the Python debugger.
In [ ]: