**4. Heuristics**

The mathematical model presented in Section 3 can be solved through off-the-shelf solvers for mixed-integer linear programming to obtain an optimal solution for a given FQRP-G instance, i.e., the minimum number of rows that allows collision-free nonstop Manhattan paths to route vehicles on, together with the paths themselves. However, due to the computational complexity of integer linear programming, we expect that the efficiency of the model, in terms of time to obtain the optimal solution, degrades with the size of the instance to handle, as in fact our computational experiments, presented in Section 5, ascertain. We thus propose two heuristics to solve FQRP-G. The first one, called Heuristic

A, is a reinterpretation of the CaR algorithm given by Cenci et al. in [7], but it is much simpler and improves the computational complexity, as will be stated in Proposition 4. It uses the C-conflict directed graph to generate vehicle routes that are simple Manhattan paths and it is able to always provide a feasible solution to FQRP-G. The second one, called Heuristic B, is more flexible in choosing Manhattan paths and attempts to determine the vehicle routes by giving priority to the horizontal moves of vehicles ranked on the basis of measures obtained from the C-conflict directed graph.

### *4.1. Heuristic A*

Heuristic A is based on the C-conflict directed graph *F*. As from Proposition 1, each connected component of *F* is an oriented arborescence. Any such arborescence has a root, and its nodes can be partitioned according to their depth. The root has zero depth. The depth of any node is equal to the length of the unique path in *F* from the root to that node. For each node, we also define its height as the length of the longest path in *F* from that node to any of the leaves. The height of a connected component is equal to the length of the longest path from its root, i.e., the height of the root itself. Vehicles in *S*, as well as any vehicle that is not involved in C-conflicts, are isolated nodes in *F*, and have both height and depth equal to 0. The root of any non-trivial arborescence is either in *L* or in *R*.

We now state Heuristic A and, then, we discuss its correctness and properties. Given an instance of FQRP-G, in terms of the number of columns *n*, set of vehicles and related origins *α* and destinations *ω*, Heuristic A runs through the following steps:


**Proposition 2.** *The vehicle routes given by Heuristic A are nonstop collision-free simple Manhattan paths.*

 solution.

**Proof.** In the output of Heuristic A, all the horizontal moves performed at any level have the same direction. Indeed, each path in *F* is a C-conflict path and, hence, it alternates vehicles in *R* and in *L*. If follows that, under the assumption that the maximum height is related to an arborescence rooted in *R* (the case in *L* is similar) all vehicles in *R* move horizontally on an odd row, and all vehicles in *L* on an even row. This corresponds to having one-way horizontal lanes, which prevents collisions related to edge conflicts from occurring. We observe that, trivially, Heuristic A outputs simple Manhattan paths, as each vehicle performs consecutively all its horizontal moves on the same level. This, together with one-way lanes, avoids collisions related to B-conflicts.

For each pair of vehicles *p* and *q* such that *q* has a C-conflict with *p*, the directed graph *F* contains the arc (*p*, *q*), and *lq* = *lp* + 1 holds. Therefore, vehicle *p* performs its horizontal moves on a lower level than *q* does, and the route of *p* is below the one of *q* in column *<sup>ω</sup>*(*q*), as required to avoid collisions related to C-conflicts.

Notice that, if Heuristic A is applied to a single connected component of *F*, then the number of grid levels used by the output solution is equal to one plus the height of that component. Therefore, given any instance, the number of grid levels needed by Heuristic A is equal the height of the highest connected component of *F*, added by 2. The term "+2" comes from the case in which the forest *F* contains two (or more) highest components, of which, one rooted in *R* and another in *L*. This proves the following

**Proposition 3.** *Given an instance of FQRP-G and its C-conflict direct graph, let m*¯ *R and m*¯ *L be the maximum height of an arborescence rooted in R and, respectively L. The number of levels required by Heuristic A is* max{*m*¯ *R*, *m*¯ *L*} + *a, where a* = 1 *if m*¯ *R* = *m*¯ *L, a* = 2 *otherwise.*

The number of required levels is equal to the one stated for algorithm CaR proposed by Cenci et al. in [7]: as shown in [7], CaR optimally solves FQRP-G if the set of vehicle routes is restricted to simple Manhattan paths and under the hypothesis of one-way horizontal lanes. We thus have the following

**Corollary 1.** *Heuristic A finds the optimal solution of FQRP-G restricted to simple Manhattan paths and one-way horizontal lanes.*

In fact, as already stated above, Heuristic A is a reinterpretation of the CaR algorithm that improves its computational complexity (we recall that CaR runs in <sup>O</sup>(*n*)3).

**Proposition 4.** *Given an instance of FQRP-G on a grid network with n columns, the computational complexity of Heuristic A is* O(*n*)*.*

**Proof.** In order to detect all C-conflicts, O(*n*) calculations are sufficient. Indeed, for any vehicle *k* ∈ *R* (resp. in *L*), we only have to check if there is another vehicle moving from position (2 *ω*(*k*) − *<sup>α</sup>*(*k*), 1) and having its destination on the left (resp. on the right) of column *ω*(*k*); in such case, vehicle *k* has a C-conflict with the other vehicle. All the arcs of *F* can be thus detected in at most *n* (a bound on the number of vehicles) operations, and *F* built in O(*n*). All the data required by Heuristic A can be collected during a depth-first visit of *F*, which allows computing the depth and the height of any node in O(*n*). This shows that Step 1 takes O(*n*) operations. Concerning Steps 2 to 4, they simply assign the horizontal level to each vehicle, which can still be done in O(*n*).

### *4.2. Heuristic B*

Heuristic B aims at calling non-simple Manhattan paths conveniently into play. The underlying idea is to find an appropriate order of the vehicles and, then, to sequentially route each vehicle on the "lowest" Manhattan path possible, i.e., a Manhattan path obtained by choosing a horizontal step whenever this is compatible with previously assigned paths.

Vehicles are sorted according to a measure of how critical it is to route them. For example, an order of the vehicles could provide a feasible set of routes only if, for any pair of vehicles *k*1, *k*2 such that *k*2 has a C-conflict with *k*1 on column *<sup>ω</sup>*(*k*2), vehicle *k*1 precedes *k*2 in the order, since otherwise *k*2 would have precedence in the horizontal move to reach the conflict column and stay below *k*1 on it, which means that the C-conflict cannot be resolved (see Section 3.1). It follows that vehicles belonging to a C-conflict path should be sorted in the increasing order of their depth in the C-conflict directed graph *F*, which again plays an important role in prioritizing vehicles. We also observe that, in general, the assigned Manhattan paths are not simple and each level can be run in opposite directions; therefore, both edge conflicts and B-conflicts may actually generate collisions and have to be taken into account.

For each vehicle *k*, the following measures are considered:

•*lk*: the depth of *k* in *F*;

• *γk*: length of the longest C-conflict path *k* belongs to. Notice that, if *lk* and *hk* are, respectively, the depth and the height of *k* in *F*, *γk* = *lk* + *hk*, and, in particular, *γk* = 0 if *k* is not involved in any C-conflict;


Given an instance of FQRP-G, in terms of number of columns *n*, set of vehicles and related origins *α* and destinations *ω*, Heuristic B runs through the following steps:

	- (a) let (*i*, *j*) be the actual position of vehicle *k* in the grid (initially set to (*α*(*k*), 1));
	- (b) if *i* = *ω*(*k*) and *j* = *m*, then output "feasible path for *k* found" and consider the next vehicle;
	- (c) if *i* = *ω*(*k*) and all vehicles up to *k* in a C-conflict path are not involved in further conflicts, then *k* performs a vertical move;
	- (d) otherwise, if *i* = *<sup>ω</sup>*(*k*), then check if the horizontal move to node (*i* + 1, *j*) involves any collision with previously assigned paths (this could be related to a node-conflict if, after a unit of time, another vehicle will be in node (*i* + 1, *j*), or an edge conflict if another vehicle is performing the opposite move from (*i* +1, *j*) to (*i*, *j*) at the same time); if the answer is "no conflict", then *k* performs the horizontal move to node (*i* + 1, *j*);
	- (e) otherwise, check if the vertical move to (*i*, *j* + 1) involves any conflict with previously assigned paths (this could be a node-conflict if, after a unit of time, another vehicle will be in node (*i*, *j* + 1)); if the answer is "no conflict", then *k* vertically moves to node (*i*, *j* + <sup>1</sup>);
	- (f) otherwise, output "no feasible path for *k* found" and stop.

With reference to Step 4c, we remark that, since vehicles are sorted by non-decreasing *lk*, collisions related to C-conflicts are avoided, as for any arc (*k*1, *k*2) of *F*, the path of vehicle *k*1 is set before the path of *k*2. These are the only collisions associated with vertical moves on the destination columns, so that, in the case specified by Step 4c, checking their occurrence is redundant.

While, in the above case, C-conflicts are solved by appropriately ordering the vehicles in the first phase of the algorithm, remaining node-conflicts and edge conflicts are tentatively solved during Steps 4d–4e. However, we have no guarantee to avoid related collisions and, indeed, Heuristic B may ge<sup>t</sup> stuck if both horizontal and vertical moves of a vehicle at a given node are forbidden. Nevertheless, if Heuristic B is successful, the required number of levels is not bounded from below by the length of the longest C-conflict path, as it is the case for Heuristic A: we thus aim to empirically evaluate the probability of getting stuck and, if this is not the case, the ability of Heuristic B to provide better results than Heuristic A.

The actual performance of Heuristic B depends on the specific sorting adopted by Step 3. We propose two alternatives giving rise to:


We now discuss the computational complexity of Heuristic B.

**Proposition 5.** *Given an instance of FQRP-G on a grid graph with n columns, the computational complexity of Heuristic B is* <sup>O</sup>(*n*<sup>2</sup> *<sup>m</sup>*)*.*

**Proof.** Step 1 to determine *m* can be done in O(*n*). The measures required by the sorting step can be computed by building and depth-first visiting the C-conflict directed graph *F*, which can be done in O(*n*) (as discussed in proof of Proposition 4). The sorting Step 3 takes O(*n* log *<sup>n</sup>*). Since the number of moves in a Manhattan path is bounded by *n* + *m*, and the number of vehicles by *n*, the complexity of Step 4, and of overall Heuristic B, is <sup>O</sup>(*n*<sup>2</sup> *<sup>m</sup>*).
