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

#include <model.h>

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

Public Member Functions

 Model (api::model::AgentGraph &graph, api::scheduler::Scheduler &scheduler, api::runtime::Runtime &runtime, api::model::LoadBalancing &load_balancing)
 
 Model (const Model &)=delete
 
 Model (Model &&)=delete
 
Modeloperator= (const Model &)=delete
 
Modeloperator= (Model &&)=delete
 
api::model::AgentGraphgraph () override
 
const api::model::AgentGraphgraph () const override
 
api::scheduler::Schedulerscheduler () override
 
const api::scheduler::Schedulerscheduler () const override
 
api::runtime::Runtimeruntime () override
 
const api::runtime::Runtimeruntime () const override
 
const scheduler::JobloadBalancingJob () const override
 
api::model::AgentGroupbuildGroup (api::model::GroupId id) override
 
api::model::AgentGroupbuildGroup (api::model::GroupId id, const api::model::Behavior &behavior) override
 
void removeGroup (api::model::AgentGroup &group) override
 
api::model::AgentGroupgetGroup (api::model::GroupId id) const override
 
const std::unordered_map< GroupId, api::model::AgentGroup * > & groups () const override
 
AgentEdge * link (api::model::Agent *src_agent, api::model::Agent *tgt_agent, api::graph::LayerId layer) override
 
void unlink (api::model::AgentEdge *edge) override
 
api::communication::MpiCommunicatorgetMpiCommunicator () override
 
const api::communication::MpiCommunicatorgetMpiCommunicator () const override
 
void clear () override
 
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

void insert (api::model::GroupId id, api::model::AgentGroup *group) override
 
virtual void insert (GroupId id, AgentGroup *group)=0
 

Detailed Description

api::model::Model implementation.

Constructor & Destructor Documentation

◆ Model()

fpmas::model::detail::Model::Model ( api::model::AgentGraph graph,
api::scheduler::Scheduler scheduler,
api::runtime::Runtime runtime,
api::model::LoadBalancing load_balancing 
)

Model constructor.

Parameters
graphsimulation graph
schedulerscheduler
runtimeruntime
load_balancingload balancing algorithm

◆ ~Model()

fpmas::model::detail::Model::~Model ( )
virtual

Reimplemented from fpmas::api::model::Model.

Member Function Documentation

◆ insert()

void fpmas::model::detail::Model::insert ( api::model::GroupId  id,
api::model::AgentGroup group 
)
overrideprotectedvirtual

Inserts an AgentGroup into this model.

Parameters
idid of the group
groupagent group to insert

Implements fpmas::api::model::Model.

◆ graph() [1/2]

api::model::AgentGraph & fpmas::model::detail::Model::graph ( )
inlineoverridevirtual

Model's AgentGraph.

Returns
agent graph

Implements fpmas::api::model::Model.

◆ graph() [2/2]

const api::model::AgentGraph & fpmas::model::detail::Model::graph ( ) const
inlineoverridevirtual

Model's AgentGraph.

Returns
agent graph

Implements fpmas::api::model::Model.

◆ scheduler() [1/2]

api::scheduler::Scheduler & fpmas::model::detail::Model::scheduler ( )
inlineoverridevirtual

Model's Scheduler.

Returns
scheduler

Implements fpmas::api::model::Model.

◆ scheduler() [2/2]

const api::scheduler::Scheduler & fpmas::model::detail::Model::scheduler ( ) const
inlineoverridevirtual

Model's Scheduler.

Returns
scheduler

Implements fpmas::api::model::Model.

◆ runtime() [1/2]

api::runtime::Runtime & fpmas::model::detail::Model::runtime ( )
inlineoverridevirtual

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

Returns
runtime

Implements fpmas::api::model::Model.

◆ runtime() [2/2]

const api::runtime::Runtime & fpmas::model::detail::Model::runtime ( ) const
inlineoverridevirtual

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

Returns
runtime

Implements fpmas::api::model::Model.

◆ loadBalancingJob()

const scheduler::Job & fpmas::model::detail::Model::loadBalancingJob ( ) const
inlineoverridevirtual

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

Implements fpmas::api::model::Model.

◆ buildGroup() [1/2]

api::model::AgentGroup & fpmas::model::detail::Model::buildGroup ( api::model::GroupId  id)
overridevirtual

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

Implements fpmas::api::model::Model.

◆ buildGroup() [2/2]

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

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

Implements fpmas::api::model::Model.

◆ removeGroup()

void fpmas::model::detail::Model::removeGroup ( api::model::AgentGroup group)
overridevirtual

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

Implements fpmas::api::model::Model.

◆ getGroup()

fpmas::api::model::AgentGroup & fpmas::model::detail::Model::getGroup ( api::model::GroupId  id) const
overridevirtual

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

Implements fpmas::api::model::Model.

◆ groups()

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

Returns the map of AgentGroups currently defined in the Model.

Returns
agent groups

Implements fpmas::api::model::Model.

◆ link()

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

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

Implements fpmas::api::model::Model.

◆ unlink()

void fpmas::model::detail::Model::unlink ( api::model::AgentEdge edge)
overridevirtual

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

Parameters
edgeedge to unlink

Implements fpmas::api::model::Model.

◆ getMpiCommunicator() [1/2]

api::communication::MpiCommunicator & fpmas::model::detail::Model::getMpiCommunicator ( )
inlineoverridevirtual

Returns the MPI communicator used by this model.

Returns
MPI communicator

Implements fpmas::api::model::Model.

◆ getMpiCommunicator() [2/2]

const api::communication::MpiCommunicator & fpmas::model::detail::Model::getMpiCommunicator ( ) const
inlineoverridevirtual

Returns the MPI communicator used by this model.

Returns
MPI communicator

Implements fpmas::api::model::Model.

◆ clear()

void fpmas::model::detail::Model::clear ( )
inlineoverridevirtual

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).

Implements fpmas::api::model::Model.


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