API reference

Only exported names are part of the API.

Structures

MultiAgentPathFinding.MAPFType
struct MAPF{G<:Graphs.AbstractGraph{Int64}, M, VC, EC}

Instance of a Multi-Agent Path Finding problem with custom conflict rules.

Fields

  • g::Graphs.AbstractGraph{Int64}: underlying graph

  • edge_costs::Any: edge costs, typically stored as a matrix

  • departures::Vector{Int64}: agent departure vertices

  • arrivals::Vector{Int64}: agent arrival vertices

  • departure_times::Vector{Int64}: agent departure times

  • vertex_conflicts::Any: dict-like object linking vertices to their incompatibility set

  • edge_conflicts::Any: dict-like object linking edges (as tuples) to their incompatibility set

Note

Agents appear at their departure vertex when the departure time comes, and they disappear as soon as they have reached the arrival vertex.

source
MultiAgentPathFinding.ReservationType
struct Reservation

Keep track of which vertices and edges are known to be occupied and by whom.

It does not have to be a physical occupation: some agent might be occupying a related vertex or edge which generates a conflict.

Fields

  • single_occupied_vertices::Dict{Tuple{Int64, Int64}, Int64}: (t, v) -> a where a is the only agent occupying v at time t

  • single_occupied_edges::Dict{Tuple{Int64, Int64, Int64}, Int64}: (t, u, v) -> a where a is the only agent occupying (u, v) at time t

  • multi_occupied_vertices::Dict{Tuple{Int64, Int64}, Vector{Int64}}: (t, v) -> [a1, a2] where a1, a2 are the multiple agents occupying v at time t

  • multi_occupied_edges::Dict{Tuple{Int64, Int64, Int64}, Vector{Int64}}: (t, u, v) -> [a1, a2] where a1, a2 are the multiple agents occupying (u, v) at time t

Note

The split between single and multi is done for efficiency reasons: there will be many more single_occupied than multi_occupied, so allocating a set for all of these would be wasteful (and using Union{Int, Set{Int}} would be type-unstable).

source

Access

Feasibility and cost

MultiAgentPathFinding.path_costFunction
path_cost(
    timed_path::TimedPath,
    a::Integer,
    mapf::MAPF
) -> Any

Sum the costs of all the edges in timed_path. Costs are computed within mapf for agent a.

source
MultiAgentPathFinding.is_feasibleFunction
is_feasible(solution::Solution, mapf::MAPF; verbose) -> Bool

Check whether solution is both individually and collectively feasible (correct paths and no conflicts).

source
MultiAgentPathFinding.VertexConflictType
struct VertexConflict

Temporal vertex conflict between two agents (for debugging purposes).

Fields

  • t::Int64: time

  • v::Int64: vertex

  • a1::Int64: first agent

  • a2::Int64: second agent

source
MultiAgentPathFinding.EdgeConflictType
struct EdgeConflict

Temporal edge conflict between two agents (for debugging purposes).

Fields

  • t::Int64: time

  • u::Int64: edge source

  • v::Int64: edge destination

  • a1::Int64: first agent

  • a2::Int64: second agent

source

Basic algorithms

Benchmarks

MultiAgentPathFinding.read_benchmarkFunction
read_benchmark(
    map_name::AbstractString,
    scenario_name::AbstractString;
    check
) -> MAPF{SimpleWeightedGraphs.SimpleWeightedGraph{Int64, Float64}, SparseArrays.SparseMatrixCSC{Float64, Int64}, MultiAgentPathFinding.LazyVertexConflicts, MultiAgentPathFinding.LazySwappingConflicts}

Create a MAPF instance by reading a map ("something.map") and scenario ("something.scen") from files.

See possible names at https://movingai.com/benchmarks/mapf/index.html (data will be downloaded automatically).

source

Internals

MultiAgentPathFinding.MAPFBenchmarkProblemType
struct MAPFBenchmarkProblem

Encode one agent of a MAPF scenario.

Fields

  • index::Int64

  • bucket::Int64

  • map_path::String

  • width::Int64

  • height::Int64

  • start_i::Int64

  • start_j::Int64

  • goal_i::Int64

  • goal_j::Int64

  • optimal_length::Float64

source
MultiAgentPathFinding.ShortestPathTreeType
struct ShortestPathTree{V, W}

Storage for the result of Dijkstra's algorithm run backwards.

Fields

  • children::Vector: successor of each vertex in a shortest path

  • dists::Vector: distance of each vertex to the arrival

source
MultiAgentPathFinding.benchmark_cell_colorMethod
benchmark_cell_color(
    c::Char
) -> ColorTypes.RGB{FixedPointNumbers.N0f8}

Give a color object corresponding to the type of cell.

To visualize a map in VSCode, just run cell_color.(map_matrix) in the REPL.

source
MultiAgentPathFinding.edge_at_timeMethod
edge_at_time(
    timed_path::TimedPath,
    t::Integer
) -> Tuple{Any, Any}

Return the edge crossed by timed_path at a given time t, throws an error if it does not exist.

source
MultiAgentPathFinding.edge_costMethod
edge_cost(edge_costs::AbstractMatrix, u, v)
edge_cost(edge_costs::AbstractMatrix, u, v, a, t)

Return the cost of edge (u, v) for agent a at time t when the cost storage edge_costs is a matrix (hence agent- and time-independent).

This method, as well as Base.eltype, must be overridden for other storage formats.

source
MultiAgentPathFinding.exists_in_graphMethod
exists_in_graph(
    timed_path::TimedPath,
    g::Graphs.AbstractGraph
) -> Bool

Check that timed_path is feasible in the graph g, i.e. that all vertices and edges exist.

source
MultiAgentPathFinding.occupy!Method
occupy!(
    reservation::Reservation,
    a::Integer,
    t::Integer,
    v::Integer
)

Update reservation so that agent a occupies vertex v at time t.

source
MultiAgentPathFinding.occupy!Method
occupy!(
    reservation::Reservation,
    a::Integer,
    t::Integer,
    u::Integer,
    v::Integer
)

Update reservation so that agent a occupies edge (u, v) at time t.

source
MultiAgentPathFinding.parse_benchmark_mapMethod
parse_benchmark_map(
    map_matrix::Matrix{Char}
) -> Tuple{SimpleWeightedGraphs.SimpleWeightedGraph{Int64, Float64}, Dict{Tuple{Int64, Int64}, Int64}}

Create a sparse grid graph from a map specified as a matrix of characters.

source
MultiAgentPathFinding.parse_benchmark_scenarioMethod
parse_benchmark_scenario(
    scenario::Vector{MultiAgentPathFinding.MAPFBenchmarkProblem},
    coord_to_vertex::Dict
) -> Tuple{Vector{Int64}, Vector{Int64}}

Turn a scenario into vectors of departure and arrival vertices.

source
MultiAgentPathFinding.read_benchmark_scenarioMethod
read_benchmark_scenario(
    scenario_name::AbstractString,
    map_name::AbstractString
) -> Vector{MultiAgentPathFinding.MAPFBenchmarkProblem}

Read a scenario from a text file, and check that it corresponds to a given map.

Returns a Vector{MAPFBenchmarkProblem}.

source
MultiAgentPathFinding.remove_agents!Method
remove_agents!(
    solution::Solution,
    agents::AbstractVector{<:Integer}
) -> Solution

Remove a set of agents from solution and return a backup_solution containing only them.

source
MultiAgentPathFinding.temporal_astarMethod
temporal_astar(
    ::MultiAgentPathFinding.HardConflicts,
    g::Graphs.AbstractGraph,
    edge_costs;
    a,
    dep,
    arr,
    tdep,
    reservation,
    heuristic,
    max_nodes
)

Apply temporal A* to graph g, with specified edge costs.

Keyword arguments

  • a: agent
  • dep: departure vertex
  • arr: arrival vertex
  • tdep: departure time
  • reservation: reservation indicating occupied vertices and edges at various times
  • heuristic: indexable giving an underestimate of the remaining distance to arr
  • max_nodes: maximum number of nodes in the search tree, defaults to nv(g)^3
source
MultiAgentPathFinding.temporal_astarMethod
temporal_astar(
    ::MultiAgentPathFinding.SoftConflicts,
    g::Graphs.AbstractGraph,
    edge_costs;
    a,
    dep,
    arr,
    tdep,
    reservation,
    heuristic,
    conflict_price,
    max_nodes
)

Apply a bi-objective variant of temporal A* to graph g with specified edge_costs.

The objective is to minimize a weighted combination of (1) the number of conflicts and (2) the path cost.

Keyword arguments

  • a, dep, arr, tdep, reservation, heuristic, max_nodes: see temporal_astar.
  • conflict_price: price given to the number of conflicts in the objective
source

Index