From d244c0a349886277ed0ce8ca7d2b50db97e0d0df Mon Sep 17 00:00:00 2001 From: Felix Wittwer Date: Wed, 17 Apr 2019 14:28:06 +0200 Subject: [PATCH] Fix algorithm to circumvent ohua-dev/ohua-core#36 --- labyrinth/src/bin/ohua.rs | 231 +---------------------------------- labyrinth/src/grid.rs | 1 + labyrinth/src/transact.ohuac | 8 +- 3 files changed, 7 insertions(+), 233 deletions(-) diff --git a/labyrinth/src/bin/ohua.rs b/labyrinth/src/bin/ohua.rs index bdf1bd5..0fffa39 100644 --- a/labyrinth/src/bin/ohua.rs +++ b/labyrinth/src/bin/ohua.rs @@ -57,233 +57,6 @@ fn main() { let start = PreciseTime::now(); - /* let filled_maze = { - use crate::is_empty; - use labyrinth::grid::update_maze; - use labyrinth::pathfinder::find_path; - use ohua_runtime::arcs::*; - use ohua_runtime::lang::collect; - use ohua_runtime::lang::id; - use ohua_runtime::lang::smapFun; - use ohua_runtime::lang::{send_once, Unit}; - use ohua_runtime::*; - use std::boxed::FnBox; - use std::sync::mpsc::Receiver; - fn ctrl_1( - ctrl_inp: &Receiver<(bool, isize)>, - var_in_0: &Receiver, - var_out_0: &dyn ArcInput, - ) -> Result<(), RunError> { - let (renew_next_time, count) = ctrl_inp.recv()?; - let (var_0,) = (var_in_0.recv()?,); - for _ in 0..count { - var_out_0.dispatch(var_0.clone())?; - } - ctrl_sf_1(ctrl_inp, var_in_0, var_out_0, renew_next_time, (var_0,)) - }; - fn ctrl_sf_1( - ctrl_inp: &Receiver<(bool, isize)>, - var_in_0: &Receiver, - var_out_0: &dyn ArcInput, - renew: bool, - state_vars: (T0,), - ) -> Result<(), RunError> { - let (renew_next_time, count) = ctrl_inp.recv()?; - let (var_0,) = if renew { - (var_in_0.recv()?,) - } else { - state_vars - }; - for _ in 0..count { - var_out_0.dispatch(var_0.clone())?; - } - ctrl_sf_1(ctrl_inp, var_in_0, var_out_0, renew_next_time, (var_0,)) - }; - fn ctrl_2( - ctrl_inp: &Receiver<(bool, isize)>, - var_in_0: &Receiver, - var_in_1: &Receiver, - var_out_0: &dyn ArcInput, - var_out_1: &dyn ArcInput, - ) -> Result<(), RunError> { - let (renew_next_time, count) = ctrl_inp.recv()?; - let (var_0, var_1) = (var_in_0.recv()?, var_in_1.recv()?); - for _ in 0..count { - var_out_0.dispatch(var_0.clone())?; - var_out_1.dispatch(var_1.clone())?; - } - ctrl_sf_2( - ctrl_inp, - var_in_0, - var_in_1, - var_out_0, - var_out_1, - renew_next_time, - (var_0, var_1), - ) - }; - fn ctrl_sf_2( - ctrl_inp: &Receiver<(bool, isize)>, - var_in_0: &Receiver, - var_in_1: &Receiver, - var_out_0: &dyn ArcInput, - var_out_1: &dyn ArcInput, - renew: bool, - state_vars: (T0, T1), - ) -> Result<(), RunError> { - let (renew_next_time, count) = ctrl_inp.recv()?; - let (var_0, var_1) = if renew { - (var_in_0.recv()?, var_in_1.recv()?) - } else { - state_vars - }; - for _ in 0..count { - var_out_0.dispatch(var_0.clone())?; - var_out_1.dispatch(var_1.clone())?; - } - ctrl_sf_2( - ctrl_inp, - var_in_0, - var_in_1, - var_out_0, - var_out_1, - renew_next_time, - (var_0, var_1), - ) - }; - fn nth_0_2(t: (T0, T1)) -> T0 { - let (var_0, var_1) = t; - var_0 - }; - fn nth_1_2(t: (T0, T1)) -> T1 { - let (var_0, var_1) = t; - var_1 - }; - fn recur_2( - condition: &Receiver, - result_arc: &Receiver, - init_0: &Receiver, - init_1: &Receiver, - loop_0: &Receiver, - loop_1: &Receiver, - ctrl_arc: &dyn ArcInput<(bool, isize)>, - cont_arc: &dyn ArcInput<(T0, T1)>, - finish_arc: &dyn ArcInput, - ) -> Result<(), RunError> { - ctrl_arc.dispatch((true, 1)); - cont_arc.dispatch((init_0.recv()?, init_1.recv()?)); - while (condition.recv()?) { - ctrl_arc.dispatch((true, 1)); - cont_arc.dispatch((loop_0.recv()?, loop_1.recv()?)); - } - ctrl_arc.dispatch((false, 0)); - finish_arc.dispatch(result_arc.recv()?); - Ok(()) - } - let (sf_19_out_0__sf_1_in_0, sf_1_in_0) = std::sync::mpsc::channel(); - let (sf_18_out_0__sf_1_in_1, sf_1_in_1) = std::sync::mpsc::channel(); - let (sf_20_out_0__sf_1_in_2, sf_1_in_2) = std::sync::mpsc::channel(); - let (sf_21_out_0__sf_1_in_3, sf_1_in_3) = std::sync::mpsc::channel(); - let (sf_18_out_0__sf_1_in_4, sf_1_in_4) = std::sync::mpsc::channel(); - let (sf_17_out_0__sf_1_in_5, sf_1_in_5) = std::sync::mpsc::channel(); - let (sf_1_out_0__sf_5_in_0, sf_5_in_0) = std::sync::mpsc::channel(); - let (sf_1_out_1__sf_5_in_1, sf_5_in_1) = std::sync::mpsc::channel(); - let (sf_1_out_2__sf_5_in_2, sf_5_in_2) = std::sync::mpsc::channel(); - let (sf_5_out_1__sf_8_in_0, sf_8_in_0) = std::sync::mpsc::channel(); - let (sf_8_out_1__sf_12_in_0, sf_12_in_0) = std::sync::mpsc::channel(); - let (sf_5_out_0__sf_12_in_1, sf_12_in_1) = std::sync::mpsc::channel(); - let (sf_12_out_0__sf_14_in_0, sf_14_in_0) = std::sync::mpsc::channel(); - let (sf_8_out_0__sf_14_in_1, sf_14_in_1) = std::sync::mpsc::channel(); - let (sf_8_out_2__sf_15_in_0, sf_15_in_0) = std::sync::mpsc::channel(); - let (sf_14_out_0__sf_15_in_1, sf_15_in_1) = std::sync::mpsc::channel(); - let (sf_5_out_0__sf_16_in_0, sf_16_in_0) = std::sync::mpsc::channel(); - let (sf_15_out_0__sf_16_in_1, sf_16_in_1) = std::sync::mpsc::channel(); - let (sf_16_out_0__sf_17_in_0, sf_17_in_0) = std::sync::mpsc::channel(); - let (sf_16_out_0__sf_18_in_0, sf_18_in_0) = std::sync::mpsc::channel(); - let (sf_17_out_0__sf_19_in_0, sf_19_in_0) = std::sync::mpsc::channel(); - let sf_5_out_0 = - DispatchQueue::new(vec![sf_5_out_0__sf_12_in_1, sf_5_out_0__sf_16_in_0]); - let sf_16_out_0 = - DispatchQueue::new(vec![sf_16_out_0__sf_17_in_0, sf_16_out_0__sf_18_in_0]); - let sf_17_out_0 = - DispatchQueue::new(vec![sf_17_out_0__sf_1_in_5, sf_17_out_0__sf_19_in_0]); - let sf_18_out_0 = - DispatchQueue::new(vec![sf_18_out_0__sf_1_in_1, sf_18_out_0__sf_1_in_4]); - let (result_snd, result_rcv) = std::sync::mpsc::channel(); - let mut tasks: Vec Result<(), RunError> + Send + 'static>> = Vec::new(); - tasks.push(Box::new(move || loop { - let r = find_path(sf_14_in_0.recv()?, sf_14_in_1.recv()?); - sf_14_out_0__sf_15_in_1.dispatch(r)? - })); - tasks.push(Box::new(move || loop { - let r = update_maze(sf_16_in_0.recv()?, sf_16_in_1.recv()?); - sf_16_out_0.dispatch(r)? - })); - tasks.push(Box::new(move || loop { - let r = nth_0_2(sf_17_in_0.recv()?); - sf_17_out_0.dispatch(r)? - })); - tasks.push(Box::new(move || loop { - let r = nth_1_2(sf_18_in_0.recv()?); - sf_18_out_0.dispatch(r)? - })); - tasks.push(Box::new(move || loop { - let r = is_empty(sf_19_in_0.recv()?); - sf_19_out_0__sf_1_in_0.dispatch(r)? - })); - tasks.push(Box::new(move || { - let r = id(maze); - sf_20_out_0__sf_1_in_2.dispatch(r)?; - Ok(()) - })); - tasks.push(Box::new(move || { - let r = id(paths.clone()); - sf_21_out_0__sf_1_in_3.dispatch(r)?; - Ok(()) - })); - tasks.push(Box::new(move || { - recur_2( - &sf_1_in_0, - &sf_1_in_1, - &sf_1_in_2, - &sf_1_in_3, - &sf_1_in_4, - &sf_1_in_5, - &sf_1_out_0__sf_5_in_0, - &sf_1_out_1__sf_5_in_1, - &sf_1_out_2__sf_5_in_2, - )?; - Ok(()) - })); - tasks.push(Box::new(move || { - ctrl_2( - &sf_5_in_0, - &sf_5_in_1, - &sf_5_in_2, - &sf_5_out_0, - &sf_5_out_1__sf_8_in_0, - )?; - Ok(()) - })); - tasks.push(Box::new(move || loop { - smapFun( - &sf_8_in_0, - &sf_8_out_0__sf_14_in_1, - &sf_8_out_1__sf_12_in_0, - &sf_8_out_2__sf_15_in_0, - )?; - })); - tasks.push(Box::new(move || { - ctrl_1(&sf_12_in_0, &sf_12_in_1, &sf_12_out_0__sf_14_in_0)?; - Ok(()) - })); - tasks.push(Box::new(move || loop { - collect(&sf_15_in_0, &sf_15_in_1, &sf_15_out_0__sf_16_in_1)?; - })); - run_tasks(tasks); - result_rcv.recv().unwrap() - }; */ - let paths2 = paths.clone(); #[ohua] @@ -342,6 +115,6 @@ fn main() { } } -pub fn is_empty(v: Vec<(Point, Point)>) -> bool { - v.len() == 0 +pub fn is_not_empty(v: Vec<(Point, Point)>) -> bool { + !v.is_empty() } diff --git a/labyrinth/src/grid.rs b/labyrinth/src/grid.rs index aa1c289..2c29261 100644 --- a/labyrinth/src/grid.rs +++ b/labyrinth/src/grid.rs @@ -54,6 +54,7 @@ pub fn update_maze(mut maze: Maze, paths: Vec>) -> (Vec<(Point, Poi for pt in &path.path { maze.grid[pt.x][pt.y][pt.z] = Field::Used; } + maze.paths.push(path); } else { remap.push((path.start, path.end)); } diff --git a/labyrinth/src/transact.ohuac b/labyrinth/src/transact.ohuac index 548f80b..a87da15 100644 --- a/labyrinth/src/transact.ohuac +++ b/labyrinth/src/transact.ohuac @@ -1,6 +1,6 @@ ns some_ns; -use sf crate::is_empty; +use sf crate::is_not_empty; use sf labyrinth::grid::update_maze; use sf labyrinth::pathfinder::find_path; @@ -33,9 +33,9 @@ fn transact(maze: Maze, to_map: Vec<(Point, Point)>) -> Maze { let (remap_paths, new_maze) = update_maze(maze, paths); // simple check for len == 0 - if (is_empty(remap_paths)) { - new_maze - } else { + if (is_not_empty(remap_paths)) { transact(new_maze, remap_paths) + } else { + new_maze } }