summaryrefslogtreecommitdiff
path: root/src/solvers
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
parentc583ee4faa552962594f7d5bf9b57bf62b6db5c0 (diff)
parent492045e538cf806bb49631dfbbaabbd8b566147e (diff)
Merge branch 'master' of kobert:/var/repos/babel
Diffstat (limited to 'src/solvers')
-rw-r--r--src/solvers/gpusolver.rs65
-rwxr-xr-xsrc/solvers/intuitive.rs2
-rwxr-xr-xsrc/solvers/mod.rs1
-rw-r--r--src/solvers/opencl.rs3
4 files changed, 68 insertions, 3 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()
+ }
+}
diff --git a/src/solvers/intuitive.rs b/src/solvers/intuitive.rs
index a5ff935..3db1d33 100755
--- a/src/solvers/intuitive.rs
+++ b/src/solvers/intuitive.rs
@@ -22,7 +22,7 @@ impl NormalSolver {
pub fn new(n: u32) -> Self {
let h = n / 2 + 1;
let w = h * (n - 1);
- let mut heap = (1..=n).collect::<Vec<u32>>();
+ let mut heap: Vec<_> = (1..=n).collect();
let heap = permutohedron::Heap::new(&mut heap);
let n_f = permutohedron::factorial(n as usize);
let chunk = n_f as u32 / n;
diff --git a/src/solvers/mod.rs b/src/solvers/mod.rs
index 6eb2ec4..1bdc228 100755
--- a/src/solvers/mod.rs
+++ b/src/solvers/mod.rs
@@ -1,4 +1,5 @@
//pub mod incremental_block;
pub mod intuitive;
//#[cfg(feature = "gpu")]
+pub mod gpusolver;
pub mod opencl;
diff --git a/src/solvers/opencl.rs b/src/solvers/opencl.rs
index ae5bfa3..676c5cc 100644
--- a/src/solvers/opencl.rs
+++ b/src/solvers/opencl.rs
@@ -1,5 +1,4 @@
-#[macro_use]
-use ocl::{Buffer, Context, Device, Platform, Program, Queue};
+use ocl::{Buffer, Context, Device, Platform, Queue};
use std::sync::mpsc::{Receiver, Sender};
pub struct Job {