API reference
Docs
GridGraphs.GridGraphs
— ModuleGridGraphs
A package for graphs defined by a grid of vertices.
GridGraphs.GridDirection
— TypeGridDirection
Enum type for the 9 possible move directions on a 2-dimensional grid with square cells: northwest
, west
, southwest
, north
, center
, south
, northeast
, east
, southeast
.
Various subsets of these directions are defined as constants, but not exported. They are based on an analogy with the game of chess:
QUEEN_DIRECTIONS_PLUS_CENTER
ROOK_DIRECTIONS_PLUS_CENTER
QUEEN_DIRECTIONS
ROOK_DIRECTIONS
QUEEN_ACYCLIC_DIRECTIONS
ROOK_ACYCLIC_DIRECTIONS
Acyclic direction sets give rise to an acyclic graph because they are contained in {south, east, southeast}
.
GridGraphs.GridGraph
— TypeGridGraph{
T<:Integer,
R<:Real,
W<:AbstractMatrix{R},
A<:AbstractMatrix{Bool}
}
Graph defined by a grid of vertices with index type T
.
Fields
weights::W
: vertex weights matrix, which serve to define edge weights.active::A
: vertex activity matrix. All the vertices on the grid exist, but only active vertices can have edges (inactive vertices are isolated).directions::Vector{GridDirection}
: the set of legal directions which are used to define edges.diag_through_corner::Bool
: defines how the weight of a diagonal edge is computed.
See also
GridGraphs.GridGraph
— MethodGridGraph{T}(weights[; active, directions, diag_through_corner])
User-friendly constructor. By default, all vertices are active, all directions are allowed, and edge weights are always computed based on the arrival vertex alone.
GridGraphs.ShortestPathTree
— TypeShortestPathTree{T<:Integer,R<:Real}
Storage for the result of a single-source shortest paths query with source s
.
Fields
parents::Vector{T}
: the parent of each vertexv
in a shortests -> v
path.dists::Vector{R}
: the distance of each vertexv
froms
.
Base.:+
— MethodBase.+((i, j), dir)
Add a GridDirection
to a couple of grid coordinates and return the new coordinates.
Base.:-
— MethodBase.-(dir)
Compute the opposite GridDirection
(e.g. northwest
/ southeast
).
Base.:-
— MethodBase.-((i, j), dir)
Subtract a GridDirection
from a couple of grid coordinates and return the new coordinates.
Base.show
— MethodBase.show(io, g)
Display a GridGraph using braille patterns when not all vertices are active.
Graphs.weights
— MethodGraphs.weights(g)
Efficiently compute a sparse matrix of edge weights based on the vertex weights.
GridGraphs.active_vertex
— Methodactive_vertex(g, v)
Check if vertex v
is active.
GridGraphs.coord_to_index
— Methodcoord_to_index(g, i, j)
Convert a grid coordinate tuple (i,j)
into the index v
of the associated vertex.
GridGraphs.diag_through_corner
— Methoddiag_through_corner(g)
Check if diagonal edge weights are computed using the corner vertices.
GridGraphs.edge_weight
— Methodedge_weight(g, s, d)
Compute the weight of the edge from s
to d
.
- If
diag_through_corner(g)
isfalse
, return the vertex weight of the destinationd
- If
diag_through_corner(g)
istrue
, use Pythagoras' theorem on the cheapest of the two corner vertices.
See also
GridGraphs.edge_weight_corner
— Methodedge_weight_corner(g, s, d)
GridGraphs.edge_weight_direct
— Methodedge_weight_direct(g, s, d)
GridGraphs.get_direction
— Methodget_direction(Δi, Δj)
Translate a couple of grid steps in {±1,0}
into a GridDirection
.
GridGraphs.get_path
— Methodget_path(spt::ShortestPathTree, s, d)
Reconstruct the shortest s -> d
path from a ShortestPathTree
with source s
.
GridGraphs.get_tuple
— Methodget_tuple(::Type{T}, dir)
Translate a GridDirection
into a couple of grid steps in {±1,0}
with integer type T
.
GridGraphs.grid_bellman_ford
— Methodgrid_bellman_ford(g, s, d)
Apply grid_bellman_ford(g, s)
and retrieve the shortest path from s
to d
.
GridGraphs.grid_bellman_ford
— Methodgrid_bellman_ford(g, s)
Apply the Bellman-Ford algorithm on an GridGraph
g
, and return a ShortestPathTree
with source s
.
Compatible with ForwardDiff.
GridGraphs.grid_dijkstra
— Methodgrid_dijkstra(g, s, d)
Apply grid_dijkstra(g, s)
and retrieve the shortest path from s
to d
.
GridGraphs.grid_dijkstra
— Methodgrid_dijkstra(g, s)
Apply Dijkstra's algorithm on an GridGraph
g
, and return a ShortestPathTree
with source s
.
Uses a DataStructures.BinaryHeap
internally instead of a DataStructures.PriorityQueue
. Compatible with ForwardDiff.
GridGraphs.grid_topological_sort
— Methodgrid_topological_sort(g, s, d)
Apply grid_topological_sort(g, s)
and retrieve the shortest path from s
to d
.
GridGraphs.grid_topological_sort
— Methodgrid_topological_sort(g, s)
Apply the topological sort on an acyclic GridGraph
g
, and return a ShortestPathTree
with source s
.
Assumes vertex indices correspond to topological ranks. Compatible with ForwardDiff.
GridGraphs.has_direction
— Methodhas_direction(g, dir)
Check if direction dir
is a valid edge direction.
GridGraphs.has_negative_weights
— Methodhas_negative_weights(g)
Check if any of the vertex weights are negative.
By default this check is not included in Dijkstra's algorithm to save time.
GridGraphs.height
— Methodheight(g)
Compute the height of the grid (number of rows).
GridGraphs.index_to_coord
— Methodindex_to_coord(g, v)
Convert a vertex index v
into the tuple (i,j)
of associated grid coordinates.
GridGraphs.is_acyclic
— Methodis_acyclic(directions)
Check if a set of directions is contained in {south, east, southeast}
.
GridGraphs.path_to_matrix
— Methodpath_to_matrix(g::GridGraph, path::Vector{<:Integer})
Store the shortest s -> d
path in g
as an integer matrix of size height(g) * width(g)
, where entry (i,j)
counts the number of visits to the associated vertex.
GridGraphs.vertex_weight
— Methodvertex_weight(g, v)
Retrieve the vertex weight associated with index v
.
GridGraphs.width
— Methodwidth(g)
Compute the width of the grid (number of columns).
Index
GridGraphs.GridGraphs
GridGraphs.GridDirection
GridGraphs.GridGraph
GridGraphs.GridGraph
GridGraphs.ShortestPathTree
Base.:+
Base.:-
Base.:-
Base.show
Graphs.weights
GridGraphs.active_vertex
GridGraphs.coord_to_index
GridGraphs.diag_through_corner
GridGraphs.edge_weight
GridGraphs.edge_weight_corner
GridGraphs.edge_weight_direct
GridGraphs.get_direction
GridGraphs.get_path
GridGraphs.get_tuple
GridGraphs.grid_bellman_ford
GridGraphs.grid_bellman_ford
GridGraphs.grid_dijkstra
GridGraphs.grid_dijkstra
GridGraphs.grid_topological_sort
GridGraphs.grid_topological_sort
GridGraphs.has_direction
GridGraphs.has_negative_weights
GridGraphs.height
GridGraphs.index_to_coord
GridGraphs.is_acyclic
GridGraphs.path_to_matrix
GridGraphs.vertex_weight
GridGraphs.width