Loading [MathJax]/extensions/tex2jax.js

Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
SpannerIteratedWrapper.h
Go to the documentation of this file.
1
31#pragma once
32
34
35#include <memory>
36
37namespace ogdf {
38
57template<typename TWeight>
58class SpannerIteratedWrapper : public SpannerModule<TWeight> {
59public:
69
71 virtual bool preconditionsOk(const GraphAttributes& GA, double stretch,
72 std::string& error) override {
73 return m_module->preconditionsOk(GA, stretch, error);
74 }
75
80
81private:
82 std::unique_ptr<SpannerModule<TWeight>> m_module;
83 const int m_maxIterations;
85
87 virtual typename SpannerModule<TWeight>::ReturnType execute() override {
88 const Graph& G = m_GA->constGraph();
89 if (isTimelimitEnabled()) {
90 int64_t timeLeft = max(getTimeLeft(), static_cast<int64_t>(0));
91 m_module->setTimelimit(timeLeft);
92 }
93
94 int bestSize = std::numeric_limits<int>::max();
95
97 // No assertTimeLeft here: If there is an timeout, check, if we had a previous solution
98 if (isTimelimitEnabled() && getTimeLeft() <= 0) {
99 if (bestSize == std::numeric_limits<int>::max()) {
101 } else {
103 }
104 }
105
108
112 continue;
113 }
115 // do we found at least one solution?
116 if (bestSize == std::numeric_limits<int>::max()) {
118 } else {
120 }
121 }
123 return r; // return errors directly
124 }
125
126 if (spanner.numberOfEdges() < bestSize) {
127 // found a new best solution
128 bestSize = spanner.numberOfEdges();
129
130 // Copy solution to the members
131 m_spanner->clear();
133 for (node n : G.nodes) {
134 m_spanner->newNode(n);
135 }
136 m_inSpanner->init(G, false);
137
138 for (edge e : spanner.edges) {
139 edge eOrig = spanner.original(e);
140 (*m_inSpanner)[eOrig] = true;
142 }
143 }
144 }
145 m_iterations--; // remove the overflow iteration, which is not executed
146
147 if (bestSize == std::numeric_limits<int>::max()) {
149 } else {
151 }
152 }
153
160};
161
162}
Basic module for spanner algorithms.
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
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 newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
Definition GraphCopy.h:173
void createEmpty(const Graph &G)
Re-initializes the copy using G, but does not create any nodes or edges.
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
virtual void clear()
Removes all nodes and all edges from the graph.
ReturnType
The return type of a module.
Definition Module.h:50
Class for the representation of nodes.
Definition Graph_d.h:177
A implementation-independed wrapper class to execute a spanner algorithm multiple times.
virtual SpannerModule< TWeight >::ReturnType execute() override
Executes the core algorithm.
std::unique_ptr< SpannerModule< TWeight > > m_module
SpannerIteratedWrapper(SpannerModule< TWeight > *module, int maxIterations)
Initializes the wrapper.
virtual bool preconditionsOk(const GraphAttributes &GA, double stretch, std::string &error) override
Interface for spanner algorithms.
const GraphAttributes * m_GA
EdgeArray< bool > * m_inSpanner
GraphCopySimple * m_spanner
int r[]
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.