Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

SpannerBermanDisconnected.h
Go to the documentation of this file.
1 
32 #pragma once
33 
37 
38 namespace ogdf {
39 
47 template<typename TWeight>
48 class SpannerBermanDisconnected : public SpannerModule<TWeight> {
49 public:
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 
64 private:
66  virtual typename SpannerModule<TWeight>::ReturnType execute() override {
67  const Graph& G = m_GA->constGraph();
68 
69  if (G.numberOfNodes() == 0) {
71  }
72 
73  Graph::CCsInfo ccsInfo(G);
74  SpannerBerman<TWeight> spannerBerman;
75 
76  for (int c = 0; c < ccsInfo.numberOfCCs(); c++) {
78 
79  GraphCopySimple GC;
80  GC.setOriginalGraph(G);
81  NodeArray<node> nodeMap(G, nullptr);
82  EdgeArray<edge> edgeMap(G, nullptr);
83  GC.insert(ccsInfo, c, nodeMap, edgeMap);
84 
85  GraphCopySimple spanner(GC);
86  EdgeArray<bool> inSpanner;
87  GraphAttributes GCA(GC, 0);
88  GCA.directed() = m_GA->directed();
91  for (edge e : GC.edges) {
92  GCA.intWeight(e) = m_GA->intWeight(GC.original(e));
93  }
94  }
97  for (edge e : GC.edges) {
98  GCA.doubleWeight(e) = m_GA->doubleWeight(GC.original(e));
99  }
100  }
101 
102  if (isTimelimitEnabled()) {
103  int64_t timeLeft = max(getTimeLeft(), static_cast<int64_t>(0));
104  spannerBerman.setTimelimit(timeLeft);
105  }
107  spannerBerman.call(GCA, m_stretch, spanner, inSpanner);
109  return r;
110  }
111 
112  // copy used edges to m_spanner and m_inSpanner
113  for (edge e : spanner.edges) {
114  edge eOrig = GC.original(spanner.original(e));
115  (*m_inSpanner)[eOrig] = true;
116  m_spanner->newEdge(eOrig);
117  }
118  }
119 
121  }
122 
131 };
132 
133 }
ogdf::GraphAttributes::edgeIntWeight
static const long edgeIntWeight
Corresponds to edge attribute intWeight(edge).
Definition: GraphAttributes.h:119
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::GraphAttributes
Stores additional attributes of a graph (like layout information).
Definition: GraphAttributes.h:66
ogdf::SpannerModule::isTimelimitEnabled
bool isTimelimitEnabled()
Definition: SpannerModule.h:161
SpannerBerman.h
Implementation of an k-spanner approximation algorithm from Berman et al.
ogdf::Graph::CCsInfo
Info structure for maintaining connected components.
Definition: Graph_d.h:1900
ogdf::SpannerModule::m_spanner
GraphCopySimple * m_spanner
Definition: SpannerModule.h:130
ogdf::SpannerModule::assertTimeLeft
void assertTimeLeft()
Assert, that time is left.
Definition: SpannerModule.h:172
ogdf::GraphCopySimple
Copies of graphs with mapping between nodes and edges.
Definition: GraphCopy.h:254
ogdf::SpannerBermanDisconnected
Wrapper around SpannerBerman: For each component of the graph, the algorithm will be called.
Definition: SpannerBermanDisconnected.h:48
ogdf::GraphCopySimple::setOriginalGraph
void setOriginalGraph(const Graph *G) override
Re-initializes the copy using G (which might be null), but does not create any nodes or edges.
ogdf::GraphAttributes::directed
bool directed() const
Returns if the graph is directed.
Definition: GraphAttributes.h:226
ogdf::GraphAttributes::constGraph
const Graph & constGraph() const
Returns a reference to the associated graph.
Definition: GraphAttributes.h:217
SpannerModule.h
Basic module for spanner algorithms.
ogdf::SpannerModule::setTimelimit
void setTimelimit(int64_t milliseconds)
Sets the timelimit for the algorithm in milliseconds.
Definition: SpannerModule.h:120
r
int r[]
Definition: hierarchical-ranking.cpp:8
ogdf::SpannerModule::getTimeLeft
int64_t getTimeLeft()
Definition: SpannerModule.h:166
ogdf::SpannerBermanDisconnected::execute
virtual SpannerModule< TWeight >::ReturnType execute() override
Executes the core algorithm.
Definition: SpannerBermanDisconnected.h:66
ogdf::SpannerModule::m_stretch
double m_stretch
Definition: SpannerModule.h:129
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:651
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:862
ogdf::SpannerModule
Interface for spanner algorithms.
Definition: SpannerModule.h:57
ogdf::GraphAttributes::addAttributes
void addAttributes(long attr)
Enables attributes specified by attr and allocates required memory.
ogdf::SpannerBerman
Approximation algorithm for calculating spanners.
Definition: SpannerBerman.h:77
ogdf::Graph::insert
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.
Definition: InducedSubgraph.h:93
ogdf::Graph::edges
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition: Graph_d.h:927
ogdf::SpannerModule::m_GA
const GraphAttributes * m_GA
Definition: SpannerModule.h:128
ogdf::SpannerModule::call
virtual ReturnType call(const GraphAttributes &GA, double stretch, GraphCopySimple &spanner, EdgeArray< bool > &inSpanner)
Executes the algorithm.
Definition: SpannerModule.h:86
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:356
ogdf::GraphAttributes::intWeight
int intWeight(edge e) const
Returns the (integer) weight of edge e.
Definition: GraphAttributes.h:768
ogdf::GraphAttributes::edgeDoubleWeight
static const long edgeDoubleWeight
Corresponds to edge attribute doubleWeight(edge).
Definition: GraphAttributes.h:122
ogdf::GraphAttributes::doubleWeight
double doubleWeight(edge e) const
Returns the (real number) weight of edge e.
Definition: GraphAttributes.h:786
ogdf::SpannerBermanDisconnected::preconditionsOk
virtual bool preconditionsOk(const GraphAttributes &GA, double stretch, std::string &error) override
Definition: SpannerBermanDisconnected.h:51
ogdf::Graph::CCsInfo::numberOfCCs
int numberOfCCs() const
Returns the number of connected components.
Definition: Graph_d.h:1920
ogdf::Module::ReturnType
ReturnType
The return type of a module.
Definition: Module.h:50
ogdf::GraphCopySimple::newEdge
edge newEdge(edge eOrig)
Creates a new edge in the graph copy with original edge eOrig.
Definition: GraphCopy.h:314
ogdf::isSimple
bool isSimple(const Graph &G)
Returns true iff G contains neither self-loops nor parallel edges.
Definition: simple_graph_alg.h:394
simple_graph_alg.h
Declaration of simple graph algorithms.
ogdf::GraphAttributes::has
bool has(long attr) const
Returns true iff all attributes in attr are available.
Definition: GraphAttributes.h:194
ogdf::GraphCopyBase::original
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:98
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:709