summaryrefslogtreecommitdiff
path: root/src/solvers/gpusolver.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/solvers/gpusolver.rs')
-rw-r--r--src/solvers/gpusolver.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/solvers/gpusolver.rs b/src/solvers/gpusolver.rs
index 4c58251..2b9eb4a 100644
--- a/src/solvers/gpusolver.rs
+++ b/src/solvers/gpusolver.rs
@@ -1,6 +1,8 @@
use crate::solver::{wall_stats, Solver, IteratorSolver};
use crate::structs::StoneWall;
+use crate::permutations::PermutationGenerator;
+#[derive(Debug)]
pub struct GpuSolver {
n: u32, h: u32, w: u32,
permutations: Vec<Vec<u32>>,
@@ -13,13 +15,35 @@ impl GpuSolver {
}
}
+fn generate_permutations(n: u32) -> Vec<Vec<u32>> {
+ crate::permutations::HeapsPermutations::permutations(n)
+}
+
+fn generate_masks(permutations: &[Vec<u32>]) -> Vec<u64> {
+ let mut masks = Vec::with_capacity(permutations.len());
+ for p in permutations {
+ let mut v = 0;
+ let mut x = 0u64;
+ for i in p.iter().take(p.len() - 1).map(|i| {
+ v += i;
+ v
+ }) {
+ x |= 1 << i
+ }
+ masks.push(x)
+ }
+ masks
+}
+
impl Solver for GpuSolver {
fn new(n: u32) -> Self {
let (h, w) = wall_stats(n);
+ let permutations = generate_permutations(n);
+ let masks = generate_masks(&permutations);
Self {
n, h, w,
- permutations: vec![],
- masks: vec![]
+ permutations,
+ masks,
}
}
fn n(&self) -> u32 {