Markovian agents deployment

Error m3am_NewAgent(M3AM *model, const char *agent_label, const char *class_label, Point *coordinates, Density csi);

m3am_NewAgent creates an agent, whose name is agent_label, belonging to the class class_label in the model referenced by model; multiple agents are located in position coordinates with density csi. Parameter coordinates is assumed to be an array whose dimensions are the space dimension declared when the model is created with m3am_NewModel. csi must be a non negative value, otherwise an error code is returned. If either class_label class or message_label message are not defined an error code is returned. Two Markovian agents with the same name cannot exist in the same model; creating a Markovian agent with an already used name returns an error code.
Returned values are as in the following:

NOERRno error
EORANGEdensity value is out of range
ENOOPalready defined Markovian agent name
ENOMEMmemory allocation error
ENOCLclass name does not exist


Error m3am_AddPer(M3AM *model, const char *msg, const char *rx, const char *tx, NumStates r, NumStates c, double val);

m3am_AddPer is the main tool for setting the values of the perception functions into the model model. A perception function per message can be defined by assigning probability val to perceive a message msg by the agent rx in the state r when the agent tx transmits it leaving the state c. Message must be previously defined in the class of agent tx with m3am_NewMSG and generated with m3am_AddMsgGenProb; the state c of transmitting agent is the state r as defined in m3m_addMsgGenProb. Both transmitting and receiving agents names must be defined, val must be a correct probability value, and r and c must be valid states.
Returned values are as in the following:

NOERRno error
ENOPRnot correct probability value
ENOMAagent not found
ENOMESmessage name does not exist
EORANGEstate index out of range



It is useful to scan messages and agent classes one by one when perceptions functions are built. The following functions are provided to this purpose.

Class m3am_ClassIterator(M3AM *model);

m3am_ClassIterator returns a reference to the first agent class object in the set of agent classes defined with m3am_NewClass in the model model.


Class m3am_NextClass(Class cl);

m3am_nextClass returns a new not visited agent class from the nearest call to m3am_ClassIterator. Note that repeated call to m3am_nextClass iterates over the set of agent classes until all of them have been visited. A NULL value is returned when all the agent classes have been visited.


short m3am_ClassIs(Class cl, const char *class_label);

m3am_ClassIs evaluates to 1 if the agent class cl is named class_label, otherwise it evaluate to 0. m3am_ClassIs can be used to check the name of an agent class referenced by iterator.


short m3am_ClassIsValid(Class cl)

m3am_ClassIsValid evaluates to 1 if cl references a correct agent class, otherwise it evaluates to 0.

The following C source code visits all the agent classes defined in the model myModel, previously defined and populated with agent classes, looking for the class named “myClass”:


myModel=m3am_NewModel("My_Markovian_Agent_model", 2);
.
.
.
Class c=m3am_ClassIterator( myModel );
while( m3am_ClassIsValid( c ) ) {
if ( m3am_ClassIs( c, "myClass") )
printf( "The class agent has been found);
c = m3am_nextClass( c );
}



Message m3am_MessageIterator(M3AM *model);

m3am_MessageIterator returns a reference to the first message object in the set of messages defined with m3am_NewMessage in the model model.


Message m3am_NextMessage(Message msg);

m3am_nextMessage returns a new not visited message from the nearest call to m3am_MessageIterator. Note that repeated calls to m3am_nextMessage iterates over the set of messages until all messages have been visited. A NULL value is returned when all the messages have been visited.


int m3am_MessageIs( Message msg, const char *message_label);

m3am_MessageIs evaluates to 1 if the message msg is named message_label, otherwise it evaluate to 0. m3am_MessageIs can be used to check the name of a message referenced by iterator.


short m3am_MsgIsValid(Message msg);

m3am_MsgIsValid evaluates to 1 if msg references a correct message, otherwise it evaluates to 0.

The following C source code visits all the messages defined in the model myModel, previously populated with messages, looking for the message named “myMessage”:


myModel=m3am_NewModel("My_Markovian_Agent_model", 2);
.
.
.
Message m=m3am_MessageIterator( myModel );
while( m3am_MsgIsValid( m ) ) {
if ( m3am_MessageIs( c, "myMessage") )
printf( "The message has been found);
c = m3am_nextMessage( c );
}