↰ Return to documentation for file (include/networkit/randomization/EdgeSwitching.hpp
)
/*
* EdgeSwitching.hpp
*
* Created on: 19.10.2019
* Author: Manuel Penschuck <networkit@manuel.jetzt>
*/
#ifndef NETWORKIT_RANDOMIZATION_EDGE_SWITCHING_HPP_
#define NETWORKIT_RANDOMIZATION_EDGE_SWITCHING_HPP_
#include <random>
#include <string>
#include <utility>
#include <networkit/Globals.hpp>
#include <networkit/base/Algorithm.hpp>
#include <networkit/graph/Graph.hpp>
namespace NetworKit {
class EdgeSwitchingInPlace : public Algorithm {
public:
EdgeSwitchingInPlace(Graph &G, double numberOfSwitchesPerEdge = 10.0) : graph(G) {
setNumberOfSwitchesPerEdge(numberOfSwitchesPerEdge);
}
~EdgeSwitchingInPlace() override = default;
void run() override;
Graph &getGraph() const { return graph; }
count getNumberOfAffectedEdges() const noexcept { return 2 * numberOfSwapsPerformed; }
double getNumberOfSwitchesPerEdge() const noexcept { return numberOfSwitchesPerEdge; }
void setNumberOfSwitchesPerEdge(double x);
protected:
Graph &graph;
std::discrete_distribution<node>
degreeDistribution;
double numberOfSwitchesPerEdge;
count numberOfSwapsPerformed{0};
};
class EdgeSwitching : public Algorithm {
public:
explicit EdgeSwitching(const Graph &G, double numberOfSwitchesPerEdge = 10.0,
bool degreePreservingShufflePreprocessing = true);
~EdgeSwitching() override = default;
void run() override { inPlaceAlgorithm.run(); }
const Graph &getGraph() const { return ownedGraph; }
Graph moveGraph() { return std::move(ownedGraph); }
count getNumberOfAffectedEdges() const noexcept {
return inPlaceAlgorithm.getNumberOfAffectedEdges();
}
double getNumberOfSwitchesPerEdge() const noexcept {
return inPlaceAlgorithm.getNumberOfSwitchesPerEdge();
}
void setNumberOfSwitchesPerEdge(double x) { inPlaceAlgorithm.setNumberOfSwitchesPerEdge(x); }
private:
Graph ownedGraph;
EdgeSwitchingInPlace inPlaceAlgorithm;
};
} // namespace NetworKit
#endif // NETWORKIT_RANDOMIZATION_EDGE_SWITCHING_HPP_