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/NodeSet.h>
36
37namespace ogdf {
38
59template<typename TWeight>
60class SpannerBasicGreedy : public SpannerModule<TWeight> {
63
64public:
66 virtual bool preconditionsOk(const GraphAttributes& GA, double stretch,
67 std::string& error) override {
68 if (GA.directed()) {
69 error = "The graph must be undirected";
70 return false;
71 }
72 if (stretch < 1.0) {
73 error = "The stretch must be >= 1.0";
74 return false;
75 }
76 return true;
77 }
78
79private:
85
86 virtual typename SpannerModule<TWeight>::ReturnType execute() override {
88 int i = 0;
89 for (edge e : m_GA->constGraph().edges) {
90 edges[i++] = e;
91 }
93
95
96 for (edge e : edges) {
97 node u = m_spanner->copy(e->source());
98 node v = m_spanner->copy(e->target());
99 double maxDistance = m_stretch * weight(e);
102 edge newEdge = m_spanner->newEdge(e);
103 m_spannerWeights[newEdge] = weight(e);
104 (*m_inSpanner)[e] = true;
105 }
107 }
108
110 }
111
113
117 inline TWeight weight(edge e) { return getWeight(*m_GA, e); }
118
133
140};
141
142}
Declaration and implementation of ogdf::NodeSet.
Basic module for spanner algorithms.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:214
void quicksort()
Sorts array using Quicksort.
Definition Array.h:634
Dynamic arrays indexed with edges.
Definition EdgeArray.h:125
void init()
Reinitializes the array. Associates the array with no graph.
Definition EdgeArray.h:292
Class for the representation of edges.
Definition Graph_d.h:300
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:57
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).
const Graph & constGraph() const
Returns a reference to the associated graph.
Copies of graphs with mapping between nodes and edges.
Definition GraphCopy.h:59
edge newEdge(edge eOrig)
Creates a new edge in the graph copy with original edge eOrig.
Definition GraphCopy.h:188
node copy(node v) const
Returns the node in the graph copy corresponding to v.
Definition GraphCopy.h:124
int numberOfEdges() const
Returns the number of edges in the graph.
Definition Graph_d.h:625
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition Graph_d.h:592
ReturnType
The return type of a module.
Definition Module.h:50
Class for the representation of nodes.
Definition Graph_d.h:177
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
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
EdgeWeightComparator(const EdgeWeightComparator &)=delete
EdgeWeightComparator & operator=(const EdgeWeightComparator &)=delete