fpmas 1.6
Public Member Functions | Protected Member Functions | List of all members
fpmas::api::model::Model Class Referenceabstract

#include <model.h>

Inheritance diagram for fpmas::api::model::Model:
Inheritance graph
[legend]

Public Member Functions

virtual AgentGraphgraph ()=0
 
virtual const AgentGraphgraph () const =0
 
virtual api::scheduler::Schedulerscheduler ()=0
 
virtual const api::scheduler::Schedulerscheduler () const =0
 
virtual api::runtime::Runtimeruntime ()=0
 
virtual const api::runtime::Runtimeruntime () const =0
 
virtual const api::scheduler::JobloadBalancingJob () const =0
 
virtual AgentGroupbuildGroup (GroupId id)=0
 
virtual AgentGroupbuildGroup (GroupId id, const Behavior &behavior)=0
 
virtual void removeGroup (AgentGroup &group)=0
 
virtual AgentGroupgetGroup (GroupId id) const =0
 
virtual const std::unordered_map< GroupId, AgentGroup * > & groups () const =0
 
virtual AgentEdgelink (Agent *src_agent, Agent *tgt_agent, api::graph::LayerId layer)=0
 
virtual void unlink (AgentEdge *edge)=0
 
virtual api::communication::MpiCommunicatorgetMpiCommunicator ()=0
 
virtual const api::communication::MpiCommunicatorgetMpiCommunicator () const =0
 
virtual void clear ()=0
 

Protected Member Functions

virtual void insert (GroupId id, AgentGroup *group)=0
 

Detailed Description

Model API.

A Model defines and instantiates all the components required to run an FPMAS Multi-Agent simulation.

Member Function Documentation

◆ insert()

virtual void fpmas::api::model::Model::insert ( GroupId  id,
AgentGroup group 
)
protectedpure virtual

Inserts an AgentGroup into this model.

Parameters
idid of the group
groupagent group to insert

Implemented in fpmas::model::detail::Model.

◆ graph() [1/2]

virtual AgentGraph & fpmas::api::model::Model::graph ( )
pure virtual

Model's AgentGraph.

Returns
agent graph

Implemented in fpmas::model::detail::Model.

◆ graph() [2/2]

virtual const AgentGraph & fpmas::api::model::Model::graph ( ) const
pure virtual

Model's AgentGraph.

Returns
agent graph

Implemented in fpmas::model::detail::Model.

◆ scheduler() [1/2]

virtual api::scheduler::Scheduler & fpmas::api::model::Model::scheduler ( )
pure virtual

Model's Scheduler.

Returns
scheduler

Implemented in fpmas::model::detail::Model.

◆ scheduler() [2/2]

virtual const api::scheduler::Scheduler & fpmas::api::model::Model::scheduler ( ) const
pure virtual

Model's Scheduler.

Returns
scheduler

Implemented in fpmas::model::detail::Model.

◆ runtime() [1/2]

virtual api::runtime::Runtime & fpmas::api::model::Model::runtime ( )
pure virtual

Model's Runtime, used to execute the scheduler().

Returns
runtime

Implemented in fpmas::model::detail::Model.

◆ runtime() [2/2]

virtual const api::runtime::Runtime & fpmas::api::model::Model::runtime ( ) const
pure virtual

Model's Runtime, used to execute the scheduler().

Returns
runtime

Implemented in fpmas::model::detail::Model.

◆ loadBalancingJob()

virtual const api::scheduler::Job & fpmas::api::model::Model::loadBalancingJob ( ) const
pure virtual

A predefined LoadBalancing Job.

This Job can be scheduled to define when and at which frequency the LoadBalancing algorithm (and the graph distribution) will be performed.

Example
// Schedules the LoadBalancing algorithm to be applied every 10
// iterations.
model.scheduler().schedule(0, 10, model.loadBalancingJob());
Returns
reference to the predefined load balancing job

Implemented in fpmas::model::detail::Model.

◆ buildGroup() [1/2]

virtual AgentGroup & fpmas::api::model::Model::buildGroup ( GroupId  id)
pure virtual

Builds a new AgentGroup associated to this Model.

The user can add its own Agents to the built group, and schedule it so that Agents will be executed. More precisely, the default behavior defined by this group calls the Agent::act() method, that do nothing by default but can be overriden by the user. Other behaviors can be specified using the addGroup(GroupId, const Behavior&) method.

Notice that each AgentGroup is expected to be associated to a unique GroupId. The FPMAS_DEFINE_GROUPS() macro can be used to easily generate unique GroupIds.

Example
Assuming Agent1 and Agent2 are predefined user implemented Agents :
G_1, G_2
};
AgentGroup& group_1 = model.buildGroup(G_1);
AgentGroup& group_2 = model.buildGroup(G_2);
group_1.add(new Agent1);
group_1.add(new Agent1);
group_2.add(new Agent2);
// Different Agent types can be added
// to each group
group_2.add(new Agent1);
// Schedules Agents of group_1 to be executed each iteration
model.scheduler().schedule(0, 1, group_1.job());
// Schedules Agents of group_2 to be executed each 2 iterations
model.scheduler().schedule(0, 2, group_2.job());
Definition: model.h:547
virtual void add(Agent *agent)=0
int GroupId
Definition: model.h:78
Parameters
idunique group id

Implemented in fpmas::model::detail::Model.

◆ buildGroup() [2/2]

virtual AgentGroup & fpmas::api::model::Model::buildGroup ( GroupId  id,
const Behavior behavior 
)
pure virtual

Builds a new AgentGroup associated to this Model.

The user can add its own Agents to the built group, and schedule it so that Agents will be executed.

Jobs generated by the build AgentGroup will execute the specified behavior on agents contained in the group.

The behaviors storage duration must be greater or equal to this AgentGroup storage duration.

Each AgentGroup is expected to be associated to a unique GroupId. The FPMAS_DEFINE_GROUPS() macro can be used to easily generate unique GroupIds.

Parameters
idunique group id
behaviorbehavior to execute on agents of the group

Implemented in fpmas::model::detail::Model.

◆ removeGroup()

virtual void fpmas::api::model::Model::removeGroup ( AgentGroup group)
pure virtual

Removes the specified group from the model.

All local agents are removed from group, and the group is deleted.

Parameters
groupgroup to remove from the model

Implemented in fpmas::model::detail::Model.

◆ getGroup()

virtual AgentGroup & fpmas::api::model::Model::getGroup ( GroupId  id) const
pure virtual

Gets a reference to an AgentGroup previously created with buildGroup().

Behavior is undefined if the specified ID does not correspond to a previously built group.

Parameters
idgroup id
Returns
associated agent group

Implemented in fpmas::model::detail::Model.

◆ groups()

virtual const std::unordered_map< GroupId, AgentGroup * > & fpmas::api::model::Model::groups ( ) const
pure virtual

Returns the map of AgentGroups currently defined in the Model.

Returns
agent groups

Implemented in fpmas::model::detail::Model.

◆ link()

virtual AgentEdge * fpmas::api::model::Model::link ( Agent src_agent,
Agent tgt_agent,
api::graph::LayerId  layer 
)
pure virtual

Defines a new relation from src_agent to tgt_agent on the given layer, that can be interpreted as a relation type.

The FPMAS_DEFINE_LAYERS() macro can be used to easily generate LayerIds.

Parameters
src_agentsource agent
tgt_agenttarget agent
layerlayer id

Implemented in fpmas::model::detail::Model.

◆ unlink()

virtual void fpmas::api::model::Model::unlink ( AgentEdge edge)
pure virtual

Delete a previously defined agent relation, unlinking the corresponding edge.

Parameters
edgeedge to unlink

Implemented in fpmas::model::detail::Model.

◆ getMpiCommunicator() [1/2]

virtual api::communication::MpiCommunicator & fpmas::api::model::Model::getMpiCommunicator ( )
pure virtual

Returns the MPI communicator used by this model.

Returns
MPI communicator

Implemented in fpmas::model::detail::Model.

◆ getMpiCommunicator() [2/2]

virtual const api::communication::MpiCommunicator & fpmas::api::model::Model::getMpiCommunicator ( ) const
pure virtual

Returns the MPI communicator used by this model.

Returns
MPI communicator

Implemented in fpmas::model::detail::Model.

◆ clear()

virtual void fpmas::api::model::Model::clear ( )
pure virtual

Erases all agents from the Model.

This is assumed to be performed by all the processes in the same epoch, even if the operation itself does not necessarily requires communications (since it is assumed that all agents are erased from any process anyway).

Implemented in fpmas::model::detail::Model.


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