fpmas 1.6
Public Types | Public Member Functions | Protected Member Functions | List of all members
fpmas::api::model::SpatialAgent< CellType > Class Template Referenceabstract

#include <spatial_model.h>

Inheritance diagram for fpmas::api::model::SpatialAgent< CellType >:
Inheritance graph
[legend]
Collaboration diagram for fpmas::api::model::SpatialAgent< CellType >:
Collaboration graph
[legend]

Public Types

typedef CellType Cell
 

Public Member Functions

virtual DistributedId locationId () const =0
 
virtual CellType * locationCell () const =0
 
virtual void initLocation (Cell *cell)=0
 
virtual const Range< CellType > & mobilityRange () const =0
 
virtual const Range< CellType > & perceptionRange () const =0
 
- Public Member Functions inherited from fpmas::api::model::Agent
virtual GroupId groupId () const =0
 
virtual std::vector< GroupIdgroupIds () const =0
 
virtual void setGroupId (GroupId id)=0
 
virtual void addGroupId (GroupId id)=0
 
virtual void removeGroupId (GroupId id)=0
 
virtual AgentGroupgroup ()=0
 
virtual const AgentGroupgroup () const =0
 
virtual std::vector< AgentGroup * > groups ()=0
 
virtual std::vector< const AgentGroup * > groups () const =0
 
virtual void setGroup (AgentGroup *group)=0
 
virtual void addGroup (AgentGroup *group)=0
 
virtual void removeGroup (AgentGroup *group)=0
 
virtual void setGroupPos (api::model::GroupId gid, std::list< Agent * >::iterator pos)=0
 
virtual std::list< Agent * >::iterator getGroupPos (api::model::GroupId gid) const =0
 
virtual TypeId typeId () const =0
 
virtual Agentcopy () const =0
 
virtual void copyAssign (Agent *agent)=0
 
virtual void moveAssign (Agent *agent)=0
 
virtual AgentNodenode ()=0
 
virtual const AgentNodenode () const =0
 
virtual void setNode (AgentNode *node)=0
 
virtual Modelmodel ()=0
 
virtual const Modelmodel () const =0
 
virtual void setModel (Model *model)=0
 
virtual AgentTasktask ()=0
 
virtual const AgentTasktask () const =0
 
virtual void setTask (AgentTask *task)=0
 
virtual AgentTasktask (GroupId id)=0
 
virtual const AgentTasktask (GroupId id) const =0
 
virtual void setTask (GroupId id, AgentTask *task)=0
 
virtual const std::unordered_map< GroupId, AgentTask * > & tasks ()=0
 
virtual void act ()=0
 
- Public Member Functions inherited from fpmas::api::model::SpatialAgentBehavior
virtual void handleNewMove ()=0
 
virtual void handleNewPerceive ()=0
 

Protected Member Functions

virtual void moveTo (DistributedId id)=0
 
virtual void moveTo (Cell *cell)=0
 

Detailed Description

template<typename CellType>
class fpmas::api::model::SpatialAgent< CellType >

SpatialAgent API.

In addition to the classical Agent properties, SpatialAgents can be located on a Cell network, move and perceive objects within it.

The mobility field of a SpatialAgent is defined as the set of outgoing neighbors of type Cell on the MOVE layer.

The perceptions of a SpatialAgent are defined as elements of the set of outgoind neighbors of type Agent on the PERCEPTION layer.

Helper functions might be defined in implementing classes to access those elements.

The specified CellType must extend Cell.

Member Typedef Documentation

◆ Cell

template<typename CellType >
typedef CellType fpmas::api::model::SpatialAgent< CellType >::Cell

Type of Cell on which the SpatialAgent is moving.

Member Function Documentation

◆ locationId()

template<typename CellType >
virtual DistributedId fpmas::api::model::SpatialAgent< CellType >::locationId ( ) const
pure virtual

Returns the id of the location Cell of this SpatialAgent.

This id can be used to easily move to the location of DISTANT perceived SpatialAgent.

For example, let's consider a SpatialAgent A, that is LOCAL. It can perceive a DISTANT agent B, located on a Cell C, that is also DISTANT. We also assume C is currently in the mobility field of A. Considering the properties of an FPMAS DistributedGraph, B is guaranteed to be represented on the current process, since it's linked to A on the PERCEPTION layer, and so does C on the MOVE layer. However, since B and C are distant, the LOCATION link from B to C is not expected to be presented on the current process, so calling B->locationCell() will produce an unexpected behavior. However, A can still move to the current location of B using the locationId() method:

A->moveTo(B->locationId());

Notice that this is valid whatever the current SynchronizationMode is. Indeed, moveTo operations are only committed at the next DistributedMoveAlgorithm execution, that includes a Graph synchronization process. So, in any case, even if B moves during its execution on an other process while A->moveTo() is executed on the current process, its new location will effectively be committed only when all SpatialAgents are synchronized, so it is still consistent to assume that, during this epoch, B is still located at B->locationId(). However, when the DistributedMoveAlgorithm will be applied, A will finally end on a different location than B.

Returns
id of the current location

Implemented in fpmas::model::SpatialAgentBase< api::model::GridAgent< model::GridCell >, AgentType, model::GridCell, GridAgent< AgentType, model::GridCell, AgentType > >, and fpmas::model::SpatialAgentBase< api::model::SpatialAgent< api::model::Cell >, AgentType, api::model::Cell, AgentType >.

◆ locationCell()

template<typename CellType >
virtual CellType * fpmas::api::model::SpatialAgent< CellType >::locationCell ( ) const
pure virtual

Returns the current location of this SpatialAgent.

The location of a SpatialAgent is defined as the target of the only outgoing edge connected to this SpatialAgent on the LOCATION layer.

Contrary to locationId(), this method produces an unexpected result when called on a DISTANT SpatialAgent.

Returns
current location

Implemented in fpmas::model::SpatialAgentBase< api::model::GridAgent< model::GridCell >, AgentType, model::GridCell, GridAgent< AgentType, model::GridCell, AgentType > >, and fpmas::model::SpatialAgentBase< api::model::SpatialAgent< api::model::Cell >, AgentType, api::model::Cell, AgentType >.

◆ initLocation()

template<typename CellType >
virtual void fpmas::api::model::SpatialAgent< CellType >::initLocation ( Cell cell)
pure virtual

Initializes the location of this SpatialAgent.

Contrary to moveTo, this method is public and does not assume that old location, mobility field and perceptions must be unlinked. If the SpatialAgent location was already defined (using initLocation() or moveTo()), the behavior of this method is undefined. However, notice that the location of the SpatialAgent can also be initialized internally using a moveTo() operation.

The DistributedMoveAlgorithm must still be applied to commit the initial location, as with regular moveTo() operations.

Parameters
cellinitial location of the SpatialAgent

Implemented in fpmas::model::SpatialAgentBase< api::model::SpatialAgent< api::model::Cell >, AgentType, api::model::Cell, AgentType >.

◆ mobilityRange()

template<typename CellType >
virtual const Range< CellType > & fpmas::api::model::SpatialAgent< CellType >::mobilityRange ( ) const
pure virtual

Returns the current mobility range of this SpatialAgent.

Returns
mobility range

◆ perceptionRange()

template<typename CellType >
virtual const Range< CellType > & fpmas::api::model::SpatialAgent< CellType >::perceptionRange ( ) const
pure virtual

Returns the current perception range of this SpatialAgent.

Returns
perception range

◆ moveTo() [1/2]

template<typename CellType >
virtual void fpmas::api::model::SpatialAgent< CellType >::moveTo ( DistributedId  id)
protectedpure virtual

Moves to the Cell with the provided id.

If the id does not correspond to any Cell in the current mobility field, an OutOfMobilityFieldException is thrown.

If a corresponding Cell is found, the move operation is performed as described in moveTo(Cell*).

Parameters
idCell id
Exceptions
OutOfMobilityFieldException

Implemented in fpmas::model::SpatialAgentBase< api::model::GridAgent< model::GridCell >, AgentType, model::GridCell, GridAgent< AgentType, model::GridCell, AgentType > >, and fpmas::model::SpatialAgentBase< api::model::SpatialAgent< api::model::Cell >, AgentType, api::model::Cell, AgentType >.

◆ moveTo() [2/2]

template<typename CellType >
virtual void fpmas::api::model::SpatialAgent< CellType >::moveTo ( Cell cell)
protectedpure virtual

Moves to the input Cell.

The input Cell is not required to be contained in the current mobility field of this SpatialAgent, what allows:

  1. To initialize the location of this SpatialAgent (since in this case, the mobility field is still empty)
  2. A SpatialAgent to move an other DISTANT SpatialAgent.

The execution of a DistributedMoveAlgorithm is required to commit the operation and update mobility fields and perceptions. However, this can be handled automatically on specific AgentGroups: see SpatialModel::buildMoveGroup().

More precisely, the current location, if defined, is unlinked, and so does the mobility field and perceptions, and a link from this SpatialAgent to cell is created on the NEW_LOCATION layer. In consequence, the behavior of locationCell() is undefined until a DistributedMoveAlgorithm is executed.

Notice that performing an other moveTo() operation before the previous is committed produces an undefined behavior.

Parameters
cellcell to which this SpatialAgent should move.

The documentation for this class was generated from the following file: