RepastHPC  2.3.1
Public Types | Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | List of all members
repast::Graph< V, E, Ec, EcM > Class Template Referenceabstract

Graph / Network implementation where agents are vertices in the graph. More...

#include <Graph.h>

Inheritance diagram for repast::Graph< V, E, Ec, EcM >:
repast::Projection< V > repast::SharedNetwork< V, E, Ec, EcM >

Public Types

typedef boost::transform_iterator< NodeGetter< V, E >, typename VertexMap::const_iterator > vertex_iterator
 An iterator over the agents that are the vertices in this Graph.
 
- Public Types inherited from repast::Projection< V >
enum  RADIUS
 

Public Member Functions

 Graph (std::string name, bool directed, EcM *edgeContentMgr)
 Creates a Graph with the specified name. More...
 
 Graph (const Graph< V, E, Ec, EcM > &graph)
 Copy constructor for the graph.
 
Graphoperator= (const Graph &graph)
 
virtual boost::shared_ptr< E > addEdge (V *source, V *target)
 Adds an edge between source and target to this Graph. More...
 
virtual boost::shared_ptr< E > addEdge (V *source, V *target, double weight)
 Adds an edge with the specified weight between source and target to this Graph. More...
 
virtual boost::shared_ptr< E > findEdge (V *source, V *target)
 Gets the edge between the source and target or 0 if no such edge is found. More...
 
virtual void successors (V *vertex, std::vector< V * > &out)
 Gets the sucessors of the specified vertex and puts them in out. More...
 
virtual void predecessors (V *vertex, std::vector< V * > &out)
 Gets the predecessors of the specified vertex and puts them in out. More...
 
virtual void adjacent (V *vertex, std::vector< V * > &out)
 Gets all the agent adjacent to the specified vertex. More...
 
virtual void removeEdge (V *source, V *target)
 Removes the edge between source and target from this Graph. More...
 
virtual void removeEdge (const AgentId &source, const AgentId &target)
 Removes the edge between source and target from this Graph. More...
 
virtual int inDegree (V *vertex)
 Gets the in-degree of the specified vertex. More...
 
virtual int outDegree (V *vertex)
 Gets the out-degree of the specified vertex. More...
 
int edgeCount () const
 Gets the number of edges in this Graph. More...
 
int vertexCount () const
 Gets the number of vertices in this Graph. More...
 
vertex_iterator verticesBegin ()
 Gets the start of an iterator over all the vertices in this graph. More...
 
vertex_iterator verticesEnd ()
 Gets the end of an iterator over all the vertices in this graph. More...
 
void showEdges ()
 
virtual bool isMaster (E *e)=0
 
virtual bool keepsAgentsOnSyncProj ()
 Should return true if the Projection implemented can 'keep' some (non-local) agents during a projection information synchronization operation. More...
 
virtual bool sendsSecondaryAgentsOnStatusExchange ()
 Should return true if the Projection implemented will send secondary agents during a status exchange. More...
 
virtual void getInfoExchangePartners (std::set< int > &psToSendTo, std::set< int > &psToReceiveFrom)
 Gets the set of processes with which this Projection exchanges projection info. More...
 
virtual void getAgentStatusExchangePartners (std::set< int > &psToSendTo, std::set< int > &psToReceiveFrom)
 Gets the set of processes with which this Projection exchanges agent status info- that is, the set of processes from which agents can move to this one or to which they can move when moving from this one. More...
 
virtual void getProjectionInfo (std::vector< AgentId > &agents, std::vector< ProjectionInfoPacket * > &packets, bool secondaryInfo=false, std::set< AgentId > *secondaryIds=0, int destProc=-1)
 Convenience wrapper that gets all of the projection information for the agents specified (calls implementation in child class that gets only the information for one agent).
 
virtual ProjectionInfoPacketgetProjectionInfo (AgentId id, bool secondaryInfo=false, std::set< AgentId > *secondaryIds=0, int destProc=-1)
 
virtual void updateProjectionInfo (ProjectionInfoPacket *pip, Context< V > *context)
 
virtual void getRequiredAgents (std::set< AgentId > &agentsToTest, std::set< AgentId > &agentsRequired, RADIUS radius=Projection< V >::PRIMARY)
 
virtual void getAgentsToPush (std::set< AgentId > &agentsToTest, std::map< int, std::set< AgentId > > &agentsToPush)
 Given a set of agents, gets the agents that this projection implementation must 'push' to other processes. More...
 
virtual void cleanProjectionInfo (std::set< AgentId > &agentsToKeep)
 
void clearConflictedEdges ()
 
void getConflictedEdges (std::set< boost::shared_ptr< E > > &conflictedEdges)
 
- Public Member Functions inherited from repast::Projection< V >
void updateProjectionInfo (std::vector< ProjectionInfoPacket * > &pips, Context< V > *context)
 Updates the projection information for the agents in this projection according to the information contained in the vector of information packets passed.
 
 Projection (std::string name)
 Creates a projection with specified name. More...
 
const std::string name () const
 Gets the name of this projection.
 
void addFilterVal (int type)
 Adds an entry to the list of agent types that can be added to this projection. More...
 
void removeFilterVal (int type)
 Removes an entry from the list of agent types that can be added to this projection. More...
 
void clearFilter ()
 Clears the list of agent types that can be added to this projection; the result is that the filter is empty, and any agent can be added.
 
bool agentCanBeAdded (boost::shared_ptr< V > agent)
 Returns true if the agent can be added to the projection, which will be the case if the filter list is empty or if the agent's type is in the filter list. More...
 
virtual void getRequiredAgents (std::set< AgentId > &agentsToTest, std::set< AgentId > &agentsRequired, RADIUS radius=PRIMARY)=0
 Given a set of agents to test, gets the subset that must be kept in order to fulfill the projection's 'contract' to the specified radius. More...
 
virtual void balance ()
 

Public Attributes

std::set< int > ranksToSendProjInfoTo
 
std::set< int > ranksToReceiveProjInfoFrom
 
std::set< int > ranksToSendAgentStatusInfoTo
 
std::set< int > ranksToReceiveAgentStatusInfoFrom
 
bool keepsAgents
 
bool sendsSecondaryAgents
 

Protected Types

typedef boost::unordered_map< AgentId, Vertex< V, E > *, HashIdVertexMap
 
typedef VertexMap::iterator VertexMapIterator
 
typedef Projection< V >::RADIUS RADIUS
 

Protected Member Functions

void cleanUp ()
 
void init (const Graph &graph)
 
virtual bool addAgent (boost::shared_ptr< V > agent)
 
virtual void removeAgent (V *agent)
 
virtual void doAddEdge (boost::shared_ptr< E > edge, bool allowOverwrite=true)
 

Protected Attributes

int edgeCount_
 
bool isDirected
 
VertexMap vertices
 
EcM * edgeContentManager
 
- Protected Attributes inherited from repast::Projection< V >
std::string name_
 
std::set< int > filter
 

Detailed Description

template<typename V, typename E, typename Ec, typename EcM>
class repast::Graph< V, E, Ec, EcM >

Graph / Network implementation where agents are vertices in the graph.

Template Parameters
Vthe type agents in the graph. This type should extend repast::Agent
Ethe edge type of the graph. This type should extend repast::RepastEdge.
Ecclass of serializable Edge Content
EcMClass that is capable of transforming an Edge into Edge Content and vice versa

Constructor & Destructor Documentation

◆ Graph()

template<typename V , typename E , typename Ec , typename EcM >
repast::Graph< V, E, Ec, EcM >::Graph ( std::string  name,
bool  directed,
EcM *  edgeContentMgr 
)
inline

Creates a Graph with the specified name.

Parameters
namethe name of the graph
directedwhether or not the created Graph is directed

Member Function Documentation

◆ addEdge() [1/2]

template<typename V , typename E , typename Ec , typename EcM >
boost::shared_ptr< E > repast::Graph< V, E, Ec, EcM >::addEdge ( V *  source,
V *  target 
)
virtual

Adds an edge between source and target to this Graph.

Parameters
sourcethe source of the edge
targetthe target of the edge
Returns
the added edge.

◆ addEdge() [2/2]

template<typename V , typename E , typename Ec , typename EcM >
boost::shared_ptr< E > repast::Graph< V, E, Ec, EcM >::addEdge ( V *  source,
V *  target,
double  weight 
)
virtual

Adds an edge with the specified weight between source and target to this Graph.

Parameters
sourcethe source of the edge
targetthe target of the edge
weightthe weight of the edge
Returns
the added edge.

◆ adjacent()

template<typename V , typename E , typename Ec , typename EcM >
void repast::Graph< V, E, Ec, EcM >::adjacent ( V *  vertex,
std::vector< V * > &  out 
)
virtual

Gets all the agent adjacent to the specified vertex.

Parameters
vertexthe vertex whose adjacent agents we want to get
[out]thevector where the results will be put

◆ edgeCount()

template<typename V , typename E , typename Ec , typename EcM >
int repast::Graph< V, E, Ec, EcM >::edgeCount ( ) const
inline

Gets the number of edges in this Graph.

Returns
the number of edges in this Graph.

◆ findEdge()

template<typename V , typename E , typename Ec , typename EcM >
boost::shared_ptr< E > repast::Graph< V, E, Ec, EcM >::findEdge ( V *  source,
V *  target 
)
virtual

Gets the edge between the source and target or 0 if no such edge is found.

Parameters
sourcethe source of the edge to find
targetthe target of the edge to find
Returns
the found edge or 0.

◆ getAgentStatusExchangePartners()

template<typename V , typename E , typename Ec , typename EcM >
void repast::Graph< V, E, Ec, EcM >::getAgentStatusExchangePartners ( std::set< int > &  psToSendTo,
std::set< int > &  psToReceiveFrom 
)
virtual

Gets the set of processes with which this Projection exchanges agent status info- that is, the set of processes from which agents can move to this one or to which they can move when moving from this one.

In the most general case this will be all other processors. However, simulations where agents move in spaces will usually exchange agents only with a small subset of 'neighbor' processes, which is knowable in advance and constant. To accommodate the general case, the algorithm for exchanging information must poll all other processes to see which are sending to this one; if this is known in advance, this additional (expensive) step can be skipped.

Implements repast::Projection< V >.

◆ getAgentsToPush()

template<typename V , typename E , typename Ec , typename EcM >
void repast::Graph< V, E, Ec, EcM >::getAgentsToPush ( std::set< AgentId > &  agentsToTest,
std::map< int, std::set< AgentId > > &  agentsToPush 
)
virtual

Given a set of agents, gets the agents that this projection implementation must 'push' to other processes.

Generally spaces must push agents that are in 'buffer zones' and graphs must push local agents that are vertices to master edges where the other vertex is non- local. The results are returned per-process in the agentsToPush map.

Implements repast::Projection< V >.

◆ getInfoExchangePartners()

template<typename V , typename E , typename Ec , typename EcM >
void repast::Graph< V, E, Ec, EcM >::getInfoExchangePartners ( std::set< int > &  psToSendTo,
std::set< int > &  psToReceiveFrom 
)
virtual

Gets the set of processes with which this Projection exchanges projection info.

In the most general case this will be all other processors; this is the case for graphs, where agent connections can be arbitrary. However, spaces usually exchange information only with a small subset of 'neighbor' processes, which is knowable in advance and constant. To accommodate the general case, the algorithm for exchanging information must poll all other processes to see which are sending to this one; if this is known in advance, this additional (expensive) step can be skipped.

Implements repast::Projection< V >.

◆ inDegree()

template<typename V , typename E , typename Ec , typename EcM >
int repast::Graph< V, E, Ec, EcM >::inDegree ( V *  vertex)
virtual

Gets the in-degree of the specified vertex.

Returns
the in-degree of the specified vertex.

◆ keepsAgentsOnSyncProj()

template<typename V , typename E , typename Ec , typename EcM >
virtual bool repast::Graph< V, E, Ec, EcM >::keepsAgentsOnSyncProj ( )
inlinevirtual

Should return true if the Projection implemented can 'keep' some (non-local) agents during a projection information synchronization operation.

Generally spaces will allow all non-local agents to be deleted, but graphs keep the non-local agents that participate in Master edges.

It is possible to override these. A graph projection can be created that does not permit non-local agents to be 'kept'. This would be an extremely unusual use case, but it is possible.

Note that these are used for optimization. If no projection in a given context keeps any agents, several steps in the synchronization algorithm can be omitted. Of course, omitting these steps when a projection actually retains agents can caused undefined problems.

Returns
true if this projection will keep non-local agents during a projection information synchronziation event, false if it will not.

Implements repast::Projection< V >.

◆ outDegree()

template<typename V , typename E , typename Ec , typename EcM >
int repast::Graph< V, E, Ec, EcM >::outDegree ( V *  vertex)
virtual

Gets the out-degree of the specified vertex.

Returns
the out-degree of the specified vertex.

◆ predecessors()

template<typename V , typename E , typename Ec , typename EcM >
void repast::Graph< V, E, Ec, EcM >::predecessors ( V *  vertex,
std::vector< V * > &  out 
)
virtual

Gets the predecessors of the specified vertex and puts them in out.

Parameters
vertexthe vertex whose predecessors we want to get
[out]wherethe predecessors will be returned

◆ removeEdge() [1/2]

template<typename V , typename E , typename Ec , typename EcM >
void repast::Graph< V, E, Ec, EcM >::removeEdge ( const AgentId source,
const AgentId target 
)
virtual

Removes the edge between source and target from this Graph.

Parameters
sourcethe id of the vertex that is the source of the edge
targetthe id of the vertex that is the target of the edge

◆ removeEdge() [2/2]

template<typename V , typename E , typename Ec , typename EcM >
void repast::Graph< V, E, Ec, EcM >::removeEdge ( V *  source,
V *  target 
)
virtual

Removes the edge between source and target from this Graph.

Parameters
sourcethe source of the edge
targetthe target of the edge

Reimplemented in repast::SharedNetwork< V, E, Ec, EcM >.

◆ sendsSecondaryAgentsOnStatusExchange()

template<typename V , typename E , typename Ec , typename EcM >
virtual bool repast::Graph< V, E, Ec, EcM >::sendsSecondaryAgentsOnStatusExchange ( )
inlinevirtual

Should return true if the Projection implemented will send secondary agents during a status exchange.

Generally spaces do not and graphs do.

If no secondary agents will be sent, portions of the algorithm can be omitted for optimization.

Returns
true if the Projection returns secondary agents, false if not

Implements repast::Projection< V >.

◆ successors()

template<typename V , typename E , typename Ec , typename EcM >
void repast::Graph< V, E, Ec, EcM >::successors ( V *  vertex,
std::vector< V * > &  out 
)
virtual

Gets the sucessors of the specified vertex and puts them in out.

Parameters
vertexthe vertex whose successors we want to get
[out]wherethe successors will be returned

◆ vertexCount()

template<typename V , typename E , typename Ec , typename EcM >
int repast::Graph< V, E, Ec, EcM >::vertexCount ( ) const
inline

Gets the number of vertices in this Graph.

Returns
the number of vertices in this Graph.

◆ verticesBegin()

template<typename V , typename E , typename Ec , typename EcM >
vertex_iterator repast::Graph< V, E, Ec, EcM >::verticesBegin ( )
inline

Gets the start of an iterator over all the vertices in this graph.

The iterator dereferences to a pointer to agents of type V.

Returns
the start of an iterator over all the vertices in this graph.

◆ verticesEnd()

template<typename V , typename E , typename Ec , typename EcM >
vertex_iterator repast::Graph< V, E, Ec, EcM >::verticesEnd ( )
inline

Gets the end of an iterator over all the vertices in this graph.

The iterator dereferences to a pointer to agents of type V.

Returns
the end of an iterator over all the vertices in this graph.

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