Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Voronoi.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/ArrayBuffer.h>
35 #include <ogdf/basic/Graph.h>
36 #include <ogdf/basic/GraphList.h>
37 #include <ogdf/basic/List.h>
38 #include <ogdf/graphalg/Dijkstra.h>
39 
40 #include <map>
41 
42 namespace ogdf {
43 
45 
48 template<typename T>
49 class Voronoi {
50 protected:
54  std::map<node, ArrayBuffer<node>> m_nodeList;
55  const Graph& m_graph;
57 
58  void computeVoronoiRegions(const Graph& G, const EdgeArray<T>& weights, const List<node>& seeds);
59 
60 public:
65  Voronoi(const Graph& G, const EdgeArray<T>& weights, const List<node>& seeds)
66  : m_seedOfNode(G), m_nodeList(), m_graph(G), m_seeds(seeds) {
67  computeVoronoiRegions(G, weights, seeds);
68  }
69 
71  const Graph& getGraph() const { return m_graph; }
72 
74  const List<node>& getSeeds() const { return m_seeds; }
75 
78  edge predecessorEdge(node v) const { return m_predecessor[v]; }
79 
81  node predecessor(node v) const {
82  edge tmp = predecessorEdge(v);
83  return tmp ? tmp->opposite(v) : nullptr;
84  }
85 
87  T distance(node v) const { return m_distance[v]; }
88 
90  node seed(node v) const { return m_seedOfNode[v]; }
91 
94  return m_nodeList.find(seed(v))->second;
95  }
96 };
97 
99 
100 template<typename T>
102  const List<node>& seeds) {
103  Dijkstra<T> sssp;
104  sssp.call(G, weights, seeds, m_predecessor, m_distance);
105 
106  // extract Voronoi seeds for each node and Voronoi regions for each seed
107  NodeArray<bool> processed(G, false);
108  for (node seed : seeds) {
109  processed[seed] = true;
110  m_seedOfNode[seed] = seed;
111  m_nodeList[seed].push(seed);
112  }
113 
114  for (node u : G.nodes) {
115  ArrayBuffer<node> foundNodes;
116  node v;
117  for (v = u; !processed[v]; v = predecessor(v)) {
118  processed[v] = true;
119  foundNodes.push(v);
120  }
121 
122  for (node passedNode : foundNodes) {
123  m_seedOfNode[passedNode] = m_seedOfNode[v];
124  m_nodeList[m_seedOfNode[v]].push(passedNode);
125  }
126  }
127 }
128 
129 }
ogdf::ArrayBuffer
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition: Array.h:53
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ArrayBuffer.h
Declaration and implementation of ArrayBuffer class.
ogdf::Voronoi::m_seedOfNode
NodeArray< node > m_seedOfNode
Definition: Voronoi.h:53
Graph.h
Includes declaration of graph class.
ogdf::Voronoi::getGraph
const Graph & getGraph() const
Returns a reference to the graph the Voronoi region has been computed for.
Definition: Voronoi.h:71
ogdf::Voronoi
Computes Voronoi regions in an edge-weighted graph.
Definition: Voronoi.h:49
ogdf::Voronoi::m_nodeList
std::map< node, ArrayBuffer< node > > m_nodeList
Definition: Voronoi.h:54
ogdf::Voronoi::m_graph
const Graph & m_graph
Definition: Voronoi.h:55
ogdf::Voronoi::predecessorEdge
edge predecessorEdge(node v) const
Returns the edge incident to v and its predecessor. Note that the predecessor of a terminal is nullpt...
Definition: Voronoi.h:78
ogdf::Voronoi::nodesInRegion
const ArrayBuffer< node > & nodesInRegion(node v) const
Returns the list of nodes in the Voronoi region of node v.
Definition: Voronoi.h:93
ogdf::Dijkstra
Dijkstra's single source shortest path algorithm.
Definition: Dijkstra.h:60
ogdf::Voronoi::getSeeds
const List< node > & getSeeds() const
Returns a reference to the list of seeds the Voronoi region has been computed for.
Definition: Voronoi.h:74
GraphList.h
Decralation of GraphElement and GraphList classes.
ogdf::Dijkstra::call
void call(const Graph &G, const EdgeArray< T > &weight, const List< node > &sources, NodeArray< edge > &predecessor, NodeArray< T > &distance, bool directed=false, bool arcsReversed=false, node target=nullptr, T maxLength=std::numeric_limits< T >::max())
Calculates, based on the graph G with corresponding edge costs and source nodes, the shortest paths a...
Definition: Dijkstra.h:253
ogdf::ArrayBuffer::push
void push(E e)
Puts a new element in the buffer.
Definition: ArrayBuffer.h:217
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: DfsMakeBiconnected.h:40
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::Voronoi::computeVoronoiRegions
void computeVoronoiRegions(const Graph &G, const EdgeArray< T > &weights, const List< node > &seeds)
Definition: Voronoi.h:101
ogdf::Voronoi::distance
T distance(node v) const
Returns the distance between v and its Voronoi seed.
Definition: Voronoi.h:87
ogdf::Voronoi::Voronoi
Voronoi(const Graph &G, const EdgeArray< T > &weights, const List< node > &seeds)
Build data structure to query Voronoi regions of edge-weighted graph G with given Voronoi seeds.
Definition: Voronoi.h:65
ogdf::EdgeElement::opposite
node opposite(node v) const
Returns the adjacent node different from v.
Definition: Graph_d.h:413
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
Dijkstra.h
Implementation of Dijkstra's single source shortest path algorithm.
List.h
Declaration of doubly linked lists and iterators.
ogdf::Voronoi::m_predecessor
NodeArray< edge > m_predecessor
Definition: Voronoi.h:51
ogdf::Voronoi::m_seeds
const List< node > & m_seeds
Definition: Voronoi.h:56
ogdf::Voronoi::predecessor
node predecessor(node v) const
Returns the nearest node to v on the shortest path to its Voronoi seed.
Definition: Voronoi.h:81
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::Voronoi::seed
node seed(node v) const
Returns the Voronoi seed of node v.
Definition: Voronoi.h:90
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716
ogdf::Voronoi::m_distance
NodeArray< T > m_distance
Definition: Voronoi.h:52