fpmas 1.6
Public Types | Public Member Functions | Protected Member Functions | List of all members
fpmas::model::SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, Derived > Class Template Reference

#include <spatial_model.h>

Inheritance diagram for fpmas::model::SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, Derived >:
Inheritance graph
[legend]
Collaboration diagram for fpmas::model::SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, Derived >:
Collaboration graph
[legend]

Public Types

typedef SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, Derived > JsonBase
 
- Public Types inherited from fpmas::model::detail::AgentBase< SpatialAgentInterface, AgentType, SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, AgentType > >
typedef AgentType FinalAgentType
 

Public Member Functions

void initLocation (CellType *cell) override
 
DistributedId locationId () const override
 
CellType * locationCell () const override
 
- Public Member Functions inherited from fpmas::model::detail::AgentBase< SpatialAgentInterface, AgentType, SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, AgentType > >
 AgentBase ()=default
 
 AgentBase (const AgentBase &agent)=default
 
 AgentBase (AgentBase &&)=default
 
AgentBaseoperator= (const AgentBase &agent)=default
 
AgentBaseoperator= (AgentBase &&)
 
GroupId groupId () const override
 
std::vector< GroupId > groupIds () const override
 
void setGroupId (api::model::GroupId id) override
 
void addGroupId (api::model::GroupId id) override
 
void removeGroupId (api::model::GroupId id) override
 
api::model::AgentGroupgroup () override
 
const api::model::AgentGroupgroup () const override
 
std::vector< const api::model::AgentGroup * > groups () const override
 
std::vector< api::model::AgentGroup * > groups () override
 
void setGroup (api::model::AgentGroup *group) override
 
void addGroup (api::model::AgentGroup *group) override
 
void removeGroup (api::model::AgentGroup *group) override
 
void setGroupPos (api::model::GroupId gid, std::list< api::model::Agent * >::iterator pos) override
 
std::list< api::model::Agent * >::iterator getGroupPos (api::model::GroupId gid) const override
 
api::model::TypeId typeId () const override
 
api::model::Agentcopy () const override
 
void copyAssign (api::model::Agent *agent) override
 
void moveAssign (api::model::Agent *agent) override
 
api::model::AgentNodenode () override
 
const api::model::AgentNodenode () const override
 
void setNode (api::model::AgentNode *node) override
 
api::model::Modelmodel () override
 
const api::model::Modelmodel () const override
 
void setModel (api::model::Model *model) override
 
api::model::AgentTasktask () override
 
const api::model::AgentTasktask () const override
 
api::model::AgentTasktask (api::model::GroupId id) override
 
const api::model::AgentTasktask (api::model::GroupId id) const override
 
void setTask (api::model::AgentTask *task) override
 
void setTask (api::model::GroupId id, api::model::AgentTask *task) override
 
const std::unordered_map< api::model::GroupId, api::model::AgentTask * > & tasks () override
 
virtual void act () override
 
Neighbors< NeighborAgentType > outNeighbors () const
 
Neighbors< NeighborAgentType > outNeighbors (api::graph::LayerId layer) const
 
Neighbors< NeighborAgentType > inNeighbors () const
 
Neighbors< NeighborAgentType > inNeighbors (api::graph::LayerId layer) const
 

Protected Member Functions

void updateLocation (CellType *cell)
 
void handleNewMove () override
 
void handleNewPerceive () override
 
void moveTo (DistributedId id) override
 
Neighbors< CellType > mobilityField () const
 
template<typename NeighborType = api::model::Agent>
Neighbors< NeighborType > perceptions () const
 

Additional Inherited Members

- Static Public Attributes inherited from fpmas::model::detail::AgentBase< SpatialAgentInterface, AgentType, SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, AgentType > >
static const api::model::TypeId TYPE_ID
 

Detailed Description

template<typename SpatialAgentInterface, typename AgentType, typename CellType, typename Derived = AgentType>
class fpmas::model::SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, Derived >

api::model::SpatialAgent API implementation.

The SpatialAgentInterface template parameter specifies the API actually implemented by this class. It can be api::model::SpatialAgent, or any other api that extends the api::model::SpatialAgent interface.

See fpmas::model::detail::AgentBase for more details about the implementation scheme.

This is a partial implementation, that does not implement moveTo(CellType*).

Template Parameters
SpatialAgentInterfaceSpatialAgent interface implemented by this SpatialAgentBase
AgentTypefinal SpatialAgentBase type (i.e. most derived class from this SpatialAgentBase)
CellTypetype of cells on which the agent moves
Deriveddirect derived class, or at least the next class in the serialization chain
See also
SpatialAgent
GridAgent

Member Typedef Documentation

◆ JsonBase

template<typename SpatialAgentInterface , typename AgentType , typename CellType , typename Derived = AgentType>
typedef SpatialAgentBase<SpatialAgentInterface, AgentType, CellType, Derived> fpmas::model::SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, Derived >::JsonBase

The type that must be used in FPMAS_REGISTER_AGENT_TYPES and FPMAS_JSON_SET_UP to enable json serialization of AgentType, which is the dynamic type of any SpatialAgentBase<AgentType, CellType, Derived>.

Example
class UserAgent : public fpmas::model::GridAgent<UserAgent> {
...
};
// alternatively, custom json serialization rules might be
// defined
...
FPMAS_JSON_SET_UP(..., UserAgent::JsonBase, ...)
int main(int argc, char** argv) {
FPMAS_REGISTER_AGENT_TYPES(..., UserAgent::JsonBase, ...)
...
}
Definition: grid.h:121
#define FPMAS_DEFAULT_JSON(AGENT)
Definition: json_serializer.h:127
#define FPMAS_REGISTER_AGENT_TYPES(...)
Definition: serializer.h:214

Member Function Documentation

◆ updateLocation()

template<typename SpatialAgentInterface , typename AgentType , typename CellType , typename Derived >
void fpmas::model::SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, Derived >::updateLocation ( CellType *  cell)
protected

Updates this SpatialAgent location.

  1. Links this agent to cell on the NEW_LOCATION layer.
  2. Unlinks links on LOCATION, MOVE and PERCEPTION layers.
  3. Updates the current locationId() with the cells node id.

This function is likely to be used by moveTo(CellType*) implementation, that is not implemented by this base.

Parameters
cellcell to which this agent should move

◆ handleNewMove()

template<typename SpatialAgentInterface , typename AgentType , typename CellType , typename Derived >
void fpmas::model::SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, Derived >::handleNewMove
overrideprotected

Handles links on the NEW_MOVE layer.

Crops the current mobility field according to the current mobility range of the agent.

For each outgoing edge on the NEW_MOVE layer:

  • if agent->mobilityRange().contains(agent->locationCell(), edge->getTargetNode()), edge is replaced by an edge on the MOVE layer.
  • else, the edge is just unlinked.

◆ handleNewPerceive()

template<typename SpatialAgentInterface , typename AgentType , typename CellType , typename Derived >
void fpmas::model::SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, Derived >::handleNewPerceive
overrideprotected

Handles links on the NEW_PERCEIVE layer.

Crops the current perception field according to the current perception range of the agent.

For each outgoing edge on the NEW_PERCEIVE layer:

  • if agent->perceptionRange().contains(agent->locationCell(), edge->getTargetNode()), edge is replaced by an edge on the PERCEIVE layer.
  • else, the edge is just unlinked.

◆ moveTo()

template<typename SpatialAgentInterface , typename AgentType , typename CellType , typename Derived >
void fpmas::model::SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, Derived >::moveTo ( DistributedId  id)
overrideprotected

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

◆ mobilityField()

template<typename SpatialAgentInterface , typename AgentType , typename CellType , typename Derived = AgentType>
Neighbors< CellType > fpmas::model::SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, Derived >::mobilityField ( ) const
inlineprotected

Returns Cells currently contained in the agent's mobility field.

Returns
mobility field

◆ perceptions()

template<typename SpatialAgentInterface , typename AgentType , typename CellType , typename Derived = AgentType>
template<typename NeighborType = api::model::Agent>
Neighbors< NeighborType > fpmas::model::SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, Derived >::perceptions ( ) const
inlineprotected

Returns Agents currently perceived by this agent.

Only agents of type NeighborType are selected: other are ignored and not returned by this method.

Template Parameters
NeighborTypetype of perceived agents to return
Returns
list of perceived Agents of type NeighborType

◆ initLocation()

template<typename SpatialAgentInterface , typename AgentType , typename CellType , typename Derived = AgentType>
void fpmas::model::SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, Derived >::initLocation ( CellType *  cell)
inlineoverride

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

◆ locationId()

template<typename SpatialAgentInterface , typename AgentType , typename CellType , typename Derived = AgentType>
DistributedId fpmas::model::SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, Derived >::locationId ( ) const
inlineoverride

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

◆ locationCell()

template<typename SpatialAgentInterface , typename AgentType , typename CellType , typename Derived >
CellType * fpmas::model::SpatialAgentBase< SpatialAgentInterface, AgentType, CellType, Derived >::locationCell
override

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

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