🐛 Changed the indices sampling logic to use lists to prevent duplicate clauses.

main
Isabell Pflug 2 days ago
parent 548ef99a09
commit 706ef6d3bc

@ -6,6 +6,7 @@
#include <iostream> #include <iostream>
#include <random> #include <random>
#include <stdexcept> #include <stdexcept>
#include <unordered_set>
#include <vector> #include <vector>
#ifdef _OPENMP #ifdef _OPENMP
@ -50,18 +51,18 @@ std::vector<int> unrank_combination(long n, long k, long long idx) {
// sample c indices in [0,total] for our c = # of clauses // sample c indices in [0,total] for our c = # of clauses
// this is the heart of the program as we are flattening the problem with our sampled indices and the unrank function! // this is the heart of the program as we are flattening the problem with our sampled indices and the unrank function!
std::vector<long long> sample_indices(long long total, long c) { std::vector<long long> sample_indices(long long total, long c) {
std::vector<long long> idx; std::unordered_set<long long> set;
idx.reserve(c); set.reserve(c);
std::random_device rd; std::random_device rd;
std::mt19937 gen(rd()); std::mt19937 gen(rd());
std::uniform_int_distribution<long long> dist(0, total - 1); std::uniform_int_distribution<long long> dist(0, total - 1);
for (long i = 0; i < c; i++) { while ((long)set.size() < c) {
idx.push_back(dist(gen)); set.insert(dist(gen));
} }
return idx; return std::vector<long long>(set.begin(), set.end());
} }
// decode one clause from global index (think of it like a hash function for better understanding!) // decode one clause from global index (think of it like a hash function for better understanding!)

Loading…
Cancel
Save