Skip to content

Commit

Permalink
Adhere to NetworKit code style
Browse files Browse the repository at this point in the history
  • Loading branch information
manpen committed Jun 18, 2019
1 parent 1440271 commit ca34425
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
12 changes: 6 additions & 6 deletions include/networkit/generators/GeometricInhomogenousGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace NetworKit {

class GeometricInhomogenousGenerator: public StaticGraphGenerator {
public:
using coordinate_t = std::vector<double>;
using Coordinate = std::vector<double>;

/**
* @param[in] n Number of nodes
Expand All @@ -39,7 +39,7 @@ class GeometricInhomogenousGenerator: public StaticGraphGenerator {
* @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_t> points, std::vector<double> weights, double avgDegree, double alpha);
GeometricInhomogenousGenerator(std::vector<Coordinate> points, std::vector<double> weights, double avgDegree, double alpha);

/**
* Construct generator from *already scaled* weights.
Expand All @@ -51,7 +51,7 @@ class GeometricInhomogenousGenerator: public StaticGraphGenerator {
* @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_t> points, std::vector<double> weights, double alpha);
GeometricInhomogenousGenerator(std::vector<Coordinate> points, std::vector<double> weights, double alpha);

// Add virtual destructor
virtual ~GeometricInhomogenousGenerator() = default;
Expand All @@ -74,17 +74,17 @@ class GeometricInhomogenousGenerator: public StaticGraphGenerator {
* @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_t>& positions() const noexcept {
const std::vector<Coordinate>& positions() const noexcept {
return pointPositions;
}

private:
double alpha;

std::vector<coordinate_t> pointPositions;
std::vector<Coordinate> pointPositions;
std::vector<double> pointWeights;

void check_input_parameters_() const;
void checkInputParameters() const;
};

} // NetworKit
Expand Down
14 changes: 8 additions & 6 deletions networkit/cpp/generators/GeometricInhomogenousGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ GeometricInhomogenousGenerator::GeometricInhomogenousGenerator(count n, double a
girgs::scaleWeights(pointWeights, avgDegree, dim, alpha);
}

GeometricInhomogenousGenerator::GeometricInhomogenousGenerator(std::vector<coordinate_t> points, std::vector<double> weights, double avgDegree, double 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))
{
check_input_parameters_();
checkInputParameters();
const auto dim = static_cast<int>(pointPositions.front().size());
girgs::scaleWeights(pointWeights, avgDegree, dim, alpha);
}

// Construct without scaling
GeometricInhomogenousGenerator::GeometricInhomogenousGenerator(std::vector<coordinate_t> points, std::vector<double> weights, double alpha) :
GeometricInhomogenousGenerator::GeometricInhomogenousGenerator(std::vector<Coordinate> points, std::vector<double> weights, double alpha) :
alpha(alpha),
pointPositions(std::move(points)),
pointWeights(std::move(weights))
{
check_input_parameters_();
checkInputParameters();
}

Graph GeometricInhomogenousGenerator::generate() {
Expand All @@ -56,7 +56,7 @@ Graph GeometricInhomogenousGenerator::generateKeepingInput() {
return girgs::generateEdges(pointWeights, pointPositions, alpha, true);
}

void GeometricInhomogenousGenerator::check_input_parameters_() const {
void GeometricInhomogenousGenerator::checkInputParameters() const {
if (alpha <= 1)
throw std::runtime_error("Alpha has to be larger than 1");

Expand All @@ -74,17 +74,19 @@ void GeometricInhomogenousGenerator::check_input_parameters_() const {
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(double x : pt) {
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

0 comments on commit ca34425

Please sign in to comment.