digiKam Developer Documentation
Professional Photo Management with the Power of Open Source
Loading...
Searching...
No Matches
Digikam::Graph< VertexProperties, EdgeProperties > Class Template Reference

The graph base class template.

+ Inheritance diagram for Digikam::Graph< VertexProperties, EdgeProperties >:

Classes

class  DominatorTree
 
class  Edge
 
class  GraphSearch
 
class  Path
 Helper class to find paths through the graph. More...
 
class  Vertex
 These two classes provide source-compatible wrappers for the vertex and edge descriptors, providing default construction to null and the isNull() method. More...
 

Public Types

typedef graph_traits::adjacency_iterator adjacency_iter
 
typedef std::pair< adjacency_iter, adjacency_iter > adjacency_vertex_range_t
 
enum  AdjacencyFlags {
  OutboundEdges = 1 << 0 , InboundEdges = 1 << 1 , EdgesToLeaf = 1 << 2 , EdgesToRoot = 1 << 3 ,
  AllEdges = InboundEdges | OutboundEdges
}
 
typedef boost::property_map< GraphContainer, edge_properties_t >::const_type const_edge_property_map_t
 
typedef boost::property_map< GraphContainer, boost::vertex_index_t >::const_type const_vertex_index_map_t
 
typedef boost::property_map< GraphContainer, vertex_properties_t >::const_type const_vertex_property_map_t
 
typedef graph_traits::degree_size_type degree_t
 
typedef graph_traits::edge_iterator edge_iter
 
typedef boost::property_map< GraphContainer, edge_properties_t >::type edge_property_map_t
 
typedef std::pair< edge_iter, edge_iter > edge_range_t
 
typedef graph_traits::edge_descriptor edge_t
 
typedef QPair< Edge, EdgeEdgePair
 
typedef boost::graph_traits< GraphContainer > graph_traits
 a bunch of graph-specific typedefs that make the long boost types manageable.
 
typedef boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, boost::property< boost::vertex_index_t, int, boost::property< vertex_properties_t, VertexProperties > >, boost::property< edge_properties_t, EdgeProperties > > GraphContainer
 
enum  GraphCopyFlags { CopyVertexProperties = 1 << 0 , CopyEdgeProperties = 1 << 1 , CopyAllProperties = CopyVertexProperties | CopyEdgeProperties }
 
typedef graph_traits::in_edge_iterator in_edge_iter
 
typedef boost::inv_adjacency_iterator_generator< GraphContainer, vertex_t, in_edge_iter >::type inv_adjacency_iter
 
typedef std::pair< inv_adjacency_iter, inv_adjacency_iter > inv_adjacency_vertex_range_t
 
typedef graph_traits::out_edge_iterator out_edge_iter
 
typedef std::pair< out_edge_iter, out_edge_iter > out_edge_range_t
 
enum  ReturnOrder { BreadthFirstOrder , DepthFirstOrder }
 
typedef boost::property_map< GraphContainer, boost::vertex_index_t >::type vertex_index_map_t
 
typedef graph_traits::vertex_iterator vertex_iter
 
typedef boost::property_map< GraphContainer, vertex_properties_t >::type vertex_property_map_t
 
typedef std::pair< vertex_iter, vertex_iter > vertex_range_t
 
typedef graph_traits::vertex_descriptor vertex_t
 
typedef QMapForAdaptors< Vertex, int > VertexIntMap
 
typedef boost::associative_property_map< VertexIntMapVertexIntMapAdaptor
 
typedef QPair< Vertex, VertexVertexPair
 
typedef QMapForAdaptors< Vertex, VertexVertexVertexMap
 
typedef boost::associative_property_map< VertexVertexMapVertexVertexMapAdaptor
 

Public Member Functions

 Graph (const Graph &g)
 
 Graph (MeaningOfDirection dir=ParentToChild)
 
Edge addEdge (const Vertex &v1, const Vertex &v2)
 
Vertex addVertex ()
 
Vertex addVertex (const VertexProperties &properties)
 
QList< VertexadjacentVertices (const Vertex &v, AdjacencyFlags flags=AllEdges) const
 
void clear ()
 
Edge edge (const Vertex &v1, const Vertex &v2) const
 
int edgeCount () const
 
QList< VertexPair > edgePairs () const
 
QList< Edgeedges () const
 
QList< Edgeedges (const Vertex &v, AdjacencyFlags flags=AllEdges) const
 
template<class T >
Vertex findVertexByProperties (const T &value) const
 
const GraphContainer & getGraph () const
 Accessing vertices and edges.
 
bool hasEdge (const Vertex &v1, const Vertex &v2) const
 
bool hasEdges () const
 
bool hasEdges (const Vertex &v, AdjacencyFlags flags=AllEdges) const
 
int inDegree (const Vertex &v) const
 
bool isConnected (const Vertex &v1, const Vertex &v2) const
 
bool isEmpty () const
 
bool isLeaf (const Vertex &v) const
 
bool isRoot (const Vertex &v) const
 
QList< Vertexleaves () const
 Returns all leaves, i.e.
 
QList< VertexleavesFrom (const Vertex &v) const
 
QList< VertexlongestPathTouching (const Vertex &v) const
 Returns the longest path through the graph, starting from a vertex in roots(), ending on a vertex in leaves(), and passing vertex v.
 
template<typename LessThan >
QList< VertexlongestPathTouching (const Vertex &v, LessThan lessThan) const
 
MeaningOfDirection meaningOfDirection () const
 
Graphoperator= (const Graph &other)
 
int outDegree (const Vertex &v) const
 
EdgeProperties & properties (const Edge &e)
 
const EdgeProperties & properties (const Edge &e) const
 
VertexProperties & properties (const Vertex &v)
 
const VertexProperties & properties (const Vertex &v) const
 
EdgeProperties properties (const Vertex &v1, const Vertex &v2) const
 
void remove (const Vertex &v)
 
QList< Vertexroots () const
 Returns all roots, i.e.
 
QList< VertexrootsOf (const Vertex &v) const
 Returns all roots of vertex v.
 
void setProperties (const Edge &e, const EdgeProperties &props)
 
void setProperties (const Vertex &v, const VertexProperties &props)
 
QMap< Vertex, int > shortestDistancesFrom (const Vertex &v) const
 Returns the shortest distances from Vertex to all vertices in the graph.
 
QList< VertexshortestPath (const Vertex &v1, const Vertex &v2) const
 Returns the shortestPath between id1 and id2.
 
Vertex source (const Edge &e) const
 
Vertex target (const Edge &e) const
 
QList< VertextopologicalSort () const
 Returns the vertex ids of this graph, in topological order.
 
Graph transitiveClosure (GraphCopyFlags flags=CopyAllProperties) const
 Returns a copy of this graph with all edges added to form the transitive closure.
 
Graph transitiveReduction (QList< Edge > *removedEdges=0, GraphCopyFlags flags=CopyAllProperties) const
 Returns a copy of this graph, with edges removed so that the transitive reduction is formed.
 
int vertexCount () const
 
QList< Vertexvertices () const
 
QList< VertexverticesBreadthFirst (const Vertex &givenRef=Vertex()) const
 Orders all vertices of the graph in a breadth-first manner.
 
template<typename LessThan >
QList< VertexverticesDepthFirstSorted (const Vertex &givenRef, LessThan lessThan) const
 Orders all vertices of the graph in a depth-first manner.
 
QList< VertexverticesDominatedBy (const Vertex &v, const Vertex &root, const QList< Vertex > &presortedVertices) const
 For a vertex v reachable from a vertex root returns all vertices dominated by v starting from root.
 
QList< VertexverticesDominatedBy (const Vertex &v, const Vertex &root, ReturnOrder order=BreadthFirstOrder) const
 For a vertex v reachable from a vertex root, returns, in depth-first or breadth-first order, all vertices dominated by v starting from root.
 
template<typename LessThan >
QList< VertexverticesDominatedByDepthFirstSorted (const Vertex &v, const Vertex &root, LessThan lessThan) const
 For a vertex v reachable from a vertex root all vertices dominated by v starting from root.
 

Static Public Member Functions

template<typename T >
static bool alwaysFalse (const T &, const T &)
 

Protected Member Functions

void copyProperties (Graph &other, GraphCopyFlags flags, const std::vector< vertex_t > &copiedVertices) const
 According to the given flags and based on the map, copies vertex and edge properties from this to the other graph.
 
QList< EdgeedgeDifference (const Graph &other, const std::vector< vertex_t > &copiedVertices) const
 Returns a list of edges of this graph that have been removed in other.
 
QList< VertexfindZeroDegree (bool inOrOut) const
 Finds vertex ids of all vertices with zero in- our out-degree.
 
QList< VertexfindZeroDegreeFrom (const Vertex &v, bool inOrOut) const
 
QList< VertexlistPath (const Vertex &root, const Vertex &target, const VertexVertexMap &predecessors, MeaningOfDirection dir=ParentToChild) const
 Get a list of vertex ids for the path from root to target, using the given predecessors.
 
QList< VertexmostRemoteNodes (const VertexIntMap &distances) const
 Get the list of vertices with the largest value in the given distance map.
 
QList< VertextreeFromPredecessors (const Vertex &v, const VertexVertexMap &predecessors) const
 
void treeFromPredecessorsRecursive (const Vertex &v, QList< Vertex > &vertices, const VertexVertexMap &predecessors) const
 

Static Protected Member Functions

template<typename range_t >
static bool isEmptyRange (const range_t &range)
 
template<typename range_t >
static QList< EdgetoEdgeList (const range_t &range)
 
template<typename Value , typename range_t >
static QList< Value > toList (const range_t &range)
 Returns a list of vertex ids of vertices in the given range.
 
template<typename range_t >
static QList< VertextoVertexList (const range_t &range)
 

Protected Attributes

MeaningOfDirection direction = ParentToChild
 
GraphContainer graph
 

Member Enumeration Documentation

◆ AdjacencyFlags

template<class VertexProperties , class EdgeProperties >
enum Digikam::Graph::AdjacencyFlags
Enumerator
EdgesToLeaf 

These resolve to one of the flags above, depending on MeaningOfDirection.

Member Function Documentation

◆ edgeDifference()

template<class VertexProperties , class EdgeProperties >
QList< Edge > Digikam::Graph< VertexProperties, EdgeProperties >::edgeDifference ( const Graph< VertexProperties, EdgeProperties > &  other,
const std::vector< vertex_t > &  copiedVertices 
) const
inlineprotected

copiedVertices maps the vertices of this graph to other.

◆ leaves()

template<class VertexProperties , class EdgeProperties >
QList< Vertex > Digikam::Graph< VertexProperties, EdgeProperties >::leaves ( ) const
inline

vertices with no children Takes the graph direction into account.

◆ listPath()

template<class VertexProperties , class EdgeProperties >
QList< Vertex > Digikam::Graph< VertexProperties, EdgeProperties >::listPath ( const Vertex root,
const Vertex target,
const VertexVertexMap predecessors,
MeaningOfDirection  dir = ParentToChild 
) const
inlineprotected

Depending on MeaningOfDirection, the ids are listed inverted, from target to root.

◆ longestPathTouching()

template<class VertexProperties , class EdgeProperties >
QList< Vertex > Digikam::Graph< VertexProperties, EdgeProperties >::longestPathTouching ( const Vertex v) const
inline

The returned list is given in that order, root - v - leave. If there is more than one candidate for root or leave, lessThan is used to determine the first candidate.

◆ roots()

template<class VertexProperties , class EdgeProperties >
QList< Vertex > Digikam::Graph< VertexProperties, EdgeProperties >::roots ( ) const
inline

vertices with no parents. Takes the graph direction into account.

◆ rootsOf()

template<class VertexProperties , class EdgeProperties >
QList< Vertex > Digikam::Graph< VertexProperties, EdgeProperties >::rootsOf ( const Vertex v) const
inline

Subset of roots(). I case any leaves have roots that are not roots of v, they will not be contained in this list.

◆ shortestDistancesFrom()

template<class VertexProperties , class EdgeProperties >
QMap< Vertex, int > Digikam::Graph< VertexProperties, EdgeProperties >::shortestDistancesFrom ( const Vertex v) const
inline

If the value is -1, a vertex is not reachable from v.

◆ shortestPath()

template<class VertexProperties , class EdgeProperties >
QList< Vertex > Digikam::Graph< VertexProperties, EdgeProperties >::shortestPath ( const Vertex v1,
const Vertex v2 
) const
inline

If s2 is not reachable from s1, the path is searched from s2 to s1. The returned list always starts with s1, contains the intermediate vertices, and ends with s2. If no path is available, an empty list is returned.

◆ transitiveReduction()

template<class VertexProperties , class EdgeProperties >
Graph Digikam::Graph< VertexProperties, EdgeProperties >::transitiveReduction ( QList< Edge > *  removedEdges = 0,
GraphCopyFlags  flags = CopyAllProperties 
) const
inline

Optionally, a list of edges of this graph that have been removed in the returned graph is given.

◆ vertexCount()

template<class VertexProperties , class EdgeProperties >
int Digikam::Graph< VertexProperties, EdgeProperties >::vertexCount ( ) const
inline
Note
for "hasAdjacentVertices", simply use hasEdges(v, flags).

◆ verticesBreadthFirst()

template<class VertexProperties , class EdgeProperties >
QList< Vertex > Digikam::Graph< VertexProperties, EdgeProperties >::verticesBreadthFirst ( const Vertex givenRef = Vertex()) const
inline

A single vertex is taken as reference to distinguish main root and side paths. Otherwise the first root is taken as reference.

◆ verticesDepthFirstSorted()

template<class VertexProperties , class EdgeProperties >
template<typename LessThan >
QList< Vertex > Digikam::Graph< VertexProperties, EdgeProperties >::verticesDepthFirstSorted ( const Vertex givenRef,
LessThan  lessThan 
) const
inline

When discovering a vertex, the adjacent vertices are sorted with the given lessThan. A single vertex is taken as starting point. If null, the first root is taken as reference.

◆ verticesDominatedBy()

template<class VertexProperties , class EdgeProperties >
QList< Vertex > Digikam::Graph< VertexProperties, EdgeProperties >::verticesDominatedBy ( const Vertex v,
const Vertex root,
const QList< Vertex > &  presortedVertices 
) const
inline

The order is the same as in the given, sorted list of all vertices in this graph (or all vertices expected to be returned. The returned list is the intersection of the dominated vertices and presortedVertices, in order of presortedVertices).

Remove all vertices from the DFS of v that are not in the dominated tree.

◆ verticesDominatedByDepthFirstSorted()

template<class VertexProperties , class EdgeProperties >
template<typename LessThan >
QList< Vertex > Digikam::Graph< VertexProperties, EdgeProperties >::verticesDominatedByDepthFirstSorted ( const Vertex v,
const Vertex root,
LessThan  lessThan 
) const
inline

The returned list is in depth-first order, using root as starting point, and when discovering a vertex, sorting the adjacent vertices with the given lessThan.