Skip to main content

OrientedGraph

Trait OrientedGraph 

Source
pub trait OrientedGraph: Graph {
    // Required methods
    fn heading_count(&self) -> usize;
    fn forward(&self, vertex: Vertex, heading: Heading) -> Option<Vertex>;
    fn turns(&self, heading: Heading, emit: impl FnMut(Heading));
}
Expand description

A Graph on which agents face a heading and only move forward, for solvers that model turning in place as taking time (pibt_turns).

Each step an agent either moves to OrientedGraph::forward of its vertex and heading, keeping the heading, or turns in place to one of OrientedGraph::turns, or waits. The out-neighbours of a vertex in Graph::neighbors must be exactly the vertices some heading moves forward to, so that a vertex path alone still describes where an agent is; a turn is a wait in it.

Required Methods§

Source

fn heading_count(&self) -> usize

The number of headings. Headings are 0..heading_count(), the same at every vertex.

Source

fn forward(&self, vertex: Vertex, heading: Heading) -> Option<Vertex>

The vertex an agent at vertex facing heading reaches by moving forward, or None if there is no edge that way.

Source

fn turns(&self, heading: Heading, emit: impl FnMut(Heading))

Calls emit once for every heading one turn away from heading. Turning must be able to reach every heading from every other.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl OrientedGraph for Grid

A grid as an OrientedGraph: four headings (Grid::EAST, Grid::NORTH, Grid::WEST, Grid::SOUTH, counter-clockwise), and a turn is a quarter turn either way, counter-clockwise first.

§Examples

use mapf_search::{Grid, OrientedGraph};

let grid = Grid::parse(&["..", "@."]);
assert_eq!(grid.forward(grid.vertex(0, 0), Grid::EAST), Some(grid.vertex(1, 0)));
assert_eq!(grid.forward(grid.vertex(0, 0), Grid::SOUTH), None);

let mut turns = Vec::new();
grid.turns(Grid::EAST, |heading| turns.push(heading));
assert_eq!(turns, [Grid::NORTH, Grid::SOUTH]);