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
34#include <ogdf/basic/Graph.h>
41
42#include <algorithm>
43#include <cstdint>
44#include <string>
45
46namespace ogdf {
47
55template<typename TWeight>
57public:
59 virtual bool preconditionsOk(const GraphAttributes& GA, double stretch,
60 std::string& error) override {
61 if (!isSimple(GA.constGraph())) {
62 error = "The graph is not simple";
63 return false;
64 }
65 if (stretch < 1.0) {
66 error = "The stretch must be >= 1.0";
67 return false;
68 }
69 return true;
70 }
71
72private:
74 virtual typename SpannerModule<TWeight>::ReturnType execute() override {
75 const Graph& G = m_GA->constGraph();
76
77 if (G.numberOfNodes() == 0) {
79 }
80
81 Graph::CCsInfo ccsInfo(G);
82 SpannerBerman<TWeight> spannerBerman;
83
84 for (int c = 0; c < ccsInfo.numberOfCCs(); c++) {
86
88 GC.setOriginalGraph(G);
89 NodeArray<node> nodeMap(G, nullptr);
90 EdgeArray<edge> edgeMap(G, nullptr);
91 GC.insert(ccsInfo, c, nodeMap, edgeMap);
92
93 GraphCopySimple spanner(GC);
94 EdgeArray<bool> inSpanner;
95 GraphAttributes GCA(GC, 0);
96 GCA.directed() = m_GA->directed();
99 for (edge e : GC.edges) {
100 GCA.intWeight(e) = m_GA->intWeight(GC.original(e));
101 }
102 }
105 for (edge e : GC.edges) {
106 GCA.doubleWeight(e) = m_GA->doubleWeight(GC.original(e));
107 }
108 }
109
110 if (isTimelimitEnabled()) {
111 int64_t timeLeft = max(getTimeLeft(), static_cast<int64_t>(0));
112 spannerBerman.setTimelimit(timeLeft);
113 }
115 spannerBerman.call(GCA, m_stretch, spanner, inSpanner);
117 return r;
118 }
119
120 // copy used edges to m_spanner and m_inSpanner
121 for (edge e : spanner.edges) {
122 edge eOrig = GC.original(spanner.original(e));
123 (*m_inSpanner)[eOrig] = true;
124 m_spanner->newEdge(eOrig);
125 }
126 }
127
129 }
130
131 using SpannerModule<TWeight>::getWeight;
132 using SpannerModule<TWeight>::assertTimeLeft;
133 using SpannerModule<TWeight>::getTimeLeft;
135 using SpannerModule<TWeight>::m_GA;
136 using SpannerModule<TWeight>::m_stretch;
137 using SpannerModule<TWeight>::m_spanner;
138 using SpannerModule<TWeight>::m_inSpanner;
139};
140
141}
Includes declaration of graph class.
Declaration of class GraphAttributes which extends a Graph by additional attributes.
Declaration of graph copy classes.
Decralation of GraphElement and GraphList classes.
Implementation of an k-spanner approximation algorithm from Berman et al.
Basic module for spanner algorithms.
Class for the representation of edges.
Definition Graph_d.h:364
Info structure for maintaining connected components.
Definition Graph_d.h:1896
int numberOfCCs() const
Returns the number of connected components.
Definition Graph_d.h:1916
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).
void addAttributes(long attr)
Enables attributes specified by attr and allocates required memory.
bool has(long attr) const
Returns true iff all attributes in attr are available.
static const long edgeIntWeight
Corresponds to edge attribute intWeight(edge).
const Graph & original() const
Returns a reference to the original graph.
Definition GraphCopy.h:104
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
void setOriginalGraph(const Graph *G) override
Re-initializes the copy using G (which might be null), but does not create any nodes or edges.
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition Graph_d.h:932
std::pair< int, int > insert(const NI &nodesBegin, const NI &nodesEnd, const EI &edgesBegin, const EI &edgesEnd, NodeArray< node > &nodeMap, EdgeArray< edge > &edgeMap)
Inserts a copy of a given subgraph into this graph.
ReturnType
The return type of a module.
Definition Module.h:52
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.
virtual ReturnType call(const GraphAttributes &GA, double stretch, GraphCopySimple &spanner, EdgeArray< bool > &inSpanner)
Executes the algorithm.
const GraphAttributes * m_GA
EdgeArray< bool > * m_inSpanner
void setTimelimit(int64_t milliseconds)
Sets the timelimit for the algorithm in milliseconds.
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
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
bool isSimple(const Graph &G)
Returns true iff G contains neither self-loops nor parallel edges.
The namespace for all OGDF objects.
Declaration of simple graph algorithms.