-
Notifications
You must be signed in to change notification settings - Fork 17
feat(path): Add probabilistic edge generation with p parameter #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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]"); | ||
| } | ||
|
Comment on lines
+21
to
+26
|
||
| 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); | ||
| } | ||
|
Comment on lines
67
to
+72
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Comment on lines
77
to
81
|
||
| 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); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CLI option
-p/--probis added forpath-directed, but the help/default shown to users will still reflectconfig.p’s initial value (0.0), while runtime behavior normalizes it to1.0. Consider setting the CLI default explicitly (e.g., default value 1.0 for this subcommand) so--helpmatches the documented “defaulting p=1.0” behavior and sop=0can remain a valid, explicit input.