API¶
- gtravyl.euclidean_dist(ind1: tuple[int, int], ind2: tuple[int, int], value1: Any, value2: Any)¶
Neighbor indices are computed under the standard Euclidean distance.
- Parameters:
ind1 – Location in Euclidean space for the first point.
ind2 – Location in Euclidean space for the second point.
value1 – Needed for type signature, essentially ignored.
value2 – Needed for type signature, essentially ignored.
- gtravyl.in_bounds(pt: tuple[int, int], dim: tuple[int, int]) bool¶
Checks if the candidate point actually exists in the grid.
- Parameters:
pt – The point to check if it is in bounds.
dim – Dimensions (row, column) of the grid.
- gtravyl.moore_neighbors(ind: tuple[int, int], grid: ~numpy.ndarray[tuple[~typing.Any, ...], ~numpy.dtype[~numpy._typing._array_like._ScalarT]], wrap=<function no_wrap>)¶
Return the Moore neighborhood of a particular cell in the grid.
- Parameters:
ind – Index to compute Moore neighborhood of.
grid – The grid
indbelongs to.
- gtravyl.no_wrap(ind: tuple[int, int], dim: tuple[int, int]) tuple[int, int]¶
Does not wrap indices. Essentially does nothing in this case.
- Parameters:
ind – Needed for type signature. This function is equivalent to: id(ind) -> ind
dim – Needed for type signature, it is otherwise ignored.
- gtravyl.not_one(value: Any)¶
Checks if a value is not 1. You can think of 1 as though there is a wall and you are not allowed to traverse there. Any other value is fine. (This is the default function for the keyword argument
allowedofshortest_path.- Parameters:
value – Value to check.
- gtravyl.shortest_path(grid: ~numpy.ndarray[tuple[~typing.Any, ...], ~numpy.dtype[~numpy._typing._array_like._ScalarT]], si: tuple[int, int] | None = None, ti: tuple[int, int] | None = None, sv: ~typing.Any | None = None, tv: ~typing.Any | None = None, neighbors=<function vn_neighbors>, allowed=<function not_one>, wrap=<function no_wrap>, dist=<function unit_dist>, heuristic=<function no_heuristic>) list[tuple[int, int]]¶
Find shortest path from
stotin a given grid.- Parameters:
grid – grid (2d array) representation of the world to traverse.
si – The “source” index, i.e. where the path search starts.
ti – The “destination” index, i.e. where the path should end.
sv – The “source” value, i.e. the value of the start index.
tv – The “destination” value, i.e. the value of the end index.
neighbors – Computes the neighborhood of any choice of index in the grid.
wrap – Does the grid wrap around. Defaults to no wrap.
dist – The distance function used. Defaults to unit distance.
- gtravyl.unit_dist(ind1: tuple[int, int], ind2: tuple[int, int], value1: Any, value2: Any)¶
Every neighbor is
1unit distant from the other.
- gtravyl.vn_neighbors(ind: tuple[int, int], grid: ~numpy.ndarray[tuple[~typing.Any, ...], ~numpy.dtype[~numpy._typing._array_like._ScalarT]], wrap=<function no_wrap>)¶
Return the von Neumann neighborhood of a particular cell in the grid.
- Parameters:
ind – Index to compute von Neumann neighborhood of.
grid – The grid
indbelongs to.
- gtravyl.wrap(ind: tuple[int, int], dim: tuple[int, int]) tuple[int, int]¶
Wraps the cell values around. So, if you start at (0, 0) and go left you end up at (x dimension, 0) :param ind: The index to potentially modify (that is, wrap it if
applicable).
- Parameters:
dim – Dimensions of the grid.