Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
SpannerBermanDisconnected.h
Go to the documentation of this file.
1
32#pragma once
33
37
38namespace ogdf {
39
47template<typename TWeight>
49public:
51 virtual bool preconditionsOk(const GraphAttributes& GA, double stretch,
52 std::string& error) override {
53 if (!isSimple(GA.constGraph())) {
54 error = "The graph is not simple";
55 return false;
56 }
57 if (stretch < 1.0) {
58 error = "The stretch must be >= 1.0";
59 return false;
60 }
61 return true;
62 }
63
64private:
66 virtual typename SpannerModule<TWeight>::ReturnType execute() override {
67 const Graph& G = m_GA->constGraph();
68
69 if (G.numberOfNodes() == 0) {
71 }
72
75
77
78 for (int c = 0; c < amountComponenets; c++) {
80
81 List<node> nodes;
82 for (node n : G.nodes) {
83 if (components[n] == c) {
84 nodes.pushBack(n);
85 }
86 }
87
89 GC.createEmpty(G);
90 inducedSubGraph(G, nodes.begin(), GC);
91
95 GCA.directed() = m_GA->directed();
98 for (edge e : GC.edges) {
99 GCA.intWeight(e) = m_GA->intWeight(GC.original(e));
100 }
101 }
104 for (edge e : GC.edges) {
105 GCA.doubleWeight(e) = m_GA->doubleWeight(GC.original(e));
106 }
107 }
108
109 if (isTimelimitEnabled()) {
110 int64_t timeLeft = max(getTimeLeft(), static_cast<int64_t>(0));
111 spannerBerman.setTimelimit(timeLeft);
112 }
116 return r;
117 }
118
119 // copy used edges to m_spanner and m_inSpanner
120 for (edge e : spanner.edges) {
121 edge eOrig = GC.original(spanner.original(e));
122 (*m_inSpanner)[eOrig] = true;
124 }
125 }
126
128 }
129
138};
139
140}
Implementation of an k-spanner approximation algorithm from Berman et al.
Basic module for spanner algorithms.
Dynamic arrays indexed with edges.
Definition EdgeArray.h:125
Class for the representation of edges.
Definition Graph_d.h:300
Stores additional attributes of a graph (like layout information).
int intWeight(edge e) const
Returns the (integer) weight of edge e.
bool directed() const
Returns if the graph is directed.
const Graph & constGraph() const
Returns a reference to the associated graph.
double doubleWeight(edge e) const
Returns the (real number) weight of edge e.
static const long edgeDoubleWeight
Corresponds to edge attribute doubleWeight(edge).
bool has(long attr) const
Returns true iff all attributes in attr are available.
static const long edgeIntWeight
Corresponds to edge attribute intWeight(edge).
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
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
Doubly linked lists (maintaining the length of the list).
Definition List.h:1435
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition List.h:1531
iterator begin()
Returns an iterator to the first element of the list.
Definition List.h:375
ReturnType
The return type of a module.
Definition Module.h:50
Dynamic arrays indexed with nodes.
Definition NodeArray.h:125
Class for the representation of nodes.
Definition Graph_d.h:177
Wrapper around SpannerBerman: For each component of the graph, the algorithm will be called.
virtual SpannerModule< TWeight >::ReturnType execute() override
Executes the core algorithm.
virtual bool preconditionsOk(const GraphAttributes &GA, double stretch, std::string &error) override
Approximation algorithm for calculating spanners.
Interface for spanner algorithms.
void assertTimeLeft()
Assert, that time is left.
const GraphAttributes * m_GA
EdgeArray< bool > * m_inSpanner
static TWeight getWeight(const GraphAttributes &GA, edge e)
GraphCopySimple * m_spanner
int connectedComponents(const Graph &G, NodeArray< int > &component, List< node > *isolated=nullptr)
Computes the connected components of G and optionally generates a list of isolated nodes.
void inducedSubGraph(const Graph &G, LISTITERATOR start, Graph &subGraph)
Computes the subgraph induced by a list of nodes.
bool isSimple(const Graph &G)
Returns true iff G contains neither self-loops nor parallel edges.
int r[]
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
Declaration of simple graph algorithms.