Skip to content

Incorrect Result from get_path_multiple_goals #5

@ficapy

Description

@ficapy

I modified multiple_goals.rs to use a 10x10 grid while keeping the same obstacle nodes. changed the goals to (2,2) and (9,9). However, it incorrectly outputs (9,9) as the optimal target.but shouldn't it correctly choose (2,2)?

use grid_pathfinding::PathingGrid;
use grid_util::grid::Grid;
use grid_util::point::Point;

// In this example a path is found to one of two goals on a 3x3 grid with shape
//  ___
// |S G|
// | # |
// |  G|
//  ___
// where
// - \# marks an obstacle
// - S marks the start
// - G marks a goal
// The found path moves to the closest goal, which is the top one.

fn main() {
   let mut pathing_grid: PathingGrid = PathingGrid::new(10, 10, false);
   pathing_grid.set(1, 1, true);
   pathing_grid.generate_components();
   println!("{}", pathing_grid);
   let start = Point::new(0, 0);
   let goal_1 = Point::new(2, 2);
   let goal_2 = Point::new(9, 9);
   let goals = vec![&goal_1, &goal_2];
   let (selected_goal, path) = pathing_grid.get_path_multiple_goals(start, goals).unwrap();
   println!("Selected goal: {:?}\n", selected_goal);
   println!("Path:");
   for p in path {
       println!("{:?}", p);
   }
}

Output

Grid:
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Neighbours:
[5, 198, 71, 199, 199, 199, 199, 199, 199, 193]
[27, 255, 191, 255, 255, 255, 255, 255, 255, 241]
[23, 239, 223, 255, 255, 255, 255, 255, 255, 241]
[31, 255, 255, 255, 255, 255, 255, 255, 255, 241]
[31, 255, 255, 255, 255, 255, 255, 255, 255, 241]
[31, 255, 255, 255, 255, 255, 255, 255, 255, 241]
[31, 255, 255, 255, 255, 255, 255, 255, 255, 241]
[31, 255, 255, 255, 255, 255, 255, 255, 255, 241]
[31, 255, 255, 255, 255, 255, 255, 255, 255, 241]
[28, 124, 124, 124, 124, 124, 124, 124, 124, 112]

Selected goal: Point { x: 9, y: 9 }

Path:
Point { x: 0, y: 0 }
Point { x: 0, y: 1 }
Point { x: 1, y: 2 }
Point { x: 2, y: 3 }
Point { x: 3, y: 4 }
Point { x: 4, y: 5 }
Point { x: 5, y: 6 }
Point { x: 6, y: 7 }
Point { x: 7, y: 8 }
Point { x: 8, y: 9 }
Point { x: 9, y: 9 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions