My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
BuiltIn14  
Built-in items(Modeling Guide)
Updated Dec 2, 2011 by benoit.g...@gmail.com



Introduction

Species, when declared in a model, inherit some of their attributes (variables, actions) from the Java class that back them behind the scene. For "regular" agents, the number of these attributes is voluntarily limited. In a sense, that class acts exactly like a basic skill, and gives the agents a (very) limited number of common capabilities. However, some agents in the model are based on more specialized Java classes: this is the case of the world, which provides some critical global knowledge and functions to the modeller and the agents. In this section, we start by examining the built-in variables and actions common to all the agents. We then describe the global ones defined on the world.

name

string. Each agent has a default name (concatenation of its species name and unique index), which can be changed at will to something more useful for the modeler (if needed).

Note

other "built-in" read-only attributes can be accessed through special operators:
  • species or species_of, which return the species of the agent,
  • int, which returns its index;

or keywords:

  • self and myself, which return the agent itself.

Built-in actions

Three built-in actions are provided to the agents.

write

makes the agent output an arbitrary message in the console. → message: string, mandatory, the message to display. Modelers can add some formatting characters to the message (carriage returns, tabs, or Unicode characters), which will be used accordingly in the console.
do action: write {
     arg message value: 'This is a message from ' + self;
}

debug

makes the agent output an arbitrary message in the console. The message is automatically prefixed with the cycle of the simulation and followed by a carriage return and postfixed with information concerning the agent that called this action. → message: string, mandatory, the message to display.
do action: debug {
     arg message value: 'This is a message from ' + self;
}

error

makes the agent output an error dialog (if the simulation contains a user interface). Otherwise displays the error in the console. → message: string, mandatory, the message to display.
do action: error {
     arg message value: 'This is an error raised by ' + self;
}

tell

makes the agent output a dialog (if the simulation contains a user interface). The simulation goes on, but its interface is not accessible until the dialog is closed (use with caution, as it may prevent the user from accessing the interface). → message: string, mandatory, the message to display.
do action: tell {
     arg message value: 'This is a message dialog raised by ' + self;
}

Global built-in variables

Global variables can be accessed by the world and every other agent in the model.

time

int, read-only, represents the current simulated time in seconds (the default unit). Begins at zero. Although time is a read-only variable, it is possible to control its maximum value by redeclaring it. When the maximum is reached during a simulation, this simulation is automatically stopped.
global {
...
    var time type: int max: 1000;
...
}

step

int, represents the time step between two executions of the set of agents, in seconds. Its default value is 1. Each turn, the value of time is incremented by the value of step. The definition of step must be coherent with that of the agents' variables like speed.
global {
...
    var step type: int max: 10;
...
}

seed

float, represents the seed used in the computation of random numbers. Keeping the same seed between two runs of the same model ensures that the sequence of events will remain the same, which can be useful when debugging a model. Declaring it as a parameter allows the user or an external process (batch, for instance) to modify it.
global {
...
     var seed type: int value: 354 parameter: true;
...
}

agents

list, read-only, returns a list of all the agents of the model that are considered as "active" (i.e. all the agents with behaviors, excluding the places). Note that obtaining this list can be quite time consuming, as the world has to go through all the species and get their agents before assembling the result. For instance, instead of writing something like:
ask target: agents of_species my_species {
...
}

one would prefer to write (which is much faster):

ask target: list (my_species) {
...
}

Global built-in actions

halt

stops the simulation.
global {
     ...
     reflex when: length (agents) <= 0 {
            do action: halt;
     }
}

pause

pauses the simulation, which can then be continued by the user.
global {
     ...
     reflex when: time = 100 {
            do action: pause;
     }
}

Sign in to add a comment
Powered by Google Project Hosting