diff --git a/app/KaGen.cpp b/app/KaGen.cpp index 8d3a822d..f60a4cc7 100644 --- a/app/KaGen.cpp +++ b/app/KaGen.cpp @@ -346,7 +346,7 @@ This is mostly useful for experimental graph generators or when using KaGen to l auto* params = cmd->add_option_group("Parameters"); add_option_n(params); - params->require_option(1); + add_option_p(params); params->silent(); } diff --git a/kagen/generators/path/path_directed.cpp b/kagen/generators/path/path_directed.cpp index 95cf774c..7a90f8ae 100644 --- a/kagen/generators/path/path_directed.cpp +++ b/kagen/generators/path/path_directed.cpp @@ -1,4 +1,5 @@ #include "kagen/generators/path/path_directed.h" +#include "kagen/sampling/hash.hpp" #ifdef KAGEN_XXHASH_FOUND #include "kagen/tools/random_permutation.h" @@ -17,14 +18,19 @@ PGeneratorConfig PathDirectedFactory::NormalizeParameters(PGeneratorConfig confi throw ConfigurationError("path permutation requires xxHash, but build was configured without xxHash"); } #endif // KAGEN_XXHASH_FOUND - + if (config.p == 0.0) { + config.p = 1.0; + } + if (config.p > 1.0) { + throw ConfigurationError("edge probability p must be in [0, 1]"); + } return config; } PathDirected::PathDirected(const PGeneratorConfig& config, const PEID rank, const PEID size) : config_(config), rank_(rank), - size_(size) {} + size_(size), rng_(config) {} void PathDirected::GenerateEdgeList() { if (config_.n <= 1) { @@ -59,7 +65,11 @@ void PathDirected::GenerateEdgeList() { }(); if (is_valid) { - PushEdge(i, j); + SInt edge_seed = std::min(i, j) *config_.n + std::max(i, j); + SInt h = sampling::Spooky::hash(config_.seed + edge_seed); + if (rng_.GenerateBinomial(h, 1, config_.p)) { + PushEdge(i, j); + } } } } diff --git a/kagen/generators/path/path_directed.h b/kagen/generators/path/path_directed.h index b6e6bde9..b889bc1f 100644 --- a/kagen/generators/path/path_directed.h +++ b/kagen/generators/path/path_directed.h @@ -3,6 +3,7 @@ #include "kagen/context.h" #include "kagen/generators/generator.h" #include "kagen/kagen.h" +#include "kagen/tools/rng_wrapper.h" namespace kagen { class PathDirectedFactory : public GeneratorFactory { @@ -27,5 +28,7 @@ class PathDirected : public virtual Generator, private EdgeListOnlyGenerator { PEID rank_; PEID size_; + + RNGWrapper<> rng_; }; } // namespace kagen diff --git a/tests/path/general_path_generator_test.cpp b/tests/path/general_path_generator_test.cpp index e1a5569b..063e0654 100644 --- a/tests/path/general_path_generator_test.cpp +++ b/tests/path/general_path_generator_test.cpp @@ -76,6 +76,7 @@ TEST_P(PathGeneratorTestFixture, path_generation_without_permutation) { PGeneratorConfig config; config.n = GetParam(); + config.p = 1.0; PathDirected generator(config, rank, size); generator.Generate(GraphRepresentation::EDGE_LIST); @@ -94,6 +95,7 @@ TEST_P(PathGeneratorTestFixture, path_generation_with_permutation) { PGeneratorConfig config; config.n = GetParam(); + config.p = 1.0; config.permute = true; PathDirected generator(config, rank, size);