graph_analysis
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
graph_analysis::BaseGraph Class Reference

General Graph template that should be implemented to wrap specific graph library functionality We assume that all graph implementations will rely and allow access to vertices and edges via integers. More...

#include <BaseGraph.hpp>

Inheritance diagram for graph_analysis::BaseGraph:
Inheritance graph
[legend]
Collaboration diagram for graph_analysis::BaseGraph:
Collaboration graph
[legend]

Public Types

enum  ImplementationType { BOOST_DIRECTED_GRAPH, LEMON_DIRECTED_GRAPH, SNAP_DIRECTED_GRAPH, IMPLEMENTATION_TYPE_END }
 
typedef shared_ptr< BaseGraph > Ptr
 

Public Member Functions

virtual ~BaseGraph ()
 Default deconstructor. More...
 
void addObserver (const BaseGraphObserver::Ptr &observer)
 
void removeObserver (const BaseGraphObserver::Ptr &observer)
 
void transactionEvent (TransactionType eventType)
 issue a transaction event The transaction event is passed to all observers, which can implement the respective response to the transaction. E.g. rollback, hold-and-forward, etc. More...
 
virtual BaseGraph::Ptr copy () const
 
BaseGraph::Ptr clone () const
 
BaseGraph::Ptr cloneEdges () const
 
virtual BaseGraph::Ptr newInstance () const
 
ImplementationType getImplementationType () const
 
std::string getImplementationTypeName () const
 
bool empty () const
 tests whether the graph is void/empty More...
 
GraphElementId addVertex (const Vertex::Ptr &vertex)
 Add a vertex. More...
 
GraphElementId getVertexId (const Vertex::Ptr &vertex) const
 Get the vertex id for this graph. More...
 
virtual Vertex::Ptr getVertex (GraphElementId id) const
 Get the vertex by id. More...
 
void removeVertex (const Vertex::Ptr &vertex)
 Remove vertex In order to reimplement, call the base function first BaseGraph::addVertex(v) More...
 
GraphElementId addEdge (const Edge::Ptr &edge)
 Add an edge Cannot be reimplemented directly, but see addEdge(Edge::Ptr, GraphElementId, GraphElementId) More...
 
void removeEdge (const Edge::Ptr &edge)
 
virtual size_t removeEdges (const Vertex::Ptr &a, const Vertex::Ptr &b)
 
GraphElementId addHyperEdge (const HyperEdge::Ptr &hyperEdge)
 
void removeHyperEdge (const HyperEdge::Ptr &hyperEdge)
 
bool contains (const Edge::Ptr &edge) const
 
bool contains (const Vertex::Ptr &vertex) const
 
GraphElementId getEdgeId (const Edge::Ptr &edge) const
 Get the edge id for this graph. More...
 
virtual Edge::Ptr getEdge (GraphElementId id) const
 Get the edge by id. More...
 
virtual std::vector< Edge::Ptr > getEdges (const Vertex::Ptr &source, const Vertex::Ptr &target) const
 Get edge by given vertices. More...
 
template<typename T >
std::vector< shared_ptr< T > > getEdges (const Vertex::Ptr &source, const Vertex::Ptr &target) const
 Get edges by given vertices and return only edges of a given type that end at target Type should be a subclass of Edge!! If dynamic_pointer_cast returns null pointer, object is not added. More...
 
template<typename T >
std::vector< shared_ptr< T > > getVertices () const
 Get all vertices of a given type Type should be a subclass of vertex If dynamic_pointer_cast returns null pointer, object is not added. More...
 
GraphId getId () const
 
virtual VertexIterator::Ptr getVertexIterator () const
 
virtual BaseIterable< VertexIterator::Ptr, BaseGraph, Vertex::Ptr > vertices ()
 
virtual EdgeIterator::Ptr getEdgeIterator () const
 
virtual BaseIterable< EdgeIterator::Ptr, BaseGraph, Edge::Ptr > edges ()
 
virtual std::vector< Vertex::Ptr > getAllVertices () const
 
virtual std::vector< Edge::Ptr > getAllEdges () const
 
virtual EdgeIterator::Ptr getEdgeIterator (const Vertex::Ptr &vertex) const
 
void clear ()
 
size_t size () const
 
size_t order () const
 
virtual EdgeIterator::Ptr getOutEdgeIterator (const Vertex::Ptr &vertex) const
 
virtual EdgeIterator::Ptr getInEdgeIterator (const Vertex::Ptr &vertex) const
 
std::vector< Edge::Ptr > getInEdges (const Vertex::Ptr &vertex) const
 
std::vector< Edge::Ptr > getOutEdges (const Vertex::Ptr &vertex) const
 
SpecializedIterable< EdgeIterator::Ptr, BaseGraph, Edge::Ptr, Vertex::Ptr > inEdges (const Vertex::Ptr &vertex) const
 
SpecializedIterable< EdgeIterator::Ptr, BaseGraph, Edge::Ptr, Vertex::Ptr > outEdges (const Vertex::Ptr &vertex) const
 
bool isUndirected () const
 
bool isDirected () const
 
- Public Member Functions inherited from graph_analysis::VertexIterable
virtual ~VertexIterable ()
 
virtual uint64_t getVertexCount () const
 
- Public Member Functions inherited from graph_analysis::EdgeIterable
virtual ~EdgeIterable ()
 
virtual uint64_t getEdgeCount () const
 
- Public Member Functions inherited from graph_analysis::Algorithms
virtual ~Algorithms ()
 
virtual shared_ptr< SubGraph > identifyConnectedComponents (const shared_ptr< BaseGraph > &baseGraph) const
 
virtual bool isConnected () const
 

Static Public Member Functions

static Ptr getInstance (ImplementationType type=LEMON_DIRECTED_GRAPH)
 
static SubGraph::Ptr getSubGraph (const Ptr &graph)
 
static SubGraph::Ptr applyFilters (const Ptr &graph, const Filter< Vertex::Ptr >::Ptr &vertexFilter, const Filter< Edge::Ptr >::Ptr &edgeFilter)
 

Static Public Attributes

static std::map< ImplementationType, std::string > ImplementationTypeTxt
 

Protected Member Functions

 BaseGraph (ImplementationType type, bool directed)
 
virtual GraphElementId addVertexInternal (const Vertex::Ptr &)
 
virtual void removeVertexInternal (const Vertex::Ptr &)
 
virtual GraphElementId addEdgeInternal (const Edge::Ptr &edge, GraphElementId sourceVertexId, GraphElementId edgeVertexId)
 
virtual void removeEdgeInternal (const Edge::Ptr &)
 
virtual SubGraph::Ptr createSubGraph (const Ptr &baseGraph) const
 

Detailed Description

General Graph template that should be implemented to wrap specific graph library functionality We assume that all graph implementations will rely and allow access to vertices and edges via integers.

Member Typedef Documentation

◆ Ptr

Member Enumeration Documentation

◆ ImplementationType

Enumerator
BOOST_DIRECTED_GRAPH 
LEMON_DIRECTED_GRAPH 
SNAP_DIRECTED_GRAPH 
IMPLEMENTATION_TYPE_END 

Constructor & Destructor Documentation

◆ ~BaseGraph()

virtual graph_analysis::BaseGraph::~BaseGraph ( )
inlinevirtual

Default deconstructor.

◆ BaseGraph()

graph_analysis::BaseGraph::BaseGraph ( ImplementationType  type,
bool  directed 
)
protected

Default constructor for a graph

Member Function Documentation

◆ addEdge()

GraphElementId graph_analysis::BaseGraph::addEdge ( const Edge::Ptr &  edge)

Add an edge Cannot be reimplemented directly, but see addEdge(Edge::Ptr, GraphElementId, GraphElementId)

◆ addEdgeInternal()

virtual GraphElementId graph_analysis::BaseGraph::addEdgeInternal ( const Edge::Ptr &  edge,
GraphElementId  sourceVertexId,
GraphElementId  edgeVertexId 
)
inlineprotectedvirtual

Add an edge using source and target vertex on the internal graph representation

Returns
Element id of this edge within this graph

Reimplemented in graph_analysis::lemon::DirectedGraph, graph_analysis::boost_graph::DirectedGraph, and graph_analysis::snap::DirectedGraph.

◆ addHyperEdge()

GraphElementId graph_analysis::BaseGraph::addHyperEdge ( const HyperEdge::Ptr &  hyperEdge)
inline

Utility function to add a hyper edge (internally handled as vertex)

Returns
id of this element

◆ addObserver()

void graph_analysis::BaseGraph::addObserver ( const BaseGraphObserver::Ptr &  observer)

Add an observer to the set of observers (see BaseGraphObserver.hpp)

◆ addVertex()

GraphElementId graph_analysis::BaseGraph::addVertex ( const Vertex::Ptr &  vertex)

Add a vertex.

The base implementation does not add the vertex to the graph, but checks only if the vertex is already associated with the graph. Reimplement for the specific graph implementation and call the base function first, i.e. BaseGraph::addVertex(v)

Exceptions
std::runtime_errorif the vertex already exists in the graph
Returns
GraphElementId which identifies the vertex in this(!) graph instance

◆ addVertexInternal()

virtual GraphElementId graph_analysis::BaseGraph::addVertexInternal ( const Vertex::Ptr &  )
inlineprotectedvirtual

Add a vertex from the internal graph representation

Returns
Element id of this vertex within this graph

Reimplemented in graph_analysis::lemon::DirectedGraph, graph_analysis::boost_graph::DirectedGraph, and graph_analysis::snap::DirectedGraph.

◆ applyFilters()

SubGraph::Ptr graph_analysis::BaseGraph::applyFilters ( const Ptr &  graph,
const Filter< Vertex::Ptr >::Ptr &  vertexFilter,
const Filter< Edge::Ptr >::Ptr &  edgeFilter 
)
static

Apply filters to base graph

Returns
subgraph with filters applied

Apply filters to base graph

◆ clear()

void graph_analysis::BaseGraph::clear ( )

Clear the graph from all nodes and edges

◆ clone()

BaseGraph::Ptr graph_analysis::BaseGraph::clone ( ) const

Clone the graph, i.e. provides a deep copy of this graph so that this graph and the clone do not share any references

◆ cloneEdges()

BaseGraph::Ptr graph_analysis::BaseGraph::cloneEdges ( ) const

Copy the vertices, but clone the edges of the graph

◆ contains() [1/2]

bool graph_analysis::BaseGraph::contains ( const Edge::Ptr &  edge) const

Test if graph contains this edge

Returns
true if graph contains edge, false otherwise

◆ contains() [2/2]

bool graph_analysis::BaseGraph::contains ( const Vertex::Ptr &  vertex) const

Test if graph contains this vertex

Returns
true if graph contains vertex, false otherwise

◆ copy()

virtual BaseGraph::Ptr graph_analysis::BaseGraph::copy ( ) const
inlinevirtual

Create a copy of this graph The copy of the graph and this graph will still share the same set of edges and vertices. If you require complete separation consider calling clone

Returns
pointer to the copy of this graph

Reimplemented in graph_analysis::snap::DirectedGraph, graph_analysis::boost_graph::DirectedGraph, and graph_analysis::lemon::DirectedGraph.

◆ createSubGraph()

virtual SubGraph::Ptr graph_analysis::BaseGraph::createSubGraph ( const Ptr &  baseGraph) const
inlineprotectedvirtual

Create subgraph of the given baseGraph

Parameters
baseGraphBaseGraph that this subgraph is related to

Reimplemented in graph_analysis::lemon::DirectedGraph, graph_analysis::snap::DirectedGraph, and graph_analysis::boost_graph::DirectedGraph.

◆ edges()

virtual BaseIterable<EdgeIterator::Ptr,BaseGraph, Edge::Ptr> graph_analysis::BaseGraph::edges ( )
inlinevirtual

◆ empty()

bool graph_analysis::BaseGraph::empty ( ) const

tests whether the graph is void/empty

Returns
true when the graph is empty (does not contain a single vertex); false otherwise

◆ getAllEdges()

std::vector< Edge::Ptr > graph_analysis::BaseGraph::getAllEdges ( ) const
virtual

Retrieve all edges The default implementation uses the iterator, thus requires O(|edges|)

Returns
all edges in the graph

◆ getAllVertices()

std::vector< Vertex::Ptr > graph_analysis::BaseGraph::getAllVertices ( ) const
virtual

Retrieve all vertices This default implementation uses the iterator, thus requires O(|vertices|)

Returns
all vertices in the graph

◆ getEdge()

virtual Edge::Ptr graph_analysis::BaseGraph::getEdge ( GraphElementId  id) const
inlinevirtual

◆ getEdgeId()

GraphElementId graph_analysis::BaseGraph::getEdgeId ( const Edge::Ptr &  edge) const
inline

Get the edge id for this graph.

Exceptions
std::runtime_errorif the edge is not part of this graph

◆ getEdgeIterator() [1/2]

virtual EdgeIterator::Ptr graph_analysis::BaseGraph::getEdgeIterator ( ) const
inlinevirtual

Get iterator over all edges in this graph

Returns
the edge iterator

Reimplemented from graph_analysis::EdgeIterable.

Reimplemented in graph_analysis::lemon::DirectedGraph, graph_analysis::snap::DirectedGraph, and graph_analysis::boost_graph::DirectedGraph.

◆ getEdgeIterator() [2/2]

virtual EdgeIterator::Ptr graph_analysis::BaseGraph::getEdgeIterator ( const Vertex::Ptr &  vertex) const
inlinevirtual

Get iterator over all edges (in/out) from the given vertex

Returns
EdgeIterator over all edges of this vertex

Reimplemented in graph_analysis::lemon::DirectedGraph, graph_analysis::snap::DirectedGraph, and graph_analysis::boost_graph::DirectedGraph.

◆ getEdges() [1/2]

std::vector< Edge::Ptr > graph_analysis::BaseGraph::getEdges ( const Vertex::Ptr &  source,
const Vertex::Ptr &  target 
) const
virtual

Get edge by given vertices.

Returns
List of edges that start at source and end at target for directed graphs – for undirected, return all edges

Reimplemented in graph_analysis::boost_graph::DirectedGraph.

◆ getEdges() [2/2]

template<typename T >
std::vector< shared_ptr<T> > graph_analysis::BaseGraph::getEdges ( const Vertex::Ptr &  source,
const Vertex::Ptr &  target 
) const
inline

Get edges by given vertices and return only edges of a given type that end at target Type should be a subclass of Edge!! If dynamic_pointer_cast returns null pointer, object is not added.

◆ getId()

GraphId graph_analysis::BaseGraph::getId ( ) const
inline

Get the graph id

Returns
id

◆ getImplementationType()

ImplementationType graph_analysis::BaseGraph::getImplementationType ( ) const
inline

Get the implementation type of this graph object

Returns
implementation type

◆ getImplementationTypeName()

std::string graph_analysis::BaseGraph::getImplementationTypeName ( ) const
inline

Get the implementation type as string

Returns
Stringified implementation type

◆ getInEdgeIterator()

virtual EdgeIterator::Ptr graph_analysis::BaseGraph::getInEdgeIterator ( const Vertex::Ptr &  vertex) const
inlinevirtual

Get in edge iterator If the graph is undirected will return the same iterator as getEdgeIterator

Reimplemented in graph_analysis::lemon::DirectedGraph, graph_analysis::snap::DirectedGraph, and graph_analysis::boost_graph::DirectedGraph.

◆ getInEdges()

std::vector< Edge::Ptr > graph_analysis::BaseGraph::getInEdges ( const Vertex::Ptr &  vertex) const

Get all in edges of a vertex as list

◆ getInstance()

BaseGraph::Ptr graph_analysis::BaseGraph::getInstance ( ImplementationType  type = LEMON_DIRECTED_GRAPH)
static

Get a graph instance of the given implementation type

Returns
Ptr to new instance

◆ getOutEdgeIterator()

virtual EdgeIterator::Ptr graph_analysis::BaseGraph::getOutEdgeIterator ( const Vertex::Ptr &  vertex) const
inlinevirtual

Get out edge iterator If the graph is undirected will return the same iterator as getEdgeIterator

Reimplemented in graph_analysis::lemon::DirectedGraph, graph_analysis::boost_graph::DirectedGraph, and graph_analysis::snap::DirectedGraph.

◆ getOutEdges()

std::vector< Edge::Ptr > graph_analysis::BaseGraph::getOutEdges ( const Vertex::Ptr &  vertex) const

Get all out edges of a vertex as list

◆ getSubGraph()

SubGraph::Ptr graph_analysis::BaseGraph::getSubGraph ( const Ptr &  graph)
static

Get the subgraph for a graph. To support this feature implementation have to provide an implementation of BaseGraph::createSubGraph

See also
createSubGraph

◆ getVertex()

virtual Vertex::Ptr graph_analysis::BaseGraph::getVertex ( GraphElementId  id) const
inlinevirtual

◆ getVertexId()

GraphElementId graph_analysis::BaseGraph::getVertexId ( const Vertex::Ptr &  vertex) const
inline

Get the vertex id for this graph.

Exceptions
std::runtime_errorif the vertex is not part of this graph

◆ getVertexIterator()

virtual VertexIterator::Ptr graph_analysis::BaseGraph::getVertexIterator ( ) const
inlinevirtual

Get the iterator over all vertices in this graph

Returns
the vertex iterator

Reimplemented from graph_analysis::VertexIterable.

Reimplemented in graph_analysis::lemon::DirectedGraph, graph_analysis::snap::DirectedGraph, and graph_analysis::boost_graph::DirectedGraph.

◆ getVertices()

template<typename T >
std::vector< shared_ptr<T> > graph_analysis::BaseGraph::getVertices ( ) const
inline

Get all vertices of a given type Type should be a subclass of vertex If dynamic_pointer_cast returns null pointer, object is not added.

◆ inEdges()

SpecializedIterable< EdgeIterator::Ptr, BaseGraph, Edge::Ptr, Vertex::Ptr > graph_analysis::BaseGraph::inEdges ( const Vertex::Ptr &  vertex) const

◆ isDirected()

bool graph_analysis::BaseGraph::isDirected ( ) const
inline

Test if graph is directed

◆ isUndirected()

bool graph_analysis::BaseGraph::isUndirected ( ) const
inline

Test if graph is undirected

◆ newInstance()

virtual BaseGraph::Ptr graph_analysis::BaseGraph::newInstance ( ) const
inlinevirtual

Allow to create an instance of the same type of graph

Reimplemented in graph_analysis::snap::DirectedGraph, graph_analysis::boost_graph::DirectedGraph, and graph_analysis::lemon::DirectedGraph.

◆ order()

size_t graph_analysis::BaseGraph::order ( ) const
inline

Get the order of the graph, i.e. by definition the number of vertices in the graph

◆ outEdges()

SpecializedIterable< EdgeIterator::Ptr, BaseGraph, Edge::Ptr, Vertex::Ptr > graph_analysis::BaseGraph::outEdges ( const Vertex::Ptr &  vertex) const

◆ removeEdge()

void graph_analysis::BaseGraph::removeEdge ( const Edge::Ptr &  edge)

Remove an edge and disassociate from this graph In order to reimplement, call the base function first BaseGraph::addVertex(v)

◆ removeEdgeInternal()

virtual void graph_analysis::BaseGraph::removeEdgeInternal ( const Edge::Ptr &  )
inlineprotectedvirtual

Remove an edge from the internal graph representation

Returns
Element id of this vertex within this graph

Reimplemented in graph_analysis::snap::DirectedGraph, graph_analysis::lemon::DirectedGraph, and graph_analysis::boost_graph::DirectedGraph.

◆ removeEdges()

size_t graph_analysis::BaseGraph::removeEdges ( const Vertex::Ptr &  a,
const Vertex::Ptr &  b 
)
virtual

Remove edges which link two vertices

Returns
number of removed edges

◆ removeHyperEdge()

void graph_analysis::BaseGraph::removeHyperEdge ( const HyperEdge::Ptr &  hyperEdge)
inline

Utility function to remove a hyper edge (internally handled as vertex) Remove hyper edge

◆ removeObserver()

void graph_analysis::BaseGraph::removeObserver ( const BaseGraphObserver::Ptr &  observer)

Removes an observer from the set of observers.

◆ removeVertex()

void graph_analysis::BaseGraph::removeVertex ( const Vertex::Ptr &  vertex)

Remove vertex In order to reimplement, call the base function first BaseGraph::addVertex(v)

◆ removeVertexInternal()

virtual void graph_analysis::BaseGraph::removeVertexInternal ( const Vertex::Ptr &  )
inlineprotectedvirtual

Remove a vertex from the internal graph representation

Returns
Element id of this vertex within this graph

Reimplemented in graph_analysis::snap::DirectedGraph, graph_analysis::lemon::DirectedGraph, and graph_analysis::boost_graph::DirectedGraph.

◆ size()

size_t graph_analysis::BaseGraph::size ( ) const
inline

Get size of the graph, i.e. by definition the number of edges in the graph

◆ transactionEvent()

void graph_analysis::BaseGraph::transactionEvent ( TransactionType  eventType)

issue a transaction event The transaction event is passed to all observers, which can implement the respective response to the transaction. E.g. rollback, hold-and-forward, etc.

Any combined actions like e.g. loading of files a.s.o. should have a

transactionsEvent( TRANSACTION_START ); ... // modify graph vertices and edges ... transactionEvent( TRANSACTION_STOP );

bracket,

◆ vertices()

virtual BaseIterable<VertexIterator::Ptr,BaseGraph, Vertex::Ptr> graph_analysis::BaseGraph::vertices ( )
inlinevirtual

Member Data Documentation

◆ ImplementationTypeTxt

std::map< BaseGraph::ImplementationType, std::string > graph_analysis::BaseGraph::ImplementationTypeTxt
static
Initial value:
= InitMap<BaseGraph::ImplementationType, std::string>
(BOOST_DIRECTED_GRAPH, "boost_graph::DirectedGraph")
(LEMON_DIRECTED_GRAPH, "lemon::DirectedGraph")
(SNAP_DIRECTED_GRAPH, "snap::DirectedGraph")

The documentation for this class was generated from the following files:
graph_analysis::BaseGraph::LEMON_DIRECTED_GRAPH
@ LEMON_DIRECTED_GRAPH
Definition: BaseGraph.hpp:31
graph_analysis::BaseGraph::SNAP_DIRECTED_GRAPH
@ SNAP_DIRECTED_GRAPH
Definition: BaseGraph.hpp:31
graph_analysis::BaseGraph::BOOST_DIRECTED_GRAPH
@ BOOST_DIRECTED_GRAPH
Definition: BaseGraph.hpp:31