‘Why Not This MAPF Plan Instead?’ Contrastive Map-based Explanations for Optimal MAPF
Abstract
Multi-Agent Path Finding (MAPF) plans can be very com- plex to analyze and understand.
Recent user studies have shown that explanations would be a welcome tool for MAPF practitioners and developers to better understand plans, as well as to tune map layouts and cost functions.
In this pa-
per we formulate two variants of an explanation problem in MAPF that we call contrastive “map-based explanation”.
The problem consists of answering the question “why don’t agents A follow paths P’ instead?”—by ﬁnding regions of the map that would have to be an obstacle in order for the expected plan to be optimal.
We propose three different methods to compute these explanations, and evaluate them quantitatively on a set of benchmark problems that we make publicly available.
Motivations for generating this type of explanation are discussed in the paper and include both user understand- ing of MAPF problems, and designer-aids to guide the improvement of map layouts.
Introduction
Multi-Agent Path Finding (MAPF) plans are able to coordinate multiple agents to arrive at their destinations without colliding with obstacles or each other (Stern et al. 2019).
These plans are complex to understand, analyze and tune (Brandao et al. 2022).
For example, when used in warehouse automation or computer games, they typically involve hundreds of agents as well as complex cost functions encoding multiple preferences.
A recent user study (Brandao et al. 2022) has showed that MAPF experts and practitioners would be interested in having explainable planners in order to, for example, tune environment layouts and cost functions and understand planner behavior.
While current explanation-generation work in MAPF has focused on visualizing feasibility of plans (Almagor and Lahijanian 2020;
Kottinger, Almagor and Lahijanian 2021), practitioners are often more interested in asking contrastive questions about agent behavior, such as “why does agent not take path X instead?”
(Brandao et al. 2022).
In this paper we look at the problem of answering questions of the type “why don’t agents A (cid:48) take paths π (cid:48) in the optimal plan?”
where A (cid:48) could be both the set of all agents or a subset.
We focus on map-based explanations for this type of questions, as these have been reported to be useful to both warehouse layout designers (Brandao et al. 2022) and
algorithm developers (Brandao et al. 2021a).
The paper provides a formalization of the problem, three methods to solve it, and an open set of problems for benchmarking.
Our approaches to solve the problem are inspired by a general search-based
XAIP approach (Chakraborti et al. 2017), and multi-agent extensions of inverse shortest-paths (Ahuja and Orlin 2001;
Brandao, Coles, and Magazzeni 2021).
The main idea is to compute the smallest set of cells in the map that would have to be obstacles in order for the expected paths to become optimal.
To the question “why don’t agents A’ take paths π (cid:48) in the optimal plan?”, we therefore compute an explanation of the type “Because of the cells/vertices X. These cells would have to be obstacles in order for π (cid:48) to be optimal”.
This paper is therefore an extension of recent work in map-based explanations for single-agent path ﬁnding (Brandao, Coles, and Magazzeni 2021).
Our contributions are the following:
We formulate two new explanation problems, called “full” and “partial” map-based MAPF explanations; 2.
We develop and openly provide a new benchmark of problems for these types of explanations; 3.
We propose and evaluate three methods for solving these problems: a search-based method which is optimal in both settings, a fast optimization-based method which is optimal in the “full” setting, and an incomplete agentconﬂict -free method.
The paper is organized in the same order: it starts by introducing the problem, then the methods, and then results.
These are followed by sections on related work and conclusions.
MAPF Map-based Explanation Problems
Consider a MAPF problem on a graph G =
( V, E ) , with
M agents
A
= { a 1 , ..., a M } whose starting vertices are given by s : A (cid:55)→ V and goal vertices g : A (cid:55)→ V .
At each timestep an agent can move to an adjacent vertex connected by an edge, or wait at the same vertex.
Let p i ( t ) be the vertex where agent a
i is located at time t .
A path p i =
[ p i (0) , ..., p i ( T i )] for agent a
i must satisfy p i (0)
=
s ( a i ) , p i ( T i )
=
g ( a i ) , and be free of collisions.
A collision is deﬁned as either a vertex collision p i ( t ) =
p j ( t ) or an edge collision p i ( t ) =
p j ( t + 1)
∧ p
i ( t + 1) =
p j ( t ) , where i (cid:54) =
j .
Let P be the space of paths.
A plan π : A (cid:55)→ P assigns paths to all agents.
An optimal plan is one that minimizes a function cost ( π )
=
(cid:80) Mi =
T i .
Finally, let “ mapf ” be an algorithm which returns an optimal plan for a problem, i.e. π = mapf ( G, A, s, g ) .
We introduce the concept of “obstacle switch”, which corresponds to turning a (traversable) vertex into an obstacle.
Let o : V (cid:55)→ { 0 , 1 } be a map from vertex to an indicator variable specifying whether that vertex is turned into an obstacle (1 for obstacle, 0 for traversable space).
In this paper we introduce problems of contrastive “mapbased explanation”: where the goal is to identify vertices that would have to become obstacles { v
i ∈
V : o i = 1 } in order for a desired path to become optimal.
In other words, our goal is to identify the vertices responsible for a desired path to not be optimal, thus leading to explanations of the type “path π (cid:48) is not optimal because of vertices V o ⊂ V .
If vertices V o were obstacles then π (cid:48) would be optimal”.
This is an instance of inverse-MAPF similar to inverse single-agent shortest-paths (Ahuja and Orlin 2001; Brandao, Coles, and
Magazzeni 2021).
Let G (cid:48)
=
( V (cid:48) , E (cid:48) ) be the graph obtained by applying obstacle switches o , i.e. V (cid:48)
= { v i ∈
V : o i = 0 } , and
E (cid:48) ⊆
E are the edges connecting remaining vertices V (cid:48) .
Furthermore let f be the function that applies this transformation, i.e. G (cid:48)
=
f ( G, o ) .
Full Map-based Explanation Problem Given graph G and a desired or expected plan π (cid:48) , ﬁnd obstacle switches o such that cost ( π (cid:48) )
=
cost ( mapf ( G (cid:48) , A, s, g )) and (cid:80) | V | i =
o i is minimized—in other words, ﬁnd the minimal amount of obstacle switches o such that π (cid:48) is an optimal plan for
G (cid:48)
=
f ( G, o ) .
Partial
Map-based
Explanation
Problem Let π (cid:48) :
A (cid:48)
(cid:55)→ P be a partial MAPF plan, which assigns paths to a subset A (cid:48) ⊂
A of the agents.
Given graph
G and a desired or expected partial plan π (cid:48) , ﬁnd obstacle switches o such that cost ( mapf ( G (cid:48) , A, s, g ))
=
cost ( constr mapf ( G (cid:48) , A, s, g, π (cid:48) ))
(i.e. such that π (cid:48) is optimal in G (cid:48) ) and (cid:80) | V | i =
o i is minimized.
Here constr mapf ( G (cid:48) , A, s, g, π (cid:48) ) is an algorithm that ﬁnds an optimal MAPF solution to agents A \ A (cid:48) while constraining agents A (cid:48) to take paths π (cid:48) .
Methods Search-Based Method
One method applicable to solving both full and partial map-based explanation problems in MAPF is search-based “model-search”, as used in XAIP Model Reconciliation work (Chakraborti et al. 2017).
Here we propose an adaptation of model-search to these explanation problems.
Algorithm 1 shows pseudo-code for the method.
The algorithm searches for a value of o , i.e. a set of vertices to be made into obstacles, in breadth-ﬁrst order of the number of obstacles added.
Each neighbor o n of state o adds a single obstacle to the map, in vertex v j (line 17).
Only vertices that are traversed by π ∗ =
mapf ( f ( G, o ) , A, s, g ) are considered (line 16)—since those are the only ones that can change the optimal solution.
In addition to that, without loss of completeness or optimality, we trim the search space of the problem by excluding a set of “forcefully free” vertices (line 3).
For full explanation problems
ForcefullyFreeVertices( π (cid:48) , s, g ) is equal to all vertices in π (cid:48) , since π (cid:48) would become infeasible in case an obstacle was added to its vertices.
For partial problems this is equal to the vertices of the subset of agents A (cid:48) in π (cid:48) , as well as the start and goal vertices { s, g } of all agents A —since adding obstacles here would make the explanation problem infeasible.
The search stops once π (cid:48) becomes an optimal plan for G (cid:48) (line 13), or if the explanation problem is infeasible (i.e. the queue is exhausted).
The “ π (cid:48) feasible in
G (cid:48) ” condition checks whether the vertices traversed by π (cid:48) are free.
The “ π (cid:48) optimal in G (cid:48) ” condition then depends on whether π (cid:48) induces a full or partial problem, and it is implemented as in the respective deﬁnitions, i.e. cost ( π (cid:48) )
=
cost ( mapf ( G (cid:48) , A, s, g )) for full problems and cost ( π (cid:48) )
=
cost ( constr mapf ( G (cid:48) , A, s, g, π (cid:48) )) for partial problems.
Simply put, if π (cid:48) is feasible and its cost is the same as the cost of the optimal plan, then π (cid:48) is an optimal plan.
The condition is written in this form to account for the fact that in MAPF multiple optimal plans may exist with the same cost.
The method is complete since all combinations of obstacle switches are considered, and it is optimal since the queue is sorted by number of obstacles added.
1: In: graph G , agents A , start s , goal g , desired plan π
2: Out: obstacle switches o that make π (cid:48) optimal 3: F ← ForcefullyFreeVertices( π (cid:48) , s, g ) 4: o ← 0 | V | 5: Q ← PriorityQueue( ) 6: Q .add( 0 , o ) 7: while | Q | > 0 do 8:
N changes , o ← Q .pop( ) 9:
G (cid:48)
← f ( G, o ) 10: π ∗ ← mapf ( G (cid:48) , A, s, g ) 11: if π ∗ = ∅
then 12: continue 13: if π (cid:48) feasible in G (cid:48) and π (cid:48) optimal in G (cid:48) then 14: return o 15: for j in { 1 , ..., | V |} do 16: if v j / ∈ F and v j ∈ AllVertices( π ∗ ) then 17: o n ← o ; o nj ← 1 ;
N n changes ← N changes + 18: if o n not in Q then 19:
Q. add( N n changes , o n ) 20: return failure
Incremental Optimization-Based Method
In this section we propose a fast incremental method to solve the full map-based explanation problem.
It is based on the single-agent inverse shortest-paths method NISP # (Brandao, Coles, and Magazzeni 2021).
Our method works by incrementally obtaining a set of “bad” plans B =
[ π 1 , π 2 , ... ] which should be made infeasible so that a desired or expected plan π (cid:48) becomes optimal.
First, the method obtains the minimal obstacle switches o that makes all plans in B infeasible but keeps π (cid:48) feasible.
Then, it obtains a new optimal plan π ∗ for G (cid:48)
=
f ( G, o ) .
If cost ( π (cid:48) )
=
cost ( π ∗ ) then our desired path is now optimal and the algorithm can stop.
Otherwise, it adds π ∗ to the set of paths B .
The method proceeds this way until the desired plan becomes optimal (because a large amount of alternative plans was made infeasible) or until the method can no longer make progress (because it is just not possible to make π (cid:48) optimal).
Pseudocode for the incremental method is shown in Algorithm 2.
Algorithm
1: In: graph G , agents A , start s , goal g , desired plan π (cid:48) 2:
Out: obstacle switches o that make π (cid:48)
optimal 3: B ← {} 4: for iter in 1, ..., MAX ITER do 5: success, o ← StepInvMAPF ( A, B, π (cid:48) ) 6: if not success then 7: return failure 8:
G (cid:48)
← f ( G, o ) 9: π ∗ ← mapf ( G (cid:48) , A, s, g ) 10: if π ∗ = ∅ then 11: return failure 12: if π (cid:48) feasible in G (cid:48) and π (cid:48) optimal in G (cid:48) then 13: return o 14:
B ← B ∪ { π ∗ } 15: return failure
The key step in the algorithm is function “ StepInvMAPF ” in line 5.
This function is responsible for obtaining minimal obstacle switches o that lead plans B to become infeasible.
The function also needs to maintain the feasibility of π (cid:48) in order to make π (cid:48) optimal for large enough | B | .
We implement this by the following optimization problem:
[Equation]
minimize o
[Equation]
The solution to this problem will have a minimal amount of obstacles added to the graph (1a) while making each “bad” plan π b ∈ B infeasible (1d)—by placing at least one obstacle along each π b .
The problem also makes sure that no obstacles are placed along the desired plan π (cid:48) (1c), so that it is not invalidated.
For full explanation problems and a large enough
MAX ITER, the incremental method is complete because, as in the single-agent case (Brandao, Coles, and Magazzeni 2021), if a solution to the inverse problem exists then it is possible to obtain a large enough set of alternative paths B that need to be made infeasible before π (cid:48) becomes optimal.
At each iteration the method computes an optimal plan that is different from all π b ∈ B , and adds that plan to B if it is not the same cost as π (cid:48) .
Eventually, enough different (previously optimal) plans will be added to B so that π (cid:48) becomes the next optimal plan.
For full explanation problems this method is also optimal in || o
|| 1 because “ StepInvMAPF ” is optimal.
If the method did not return the ﬁrst solution found (line 13), then the amount of alternative plans B would only increase—which could only keep or increase the value of || o || 1 with respect to the ﬁrst solution found.
This method can also be applied to partial explanation problems, although it is not complete nor optimal in this case.
To apply it here we simply need to use the appropriate optimality check in line 12, as in the search-based method, as well as constraining only the subset of agents A (cid:48) of the partial problem in (1c).
In this case the method is not complete since it attempts to make a full MAPF-plan have lower cost than the alternatives B .
This target plan is a single optimal plan that respects π (cid:48) , even though many same-cost plans may potentially exist.
In order for the method to be complete, it would therefore have to go through all optimal plans that respect π (cid:48) —which is impractical in MAPF.
Even so, this method may still be useful for its speed in applications where it is not essential to have optimal explanations, as we will see in the Results section.
Since its computation time is negligible compared to search-based methods, it could be used to quickly obtain an explanation, before resorting to search in case it fails.
Joint ISP Method
We ﬁnally include a third (baseline) approach to solve the map-based explanation problems.
The idea of this method is to compute obstacles that simultaneously lead each of the single-agent paths p
i in π (cid:48) to become optimal while ignoring other agents.
We will use this method to evaluate the degree to which the single-agent inverse problem is useful in the multi-agent domain.
Let a single-agent shortest path be modeled as an LP (Ahuja, Orlin, and Magnanti 1993):
[Equation]
where w is a vector of weights w j ∈ W which model the relative cost of movement in each edge, x j is equal to 1 if e j ∈ E belongs to the shortest path, and
0 otherwise.
C is a matrix where C ij is equal to 1 if e j leaves v i , -1 if it arrives at v i , and 0 if it does neither.
Finally, b i is equal toif
v i = v start , -1 if v i
= v goal , and 0 otherwise.
Basically, the inverse shortest-path (ISP) problem for a single agent corresponds to ﬁnding a new weight vector that leads the shortest path being the desired one x (cid:48) .
As demon- strated by (Ahuja and Orlin 2001), can be solved as:
[Equation]
where ψ and λ are the dual variables of the constraints
Cx = b and x ≥
[Equation]
respectively
[Equation]
and (3b-3e) enforce the complementary slackness conditions required for x (cid:48) to become an optimal solution to (2).
The straight-forward adaptation to our setting where obstacles can be added to the map, is to model obstacles as large costs (e
[Equation]
g. w j =for movement over an obstacle, w j = 1 for free space).
Then the extension to the multi-agent setting is to simultaneously compute the ISP for each of the agents a ∈ A , while minimizing the number of obstacles added:
[Equation]
where c is the penalty constant ( 1000 in our experiments), and r ( j ) is a map from edge index to the corresponding target vertex index.
The problem is similar to (3) but has one ψ , λ and x (cid:48) for each agent i = 1 , ..., M (i.e. per-agent ISP), and replaces the weight vector by o .
This approach is not complete because it does not take interactions between agents into account.
Therefore, it cannot account for situations such as when the only way to make a certain path p (cid:48)
i for agent a i optimal is to force another agent a j to take a path that collides with p i .
The method can be used in the partial explanation setting by solving (4) over only those ψ i , λ i , x i with i ∈ { 1 , ..., M } : a i ∈ A (cid:48) .
Experiments Setup
For all experiments in this paper we used Wolfgang H¨onig’simplementation of CBS (Sharon et al. 2015) as the MAPF solver, and Gurobi 2 as the Mixed-Integer Linear Programming solver.
Computation times were measured on a
[Equation]
Generating Benchmark Problems
We used the 8x8-grid MAPF problems from 1 to generate a set of map-based explanation problems.
Full Explanation Problems For each MAPF problem we obtained an optimal plan π ∗ using CBS, and then we attempted to generate a random “question” of the type “why is the optimal plan not π (cid:48) ?”
where π (cid:48) is equal to π ∗ except for two agents a i and a j , i (cid:54)
=
j .
The procedure we used to obtain π (cid:48) was as follows:
Pick two random agents a i , a j , i (cid:54) =
j 2.
Pick two random vertices v i , v j in the map which are not in s , g , nor π ∗ 3.
Set π (cid:48) ← π ∗ and then set π (cid:48)
( a i ) equal the shortest path through v i for agent a i (similarly for agent a j ) 4.
If π (cid:48) is valid (no agent collisions), then attempt to solve the inverse-MAPF problem on ( G, A, s, g, π (cid:48) ) with one of the methods (i.e. search, ISP, incremental) 5.
If successful store ( G, A, s, g, π (cid:48) ) as a full explanation problem, otherwise go to 1.
We repeated the above procedure for a maximum of 100 tries in each MAPF problem, and thus obtained three sets of problems (each set 100% solvable by one of the methods).
A search/ISP/incremental method was deemed successful if it obtained a solution within a time budget of 5 minutes.
This lead to the generation of a total of 100 benchmark problems.
Partial Explanation Problems We used the same methodology as before to generate partial-explanation problems, but where the desired plan is partial π (cid:48) : { a i , a j } (cid:55)→
P , i.e. step 3 initializes π (cid:48)
= ∅ before setting the paths for a i , a j .
This means that all other agents are free to behave differently than they did in π ∗ , and it corresponds to asking a question of the type “why do agents a i , a j not take paths π (cid:48)
( a i ) , π (cid:48) ( a j ) in the optimal solution?”.
The process lead to a total of 140 benchmark problems.
Problem Availability
All explanation problems are available online for benchmarking purposes at https://to-addafter-review.
Evaluation in Full Explanation Problems
Table 1 shows success rates and computation times of the three methods on the three sets of explanation problems.
As expected due to completeness in the full-explanation setting, both the search and incremental methods are able to solve all problems.
Joint single-agent ISP, however, is only able to solve 24 out of 36 problems generated for the incremental method, and 24 out of 39 generated for search.
This shows that the single-agent inverse problem can actually be used in some MAPF problems—i.e. it is often possible to identify map changes that lead to an expected plan and avoid agent conﬂicts.
Joint ISP is not optimal, and therefore it
Problems
[Table]
solved part of these problems with longer explanations than search/incremental.
In Figure 1 we show a comparison of the explanation lengths (i.e. | o | 1 ) obtained by the joint-ISP method vs the search method—which as we have just described is often higher in ISP.
Our incremental method was slightly faster than search, as seen by the average computation times in Table 1, as well as Figure 2.
The ﬁgure shows each problem as a point and compares the computation times of search vs the incremental method—showing the times are similar but often faster in the incremental method.
Figure 3 shows two examples of explanations obtained by the incremental method.
First, it shows two MAPF problems with respective optimal plans (left).
Then, a question of the type “why do these two agents not take the paths in blue instead (and other agents’ paths stay as they are)?”
(middle).
For instance, the ﬁrst example is basically asking why agents 2 and 3 do not avoid being close to each other and other agents’ paths in the center (by going around some of the obstacles the other way).
Figure 3 (right) then shows the explanations: which consist of identifying free cells that would have to be occupied in order for the desired plan to be optimal.
In text, they would read “Because the cells marked in purple are free.
Your desired plan would be optimal if there were obstacles on the marked cells.”
Evaluation in Partial Explanation Problems
Table 2 and Figure 4 show results on the partial explanation problems.
Results for the incremental method were obtained by assuming a desired plan π = constr mapf ( G, A, s, g, π (cid:48) ) .
These problems are much more challenging than full-explanation problems, as can be seen by computation times and success rates.
No method was able to solve all problems.
While the search method is complete and optimal, it ran on a 5 minute time budget, therefore solving only 35/41 problems generated for the incremental method and 25/46 generated for joint-ISP.
As seen in Figure 4, the incremental method solved problems within 3 seconds, while the search method took up to 246 seconds (and would take longer for the problems marked as unsolved due to the time budget).
We also show results obtained with a 30 minute time budget on Table 3—where search raises the success rate to 38/41 on rnd incr and 38/46 on rnd isp.
Both tables show a column named “Collection”.
This consists of the sub-optimal strategy of attempting to solve an explanation problem ﬁrst with the incremental method, then ISP if it fails, and only then by search.
The strategy can obviously solve all problems, since each method can fully solve one of the problem sets, but at a much faster speed than if only search was used.
[Figure]
Related Work
This paper is aligned with much recent work on the topic of eXplainable AI Planning (XAIP)
(Fox, Long, and Magazzeni 2017; Chakraborti et al. 2017) and explainable motion planning (Brandao et al. 2021b), in that it proposes ways to generate explanations for plans that improve users’ understanding of a problem, or a method.
Since we focus on mapbased explanations, our work is also inherently linked to the ﬁeld of design optimization (Martins and Lambe 2013).
The explanations developed by our methods could, for example, be used to guide warehouse layout designers or game map designers in improving the environments such as to obtain desired (e.g. human-predictable) paths.
This is an application that has been raised as useful by industry practitioners in warehouse automation and computer games (Brandao et al. 2022).
In this paper we focus speciﬁcally on answering questions contrasting an optimal plan to one that was desired or expected—since explanations have been shown to be contrastive (Miller 2019; Lewis 1986; Lipton 1990) and recent user studies have shown MAPF experts and practitioners ﬁnd these useful (Brandao et al. 2022).
Our incremental and ISP-based methods basically extend recent work on single-agent path planning explanations (Brandao, Coles, and Magazzeni 2021) to the multiagent domain.
To the best of our knowledge these are the ﬁrst methods to solve map-based MAPF explanations.
Few other methods have been proposed for explainable MAPF.
A notable exception is the work of (Almagor and Lahijanian 2020), that proposes a method to intuitively visualize why a
MAPF plan is free of collisions.
A similar method has since been proposed for the continuous-motion MAPF setting as well (Kottinger, Almagor, and Lahijanian 2021).
Conclusion
In this paper we introduced a map-based explanation problem for optimal MAPF.
We formulated two variants of the problem, we proposed three methods to solve them, and we evaluated them on a benchmark that we make public for future work in the problem.
The two variants correspond to answering two similar questions about a MAPF plan: 1) “why
Problems solved
[Table] [Table]
isn’t this the MAPF plan?”
(full-plan explanation setting), and 2) “why don’t these agents take these paths instead?”
(partial-plan explanation).
The search-based method is optimal in both the partial and full explanation settings.
Our incremental method is very fast by focusing on incrementally identifying paths that need to be made infeasible in order for the desired path to become optimal.
Even though it is incomplete in the partial setting, it is able to solve problems much faster than search, thus potentially being useful in applications where optimal explanation-length is not crucial.
We also showed that many problems can be solved quickly by ignoring agent conﬂicts in a joint single-agent ISP.
One interesting future direction of research is that of conducting user studies to understand whether agent-conﬂictfree explanations computed by joint ISP are more intuitive, or more quickly understood than optimal explanations.
User studies with professional warehouse layout designers and computer game map designers would also help validate the methods—and they could provide useful information on the usefulness of this type of explanation and how to further improve it.
Finally, research is needed in order to develop faster and more effective algorithms for the partialplan explanation case—both in the optimal and sub-optimal
MAPF setting.
These algorithms could leverage, for example, symmetry-reasoning (Li et al. 2021), branch-and-cutand-price (Lam et al. 2019), or incremental optimization strategies.