Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
SpannerBasicGreedy.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Array.h>
36#include <ogdf/basic/Graph.h>
38#include <ogdf/basic/basic.h>
40
41#include <string>
42
43namespace ogdf {
44class GraphCopySimple;
45
66template<typename TWeight>
67class SpannerBasicGreedy : public SpannerModule<TWeight> {
70
71public:
73 virtual bool preconditionsOk(const GraphAttributes& GA, double stretch,
74 std::string& error) override {
75 if (GA.directed()) {
76 error = "The graph must be undirected";
77 return false;
78 }
79 if (stretch < 1.0) {
80 error = "The stretch must be >= 1.0";
81 return false;
82 }
83 return true;
84 }
85
86private:
87 virtual void init(const GraphAttributes& GA, double stretch, GraphCopySimple& spanner,
88 EdgeArray<bool>& inSpanner) override {
89 SpannerModule<TWeight>::init(GA, stretch, spanner, inSpanner);
90 m_spannerWeights.init(spanner);
91 }
92
93 virtual typename SpannerModule<TWeight>::ReturnType execute() override {
95 int i = 0;
96 for (edge e : m_GA->constGraph().edges) {
97 edges[i++] = e;
98 }
100
102
103 for (edge e : edges) {
104 node u = m_spanner->copy(e->source());
105 node v = m_spanner->copy(e->target());
106 double maxDistance = m_stretch * weight(e);
107 double currentSpannerDistance = distanceInSpanner(u, v, maxDistance);
108 if (m_eps.greater(currentSpannerDistance, maxDistance)) {
109 edge newEdge = m_spanner->newEdge(e);
110 m_spannerWeights[newEdge] = weight(e);
111 (*m_inSpanner)[e] = true;
112 }
114 }
115
117 }
118
119 OGDF_EXPORT double distanceInSpanner(node s, node t, double maxLookupDist);
120
124 inline TWeight weight(edge e) { return getWeight(*m_GA, e); }
125
131
132 bool less(edge a, edge b) const {
133 return m_eps.less(getWeight(m_GA, a), getWeight(m_GA, b));
134 }
135
136 private:
139 };
140
141 using SpannerModule<TWeight>::getWeight;
142 using SpannerModule<TWeight>::assertTimeLeft;
143 using SpannerModule<TWeight>::m_GA;
144 using SpannerModule<TWeight>::m_stretch;
145 using SpannerModule<TWeight>::m_spanner;
146 using SpannerModule<TWeight>::m_inSpanner;
147};
148
149}
Declaration and implementation of Array class and Array algorithms.
Compare floating point numbers with epsilons and integral numbers with normal compare operators.
Includes declaration of graph class.
Declaration of class GraphAttributes which extends a Graph by additional attributes.
Basic module for spanner algorithms.
Basic declarations, included by all source files.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:219
void quicksort()
Sorts array using Quicksort.
Definition Array.h:639
Class for the representation of edges.
Definition Graph_d.h:364
std::enable_if< std::is_integral< T >::value, bool >::type less(const T &x, const T &y) const
Compare if x is LESS than y for integral types.
Definition EpsilonTest.h:55
std::enable_if< std::is_integral< T >::value, bool >::type greater(const T &x, const T &y) const
Compare if x is GREATER than y for integral types.
Stores additional attributes of a graph (like layout information).
bool directed() const
Returns if the graph is directed.
const Graph & constGraph() const
Returns a reference to the associated graph.
Copies of graphs with mapping between nodes and edges.
Definition GraphCopy.h:260
edge newEdge(edge eOrig)
Creates a new edge in the graph copy with original edge eOrig.
Definition GraphCopy.h:320
edge copy(edge e) const override
Returns the edge in the graph copy corresponding to e.
Definition GraphCopy.h:294
int numberOfEdges() const
Returns the number of edges in the graph.
Definition Graph_d.h:982
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition Graph_d.h:932
ReturnType
The return type of a module.
Definition Module.h:52
Class for the representation of nodes.
Definition Graph_d.h:241
Multiplicative spanner by greedily adding edges.
virtual void init(const GraphAttributes &GA, double stretch, GraphCopySimple &spanner, EdgeArray< bool > &inSpanner) override
Initializes members and create an empty spanner.
double distanceInSpanner(node s, node t, double maxLookupDist)
virtual SpannerModule< TWeight >::ReturnType execute() override
Executes the core algorithm.
EdgeArray< TWeight > m_spannerWeights
virtual bool preconditionsOk(const GraphAttributes &GA, double stretch, std::string &error) override
Interface for spanner algorithms.
void assertTimeLeft()
Assert, that time is left.
virtual void init(const GraphAttributes &GA, double stretch, GraphCopySimple &spanner, EdgeArray< bool > &inSpanner)
Initializes members and create an empty spanner.
const GraphAttributes * m_GA
EdgeArray< bool > * m_inSpanner
static TWeight getWeight(const GraphAttributes &GA, edge e)
GraphCopySimple * m_spanner
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
The namespace for all OGDF objects.
EdgeWeightComparator(const EdgeWeightComparator &)=delete
EdgeWeightComparator & operator=(const EdgeWeightComparator &)=delete