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.
+--------------------------+
| +--------------------------+ |
| |
| |
+---------------------------------+ +-------------------------+
+---------------------------------+ +-------------------------+
^ ^
| |
+------------------------------+ +-----------------------------+
+------------------------------+ +-----------------------------+
Definition: spatial_model.h:90
Definition: spatial_model.h:234
- Implementing a regular Agent
UserAgent
will produce the following hierarchy. In this case, AgentInterface=api::model::Agent
. +--------------------------+
+--------------------------+
^
|
+---------------------------------------------------------+
+---------------------------------------------------------+
^
|
+-----------+
| UserAgent |
+-----------+
detail::AgentBase< api::model::Agent, AgentType, TypeIdBase > AgentBase
Definition: model.h:1152
- Implementing a GridAgent UserAgent produces the following hierarchy. In this case,
AgentInterface=api::model::GridAgent
. +--------------------------+
+--------------------------+
^
|
+---------------------------------+
+---------------------------------+
^
|
+------------------------------+
+------------------------------+
^
|
+-------------------------------------------------------------+
+-------------------------------------------------------------+
^
|
+-------------------------------------------------------------------+
+-------------------------------------------------------------------+
^
|
+------------------------------+
+------------------------------+
^
|
+-----------+
| UserAgent |
+-----------+
Definition: spatial_model.h:756
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
-
AgentInterface | api implemented by this AgentBase |
AgentType | final Agent type, that must inherit from the current AgentBase. |
TypeIdBase | type used to define the type id of the current AgentBase implementation. |
template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
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
template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
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
template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
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
template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
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.
template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
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
-
gid | group ID |
pos | list iterator that references the current Agent within the group associated to gid |
template<typename AgentInterface , typename AgentType , typename TypeIdBase = AgentType>
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
-