Skip to content

Commit e74775b

Browse files
committed
feat(path): Add probabilistic edge generation with p parameter
- Introduce p parameter for directed path generator, defaulting p=1.0
1 parent 1489464 commit e74775b

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

app/KaGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ This is mostly useful for experimental graph generators or when using KaGen to l
346346

347347
auto* params = cmd->add_option_group("Parameters");
348348
add_option_n(params);
349-
params->require_option(1);
349+
add_option_p(params);
350350
params->silent();
351351
}
352352

kagen/generators/path/path_directed.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "kagen/generators/path/path_directed.h"
2+
#include "kagen/sampling/hash.hpp"
23

34
#ifdef KAGEN_XXHASH_FOUND
45
#include "kagen/tools/random_permutation.h"
@@ -17,14 +18,19 @@ PGeneratorConfig PathDirectedFactory::NormalizeParameters(PGeneratorConfig confi
1718
throw ConfigurationError("path permutation requires xxHash, but build was configured without xxHash");
1819
}
1920
#endif // KAGEN_XXHASH_FOUND
20-
21+
if (config.p == 0.0) {
22+
config.p = 1.0;
23+
}
24+
if (config.p > 1.0) {
25+
throw ConfigurationError("edge probability p must be in [0, 1]");
26+
}
2127
return config;
2228
}
2329

2430
PathDirected::PathDirected(const PGeneratorConfig& config, const PEID rank, const PEID size)
2531
: config_(config),
2632
rank_(rank),
27-
size_(size) {}
33+
size_(size), rng_(config) {}
2834

2935
void PathDirected::GenerateEdgeList() {
3036
if (config_.n <= 1) {
@@ -59,7 +65,11 @@ void PathDirected::GenerateEdgeList() {
5965
}();
6066

6167
if (is_valid) {
62-
PushEdge(i, j);
68+
SInt edge_seed = std::min(i, j) *config_.n + std::max(i, j);
69+
SInt h = sampling::Spooky::hash(config_.seed + edge_seed);
70+
if (rng_.GenerateBinomial(h, 1, config_.p)) {
71+
PushEdge(i, j);
72+
}
6373
}
6474
}
6575
}

kagen/generators/path/path_directed.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "kagen/context.h"
44
#include "kagen/generators/generator.h"
55
#include "kagen/kagen.h"
6+
#include "kagen/tools/rng_wrapper.h"
67

78
namespace kagen {
89
class PathDirectedFactory : public GeneratorFactory {
@@ -27,5 +28,7 @@ class PathDirected : public virtual Generator, private EdgeListOnlyGenerator {
2728

2829
PEID rank_;
2930
PEID size_;
31+
32+
RNGWrapper<> rng_;
3033
};
3134
} // namespace kagen

0 commit comments

Comments
 (0)