fpmas 1.6
Public Types | Public Member Functions | Static Public Attributes | List of all members
fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase > Class Template Reference

#include <model.h>

Inheritance diagram for fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >:
Inheritance graph
[legend]
Collaboration diagram for fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >:
Collaboration graph
[legend]

Public Types

typedef AgentType FinalAgentType
 

Public Member Functions

 AgentBase ()=default
 
 AgentBase (const AgentBase &agent)=default
 
AgentBaseoperator= (const AgentBase &agent)=default
 
 AgentBase (AgentBase &&)=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
 
std::vector< const api::model::AgentGroup * > groups () const override
 
const api::model::AgentGroupgroup () 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
 
void setTask (api::model::AgentTask *task) override
 
api::model::AgentTasktask (api::model::GroupId id) override
 
const api::model::AgentTasktask (api::model::GroupId id) const 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
 
template<typename NeighborAgentType >
Neighbors< NeighborAgentType > outNeighbors () const
 
template<typename NeighborAgentType >
Neighbors< NeighborAgentType > outNeighbors (api::graph::LayerId layer) const
 
template<typename NeighborAgentType >
Neighbors< NeighborAgentType > inNeighbors () const
 
template<typename NeighborAgentType >
Neighbors< NeighborAgentType > inNeighbors (api::graph::LayerId layer) const
 

Static Public Attributes

static const api::model::TypeId TYPE_ID = typeid(TypeIdBase)
 

Detailed Description

template<typename AgentInterface, typename AgentType, typename TypeIdBase = AgentType>
class fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >

Base implementation of the Agent API.

Users can use this class to easily define their own Agents with custom behaviors.

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

+--------------------------+
---------->| fpmas::api::model::Agent |<--------
| +--------------------------+ |
| |
| |
+---------------------------------+ +-------------------------+
+---------------------------------+ +-------------------------+
^ ^
| |
+------------------------------+ +-----------------------------+
+------------------------------+ +-----------------------------+
Definition: model.h:174
Definition: spatial_model.h:90
Definition: grid.h:147
Definition: grid.h:78
Definition: spatial_model.h:234

In previous FPMAS versions, various Agent implementations was based on diamond inheritance and virtual base classes. However, such design revealed extremely costly in terms of dynamic_cast (downcasts using static_cast is not allowed with virtual bases). The new templated AgentInterface design produces vertical hierarchies that are much more efficient in case of dynamic_cast, and allow static_cast.

Template Parameters
AgentInterfaceapi implemented by this AgentBase
AgentTypefinal Agent type, that must inherit from the current AgentBase.
TypeIdBasetype used to define the type id of the current AgentBase implementation.

Member Typedef Documentation

◆ FinalAgentType

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
typedef AgentType fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::FinalAgentType

Type of the concrete, most derived Agent type that extends this AgentBase.

This type is the type actually instantiated and stored in a DistributedNode for example.

Constructor & Destructor Documentation

◆ AgentBase() [1/3]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::AgentBase ( )
default

Auto generated default constructor.

◆ AgentBase() [2/3]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::AgentBase ( const AgentBase< AgentInterface, AgentType, TypeIdBase > &  agent)
default

Auto generated copy constructor.

If AgentType does not define any custom copy constructor , the AgentType copy constructor copies all AgentType members and all base classes (including this AgentBase) members using their copy constructors.

If a custom AgentType copy constructor is defined, this AgentBase copy constructor must be called explictly to ensure required members are properly copied.

See also
https://en.cppreference.com/w/cpp/language/copy_constructor

◆ AgentBase() [3/3]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::AgentBase ( AgentBase< AgentInterface, AgentType, TypeIdBase > &&  )
default

Auto generated move constructor.

If AgentType does not define any custom move constructor , the AgentType move constructor moves all AgentType members and all base classes (including this AgentBase) members using their move constructors.

If a custom AgentType move constructor is defined, this AgentBase move constructor must be called explictly to ensure required members are properly moved.

See also
https://en.cppreference.com/w/cpp/language/move_constructor

Member Function Documentation

◆ operator=() [1/2]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
AgentBase & fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::operator= ( const AgentBase< AgentInterface, AgentType, TypeIdBase > &  agent)
default

Auto generated copy assignment operator.

If AgentType does not define any custom copy assignment operator, the AgentType copy assignment operator copies assign all AgentType members and all base classes (including this AgentBase) members.

If a custom AgentType copy assignment operator is defined, this AgentBase copy assignment operator must be called explictly to ensure required members are properly copied.

See also
https://en.cppreference.com/w/cpp/language/copy_assignment

◆ operator=() [2/2]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
AgentBase & fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::operator= ( AgentBase< AgentInterface, AgentType, TypeIdBase > &&  )
inline

Move assignment operator.

groupIds(), groups(), getGroupPos() results, tasks(), node() and model() fields are preserved, as specified in the moveAssign() requirements, i.e. those fields are not moved from other to this.

Since the current implementation does not do anything, there is no requirement to explicitly call this move constructor if a custom AgentBase move constructor is defined.

◆ groupId()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
GroupId fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::groupId ( ) const
inlineoverride

Deprecated:
Returns the ID of the AgentGroup to which this Agent belong.

This method is deprecated and will be removed in a next release. Use groupIds() instead.

Returns
group id

◆ groupIds()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
std::vector< GroupId > fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::groupIds ( ) const
inlineoverride

Returns ids of AgentGroups to which the Agent belong.

Returns
list of group ids

◆ setGroupId()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
void fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::setGroupId ( api::model::GroupId  id)
inlineoverride

Deprecated:
Sets this Agent group ID.

This method is deprecated and will be removed in a next release. Use addGroupId() instead.

Parameters
idagent group id

◆ addGroupId()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
void fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::addGroupId ( api::model::GroupId  id)
inlineoverride

Adds id to this Agent's group ids.

Parameters
idagent group id

◆ removeGroupId()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
void fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::removeGroupId ( api::model::GroupId  id)
inlineoverride

Removes id from this Agent's group ids.

Parameters
idagent group id

◆ group() [1/2]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
api::model::AgentGroup * fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::group ( )
inlineoverride

Deprecated:
Returns a pointer to the AgentGroup to which this Agent belong.

This method is deprecated and will be removed in a next release. Use groups() instead.

Returns
pointer to agent group

◆ groups() [1/2]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
std::vector< const api::model::AgentGroup * > fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::groups ( ) const
inlineoverride

Returns a list of AgentGroups to which this Agent belong.

Returns
agent group list

◆ group() [2/2]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
const api::model::AgentGroup * fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::group ( ) const
inlineoverride

Deprecated:
Returns a pointer to the AgentGroup to which this Agent belong.

This method is deprecated and will be removed in a next release. Use groups() instead.

Returns
pointer to agent group

◆ groups() [2/2]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
std::vector< api::model::AgentGroup * > fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::groups ( )
inlineoverride

Returns a list of AgentGroups to which this Agent belong.

Returns
agent group list

◆ setGroup()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
void fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::setGroup ( api::model::AgentGroup group)
inlineoverride

Deprecated:
Sets the internal pointer of the AgentGroup to which this Agent belong.

This method is deprecated and will be removed in a next release. Use addGroup() instead.

Parameters
groupagent group

◆ addGroup()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
void fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::addGroup ( api::model::AgentGroup group)
inlineoverride

Adds group to the list of AgentGroups to which this Agent belong.

Parameters
groupagent group

◆ removeGroup()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
void fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::removeGroup ( api::model::AgentGroup group)
inlineoverride

Removes group from the list of AgentGroups to wich this Agent belong.

Morever, the entry corresponding to this group's id is removed from tasks().

Parameters
groupagent group

◆ setGroupPos()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
void fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::setGroupPos ( api::model::GroupId  gid,
std::list< api::model::Agent * >::iterator  pos 
)
inlineoverride

Sets a list position associated to the group represented by gid, that can be retrieved with getGroupPos().

There is no specific requirement about those methods, that can be used or not. However, AgentGroup implementations can take advantage of this feature to optimize Agent insertion and removal in constant time, using an std::list as an internal data structure.

Parameters
gidgroup ID
poslist iterator that references the current Agent within the group associated to gid

◆ getGroupPos()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
std::list< api::model::Agent * >::iterator fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::getGroupPos ( api::model::GroupId  gid) const
inlineoverride

Retrieves a list position that was previously stored using setGroupPos().

Parameters
gidgroup ID
Returns
list iterator that references the current Agent within the group associated to gid

◆ typeId()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
api::model::TypeId fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::typeId ( ) const
inlineoverride

Returns the ID of the type of this Agent.

◆ copy()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
api::model::Agent * fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::copy ( ) const
inlineoverride

Allocates a new Agent pointer, considered as a copy of the current Agent.

Returns
pointer to a new allocated Agent, copied from this Agent

◆ copyAssign()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
void fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::copyAssign ( api::model::Agent agent)
inlineoverride

Copies the specified agent to this.

Parameters
agentagent to copy from

◆ moveAssign()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
void fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::moveAssign ( api::model::Agent agent)
inlineoverride

Moves the specified agent into this.

The specified agent is assumed to be an updated version of this agent.

In the move process, the following fields of "this" host agent keep unchanged, and so are not moved from agent to this :

Other fields are moved according to implementation defined rules.

Parameters
agentagent to move

◆ node() [1/2]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
api::model::AgentNode * fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::node ( )
inlineoverride

Returns a pointer to the AgentNode that contains this Agent.

Returns
pointer to wrapping AgentNode

◆ node() [2/2]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
const api::model::AgentNode * fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::node ( ) const
inlineoverride

Returns a pointer to the AgentNode that contains this Agent.

Returns
pointer to wrapping AgentNode

◆ setNode()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
void fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::setNode ( api::model::AgentNode node)
inlineoverride

Sets the internal pointer of the AgentNode that contains this Agent.

Parameters
nodepointer to wrapping AgentNode

◆ model() [1/2]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
api::model::Model * fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::model ( )
inlineoverride

Returns a pointer to the Model that contains this Agent.

Returns
pointer to Model

◆ model() [2/2]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
const api::model::Model * fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::model ( ) const
inlineoverride

Returns a pointer to the Model that contains this Agent.

Returns
pointer to Model

◆ setModel()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
void fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::setModel ( api::model::Model model)
inlineoverride

Sets the internal pointer of the Model that contains this Agent.

Parameters
modelpointer to Model

◆ task() [1/4]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
api::model::AgentTask * fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::task ( )
inlineoverride

Returns a pointer to the AgentTask associated to this Agent, that is used to execute the Agent.

Returns
agent task

◆ task() [2/4]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
const api::model::AgentTask * fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::task ( ) const
inlineoverride

Returns a pointer to the AgentTask associated to this Agent, that is used to execute the Agent.

Returns
agent task

◆ setTask() [1/2]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
void fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::setTask ( api::model::AgentTask task)
inlineoverride

Sets the AgentTask associated to this Agent.

Parameters
taskagent task

◆ task() [3/4]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
api::model::AgentTask * fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::task ( api::model::GroupId  id)
inlineoverride

Returns the AgentTask associated to this Agent in the AgentGroup corresponding to id.

Behavior is undefined if the Agent does not belong to an AgentGroup with the specified id.

Parameters
idgroup id

◆ task() [4/4]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
const api::model::AgentTask * fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::task ( api::model::GroupId  id) const
inlineoverride

Returns the AgentTask associated to this Agent in the AgentGroup corresponding to id.

Behavior is undefined if the Agent does not belong to an AgentGroup with the specified id.

Parameters
idgroup id

◆ setTask() [2/2]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
void fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::setTask ( api::model::GroupId  id,
api::model::AgentTask task 
)
inlineoverride

Sets the AgentTask associated to this Agent in the AgentGroup corresponding to id.

Behavior is undefined if the Agent does not belong to an AgentGroup with the specified id.

Parameters
idgroup id
taskagent task

◆ tasks()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
const std::unordered_map< api::model::GroupId, api::model::AgentTask * > & fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::tasks ( )
inlineoverride

Returns a map containing all the tasks associated to this Agent in the AgentGroups to which it belongs.

Exactly one task is associated to the agent in each group.

Returns
tasks associated to this agent

◆ act()

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
virtual void fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::act ( )
inlineoverridevirtual

By default, no behavior is associated to act().

Implemented Agents can override the act() method to implement a default behavior.

◆ outNeighbors() [1/2]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
template<typename NeighborAgentType >
Neighbors< NeighborAgentType > fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::outNeighbors ( ) const
inline

Returns a typed list of agents that are out neighbors of the current agent.

Agents are added to the list if and only if :

  1. they are contained in a node that is an out neighbor of this agent's node
  2. they can be cast to NeighborAgentType
Returns
out neighbor agents
See also
api::graph::Node::outNeighbors()

◆ outNeighbors() [2/2]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
template<typename NeighborAgentType >
Neighbors< NeighborAgentType > fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::outNeighbors ( api::graph::LayerId  layer) const
inline

Returns a typed list of agents that are out neighbors of the current agent on the given layer.

Agents are added to the list if and only if :

  1. they are contained in a node that is an out neighbor of this agent's node, connected on the specified layer
  2. they can be cast to NeighborAgentType
Returns
out neighbor agents
See also
api::graph::Node::outNeighbors()

◆ inNeighbors() [1/2]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
template<typename NeighborAgentType >
Neighbors< NeighborAgentType > fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::inNeighbors ( ) const
inline

Returns a typed list of agents that are in neighbors of the current agent.

Agents are added to the list if and only if :

  1. they are contained in a node that is an in neighbor of this agent's node
  2. they can be cast to NeighborAgentType
Returns
in neighbor agents
See also
api::graph::Node::inNeighbors()

◆ inNeighbors() [2/2]

template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
template<typename NeighborAgentType >
Neighbors< NeighborAgentType > fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::inNeighbors ( api::graph::LayerId  layer) const
inline

Returns a typed list of agents that are in neighbors of the current agent on the given layer.

Agents are added to the list if and only if :

  1. they are contained in a node that is an in neighbor of this agent's node, connected on the specified layer
  2. they can be cast to NeighborAgentType
Returns
in neighbor agents
See also
api::graph::Node::inNeighbors()

Member Data Documentation

◆ TYPE_ID

template<typename AgentInterface , typename AgentType , typename TypeIdBase >
const api::model::TypeId fpmas::model::detail::AgentBase< AgentInterface, AgentType, TypeIdBase >::TYPE_ID = typeid(TypeIdBase)
static

Agent's TypeId.

Equal to typeid(AgentType).


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