Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

Voronoi.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/List.h>
35 #include <ogdf/graphalg/Dijkstra.h>
36 #include <map>
37 
38 namespace ogdf {
39 
41 
44 template<typename T>
45 class Voronoi {
46 protected:
50  std::map< node, List<node> > m_nodeList;
51 
52  void computeVoronoiRegions(const Graph &G, const EdgeArray<T> &weights, const List<node> &seeds);
53 
54 public:
59  Voronoi(const Graph &G, const EdgeArray<T> &weights, const List<node> &seeds)
60  : m_seedOfNode(G)
61  , m_nodeList()
62  {
63  computeVoronoiRegions(G, weights, seeds);
64  }
65 
68  {
69  return m_predecessor[v];
70  }
71 
74  {
75  edge tmp = predecessorEdge(v);
76  return (tmp ? tmp->opposite(v) : nullptr);
77  }
78 
80  T distance(node v) const
81  {
82  return m_distance[v];
83  }
84 
86  node seed(node v) const
87  {
88  return m_seedOfNode[v];
89  }
90 
92  const List<node> &nodesInRegion(node v) const
93  {
94  return m_nodeList.find(seed(v))->second;
95  }
96 };
97 
99 
100 template<typename T>
101 void Voronoi<T>::computeVoronoiRegions(const Graph &G, const EdgeArray<T> &weights, const List<node> &seeds)
102 {
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;
111  m_nodeList[seed].pushBack(seed);
112  }
113 
114  for (node u : G.nodes) {
115  List<node> foundNodes;
116  node v;
117  for (v = u; !processed[v]; v = predecessor(v)) {
118  processed[v] = true;
119  foundNodes.pushBack(v);
120  }
121 
122  for (node passedNode : foundNodes) {
123  m_seedOfNode[passedNode] = m_seedOfNode[v];
124  m_nodeList[m_seedOfNode[v]].pushBack(passedNode);
125  }
126  }
127 }
128 
129 } // end namespace ogdf
Dijkstra&#39;s single source shortest path algorithm.
Definition: Dijkstra.h:52
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1316
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
NodeArray< node > m_seedOfNode
Definition: Voronoi.h:49
void call(const Graph &G, const EdgeArray< T > &weight, const List< node > &sources, NodeArray< edge > &predecessor, NodeArray< T > &distance, bool directed=false)
Calculates, based on the graph G with corresponding edge costs and source nodes, the shortest paths a...
Definition: Dijkstra.h:61
Dynamic arrays indexed with edges.
Definition: EdgeArray.h:112
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:59
void computeVoronoiRegions(const Graph &G, const EdgeArray< T > &weights, const List< node > &seeds)
Definition: Voronoi.h:101
Computes Voronoi regions in an edge weighted graph.
Definition: Voronoi.h:45
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:423
Implementation of Dijkstra&#39;s single source shortest path algorithm.
Doubly linked lists (maintaining the length of the list).
Definition: List.h:39
node seed(node v) const
Returns the Voronoi seed of node v.
Definition: Voronoi.h:86
const List< node > & nodesInRegion(node v) const
Returns the list of nodes in the Voronoi region of node v.
Definition: Voronoi.h:92
Class for the representation of edges.
Definition: Graph_d.h:291
T distance(node v) const
Returns the distance between v and its Voronoi seed.
Definition: Voronoi.h:80
NodeArray< edge > m_predecessor
Definition: Voronoi.h:47
Class for the representation of nodes.
Definition: Graph_d.h:167
node opposite(node v) const
Returns the adjacent node different from v.
Definition: Graph_d.h:335
node predecessor(node v) const
Returns the nearest node to v on the shortest path to its Voronoi seed.
Definition: Voronoi.h:73
NodeArray< T > m_distance
Definition: Voronoi.h:48
The namespace for all OGDF objects.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:545
std::map< node, List< node > > m_nodeList
Definition: Voronoi.h:50
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:67
Declaration of doubly linked lists and iterators.