use num_traits::Zero;
use std::hash::Hash;
use crate::{ArrayIndex, Solution};
#[derive(Clone, Debug)]
pub(super) enum AlgorithmType {
Dijkstra,
}
#[derive(Debug)]
pub(super) struct Algorithm {
algorithm_type: AlgorithmType,
}
#[allow(dead_code)]
fn manhattan_distance(start: &ArrayIndex, end: &[ArrayIndex]) -> u64 {
end.iter()
.map(|end| {
let di = start.i.abs_diff(end.i);
let dj = start.j.abs_diff(end.j);
di + dj
})
.min_by(|a, b| a.partial_cmp(b).unwrap())
.unwrap()
}
impl Algorithm {
pub(super) fn new() -> Self {
Self {
algorithm_type: AlgorithmType::Dijkstra,
}
}
#[allow(unused_variables)]
pub(super) fn compute<I, C, FN, IN, FH, FS>(
&self,
start: &I,
successors: FN,
heuristic: Option<FH>,
success: FS,
) -> Option<Solution<I, f32>>
where
I: Eq + Hash + Clone,
C: Zero + Ord + Copy,
FN: FnMut(&I) -> IN,
IN: IntoIterator<Item = (I, C)>,
FH: FnMut(&I) -> C,
FS: FnMut(&I) -> bool,
u64: From<C>,
{
let ans = match self.algorithm_type {
AlgorithmType::Dijkstra => pathfinding::prelude::dijkstra(start, successors, success),
};
ans.map(|(route, total_cost)| {
Solution::new(route, super::unscaled_cost(u64::from(total_cost)))
})
}
}