Python + breve Example: a basic simulation
Here's a simple skeleton of how to write a simulation in breve using Python.
This simulation defines two objects: the controller, and an agent. The controller is a required object, and it must be a subclass of Control. It is what is responsible for initializing the simulation. The agent we create here does nothing, but in a normal simulation, we would create multiple agents and specify their behaviors in the "iterate" method.
import breve
class myController( breve.Control ):
def __init__( self ):
breve.Control.__init__( self )
self.agent = myAgent()
print '''simulation started'''
def iterate( self ):
breve.Control.iterate( self )
class myAgent( breve.Mobile ):
def __init__( self ):
breve.Mobile.__init__( self )
print '''created agent'''
def iterate( self ):
# make the agent do something interesting her
breve.Control.iterate( self )
# instantiate the controller to initialize the simulation
myController()
