-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
3,176 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule tlx
updated
46 files
Empty file.
92 changes: 92 additions & 0 deletions
92
include/networkit/generators/GeometricInhomogenousGenerator.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* GeometricInhomogenousGenerator.h | ||
* | ||
* Created on: 09.05.2019 | ||
* Author: Manuel Penschuck <networkit@manuel.jetzt> | ||
*/ | ||
|
||
#ifndef GEOMETRICINHOMOGENOUS_H_ | ||
#define GEOMETRICINHOMOGENOUS_H_ | ||
|
||
#include <limits> | ||
#include <vector> | ||
|
||
#include <networkit/generators/StaticGraphGenerator.hpp> | ||
|
||
namespace NetworKit { | ||
|
||
class GeometricInhomogenousGenerator: public StaticGraphGenerator { | ||
public: | ||
using Coordinate = std::vector<double>; | ||
|
||
/** | ||
* @param[in] n Number of nodes | ||
* @param[in] avgDegree The desired average degree with 0 < avgDegree < n-1 | ||
* @param[in] powerlawExp Target exponent of power-law distribution with powerlawExp > 2.0 | ||
* @param[in] alpha parameter (1/temperature) with alpha > 1 | ||
* @param[in] dimension Dimension of the underlying geometry with 1 <= dimension <= 5 | ||
*/ | ||
GeometricInhomogenousGenerator(count n, double avgDegree, double powerlawExp=3, double alpha=std::numeric_limits<double>::infinity(), unsigned dim=1); | ||
|
||
/** | ||
* Construct generator from weights that are then scale to match avgDegree and T. | ||
* | ||
* @param[in] points Coordinates of points | ||
* @param[in] weights Unscaled weights (assumed to be powerlaw distributed) | ||
* @param[in] avgDegree The desired average degree with 0 < avgDegree < n-1 | ||
* @param[in] alpha parameter (1/temperature) with alpha > 1 | ||
* | ||
* @warning points and weights are moved into the container. The we're not using | ||
* rvalue refs because Cython does not handle them. | ||
*/ | ||
GeometricInhomogenousGenerator(std::vector<Coordinate> points, std::vector<double> weights, double avgDegree, double alpha); | ||
|
||
/** | ||
* Construct generator from *already scaled* weights. | ||
* | ||
* @param[in] points Coordinates of points | ||
* @param[in] weights *Scaled* weights | ||
* @param[in] alpha parameter (1/temperature) with alpha > 1 | ||
* | ||
* @warning points and weights are moved into the container. The we're not using | ||
* rvalue refs because Cython does not handle them. | ||
*/ | ||
GeometricInhomogenousGenerator(std::vector<Coordinate> points, std::vector<double> weights, double alpha); | ||
|
||
// Add virtual destructor | ||
virtual ~GeometricInhomogenousGenerator() = default; | ||
|
||
/// @return Graph to be generated according to parameters specified in constructor freeing memory by deleting the input point set. | ||
Graph generate() override; | ||
|
||
/// @return Graph to be generated according to parameters specified in constructor keeping the input point set. | ||
Graph generateKeepingInput(); | ||
|
||
/** | ||
* @return Weights used to generate the graph | ||
* @warning The data is destroyed if generate is called with keep_input = false (default). | ||
*/ | ||
const std::vector<double>& weights() const noexcept { | ||
return pointWeights; | ||
} | ||
|
||
/** | ||
* @return Point positions used to generate the graph | ||
* @warning The data is destroyed if generate is called with keep_input = false (default). | ||
*/ | ||
const std::vector<Coordinate>& positions() const noexcept { | ||
return pointPositions; | ||
} | ||
|
||
private: | ||
double alpha; | ||
|
||
std::vector<Coordinate> pointPositions; | ||
std::vector<double> pointWeights; | ||
|
||
void checkInputParameters() const; | ||
}; | ||
|
||
} // NetworKit | ||
|
||
#endif // GEOMETRICINHOMOGENOUS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
networkit/cpp/generators/GeometricInhomogenousGenerator.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* GeometricInhomogenousGenerator.cpp | ||
* | ||
* Created on: 09.05.2019 | ||
* Author: Manuel Penschuck <networkit@manuel.jetzt> | ||
*/ | ||
|
||
#include <networkit/generators/GeometricInhomogenousGenerator.hpp> | ||
#include "girgs/Generator.hpp" | ||
|
||
namespace NetworKit { | ||
|
||
|
||
GeometricInhomogenousGenerator::GeometricInhomogenousGenerator(count n, double avgDegree, double exp, double alpha, unsigned dim) : | ||
alpha(alpha) | ||
// do not initialize pointWeights and pointPosition here to check paremeters before | ||
{ | ||
if (alpha <= 1) | ||
throw std::runtime_error("Temperature T has to satiesfy 0 <= T < 1"); | ||
|
||
if (!(1 <= dim && dim <= 5)) | ||
throw std::runtime_error("Support only 1 to 5 dimensions"); | ||
|
||
if (n >= static_cast<count>(std::numeric_limits<int>::max())) | ||
throw std::runtime_error("Support only INT_MAX nodes"); | ||
|
||
pointPositions = girgs::generatePositions(static_cast<int>(n), dim, true); | ||
pointWeights = girgs::generateWeights(static_cast<int>(n), exp, true); | ||
girgs::scaleWeights(pointWeights, avgDegree, dim, alpha); | ||
} | ||
|
||
GeometricInhomogenousGenerator::GeometricInhomogenousGenerator(std::vector<Coordinate> points, std::vector<double> weights, double avgDegree, double alpha) : | ||
alpha(alpha), | ||
pointPositions(std::move(points)), | ||
pointWeights(std::move(weights)) | ||
{ | ||
checkInputParameters(); | ||
const auto dim = static_cast<int>(pointPositions.front().size()); | ||
girgs::scaleWeights(pointWeights, avgDegree, dim, alpha); | ||
} | ||
|
||
// Construct without scaling | ||
GeometricInhomogenousGenerator::GeometricInhomogenousGenerator(std::vector<Coordinate> points, std::vector<double> weights, double alpha) : | ||
alpha(alpha), | ||
pointPositions(std::move(points)), | ||
pointWeights(std::move(weights)) | ||
{ | ||
checkInputParameters(); | ||
} | ||
|
||
Graph GeometricInhomogenousGenerator::generate() { | ||
return girgs::generateEdges(pointWeights, pointPositions, alpha, false); | ||
} | ||
|
||
Graph GeometricInhomogenousGenerator::generateKeepingInput() { | ||
return girgs::generateEdges(pointWeights, pointPositions, alpha, true); | ||
} | ||
|
||
void GeometricInhomogenousGenerator::checkInputParameters() const { | ||
if (alpha <= 1) | ||
throw std::runtime_error("Alpha has to be larger than 1"); | ||
|
||
|
||
if (!pointPositions.size()) | ||
throw std::runtime_error("Generator requires at least one point"); | ||
|
||
|
||
if (pointPositions.size() != pointWeights.size()) | ||
throw std::runtime_error("Number of nodes in vectors points and weight do not match"); | ||
|
||
|
||
const auto dim = pointPositions.front().size(); | ||
if (!(1 <= dim && dim <= 5)) | ||
throw std::runtime_error("Support only 1 to 5 dimensions"); | ||
|
||
|
||
#ifndef NDEBUG | ||
for(const auto& pt : pointPositions) { | ||
if (pt.size() != dim) | ||
throw std::runtime_error("All points have to have the same dimension"); | ||
|
||
|
||
for(const auto x : pt) { | ||
if (!(0 <= x && x <= 1)) | ||
throw std::runtime_error("Points have to lie within the [0:1]^d unit hypercube"); | ||
|
||
} | ||
} | ||
#endif | ||
} | ||
|
||
} // NetworKit |
Oops, something went wrong.