73template<
typename TWeight>
85 std::string& error)
override {
87 error =
"The graph must be undirected";
91 if (std::modf(stretch, &integralPart) != 0.0) {
92 error =
"The stretch is required to be an integer, not " + to_string(
m_stretch);
95 int intStretch =
static_cast<int>(stretch);
97 error =
"The stretch must be >= 1.0";
100 if (intStretch % 2 == 0) {
101 error =
"The stretch must be odd";
153 int k = (
static_cast<int>(
m_stretch) + 1) / 2;
155 for (
int iteration = 1; iteration <= k - 1; iteration++) {
162 for (
node oldCenter : clusterCenters.
nodes()) {
164 sampledClusterCenters.
insert(oldCenter);
170 if (sampledClusterCenters.
isMember(oldCluster[v])) {
182 TWeight minWeight = std::numeric_limits<TWeight>::max();
183 edge minEdge =
nullptr;
186 node center = oldCluster[a->twinNode()];
187 edge e = a->theEdge();
190 if (sampledClusterCenters.
isMember(center)) {
220 if (
A[center] !=
nullptr
221 && (minEdge ==
nullptr || minEdge ==
A[center]
237 v->allAdjEntries(adjs);
239 node center = oldCluster[a->twinNode()];
266 clusterCenters = std::move(sampledClusterCenters);
280 edge e = a->theEdge();
289 if (
A[center] !=
nullptr) {
297 while ((a = v->firstAdj()) !=
nullptr) {
323template<
typename TWeight>
Compare floating point numbers with epsilons and integral numbers with normal compare operators.
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.
Declaration and implementation of NodeSet, EdgeSet, and AdjEntrySet classes.
Declaration of doubly linked lists and iterators.
A wrapper class for iterating calls to spanner algorithms.
Basic module for spanner algorithms.
Basic declarations, included by all source files.
Class for adjacency list elements.
edge theEdge() const
Returns the edge associated with this adjacency entry.
Class for the representation of edges.
node target() const
Returns the target node of the edge.
node source() const
Returns the source node of the edge.
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.
Stores additional attributes of a graph (like layout information).
bool directed() const
Returns if the graph is directed.
const Graph & constGraph() const
Returns a reference to the associated graph.
void init(const Graph &G)
Re-initializes the copy using G, creating copies for all nodes and edges in G.
const Graph & original() const
Returns a reference to the original graph.
Copies of graphs with mapping between nodes and edges.
edge newEdge(edge eOrig)
Creates a new edge in the graph copy with original edge eOrig.
void delEdge(edge e) override
Removes edge e.
void clear() override
Removes all nodes and edges from this copy but does not break the link with the original graph.
edge copy(edge e) const override
Returns the edge in the graph copy corresponding to e.
int numberOfNodes() const
Returns the number of nodes in the graph.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
ReturnType
The return type of a module.
Class for the representation of nodes.
const list_type & nodes()
Returns a reference to the list of nodes contained in this set.
bool isMember(element_type v) const
Returns true iff element v is contained in this set.
void insert(element_type v)
Inserts element v into this set.
Randomized multiplicative spanner calculation by forming clusters.
virtual bool preconditionsOk(const GraphAttributes &GA, double stretch, std::string &error) override
virtual SpannerModule< TWeight >::ReturnType execute() override
Executes the core algorithm.
virtual void init(const GraphAttributes &GA, double stretch, GraphCopySimple &spanner, EdgeArray< bool > &inSpanner) override
Initializes members and create an empty spanner.
NodeArray< node > m_cluster
the current cluster for each iteration in phase 1 and the final cluster from phase 1 which is used in...
GraphCopySimple m_G
The copy of GA.constGraph() to work on. Edges will be removed in each iteration.
void phase2()
Phase 2: Vertex-Cluster Joining.
void phase1()
Phase 1: Forming clusters.
void addToSpanner(edge e)
Adds e from m_G to the spanner and sets inSpanner.
Use the ogdf::SpannerIteratedWrapper to execute the ogdf::SpannerBaswanaSen algorithm up to 1000 time...
SpannerBaswanaSenIterated()
A implementation-independed wrapper class to execute a spanner algorithm multiple times.
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
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
RegisteredArray for nodes, edges and adjEntries of a graph.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
double randomDouble(double low, double high)
Returns a random double value from the interval [low, high).
The namespace for all OGDF objects.