Chapter 4. Writing breve Simulations with "steve" or Python
<< previous |  | next >>

## Chapter 4. Writing breve Simulations with "steve" or Python

As of breve release 2.6, breve offers two choices of scripting languages for writing simulations:the section called “Writing breve Simulations With "steve"” and the section called “Writing breve Simulations With Python”. Python support in breve is new, and is therefore not expected to be as robust as the "steve" frontend. However, in the long run, Python will be the recommended language frontend for all new breve development. The "steve" language is still supported, but will not have any new development.

For the time being, the following considerations may be useful when deciding which frontend language to use:

Advantages of steve:

- Somewhat faster than Python for many tasks

- Has been part of breve since the first release and is generally stable and well-integrated.

- Supports breve object archiving and networking, a feature which has not yet been integrated into Python.

- Full support for all breve classes and demos.

- The primary language used in this documentation.

Advantages of Python:

- Huge amounts of existing code and modules that can be integrated into simulations

- Generally speaking a far more powerful language for developing and integrating new functionality

- A popular and well-used open-source language with applications far beyond breve.

## Overview to breve's Simulation Structure: For All Frontend Languages

This section discusses the conceptual structure of a breve simulation, which are common to both steve and Python language simulations. Familiarize yourself with the concepts in this section before proceeding, regardless of which frontend language you intend to use.

breve is an agent based modelling environment in which the behaviors of agents are simulated at each time-step. In order to write a simulation in breve, you must define these agents in terms of how they behave and how they interact. These behaviors are updated at each time-step such that the agents are continuously reacting to their environment. In addition to behaviors at each time-step, behaviors can be specified to correspond to other events as well. The most notably of these other events is object initialization—each agent has a set of behaviors that are executed when the agent is created.

Writing simulations in breve is thus nothing more than specifying the behavior of agents—there is no code written that does not correspond to an agent. In order to specify agent behaviors, breve uses object-oriented languages, either the breve-specific steve language, or the popular (and externally developed) scripting language Python. In either case, you'll create an object type corresponding to each agent in the world, and you'll implement specific methods to specify the behaviors of these agents.

As mentioned above, the behavior of agents is specified based on certain events. The "init" event happens when the object is created, and the "iterate" event happens at each time-step. In terms of the object oriented language frontends, these behaviors are specified by creating methods called "init" and "iterate" for the agent classes.

The program logic of a single agent.

The image above illustrates the program logic of a single agent. The agent is first initialized via its init method (__init__ in Python). Then at each time-step, the agent uses its iterate method to perform a series of tasks: obtain information about the world via sensors, perform computation on the information, and finally change its behavior or state based on the computed information. The only way to make agents with custom behaviors is to subclass an existing agent class. breve includes built-in classes, such as Mobile and Stationary, which serve as agent templates for more sophisticated agent behaviors. To implement a more sophisticated agent behavior, create a subclass of one of breve's built-in classes and override the init and iterate methods to behave however you want them to.

<< previous |  | next >>
Upgrading Simulations From Versions of breve Prior to 2.0 | Table of Contents | Writing breve Simulations With Python