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

#include <model.h>

Inheritance diagram for fpmas::model::DistributedAgentNodeBuilder:
Inheritance graph
[legend]
Collaboration diagram for fpmas::model::DistributedAgentNodeBuilder:
Collaboration graph
[legend]

Public Member Functions

 DistributedAgentNodeBuilder (const api::model::GroupList &groups, std::size_t agent_count, std::function< api::model::Agent *()> allocator, api::communication::MpiCommunicator &comm)
 
 DistributedAgentNodeBuilder (const api::model::GroupList &groups, std::size_t agent_count, std::function< api::model::Agent *()> allocator, std::function< api::model::Agent *()> distant_allocator, api::communication::MpiCommunicator &comm)
 
api::model::AgentNodebuildNode (api::graph::DistributedGraph< AgentPtr > &graph) override
 
api::model::AgentNodebuildDistantNode (api::graph::DistributedId id, int location, api::graph::DistributedGraph< AgentPtr > &graph) override
 
- Public Member Functions inherited from fpmas::graph::DistributedNodeBuilder< AgentPtr >
 DistributedNodeBuilder (std::size_t node_count, fpmas::api::communication::MpiCommunicator &comm)
 
std::size_t nodeCount () override
 
std::size_t localNodeCount () override
 
- Public Member Functions inherited from fpmas::api::graph::DistributedNodeBuilder< T >
virtual std::size_t localNodeCount ()=0
 
virtual DistributedNode< T > * buildDistantNode (DistributedId id, int location, DistributedGraph< T > &graph)=0
 
- Public Member Functions inherited from fpmas::api::graph::NodeBuilder< T >
virtual std::size_t nodeCount ()=0
 
virtual DistributedNode< T > * buildNode (DistributedGraph< T > &graph)=0
 

Additional Inherited Members

- Protected Attributes inherited from fpmas::graph::DistributedNodeBuilder< AgentPtr >
std::size_t local_node_count
 

Detailed Description

An api::graph::DistributedNodeBuilder implementation that can be used to easily generate a random model, that can be provided to an api::graph::DistributedGraphBuilder implementation.

AgentNodes are built automatically, and can be linked according to the api::graph::DistributedGraphBuilder algorithm implementation.

Constructor & Destructor Documentation

◆ DistributedAgentNodeBuilder() [1/2]

fpmas::model::DistributedAgentNodeBuilder::DistributedAgentNodeBuilder ( const api::model::GroupList groups,
std::size_t  agent_count,
std::function< api::model::Agent *()>  allocator,
api::communication::MpiCommunicator comm 
)

DistributedAgentNodeBuilder constructor.

allocator is a function object used to dynamically allocate Agents. When this version of the constructor is used, the allocator is used by both buildNode() and buildDistantNode() methods. A lambda function can be used to easily define an allocator.

example
...
// Vector containing 1000 integers
std::vector<int> some_agent_data(1000);
// Initializes some_agent_data
...
int index = 0;
user_group, 1000,
[&index] () {
return new UserAgent(some_agent_data[index++]);
},
model.getMpiCommunicator()
);
DistributedAgentNodeBuilder(const api::model::GroupList &groups, std::size_t agent_count, std::function< api::model::Agent *()> allocator, api::communication::MpiCommunicator &comm)
Definition: model.cpp:32
Note
Notice that the build process defined in an fpmas::api::graph::DistributedGraphBuilder implementation is distributed. In consequence, the inialization of some_agent_data should in practice take distribution into account. For example, since 1000 is the total count of initialized Agents, it is very likely that much less Agents will be effectively initialized on the local process.
Parameters
groupsgroups to which agents will be added
agent_counttotal count of Agents to build
allocatorAgent allocator
commMPI communicator

◆ DistributedAgentNodeBuilder() [2/2]

fpmas::model::DistributedAgentNodeBuilder::DistributedAgentNodeBuilder ( const api::model::GroupList groups,
std::size_t  agent_count,
std::function< api::model::Agent *()>  allocator,
std::function< api::model::Agent *()>  distant_allocator,
api::communication::MpiCommunicator comm 
)

DistributedAgentNodeBuilder constructor.

allocator and distant_allocator are function object used to dynamically allocate Agents. When this version of the constructor is used, allocator is used by buildNode(), and distant_allocator is used by buildDistantNode(). Since buildDistantNode() is used to build temporary representations of Agents, distant_allocator can be used to efficiently allocated default constructed Agents. Lambda functions can be used to easily define an allocators.

example
...
// Vector containing 1000 integers
std::vector<int> some_agent_data(1000);
// Initializes some_agent_data
...
int index = 0;
user_group, 1000,
[&index] () {
// Allocates a local agent with data
return new UserAgent(some_agent_data[index++]);
},
[] () {
// Allocates a default temporary agent
return new UserAgent;
},
model.getMpiCommunicator()
);
Note
Same note as DistributedAgentNodeBuilder(fpmas::api::model::AgentGroup&, std::size_t, std::function<api::model::Agent*()>, fpmas::api::communication::MpiCommunicator&)
Parameters
groupsgroups to which agents will be added
agent_counttotal count of Agents to build
allocatorAgent allocator
distant_allocatortemporary Agent allocator
commMPI communicator

Member Function Documentation

◆ buildNode()

api::model::AgentNode * fpmas::model::DistributedAgentNodeBuilder::buildNode ( api::graph::DistributedGraph< AgentPtr > &  graph)
override

Builds a node in the specified graph.

Parameters
graphgraph in which the node must be built
Returns
pointer to built node

◆ buildDistantNode()

api::model::AgentNode * fpmas::model::DistributedAgentNodeBuilder::buildDistantNode ( api::graph::DistributedId  id,
int  location,
api::graph::DistributedGraph< AgentPtr > &  graph 
)
override

Builds a distant node in the specified graph, with the provided id. The node is assumed to be currently owned by the process with rank location.

Such a node can be considered as a "temporary" node, that can be used by the underlying algorithm to build edges with nodes that are currently not located on this process.

Implementations are likely to behave as follow:

  1. Dynamically allocates a default DistributedNode
  2. Initiates its location using DistributedNode::setLocation()
  3. Inserts it into the graph using DistributedGraph::insertDistant()
Note
The node returned must be the node effectively contained in the graph at the end of the operation. Indeed, it is allowed to try to insert a DISTANT node already contained in the graph, and implementations might decide to ignore the new node or to replace the existing one, but the node finally contained in the graph must be returned. In any case, it is safe to return the result of DistributedGraph::insertDistant().

Notice that the count of nodes built using this method is not limited and is not correlated to localNodeCount() or nodeCount(), contrary to the buildNode() method.

Parameters
idid of the distant node
locationcurrent node location
graphgraph in which the distant node will be inserted

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