fpmas 1.6
Public Member Functions | List of all members
fpmas::model::detail::AgentGroupBase Class Reference

#include <model.h>

Inheritance diagram for fpmas::model::detail::AgentGroupBase:
Inheritance graph
[legend]
Collaboration diagram for fpmas::model::detail::AgentGroupBase:
Collaboration graph
[legend]

Public Member Functions

 AgentGroupBase (GroupId group_id, api::model::AgentGraph &agent_graph)
 
 AgentGroupBase (const AgentGroupBase &)=delete
 
AgentGroupBaseoperator= (const AgentGroupBase &)=delete
 
 AgentGroupBase (GroupId group_id, api::model::AgentGraph &agent_graph, const api::model::Behavior &behavior)
 
GroupId groupId () const override
 
const api::model::Behaviorbehavior () override
 
void add (api::model::Agent *) override
 
void remove (api::model::Agent *) override
 
void insert (api::model::AgentPtr *) override
 
void erase (api::model::AgentPtr *) override
 
void clear () override
 
scheduler::Jobjob () override
 
const scheduler::Jobjob () const override
 
api::scheduler::JobagentExecutionJob () override
 
const api::scheduler::JobagentExecutionJob () const override
 
std::vector< api::model::Agent * > agents () const override
 
std::vector< api::model::Agent * > localAgents () const override
 
std::vector< api::model::Agent * > distantAgents () const override
 
void addEventHandler (Event event, api::utils::Callback< api::model::Agent * > *callback) override
 
void removeEventHandler (Event event, api::utils::Callback< api::model::Agent * > *callback) override
 
- Public Member Functions inherited from fpmas::api::model::AgentGroup
virtual GroupId groupId () const =0
 
virtual const Behaviorbehavior ()=0
 
virtual void add (Agent *agent)=0
 
virtual void remove (Agent *agent)=0
 
virtual void clear ()=0
 
virtual void insert (AgentPtr *agent)=0
 
virtual void erase (AgentPtr *agent)=0
 
virtual std::vector< Agent * > agents () const =0
 
virtual std::vector< Agent * > localAgents () const =0
 
virtual std::vector< Agent * > distantAgents () const =0
 
virtual api::scheduler::Jobjob ()=0
 
virtual const api::scheduler::Jobjob () const =0
 
virtual api::scheduler::JobagentExecutionJob ()=0
 
virtual const api::scheduler::JobagentExecutionJob () const =0
 
virtual api::scheduler::JobList jobs () const =0
 
virtual void addEventHandler (Event event, api::utils::Callback< Agent * > *callback)=0
 
virtual void removeEventHandler (Event event, api::utils::Callback< Agent * > *callback)=0
 

Additional Inherited Members

- Public Types inherited from fpmas::api::model::AgentGroup
enum  Event { INSERT , ERASE , ADD , REMOVE }
 

Detailed Description

api::model::AgentGroup implementation.

Constructor & Destructor Documentation

◆ AgentGroupBase() [1/3]

fpmas::model::detail::AgentGroupBase::AgentGroupBase ( GroupId  group_id,
api::model::AgentGraph agent_graph 
)

AgentGroupBase constructor.

Parameters
group_idunique id of the group
agent_graphassociated agent graph

◆ AgentGroupBase() [2/3]

fpmas::model::detail::AgentGroupBase::AgentGroupBase ( const AgentGroupBase )
delete

Deletes copy constructor.

◆ AgentGroupBase() [3/3]

fpmas::model::detail::AgentGroupBase::AgentGroupBase ( GroupId  group_id,
api::model::AgentGraph agent_graph,
const api::model::Behavior behavior 
)

AgentGroupBase constructor.

Parameters
group_idunique id of the group
agent_graphassociated agent graph
behaviorgroup behavior

Member Function Documentation

◆ operator=()

AgentGroupBase & fpmas::model::detail::AgentGroupBase::operator= ( const AgentGroupBase )
delete

Deletes copy assignment operator.

◆ groupId()

GroupId fpmas::model::detail::AgentGroupBase::groupId ( ) const
inlineoverridevirtual

Returns the ID of this group.

Returns
group id

Implements fpmas::api::model::AgentGroup.

◆ behavior()

const api::model::Behavior & fpmas::model::detail::AgentGroupBase::behavior ( )
inlineoverridevirtual

Returns the Behavior associated to this group.

Returns
group's behavior

Implements fpmas::api::model::AgentGroup.

◆ add()

void fpmas::model::detail::AgentGroupBase::add ( api::model::Agent agent)
overridevirtual

Adds a new Agent to this group.

AgentGroups to which an agent is added take ownership of the agent, that must be dynamically allocated (using a new statement). The agent lives while it belongs to at least one group, and is deleted when it is removed from the last group.

add() builds a new AgentNode into the current AgentGraph and associates it to the Agent if the agent was not contained in any group yet.

This group's groupId() is added to agents Agent::groupIds().

A task is also bound to the agent and Agent::groups() is updated as defined in insert().

Moreover, if the agent is LOCAL, the previous task is added to agentExecutionJob().

In consequence, it is possible to dynamically add() LOCAL agents to groups.

Notice that when the agent is not bound to a node yet, i.e. this is the first group the agent is inserted into so that a new node is built, the agent automatically becomes LOCAL, since the new node is built locally.

If a DISTANT agent is added to the group, it is just inserted in the group. However, this is a mechanic that must be used only internally, since adding a DISTANT agent to the group is not guaranteed to report the operation on other processes.

Parameters
agentagent to add

Implements fpmas::api::model::AgentGroup.

◆ remove()

void fpmas::model::detail::AgentGroupBase::remove ( api::model::Agent agent)
overridevirtual

Removes an Agent from this group.

If this was the last group containing the Agent, it is completely removed from the simulation, so the associated AgentNode is also globally removed from the AgentGraph.

Else, the agent is simply removed from this group as defined in erase().

If the agent is LOCAL, the task associated to this group's behavior() is removed from agentExecutionJob().

Parameters
agentagent to remove

Implements fpmas::api::model::AgentGroup.

◆ insert()

void fpmas::model::detail::AgentGroupBase::insert ( api::model::AgentPtr agent)
overridevirtual

Inserts an Agent into this AgentGroup.

This function is only used during the node migration process, and is not supposed to be used by the final user.

Contrary to add(), this method assumes that an AgentNode has already been built for the Agent.

When this method is called, it is assumed that agent's Agent::groupIds() list already contains this groupId(), so the agent should be inserted in the group.

Upon return, agent's Agent::groups() must be updated, and a task that execute behavior() on this agent must be bound to the agent. The corresponding task is then accessible from Agent::task(GroupId) and Agent::tasks().

Parameters
agentagent to insert into this group

Implements fpmas::api::model::AgentGroup.

◆ erase()

void fpmas::model::detail::AgentGroupBase::erase ( api::model::AgentPtr agent)
overridevirtual

Erases an Agent from this AgentGroup.

This function is only used during the node migration process, and is not supposed to be used by the final user.

Contrary to remove(), this method does not globally removes the Agent (and its associated AgentNode) from the simulation.

Upon return, agent's Agent::groupIds() and Agent::groups() must be updated, and the task previously bound to the agent by insert() must be unbound.

Parameters
agentagent to erase from this group

Implements fpmas::api::model::AgentGroup.

◆ clear()

void fpmas::model::detail::AgentGroupBase::clear ( )
overridevirtual

Removes all local agents from this group.

Implements fpmas::api::model::AgentGroup.

◆ job() [1/2]

scheduler::Job & fpmas::model::detail::AgentGroupBase::job ( )
inlineoverridevirtual

Returns a reference to the Job associated to this AgentGroup.

This Job contains all the AgentTasks associated to all Agents in this group.

This Job can be scheduled to define when this AgentGroup must be executed.

Example
// Schedules agent_group to be executed from iteration 10 with a
// period of 2
scheduler.schedule(10, 2, agent_group.job());

See the complete api::scheduler::Scheduler interface for more scheduling options.

This method as been deprecated and will be removed in a next release. Use agentExecutionJob() or jobs() instead, depending on use case.

Implements fpmas::api::model::AgentGroup.

◆ job() [2/2]

const scheduler::Job & fpmas::model::detail::AgentGroupBase::job ( ) const
inlineoverridevirtual

Returns a reference to the Job associated to this AgentGroup.

This Job contains all the AgentTasks associated to all Agents in this group.

This Job can be scheduled to define when this AgentGroup must be executed.

Example
// Schedules agent_group to be executed from iteration 10 with a
// period of 2
scheduler.schedule(10, 2, agent_group.job());

See the complete api::scheduler::Scheduler interface for more scheduling options.

This method as been deprecated and will be removed in a next release. Use agentExecutionJob() or jobs() instead, depending on use case.

Implements fpmas::api::model::AgentGroup.

◆ agentExecutionJob() [1/2]

api::scheduler::Job & fpmas::model::detail::AgentGroupBase::agentExecutionJob ( )
inlineoverridevirtual

Returns a reference to the internal Job specifically used to execute behavior() on the agents() of the group.

Any necessary graph synchronization is included at the end of the Job, after all agents execution.

However this job is not intended to be scheduled directly: use jobs() instead.

Returns
agent execution job
See also
jobs()

Implements fpmas::api::model::AgentGroup.

◆ agentExecutionJob() [2/2]

const api::scheduler::Job & fpmas::model::detail::AgentGroupBase::agentExecutionJob ( ) const
inlineoverridevirtual

Returns a reference to the internal Job specifically used to execute behavior() on the agents() of the group.

Any necessary graph synchronization is included at the end of the Job, after all agents execution.

However this job is not intended to be scheduled directly: use jobs() instead.

Returns
agent execution job
See also
jobs()

Implements fpmas::api::model::AgentGroup.

◆ agents()

std::vector< api::model::Agent * > fpmas::model::detail::AgentGroupBase::agents ( ) const
overridevirtual

Returns the list of all Agents currently in this AgentGroup, including DISTANT representations of Agents not executed on the current process.

The returned list is invalidated by the following operations:

Returns
Agents in this group

Implements fpmas::api::model::AgentGroup.

◆ localAgents()

std::vector< api::model::Agent * > fpmas::model::detail::AgentGroupBase::localAgents ( ) const
overridevirtual

Returns the list of LOCAL Agents currently in this AgentGroup, that are executed on the current process.

The returned list is invalidated by the following operations:

Returns
LOCAL Agents in this group

Implements fpmas::api::model::AgentGroup.

◆ distantAgents()

std::vector< api::model::Agent * > fpmas::model::detail::AgentGroupBase::distantAgents ( ) const
overridevirtual

Returns the list of DISTANT Agents currently in this AgentGroup, represented to preserve LOCAL agents neighbors but not executed on this process.

The process on which a DISTANT agent is executed can be retrieved with agent->node()->location().

The returned list is invalidated by the following operations:

Returns
DISTANT Agents in this group

Implements fpmas::api::model::AgentGroup.

◆ addEventHandler()

void fpmas::model::detail::AgentGroupBase::addEventHandler ( Event  event,
api::utils::Callback< api::model::Agent * > *  callback 
)
overridevirtual

Registers a callback function to be called when the specified Event is emitted.

Parameters
eventevent that triggers the callback
callbackcallback called when the event occurs

Implements fpmas::api::model::AgentGroup.

◆ removeEventHandler()

void fpmas::model::detail::AgentGroupBase::removeEventHandler ( Event  event,
api::utils::Callback< api::model::Agent * > *  callback 
)
overridevirtual

Unregisters a callback function previously registered for the spespecified event.

The behavior is undefined if the callback was not previously registered using addEventHandler().

Parameters
eventevent that triggers the callback
callbackcallback called when the event occurs

Implements fpmas::api::model::AgentGroup.


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