summaryrefslogtreecommitdiff
path: root/src/solvers/gpusolver.rs
diff options
context:
space:
mode:
authorDennis Kobert <dennis@kobert.dev>2020-01-05 22:39:18 +0100
committerDennis Kobert <dennis@kobert.dev>2020-01-05 22:39:18 +0100
commitd343b5e10ec2dbd526decbfa984168cf2509f48c (patch)
tree6d62761a15a93d70ba68214cdb4f6f64a2e96071 /src/solvers/gpusolver.rs
parentc583ee4faa552962594f7d5bf9b57bf62b6db5c0 (diff)
parent492045e538cf806bb49631dfbbaabbd8b566147e (diff)
Merge branch 'master' of kobert:/var/repos/babel
Diffstat (limited to 'src/solvers/gpusolver.rs')
-rw-r--r--src/solvers/gpusolver.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/solvers/gpusolver.rs b/src/solvers/gpusolver.rs
new file mode 100644
index 0000000..2b9eb4a
--- /dev/null
+++ b/src/solvers/gpusolver.rs
@@ -0,0 +1,65 @@
+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>>,
+ masks: Vec<u64>,
+}
+
+impl GpuSolver {
+ fn solve_to_vec(&mut self) -> Vec<StoneWall> {
+ vec![]
+ }
+}
+
+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,
+ masks,
+ }
+ }
+ fn n(&self) -> u32 {
+ self.n
+ }
+ fn h(&self) -> u32 {
+ self.h
+ }
+ fn w(&self) -> u32 {
+ self.w
+ }
+}
+
+impl IteratorSolver for GpuSolver {
+ type IntoIter = std::vec::IntoIter<StoneWall>;
+ fn solve(mut self) -> Self::IntoIter {
+ self.solve_to_vec().into_iter()
+ }
+}