add 82 (WIP)

This commit is contained in:
Dr. Matthias Ratajczak
2022-09-27 13:56:14 +02:00
parent ab4b003fcd
commit 6da8e3d651
6 changed files with 145 additions and 6 deletions
+9 -5
View File
@@ -4,8 +4,6 @@ use std::{collections::HashSet, ops::Add};
type Coordinate = (usize, usize);
const START: Coordinate = (0, 0);
pub enum AllowedMovements {
DownRight,
DownRightUp,
@@ -25,7 +23,9 @@ impl AllowedMovements {
fn get_neighbours_down_right_up(&self, (x0, y0): &Coordinate) -> Vec<Coordinate> {
let mut result = self.get_neighbours_down_right(&(*x0, *y0));
result.push((*x0, *y0 - 1));
if *y0 > 0 {
result.push((*x0, *y0 - 1));
}
result
}
}
@@ -65,9 +65,13 @@ impl<'a, T> Dijkstra<'a, T>
where
T: PartialOrd + Add<Output = T> + Display + Copy + Debug,
{
pub fn new(matrix: &'a mut dyn Matrix<T>, allowed_movements: AllowedMovements) -> Self {
pub fn new(
matrix: &'a mut dyn Matrix<T>,
allowed_movements: AllowedMovements,
start: Coordinate,
) -> Self {
let unvisited_with_distance = HashSet::new();
let unvisited_without_distance = Self::initialize_unvisited_set(&*matrix, START);
let unvisited_without_distance = Self::initialize_unvisited_set(&*matrix, start);
Self {
matrix,
unvisited_with_distance,