Download FLAME User Manual

Transcript
3
Model Implementation
The implementations of each agent’s functions are currently written in separate files written
in C, suffixed with ‘.c’. Each file must include two header files, one for the overall framework
and one for the particular agent that the functions are for. Functions for different agents
cannot be contained in the same file. Thus, at the top of each file two headers are required:
#include "header.h"
#include "<agentname>_agent_header.h"
Where ‘<agent_name>’ is replaced with the actual agent name. Agent functions can
then be written in the following style:
/*
* \fn: int function_name()
* \brief: A brief description of the function.
*/
int function_name()
{
/* Function code here */
return 0; /* Returning zero means the agent is not removed */
}
The first commented part (four lines) is good practice and can be used to auto-generate
source code documentation. The function name should coordinate with the agent function
name and the function should return an integer. The functions have no parameters. Returning zero means the agent is not removed from the simulation, and returning the number
one removes the agent immediately from the simulation. Agents of type ‘agentname’ are
added to a simulation by:
add_agentname_agent(var1, .. varN);
New agents are only added at the start of the next iteration. This is because new agents
start in their start state and are only picked up by the simulation engine when all other
agents are also in their start states.
3.1
Accessing Agent Memory Variables
After including the specific agent header, the variables in the agent memory can be accessed
by capitalising the variable name:
AGENT_VARIABLE
To access elements of a static array use square brackets and the index number:
14