1 Introduction

In 1989, I (SF) was a fresh Ph.D. student in Waterloo and started thinking about geometric variants of the Traveling Salesman Problem. One particular version considered turn cost instead of distances; via an intermediary, I got in touch with a second-year Ph.D. student in Graz: Gerhard Woeginger. Collaborating purely by email, we managed to prove a number of theorems, which ultimately led to my first ever journal submission in 1991; for Gerhard it was one his first papers, too. Eventually, this appeared in 1997 as “Angle-restricted tours in the plane” [20].

That paper also left a number of open problems that were still being tackled by following generations of researchers. My last ever communication with Gerhard happened more than 30 years after our first paper, at the end of 2021, fittingly like our first: by email, and discussing the solution [12of one of our open problems.

It is with much gratitude for these opportunities and also some amazement to observe that highly talented member of following generations are still pursuing some of these questions. With great pride I present some of the work with my student Dominik Krupke on Turn Cost Problems, based on his masters thesis. Not only does this resolve a long-standing problem from “The Open Problems Project”; it also shows how going around in cycles can result in progress—a fitting tribute to Gerhard.

Finding roundtrips of minimum cost is one of the classic problems of theoretical computer science. In its most basic form, the objective of the Traveling Salesman Problem (TSP) is to minimize the total length of a single tour that covers all of a given set of locations. If the tour is not required to be connected, the result may be a cycle cover: a set of closed subtours that together cover the whole set. This distinction makes a tremendous difference for the computational complexity: while the TSP is NP-hard, computing a cycle cover of minimum total length can be achieved in polynomial time, based on matching techniques.

Evaluating the cost for a tour or a cycle cover by only considering its length may not always be the right measure. Figure 1 shows an example application, in which a drone has to sweep a given region to fight mosquitoes that may transmit dangerous diseases. As can be seen in the right-hand part of the figure, by far the dominant part of the overall travel cost occurs when the drone has to change its direction. (See our related video and abstract [10] for more details, and the resulting tour optimization.) There is an abundance of other related applied work, e.g., mowing lawns or moving huge wind turbines [8].

Fig. 1
figure 1

(Left) A drone equipped with an electrical grid for killing mosquitoes. (Middle) Physical aspects of the flying drone. (Right) Making turns is expensive. See our related video [10]

For many purposes, two other variants are also practically important: for subset coverage, only a prespecified subset of locations needs to be visited, while for penalty coverage, locations may be skipped at the expense of an individual penalty. From the theoretical side, Arkin et al. [6] showed that finding minimum-turn tours in grid graphs is NP-hard, even if a minimum-turn cycle cover is given. The question whether a minimum-turn cycle cover can be computed in polynomial time (just like a minimum-length cycle cover) has been open for at least 17 years, dating back to the conference paper [5]; it has been listed for 15 years as Problem 53 in The Open Problems Project edited by Demaine, Mitchell, and O’Rourke [16]. In Section 2 we resolve this problem by showing that computing a minimum-turn cycle cover in planar grid graphs is indeed NP-hard.

This raises the need for approximation algorithms. In Section 3, we present a technique based on Integer Programming (IP) formulations and their Linear Programming (LP) relaxations. Based on polyhedral results and combinatorial modifications, we prove constant approximation for all problem variants.

1.1 Related work

Milling with Turn Costs

Arkin et al. [5, 6] introduce the problem of milling (i.e., “carving out”) with turn costs. They show hardness of finding an optimal tour, even in thin 2-dimensional grid graphs (which do not contain an induced \(2\times 2\) subgraph) with a given optimal cycle cover. They give a 2.5-approximation algorithm for obtaining a cycle cover, resulting in a 3.75-approximation algorithm for tours. The complexity of finding an optimal cycle cover in a 2-dimensional grid graph was established as Problem 53 in The Open Problems Project [16].

The thesis of Maurer [26] states a proof that a cycle partition with a minimum number of turns in grid graphs can be computed in polynomial time and provides practical experiments for optimal cycle covers. De Assis and de Souza [15] computed a provably optimal solution for an instance with 76 vertices. For the abstract version on graphs (in which “turns” correspond to weighted changes between edges), Fellows et al. [21] show that the problem is fixed-parameter tractable by the number of turns, tree-width, and maximum degree. Benbernou [11] considered milling with turn costs on the surface of polyhedrons in the 3-dimensional grid. She gives a corresponding 8/3-approximation algorithm for tours.

Note that the theoretical work presented in this paper has significant practical implications. As described in our application-oriented conference paper [19], the IP/LP-characterization presented in Section 3 can be modified and combined with additional algorithm engineering techniques to allow solving instances with more than 1000 pixels to provable optimality (thereby expanding the range of de Assis and de Souza [15] by a factor of 15), and computing solutions for instances with up to 300,000 pixels within a few percentage points (thereby showing that the practical performance of our approximation techniques is dramatically better than the established worst-case bounds).

For mowing problems, i.e., covering a given area with a moving object that may leave the region, Stein and Wagner [28] give a 2-approximation algorithm on the number of turns for the case of orthogonal movement. If only the traveled distance is considered, Arkin et al. [7] provide approximation algorithms for milling and mowing.

Angle and Curvature-Constrained Tours and Paths

If the instances are in the \(\mathbb {R}^2\) plane and only the turning angles are measured, the problem is called the Angular Metric Traveling Salesman Problem. Aggarwal et al. [3] prove hardness and provide an \(O(\log n)\) approximation algorithm for cycle covers and tours that works even for distance costs and higher dimensions. As shown by Aichholzer et al. [4], this problem seems to be very hard to solve optimally with integer programming. Fekete and Woeginger [20] consider the problem of connecting a point set with a tour for which the angles between the two successive edges are constrained. Finding a curvature-constrained shortest path with obstacles has been shown to be NP-hard by Lazard et al. [25]. Without obstacles, the problem is known as the Dubins path [17] that can be computed efficiently. With complexity depending on the types of obstacles, Boissonnat and Lazard [13], Agarwal et al. [1], and Agarwal and Wang [2] provide polynomial-time algorithms when possible or \(1+\epsilon \) approximation algorithms otherwise. Takei et al. [29] consider the solution of the problem from a practical perspective.

Related Combinatorial Problems

Goemans and Williamson [22] provide an approximation technique for constrained forest problems and similar problems that deal with penalties. In particular, they provide a 2-approximation algorithm for Prize-Collecting Steiner Trees in general symmetric graphs and the Penalty Traveling Salesman Problem in graphs that satisfy the triangle inequality. An introduction into approximation algorithms for prize-collecting/penalty problems, k-MST/TSP, and minimum latency problems is given by Ausiello et al. [9].

1.2 Preliminaries

The Angular Metric Traveling Salesman Problem and the Angular Cycle Cover Problem ask for a cycle (or a set of cycles, respectively), such that all of a given set P of n points in \(\mathbb {R}^d\) is visited, and the sum of turn angles is minimized. A cycle is a closed chain of segments and covers the points of the segments’ joints. A cycle has to cover at least two points. The turn angle of a joint is the angle difference to \(180^\circ \). We consider three coverage variants: Full, subset, and penalty. In full coverage, every point has to be covered. In subset coverage, only points in a given subset \(S\subseteq P\) have to be covered. In penalty coverage, no point has to be covered, but every uncovered point \(p\in P\) induces a penalty \(c(p)\in \mathbb {Q}^+_0\) on the objective value. Optionally, the objective function can be a linear combination of distance and turn costs.

In this paper, we focus on the special case in which the points and movements are restricted to a grid graph. The repeated use of edges and vertices is explicitly allowed, which guarantees the existence of a solution if the graph is connected and has more than one vertex. Much of the literature dealing with grid graphs only considers vertex-induced subgraphs of the orthogonal integer grid \(\mathbb {Z}^2\), with two vertices pq are adjacent iff \(||p-q||=1\). While this grid also plays a prominent role in this paper, we also consider more general grid graphs, for which the grid can be defined by any regular lattice on \(\omega \) axes, and all segments have unit-length. Common grids are the triangular grid (with three axes that are offset by \(60^{\circ }\)) or the 3-dimensional cubic grid (which is just an extension of the square grid into three dimensions). See Fig. 2 for examples. We use the geometric dual (originating from the Voronoi regions of the grid) for visualization and use the term pixel synonymous to the point or vertex of the grid graph.

Fig. 2
figure 2

Different grid graphs and their number of axes. For geometric coverage problems, the dual of the graphs, defined by the Voronois cells of the grid, is of high relevance and also used by us for visualization of regular square grid graphs. The vertices or points are represented by pixels and two pixels are neighbored if they are a boundary (not just a corner)

For readability, we refrain from adding symbols for the weights of the distance and turn parts to the cost notation, as the weights do not matter for the analysis. We just add degrees to separate the turn costs and a pure unit for the number of unit-length segments. Whenever the separation is not clear, we are using a tuple with the distance in the first place and the turn angles in the second. For example \((2, 360^{\circ })\) refers to the cost of the smallest possible cycle that covers two points with a doubly used segment and a u-turn at both ends. We treat this tuple as a real number, assuming arbitray but fixed weights have been selected for the linear (conical) combination. In the hardness proof, we only use turn costs and work only in a square grid, such that we simply speak of the number of \(90^{\circ }\) turns there, with a u-turn counting twice.

1.3 Our Contribution

We provide the following results.

  • We resolve Problem 53 in The Open Problems Project [16] by proving that finding a cycle cover of minimum turn cost is NP-hard, even in the restricted case of regular square grid graphs. We also prove that finding a subset cycle cover of minimum turn cost is NP-hard, even in the restricted case of thin grid graphs, in which no induced \(2\times 2\) subgraph exists. This differs from the case of full coverage in thin grid graphs, which is known to be polynomially solvable [6].

  • We provide a general IP/LP-based technique for obtaining (\(2\omega \))-approximations for the (penalty) cycle cover problem, where \(\omega \) is the number of axes in the grid.

  • We show how to connect the cycle covers to minimum turn tours to obtain a 6-approximation for full coverage in regular square grid graphs, \(4\omega \)-approximations for full tours in general grid graphs, (\(4\omega +2\))-approximations for (subset) tours, and \(4\omega +4\) for penalty tours.

To the best of our knowledge, this is the first approximation algorithm for the subset and penalty variant with turn costs. For general grid graphs our techniques yields better guarantees than the techniques of Arkin et al., who give a factor of \(6\omega \) for cycle covers and \(6\omega +2\) for tours. In practice, our approach also yields better solutions for regular square grid graphs, see [19].

2 Complexity

Problem 53 in The Open Problems Project asks for the complexity of finding a minimum-turn (full) cycle cover in a 2-dimensional grid graph. This is by no means obvious: large parts of a solution can usually be deduced by local information and matching techniques. In fact, it was shown by Arkin et al. [5, 6] that the full coverage variant in thin grid graphs (which do not contain a \(2\times 2\) square, so every pixel is a boundary pixel) is solvable in polynomial time. In this section, we prove that finding a full cycle cover in 2-dimensional grid graphs with minimum turn cost is NP-hard, resolving Problem 53. We also show that subset coverage is NP-hard even for thin grid graphs, so the boundary techniques by Arkin et al. [5, 6] do not provide a polynomial-time algorithm.

2.1 Full Coverage in Grid Graphs

For the problem of minimizing the number of simple turns (\(180^\circ \) turns counting as two), we get the following complexity result.

Theorem 1

It is NP-hard to find a cycle cover with a minimum number of \(90^\circ \) turns in a grid graph.

The proof is based on a reduction from One-in-three 3SAT (1-in-3SAT), which was shown to be NP-hard by Schaefer [27]: for a Boolean formula in conjunctive normal form with only three literals per clause, decide whether there is a truth assignment that makes exactly one literal per clause true (and exactly two literals false). For example, \((x_1\vee x_2 \vee x_3) \wedge (\overline{x_1}\vee \overline{x_2} \vee \overline{x_3})\) is not (1-in-3) satisfiable, whereas \((x_1\vee x_2 \vee x_3) \wedge (\overline{x_1}\vee \overline{x_2} \vee \overline{x_4})\) is satisfiable.

Fig. 3
figure 3

Representing the 1-in-3SAT-formula \(x_1+x_2+x_3=1\wedge \overline{x_1}+\overline{x_2}+\overline{x_4}=1 \wedge \overline{x_1}+x_2+\overline{x_3}=1\)

An example is given in Fig. 3 for the instance \(x_1+x_2+x_3=1\wedge \overline{x_1}+\overline{x_2}+\overline{x_4}=1 \wedge \overline{x_1}+x_2+\overline{x_3}=1\). For comparison, see Fig. 4 for the one-clause formula \(x1 + x2 + x3 = 1\), along with three possible solutions. For every variable we have a  gadget consisting of a gray  gadget and a zig-zagging, high-cost path of blue pixels. A cheap solution traverses a blue path once and connects the ends through the remaining construction of gray and red pixels. Such variable cycles (highlighted in red) must either go through the upper ( ) or lower ( ) lane of the variable gadget; the former corresponds to a true, the later to a false assignment of the corresponding variable. We prove that turns in a minimum cycle cover can only happen at specific locations, such that even in the full construction the lanes cannot be changed. A clause gadget modifies a lane of all three involved variable gadgets. This involves the gray pixels that are covered by the green cycles; we can show that they do not interfere with the cycles for covering the blue and red pixels, and cannot be modified to cover them. Thus, we only have to cover red and blue pixels, but can pass over gray pixels, too.

Fig. 4
figure 4

Construction for the one-clause formula \(x_1+x_2+x_3=1\) and three possible solutions. Every variable has a cycle traversing a zig-zagging path of blue pixels. A variable is true if its cycle uses the upper path ( ) through green/red pixels, false if it takes the lower path ( ). For covering the red pixels, we may use two additional turns. This results in three classes of optimal cycle covers, shown above. If we use the blue 4-turn cycle to cover the upper two red pixels, we are forced to cover the lower red pixel by the \(x_3\) variable cycle, setting \(x_3\) to false. The variable cycles of \(x_1\) and \(x_2\) take the cheapest paths, setting them to true or false, respectively. The alternative to a blue cycle is to cover all three red pixel by the variable cycles, as in the right solution

To this end, we must connect the ends of the blue paths; as it turns out, the formula is satisfiable if and only if we can perform this connection in a manner that also covers one corresponding red pixel with at most two extra turns.

There are three important conclusions.

  1. 1.

    The gray pixels are always covered by the green cycles or the solution can be modified without extra turns. Thus, we only need to focus on the logic of covering the blue and red pixels. This is based on the observation that for keeping tight local upper bounds on the number of turns, we are only allowed to make turns at very specific locations.

  2. 2.

    There are only the red variable cycles that cover exactly the red pixels on the true or false lane and the simple 4-turn blue cycles for covering two vertically adjacent red pixels available for covering the red and blue pixels within the upper bounds of turns for satisfiable constructions.

  3. 3.

    A coverage with only two turns per red pixel is possible if and only if the underlying formula is satisfiable.

The first item is the most challenging, but also the most crucial part.

2.1.1 Basic Construction

Figure 5 shows the building block for a variable gadget, formed by a zig-zagging path, marked in blue; this path enforces its covering cycle to go through the box (gray) of the variable, because a double coverage of itself would be too expensive because of the zig-zagging part. It can be seen that this covering cycle takes the upper path if the corresponding variable is set to true and takes the lower path if the variable is set to false.

Fig. 5
figure 5

The construction of a variable gadget. The blue part has to be covered by letting the cycle corresponding to this variable go through the gray part. If the path takes the upper path, the variable is set to true; if it takes the lower path, the variable is set to false

The basic idea for representing literals in clauses is shown in Fig. 6; this basic element is employed in sets of three for each clause, arranged in a vertical vector of “connectors” to the corresponding variable paths, making use of appropriate geometric extensions to account for (logical) parity, which are described and motivated in the following subsection; of critical importance is the central “crucial” pixel marked in red in all figures.

Fig. 6
figure 6

Basic block for the hardness proof. Only the red “crucial” pixel is of algorithmic interest, as described in the text

2.1.2 Logical Ideas and Details of the Construction

The key idea of the reduction is that information can only be encoded in pixels for which we do not know in which orientation they are crossed without turning (otherwise matching techniques can be used, as utilized by our approximation algorithm). This means that, e.g., pixels on the boundary are easy to deal with. Also, pixels for which we know that there is a turn or that are crossed straight in both orientations are not critical: in a solution, they may only be used indirectly for information propagation. Based on these observations, we consider variants of the construction in Fig. 6 as fundamental information elements. The optimality of the green cycles is argued in the next section, and thus the corresponding pixels are trivially covered.

Covering a crucial pixel is more difficult. Covering it by an additional cycle or modifying the green cycles costs always at least 4 turns. Assume we create a path from one entry (ABCDEFGH) to another and cover the crucial pixel by this path. For example, a path entering at A and leaving at E would allow us to cover the crucial pixel at a cost of 2 while a path entering at A and leaving at D has at least 3 turns if also covering the crucial pixel, see Fig. 7. Actually, we can cover the crucial pixel with a cost of 2 exactly with S- and U-turns, i.e., paths that do not change the orientation. In addition, it can be seen that the crucial pixel always needs at least two turns within this construction.

Fig. 7
figure 7

Three ways of covering the crucial pixel. The first two keep the orientation and have a cost of 2. The third one changes the orientation, and thus has a cost of at least 3

Now consider the construction shown in Fig. 8 that uses a combination of elements as described above. Assume all turns made outside the construction part are free and all six “exits” ABCDEF are connected from outside. This means that every red highlighted pixel can be covered by a cycle of cost two that traverses the exits above and below (see blue paths in Fig. 8). The green cycles are still necessary; employing them for covering the crucial pixel is too expensive, so we can concentrate on how to cover the red highlighted pixels by additional cycles. It can be seen that there are only five potential cycles that involve not more than a cost of two turns per crucial pixel: these are the three mentioned red cycles that use the exterior and the two interior cycles marked in blue in Fig. 8 (the cycles can be slightly shifted without changing them in a useful manner). This results in only three potential optimal solutions (refer to Fig. 4):

  1. 1.

    Using the upper red cycle to cover the upper crucial pixel and the lower blue cycle to cover the middle crucial pixel and lower crucial pixel.

  2. 2.

    Using the lower red cycle to cover the lower crucial pixel and the upper blue cycle to cover the middle crucial pixel and the upper crucial pixel.

  3. 3.

    Using all three red cycles to cover each crucial pixel separately.

Fig. 8
figure 8

Assuming that all turns made outside the explicitly drawn construction are free, there are only five potential cycles to cover the crucial pixels: the three exterior red cycles and the two interior blue cycles. Assigning the usage of the upper red cycle the Boolean variable \(x_1\) (and analogous for the middle and the lower \(x_2\) and \(x_3\), resp.) leads to the Boolean formula \((x_1 \vee x_3) \wedge (x_2 \leftrightarrow x_1 \wedge x_3)\) equivalent to the One-in-three SAT clause \(\overline{x_1}+x_2+\overline{x_3}=1\)

For constructing a clause \(x_1+x_2+x_3=1\) with \(x_1\) being above \(x_2\) and \(x_3\) being below \(x_2\), we now place the upper crucial pixel of Fig. 8 on the false path of \(x_1\), the middle pixel on the true path of \(x_2\) and the lower crucial pixel on the false path of \(x_3\), as illustrated in Fig. 4. If we take the true path of \(x_2\), we now have to take the false paths of \(x_1\) and \(x_3\). If we take the false path of \(x_2\) we need to block the false path of either \(x_1\) or \(x_3\) (but not both) by a red cycle. The other variable paths (without the crucial pixel) do not need any turns and are hence always preferred if the red pixel does not have to be covered. Note that any external cycle that enters the construction (e.g., through A) needs at least two turns to leave it again through another exit. Hence, passing through this construction should always be combined with covering an uncovered red pixel, for which we have only one choice with two turns, in order to account for the two necessary turns. By concatenating these clauses, we can form any One-in-three 3SAT formula, see Fig. 3.

2.1.3 A Tight Lower Bound

We now give a tight lower bound on the number of turns in a cycle cover. In order to achieve it, the turns have to be made at very specific positions. For this purpose it is sufficient to limit our view onto local components and state that in each of these disjunct components a specific number of turns has to be made. The global lower bound is then the sum of all local lower bounds. Later we show that these turns are only sufficient if the corresponding formula is satisfiable.

Lemma 2

On every full strip (i.e., a maximal connected collinear set of pixels) in the grid graph, a cycle cover has to have an even number of turns (U-turns counting twice).

Proof

For every turn that enters the strip, there needs to be a turn for leaving it. Turns that do not enter/leave the strip are U-turns.\(\square \)

Lemma 3

Given any pixel p of a grid graph and a corresponding cycle cover \(\mathcal {C}\). If there is no turn on p, then there has to be a turn left of p and another turn right of p (on the horizontal full strip through p), or there has to be a turn above p and another below p (on the vertical full strip through p). If there is a turn at p, there are at least three turns on the star consisting of the horizontal and vertical full strip through p.

Proof

If there is no turn on p, there is a straight part of a cycle going through it. At either end of this straight part, it needs to turn in order to close the cycle. If there is a turn at p, the claim follows by Lemma 2.\(\square \)

Now we can deduce the turn positions for all essential parts of the construction, as stated in the next lemma.

Lemma 4

In Fig. 9, the essential parts of the construction are displayed (possibly reflected). For these parts we can give the following lower bounds on the necessary number of interior turns and constraints on the positions of turns if this bound is tight: In a part as shown in Fig. 9a/b/c/d (excluding the blue area), we need at least 10/18/14/10 interior turns. To meet any of these lower bounds, there has to be exactly one turn at every black dot and the remaining two turns have to be in the green area.

Fig. 9
figure 9

Lower bounds on the number of turns in the different parts of the construction (possibly reflected). The black dots represent turn position necessary to meet the lower bound

Proof

There needs to be at least one turn in every corner pixel, making Fig. 9a and d trivial. In Fig. 9b and c we have some additional non-corner pixels for which we need easy additional arguments based on Lemma 2 and 3.

We give the details for the part in Fig. 9b; the adaption to Fig. 9c is straightforward. The used arguments are highlighted in Fig. 10. First, there are already 12 corner pixels, so we have only 6 turns left to cover this local part. Note that we assume that we can appropriately place turns outside this local part, so we are using only local arguments and the turn constraints remain feasible in the global construction. We need at least 6 additional turns: one on each yellow area due to Lemma 2 and two on the green area due to Lemma 3. There can be no turn on the red pixel; otherwise we would need three of the six turns on the green and red pixels, contradicting the fact that we already need at least four in the yellow locations. In order to remain locally optimal, turns on the gray and red pixel thus are impossible; however, these pixels still need to be covered, in particular the pixels marked by hollow circles. Lemma 3 applied to these pixels forces us to place a turn on the adjacent yellow pixel above or below them, leaving only two further turns for covering the red pixel. Lemma 2 additionally forbids turns on two pixels to the left and right of the red pixel: We need to make turns outside this part in order to satisfy it.\(\square \)

Fig. 10
figure 10

Auxiliary figure for the proof of Lemma 4

Lemma 5

Given a construction, as described above, for an arbitrary formula with v variables and c clauses. Let k be the number of corner pixels in the zig-zagging paths of the variable gadgets (highlighted in blue). Then every cycle cover has to have at least \(20v+42c+k\) turns.

Proof

There is no interference between these local bounds, because in the proof we did not charge for exterior (not inside considered local part) turns made by possible cycles. Thus, the claim follows by summing over the local bounds for all local parts using Lemma 4.\(\square \)

2.1.4 An Upper Bound for Satisfiable Formulas

We can construct a solution that matches the lower bound given in Lemma 5 if the corresponding formula of the grid-graph construction is satisfiable.

Lemma 6

Given a construction for an arbitrary formula with v variables and c clauses, as described above. Let k be the number of corner pixels in the zig-zagging paths of the variable gadgets (highlighted in blue). If the formula is satisfiable, there exists a cycle cover with \(20v+42c+k\) turns.

Proof

It is straightforward to deduce this from the description of the construction and Fig. 3, so we only sketch the details. Cover the gray pixels using only simple green 4-turn cycles on the explicit turns (black dots), as shown in Fig. 9. Select an arbitrary but fixed satisfiable solution for the formula. If a variable assignment is true, add a cycle that traverses all blue pixels of the variable and all upper crucial pixels of the variable with a minimum number of turns. This cycle has a turn at every blue corner pixel belonging to the variable, two turns per crucial pixel, and two further turns at each end to connect to the blue pixels. If a variable assignment is false, proceed analogously, but for the lower row of crucial pixels belonging to this variable. As the assignment is feasible, there are either none or exactly two remaining crucial red pixels per clause gadget. If there are two, they are vertically adjacent and we can cover them by a simple blue 4-turn cycle. As Lemma 4 leaves us with exactly 2 turns to select per crucial pixel, this matches the lower bound.\(\square \)

2.1.5 Lower Bound for Unsatisfiable Formulas

If the formula corresponding to the grid graph construction is not satisfiable, we can deduce that the number of turns given by Lemma 5 is not sufficient for a full coverage. We first show that in a cycle cover that matches the lower bound, we can separate a cycle cover for the gray pixels from the rest.

Lemma 7

Given an optimal cycle cover that matches the lower bound of Lemma 5, then we can modify the solution (without increasing the cost) such that it contains a cycle cover of exactly the gray pixels (the green cycles in Fig. 3).

Proof

The cycle cover matches the lower bound of Lemma 5 and hence has to fulfill the restriction on the position of turns as in Lemma 4. We not only know that there has to be a turn at the exact same locations as the green cycles in Fig. 3, marked by black dots in Fig. 9, but also that these turns have to be exactly the same, due to a lack of alternatives: If there are only potential partner turns in two directions, we can only make a turn between these two (U-turns are already prohibited by Lemma 5). If two such partnered turns are not directly connected, we known that there are exactly two turns on pixels that are highlighted in green in Fig. 9 between them. We can simply connect these two turns on green pixels directly, as well as the two turns on black dots, as shown in Fig. 11. If the lower bound is matched, we can therefore always separate the green cycles as in Fig. 3.\(\square \)

Fig. 11
figure 11

Lemma 2 enforces the turns on the green pixels to be at the same y-coordinates. The cycle part can easily be separated to a cycle that covers the gray pixels and a connection between the turns in the green pixels

This allows us to only concentrate on covering the crucial and the blue pixels, because all gray pixels are already covered by the “black dot” cycles. We now show that every cycle cover that matches the lower bound results in a variable assignment (the cycle that covers the blue pixels either selects the true line or the false line and does not switch in between).

Lemma 8

In a cycle cover that matches the lower bound of Lemma 5, the cycle that covers the blue pixels of a variable also covers either all crucial pixels belonging to a true assignment of this variable and no other crucial pixel, or all crucial pixels belonging to a false assignment of this variable and no other crucial pixel.

Proof

It is impossible to cover a blue pixel twice without exceeding the lower bound, because we only have free turns in the green pixels. Therefore, the “variable” cycle has to go through the gray and crucial pixels. We are only allowed to make turns in the green pixels (as marked in Fig. 9) and only at most one in every connected green area. The variable cycle can take the upper or the lower path (Fig. 9d), but cannot switch between them, as there is only one possible “partner” turn to achieve an even number of turns on every strip. The only possible choice for a partner turn is the next turn of the cycle after applying Lemma 7. This forces the path to continue until it closes the cycle. See Fig. 12 for an illustration.\(\square \)

Fig. 12
figure 12

If the cycle uses the upper path, Lemma 2 forces us to cover exactly all crucial pixels along this way, as we have only one choice for the position of the “partner” turn

Now only the crucial pixels not covered by the variable assignment cycles are left. We have only two turns for each of them, hence we need at least two still uncovered crucial pixels in any additional cycle; this cycle must have at most twice the number of turns than the number of its newly covered crucial pixels. This, however, is impossible for unsatisfied clauses, so we must exceed the lower bound.

Lemma 9

Given a 2-dimensional grid graph produced by the above procedure for an arbitrary One-in-three 3SAT formula. Let \(\mathcal {C}\) be a set of cycles with minimum turn costs. Let v be the number of variables in the corresponding formula, c be the number of clauses, and k be the number of blue corner pixels. If the formula is not satisfiable, the cycle cover must have at least \(20v+42c+k+1\) turns.

Proof

Assume there exists a cycle cover with only \(20v+42c+k\) turns (matching the lower bound of Lemma 5). We now show that this number of turns cannot suffice to cover all pixels. By separating the cycles on the black dotted pixels using Lemma 7, only \(4v+18c+k\) turns remain for the red and blue pixels.

Due to Lemma 8 we have to cover one line of crucial pixels per variable by a blue variable assignment cycle. The remaining crucial pixels can only be covered by the red cycles known from the construction. However, the use of red cycles in a way that no crucial pixel is covered multiple times (which would exceed the budget) enforces the logic described in the construction. A valid selection of red cycles is therefore only possible if the corresponding variable assignment is feasible. Because this is not the case, \(20v+42c+k\) turns cannot be sufficient.\(\square \)

2.1.6 NP-Hardness

Finally, we can state the main theorem: The bound on the number of turns can only be met if the formula is satisfiable.

Theorem 10

Given a construction, as described above, for an arbitrary formula with v variables and c clauses. Let k be the number of blue highlighted corner pixels. Then the formula is satisfiable if and only if there exists a cycle cover with \(20v+42c+k\) turns.

Proof

This follows from Lemmas 6 and 9.\(\square \)

This concludes the proof of the NP-hardness of full coverage cycle cover (Theorem 1).

2.2 Subset Coverage in Thin Grid Graphs

For subset cover we can also show hardness for thin grid graphs. Arkin et al. [5, 6] exploit the structure of these graphs to compute an optimal minimum-turn cycle cover in polynomial time. If we only have to cover a subset of the vertices, the problem becomes NP-hard again. The proof is inspired by the construction of Aggarwal et al. [3] for the angular-metric cycle cover problem and significantly simpler than the one for full coverage.

Theorem 11

The minimum-turn subset cycle cover problem is NP-hard, even in thin grid graphs.

Fig. 13
figure 13

Example for the NP-hardness reduction using the One-in-three 3SAT formula \((x_1\vee x_2 \vee x_3)\wedge (\overline{x_1}\vee \overline{x_2} \vee \overline{x_3})\wedge (x_2\vee \overline{x_3}\vee x_4)\wedge (\overline{x_1}\vee x_2 \vee \overline{x_4})\)

Proof

The proof is inspired by the construction of Aggarwal et al. [3] for the angular-metric cycle cover and we are reducing from One-in-three 3SAT. See Fig. 13 for an overview of the construction; due to its relative simplicity, we only sketch the details. Every variable consists of a U-shape, with two rows connecting the ends of the U. The bottom of the U has to be covered in any case, so we are free to either cover the upper or the lower row without additional turn cost. Covering the upper row means setting the variable to true, covering the lower row to false. These two rows intersect with the constructions for the clauses. Every clause construction consists of three vertical columns (intersecting with the variable constructions) and a horizontal connection at each end. At the top and the bottom of each is a pixel that has to be covered. The cheapest way to cover these two pixels is by a cycle that goes through the columns. Thus, we are able to cover two of three columns per clause construction for free. The two covered columns represent the two literals of the clause that have to be false.

We mark additional pixels at the intersections of the variable constructions and the clause constructions, so that these pixels must also be covered. This is done in a such way that if we set a variable to a specific value for all clauses that now become true, the two columns to be covered are automatically enforced. In the example, if we set \(x_1\) to true and cover the upper row, we have to use the two lines on the right in clause \(x_1\vee x_2 \vee x_3\), because otherwise the two lower pixels in the intersection are not covered. On the other hand, this enforces \(x_2\) and \(x_3\) to be false, as the corresponding two left pixels to be covered can no longer be covered by the clause’s cycle. The cycle cover represents a valid solution for the One-in-three 3SAT formula, if and only if we do not need any additional cycles.\(\square \)

Arkin et al. [5, 6] showed how the structure of thin grid graphs can be exploited for computing an optimal minimum-turn cycle cover in polynomial time. If we only have to cover a subset of the vertices, the problem is NP-complete.

3 Approximation Algorithms

This section discusses techniques to efficiently approximate all problem variants for general grid graphs. We first introduce an auxiliary graph that allows us to move the turn costs into the edge weights, then we show how to approximate the cycle-cover variants in Section 3.2 on this auxiliary graph, and finally how to connect the cycles to a tour in Section 3.3.

3.1 Auxiliary Graphs

For approximating the cycle-cover variants, we use an auxiliary graph that allows us to move the turn costs into the edge weights. One could use a variant of the edge graph, as is done for shortest paths, but our auxiliary graph has the advantage of directly including the symmetry and also allowing virtual cycles for the penalty variant.

Each (generalized) grid graph \(G=(P,E)\) has a set of axes \(\mathcal {A}\). For a regular square grid, \(\mathcal {A}=\{\leftrightarrow , \updownarrow \}\) consists of the horizontal \(\leftrightarrow \) and the vertical \(\updownarrow \) axis. Each axis \(a\in \mathcal {A}\) has two directions and we denote the set of all directions by \(\mathcal {D}\).

Furthermore, let \( opp : \mathcal {D} \longrightarrow \mathcal {D}\) denote the opposite direction, i.e., the other direction on the corresponding axis. Thus, the regular square grid has the four directions \(\mathcal {D}=\{\uparrow , \rightarrow , \downarrow , \leftarrow \}\), and \( opp (\rightarrow )=\leftarrow \).

For a grid graph \(G=(P,E)\), we define \(G^\boxplus =(V^\boxplus =P\times \mathcal {D}, E^\boxplus =\{\{(p,d), (q, d')\} \mid pq \in E \wedge d, d' \in \mathcal {D}\})\). The edge weight \( cost : E^\boxplus \longrightarrow \mathbb {R}^+\) is defined by the cost of transitioning from the position (i.e., pixel) and direction of the source vertex to the position and opposite direction of the target vertex. The edge weights for \(G^\boxplus \) on a regular square grid are given in Fig. 14. Note that these edge weights are commutative, as the reverse movement has the same distance and costs. Additionally, we define the set of separate edges \(A=\{ \{\left( p, d\right) , \left( p, opp \left( d\right) \right) \} \mid p\in P, d\in \mathcal {D} \}\), and \(A(p)=\{ \{\left( p, d\right) , \left( p, opp \left( d\right) \right) \} \mid d\in \mathcal {D}\}\). We call them atomic strips because they can be considered as infinitisimal-length geometric segments. Atomic strips do not have any costs, as their only purpose is to connect the edges in \(E^\boxplus \). A cycle can now be represented as a closed chain of edges alternating between \(E^\boxplus \) and A, where the weight of the used edges from \(E^\boxplus \) coincides with its cost. A pixel \(p\in P\) of the grid graph is covered by a cycle, if an atomic strip \(a\in A(p)\) is in the cycle. An example is given in Fig. 15.

Fig. 14
figure 14

Example of the edges and their weights in \(G^\boxplus \). Every position \(p\in P\) of the grid graph gets replaced by positions with headings. The vertices in \(V^\boxplus \) corresponding to previously adjacent pixels \(pq\in E\) get fully connected in \(G^\boxplus \)

Fig. 15
figure 15

Example for alternating cycles on \(G^\boxplus \). Cycles alternating between \(E^\boxplus \) and A represent cycles with turn costs in the original grid by the \( cost \) on the used \(E^\boxplus \). However, we may have to use edges multiple times

Instead of the grid graph with its quadratic cost function, we can now work on \(G^\boxplus \) with its simple edge weights instead.

Lemma 12

A cycle of edges alternating between \(E^\boxplus \) and A can be converted to a cycle in the grid graph G with equal or lower cost that covers exactly the pixels of the used atomic strips. A cycle in the grid graph G can be converted to a cycle of edges alternating between \(E^\boxplus \) and A of the same cost that uses for every covered pixel p an atomic strip of A(p). Edges (and atomic strips) may be used multiple times.

Proof

By defintion, the edges in \(E^\boxplus \) represent feasible movements in the grid graph with corresponding costs. The atomic strips only connect matching edges of \(E^\boxplus \), such that the whole resulting trajectory is a feasible tour. For the other direction, we can easily convert a cycle in the original grid graph to such an alternating cycle in \(G^\boxplus \) by always selecting the atomic strips matching the incoming direction at a pixel. The cost of rotating and moving to the next pixel matches exactly the cost of the edge in \(E^\boxplus \).\(\square \)

Fig. 16
figure 16

\(G^\boxplus _\looparrowright \) defines a complete graph by providing the cheapest path alternating between \(E^\boxplus \) and A as direct connection. This allows us to skip doubly used edges and redundant visits of vertices in the grid graph. Moreover, once we have selected an atomic strip \(a\in A(p)\) for every pixel \(p\in P\) we want to visit, we can obtain the minimum cycle cover by a minimum-weight perfect matching on the pixels of the atomic strips in \(G^\boxplus _\looparrowright \)

Working on \(G^\boxplus \) can be tedious, because edges may have to be used multiple times, making some arguments more difficult. Thus, we extend \(G^\boxplus \) to a complete graph with loop edges \(G^\boxplus _\looparrowright =(V^\boxplus , E^\boxplus _\looparrowright )\) that allows us to use transitive edges and simply skip doubly used edges by a direct connection. The weights \( cost _\looparrowright : E^\boxplus _\looparrowright \longrightarrow \mathbb {R}^+\) of edges not in \(E^\boxplus \) are defined by the cheapest alternating path on \(E^\boxplus \) and A. We can define this formally by the following recursion (that can be efficiently resolved by a dynamic program):

$$\begin{aligned} cost _\looparrowright&\left( \begin{array}{c}e=\\ \{ (p,d_p), (q, d_q)\}\end{array}\right) = \nonumber \\&{\left\{ \begin{array}{ll} cost (e) &{}\text {if } e\in E^\boxplus \\ \displaystyle \min _{\{(p, d_p), (n, d_n)\} \in E^\boxplus } \begin{array}{l} cost (\{(p,d_p), (n, d_n)\})\\ + cost _\looparrowright (\{(n, opp (d_n)), (q, d_q)\}) \end{array}&\text {else} \end{array}\right. } \end{aligned}$$
(1)

The alternating atomic strips are implicitly contained by the transitions from \((n, d_n)\) to \((n, opp (d_n))\). In addition, this formulation explicitly contains loop edges that are later later used for simplifying an argument on a problem relaxation. See Fig. 16 for an illustration of the previous example.

An important property of \( cost _\looparrowright \) is the following relation that resembles a triangle inequality.

$$\begin{aligned} \forall v_1, v_2\in V^\boxplus , w_1w_2\in A: \begin{matrix} cost _\looparrowright (v_1v_2)\le cost _\looparrowright (v_1w_1)+ cost _\looparrowright (w_2v_2) \\ cost _\looparrowright (v_1v_2)\le cost _\looparrowright (v_1w_2)+ cost _\looparrowright (w_1v_2) \end{matrix} \end{aligned}$$
(2)

The interesting aspect of \(G^\boxplus _\looparrowright \) is that we essentially just have to select an atomic strip \(a\in A(p)\) for every pixel \(p\in P\) we want to cover, and then find a minimum-weight perfect matching in \(G^\boxplus _\looparrowright \) on the vertices of the selected atomic strips. Every atomic strip will add two vertices and because \(G^\boxplus _\looparrowright \) is complete, a perfect matching always exists. Note that duplication of edges and vertices in cycles of \(G^\boxplus _\looparrowright \) and A are still allowed, but not necessary.

The following lemma states that minimum cost cycles in the grid graph and minimum cost cycles of edges alternating between \(E^\boxplus _\looparrowright \) and A are actually equivalent and we can convert between them.

Lemma 13

A cycle of edges alternating between \(E^\boxplus _\looparrowright \) and A can be converted to a cycle in the grid graph G with equal or lower costs that covers exactly the pixels of the used atomic strips. A cycle in the grid graph G can be converted to a cycle of edges alternating between \(E^\boxplus _\looparrowright \) and A of the same cost that uses for every covered pixel p an atomic strip of A(p).

Proof

Every edge \(e\in E^\boxplus _\looparrowright , e\not \in E^\boxplus \), can be converted to a sequence of edges alternating between \(E^\boxplus \) and A of the same cost. After that, we can use Lemma 12. As \(G^\boxplus _\looparrowright \) is a supergraph of \(G^\boxplus \), the other direction directly follows from Lemma 12.\(\square \)

3.2 Cycle Cover

In the following, we describe a \(2\omega \)-approximation algorithm for the (penalty) cycle cover problem on grid graphs with \(\omega \) axes. We start with the full coverage variant and afterwards show how to easily adapt the algorithm for subset and penalty coverage.

Our approximation algorithm proceeds as follows. We first select the atomic strips via linear programming. Computing an optimal selection is NP-hard; we can show that choosing the highest valued strips for each pixel in the fractional solution suffices to obtain provably good solutions. As a next step, we connect the atomic strips to a cycle cover, using a minimum-weight perfect matching. See Fig. 17 for an illustration.

We now describe the integer program whose linear programming relaxation is solved to select the highest valued atomic strips. It searches for an optimal atomic strip cover that yields a perfect matching of minimum weight. The IP does not explicitly enforce cycles to contain at least two pixels: all small cycles consist only of transitive edges that implicitly contain at least one further pixel, automatically fulfilling this constraint when converting the solution back to the original grid graph.

For the usage of a matching edge \(e\in E^\boxplus _\looparrowright \), we use the Boolean variable \(x_e\in \mathbb {B}\). For the usage of an atomic strip \(a\in A(p), p\in P\), we use the Boolean variable \(y_a\in \mathbb {B}\).

$$\begin{aligned} \min&\displaystyle \sum _{e\in E^\boxplus _\looparrowright } cost _\looparrowright (e)\cdot x_e \end{aligned}$$
(3)
$$\begin{aligned} \text {s.t.}&\displaystyle \sum _{a\in A(p)} y_{a} = 1&\forall p\in P\end{aligned}$$
(4)
$$\begin{aligned}&\displaystyle 2x_{vv} + \sum _{vn\in E^\boxplus _\looparrowright , n\not =v} x_{vn} = y_{vw} = 2x_{ww} + \sum _{nw\in E^\boxplus _\looparrowright , n\not =w} x_{nw}&\forall vw \in A\end{aligned}$$
(5)
$$\begin{aligned}&x_e, y_a \in \mathbb {B}&\forall e\!\in \! E^\boxplus _\looparrowright , a\!\in \! A \end{aligned}$$
(6)
Fig. 17
figure 17

Example of the approximation algorithm for a simple full cycle cover instance in a grid graph. First the fractional solution of the integer program (3)-(6) is computed. Strips and edges with value 0 are omitted, while dashed ones have value 0.5. Then the highest valued atomic strips of this solution are selected. Finally, a minimum-weight perfect matching on the ends of the atomic strips is computed. (Recall that atomic strips only have an orientation but no length, so the curves in the corner indicate simple \(90^{\circ }\) turns)

We minimize the cost of the used edges in \(G^\boxplus _\looparrowright \), with (4) forcing the selection of one atomic strip per pixel (atomic strip cover) and (5) ensuring that exactly the vertices (endpoints) of the selected atomic strips are matched, with loop edges counting twice due to their two ends, resulting in cycles alternating between \(E^\boxplus _\looparrowright \) and A. The usage of loop edges is infeasible for integral solutions, but can be used by the linear relaxation.

The following two lemmas help us to extract an integral solution from the effciently computable linear relaxation of the IP that we get by dropping the integrality constraints.

Lemma 14

A solution for the linear relaxation of the integer program with objective value c can be transformed into a solution satisfying \(y_a\in \mathbb {B}, \forall a\in A\) with objective value \(c' \le \omega \cdot c\).

Proof

Due to the constraints of type (4), the highest-valued strip \(a\in A(p)\) for every \(p\in P\) has a value of \(y_a\ge \nicefrac {1}{\omega }\) in any feasible solution of the LP-relaxation, as \(|A(p)|=\omega \). Let \(a_p\) be this highest-valued strip for \(p\in P\) and \(V'\subseteq V^\boxplus \) the set of all the endpoints. There may also be further \(p \in P, a\in A(p)\) with \(y_a > 0\). We can set these to zero using the operations of Fig. 18 without increasing the objective value and without changing any \(y_{a_p}\) while also satisfying (5), because of (2). The resulting solution only violates (4) by relaxing it to \(\sum _{a\in A(p)} y_{a} \ge \nicefrac {1}{\omega }\), but we fix this later by a simple multiplication. Now we only have edges incident to the highest-valued atomic strips left (and only one atomic strip used for all \(p\in P\)). The corresponding objective value is still a lower bound on the optimal solution of the integer program.

We can multiply the solution by \(\omega \), resulting in \(y_{a_p} \ge 1\) for all \(p\in P\). We can apply the same procedure to reduce all \(y_{a_p} > 1\) to \(=1\). The new solution has a cost of at most \(\omega \) times the optimal solution and all variables \(y_a, a\in A\) are now Boolean; however, the edge usages \(x_e, e\in E^\boxplus _\looparrowright \) can still be fractional.\(\square \)

Lemma 15

The linear relaxation of the minimum-weight perfect matching on graphs with loop edges has a half-integral optimal solution.

Proof

Let \(G=(V,E)\) be a weighted graph with loop edges, and \(c: E\rightarrow \mathbb {R}^+_0\) the weight function. Then \(\forall v\in V: 2 x_{vv} +\sum _{vw\in E, w\not =v} x_{vw} = 1\) with \(\forall e\in E: x_e \ge 0\) describes a half-integral polytope. It is well known that this polytope is half-integral if G contains no loop edges, see, e.g., Theorem 6.13 in the book of Cook et al. [14]. The proof is based on splitting the vertices and converting the graph to a bipartite graph, whose perfect matching polytope is known to be integral. We essentially use the same idea for our proof and only add a (simple) special treatment for the loop edges. Clearly, loop edges are useless for matchings and therefore are not part of the original proof, but the operations in Fig. 18 in Lemma 14 force us to provide them.

Fig. 18
figure 18

Operations for reducing the usage of an atomic strip \(vw\in A\). Atomic strips are shown by thick lines, while edges are indicated by dashed lines. These costs do not increase (for \(\gamma \ge 0\)), due to Ineq. 2. For some cases as a), one needs a repetitive application of this inequality: first replace the \(\gamma /2\cdot vv\) loop edge by \(\gamma /2 \cdot vu\), while reducing uw by \(\gamma /2\) and then replace the \(\gamma /2\cdot wu\) and the \(\gamma /2\cdot vu\) by \(\gamma /2\cdot uu\). As long as the usage is greater than zero, at least one of the operations is possible

To prove the lemma, we show that we can convert any feasible fractional solution \(\hat{x}\) to a half-integral solution of at most the same weight. For this, we convert the graph G into a bipartatite graph \(G'\) by splitting every vertex \(v\in V\) into \(v_a\) and \(v_b\). Every edge \(vw\in E\) is replaced by two edges \(v_aw_b\) and \(v_bw_a\), with weights \(c'(v_aw_b)=c'(v_bw_a)=\nicefrac {c(vw)}{2}\). A loop edge \(vv\in E\) is replaced by a single edge \(v_av_b\) with weight \(c'(v_av_b)=c(vv)\). An example can be seen in Fig. 19.

Fig. 19
figure 19

Converting a graph to a bipartite graph. Every edge is doubled, except for the loop edges, which become regular edges. The matching \(v_aw_b\),\(w_au_b\) \(u_av_b\) would be converted to the matching 0.5vw, 0.5wu, 0.5uv. There always exists a perfect matching in the original graph for our problem

This new graph is bipartite (and without loop edges), because there are no edges between vertices with the same indices (a or b). Our solution \(\hat{x}\) can be transformed into a solution \(\hat{x}'\) of equal cost in the bipartite graph \(G'\) by using \(\hat{x}_{vw}=\hat{x}_{v_aw_b}=\hat{x}_{v_bw_a}\), because \(c(vw)\cdot \hat{x}_{vw} = \nicefrac {c(vw)}{2} \cdot \hat{x}'_{v_aw_b}+ \nicefrac {c(vw)}{2}\cdot \hat{x}'_{v_bw_a}= c'(v_aw_b)\cdot \hat{x}'_{v_aw_b}+c'(v_bw_a)\cdot \hat{x}'_{v_bw_a}\), or \(c(vv)\cdot \hat{x}_{vv} = c'(v_av_b)\cdot \hat{x}'(v_av_b)\), resp. By setting \(\hat{x}(vw)=\nicefrac {\hat{x}'_{v_aw_b}}{2}+\nicefrac {\hat{x}'_{v_bw_a}}{2}\) resp. \(\hat{x}_{vv}=\hat{x}'_{v_av_b}\), this also works the other way.

Because the polytope of the bipartite \(G'\) is known to be integral, we can always find an equivalent integral solution \(\hat{x}'\), resulting in a half-integral \(\hat{x}\).\(\square \)

We can now prove that computing a minimum-weight perfect matching on the endpoints of the highest-valued atomic strips in the linear relaxation yields an approximation algorithm for the full coverage variant.

Theorem 16

Given a grid graph \(G=(P,E)\) with \(\omega \) axes, we can efficiently compute a \(2\omega \)-approximation for the cycle cover problem.

Proof

We prove this theorem by showing that there exists a matching on the highest-valued atomic strips of the fractional solution with at most \(2\omega \) times the cost of the fractional solution. This implies that the minimum-weight perfect matching on these strips has to be at least that cheap.

Given an optimal solution for the linear relexation of the IP, we first make all \(y_a, a\in A\) integral by applying Lemma 14. This increases the objective value to at most \(\omega \cdot OPT\), as the optimal fractional solution is a natural lower bound. If we now fix the variables \(y_a, a\in A\), we are left with a perfect matching polytope on a graph with loop edges (\(G^\boxplus _\looparrowright \)). By Lemma 15, we know that this resulting polytope has a half-integral optimal solution. This half-integral solution can then be made integral by simply doubling it, providing us with a feasible solution of at most \(2\omega \cdot OPT\). Redundant usages can be skipped by the definition of (1) without increasing the costs, leaving us with a perfect matching on the highest-valued atomic strips with a cost of at most \(2\omega \cdot OPT\).\(\square \)

Corollary 17

Given a grid graph \(G=(P,E)\) with \(\omega \) axes, we can efficiently compute a \(2\omega \) approximation for covering the subset \(S\subseteq P\) with cycles.

Proof

Simply removing all elements involving \(P\setminus S\) from \(G^\boxplus _\looparrowright \) does not change the general properties needed for Theorem 16. Thus, we can simply apply the full coverage algorithm. Note that the pixels in \(P\setminus S\) are still implicitly used in the remaining edges of \(G^\boxplus _\looparrowright \), according to (1).\(\square \)

This technique can also be used for the subset and the penalty variants.

Corollary 18

Given a grid graph \(G=(P,E)\) with \(\omega \) axes, we can efficiently compute a \(2\omega \) approximation of a penalty cycle cover with respect to a penalty function \(c: P\rightarrow \mathbb {R}^+_0\).

Proof

We can consider paying the penalty c(p) for a pixel \(p\in P\) as covering it with a virtual cycle of cost c(p), instead of covering it by a cycle. The cheapest cycle to cover a pixel p is implicitly encoded by an edge \(e=\{(p, d), (p, opp (d))\}\in E^\boxplus _\looparrowright , d\in \mathcal {D}\) with cost \(w= cost _\looparrowright (e)\). If \(w\le c(p)\), we should never pay the penalty, but instead just use this cheap cycle. If \(w>c(p)\), we can simply replace e (and \( cost _\looparrowright (e)\)) by the virtual cycle of paying the penalty as no explicit coverages are lost by this. Thus, we can simply apply the full coverage algorithm on \(G^\boxplus _\looparrowright \) with modified \( cost _\looparrowright \). Note that the property in (2) is not violated, as \( cost _\looparrowright (e)\) is reduced but no other \( cost _\looparrowright (e')\) for \(e'\not =e\) is changed (w.l.o.g., assume that we apply this approach iteratively for each \(e=\{(p, d), (p, opp (d))\}\in E^\boxplus _\looparrowright , d\in \mathcal {D}\)). If some other \( cost _\looparrowright (e')\) was influenced, e would need to be on a cheapest alternating chain; but because e connects both ends of an atomic strip, it would always enforce a redundant usage of the atomic strip, a contradication with positive weights.\(\square \)

3.3 Tours

A given cycle cover approximation can be turned into a tour approximation at the expense of an additional constant factor. Because every cycle involves at least two points and a full rotation, we can use classic tree techniques known for TSP variants to connect the cycles and charge the necessary turns to the involved cycles.

For the classic Traveling Salesman Problem with triangle inequality, minimum spanning trees are trivial lower bounds, as any tour must contain a spanning tree. This is also true for the penalty TSP and the prize-collecting Steiner tree; note that “penalty” and “prize-collecting” variants are completely equivalent. Doubling optimal trees yields trivial 2-approximations. (The prize-collecting Steiner tree is NP-hard, but there is a 2-approximation [22].)

This is not directly possible with turn costs, because it matters from where a vertex is entered. However, if we already have a cycle cover and we aim for connecting its cycles, this gets significantly easier. If there is a path between two cycles, we can double it and merge the cycles, requiring not more than an additional \(180^{\circ }\) turn at the ends of the paths, regardless of the direction from which the path hits the cycle.

Lemma 19

We can compute the cheapest incident path \(CP(c_1, c_2)\) between two cycles \(c_1, c_2\) in polynomial time.

Proof

Computing a cheapest path with distance and turn costs in a general graph can be done with a classical shortest path algorithm on a line graph (similar to the edge graph), as described by Winter [30]. To compute the cheapest such path between two cycles, add an auxiliary start vertex connected to all segments incident to the first cycle and an auxiliary target vertex connected to all segments incident to the second cycle. A segment (edge of the grid graph) is called incident to a cycle if it shares a vertex with it.\(\square \)

Lemma 20

Given two cycles \(c_1, c_2\) and an incident path p. The endpoints of p can have any directions but have to be on \(c_1\) resp. \(c_2\). We can create a larger cycle with equal coverage of cost \( cost (c_1)+ cost (c_2)+2\cdot cost (p) + 2\cdot \left( 0, 180^{\circ }\right) \). This is true independent of the grid and extends to three-dimensional instances.

Proof

We can double the path and connect it at the intersection with the cycles at a cost of at most \(180^{\circ }\) each, as shown in Fig. 20. The additional costs are defined by only two segments, allowing us (w.l.o.g.) to project three-dimensional trajectories to two dimensions. Discretizing the cycles and the path to a grid does not change their merging properties, making this statement true for all grids.\(\square \)

Fig. 20
figure 20

Figure to Lemma 20 on how we can merge two cycles via a path, independent of the grid and even in 3-dimensions

Thus, we can merge two cycles with a cost of two times the cheapest path between them, plus \(360^{\circ }\) for connecting the elements. If we have a minimum spanning tree on these cheapest paths, we can use it to connect all cycles. The costs of the paths can be charged to the optimal tour, analogous to the classic TSP.

Lemma 21

Given a set of cycles \(\mathcal {C}\) in a graph \(G=(P,E)\) with \(\forall C\in \mathcal {C}: C\cap S\not = \emptyset \) for a subset \(S\subset P\). The MST on the complete graph with vertices \(\mathcal {C}\) and edge weights CP is a lower bound for a subset tour.

Proof

Consider an optimal tour and for each cycle, the first intersection with this tour. Cutting the tour at these places gives us a set of paths connecting all cycles with a cost less than the tour. As this also represents a tree, the minimum spanning tree has to be of the same or lower cost.\(\square \)

On the other hand, the \(360^{\circ }\) can be charged to one of the cycles, because every cycle needs to do at least a full rotation, and there are fewer such merge processes than cycles in the initial cycle cover. This directly yields a method for approximating subset tours when a cycle cover approximation is given, see Fig. 21.

Fig. 21
figure 21

Connecting subset cycles (cycles in blue, subset pixels in red) to a tour by applying Lemma 20 (green edges) to the edges of a minimum spanning tree on the cycles (with the cheapest incident paths as edges). The cost of the tour consists of the n cycles, twice the MST and \(2\cdot (n-1)\cdot \left( 0, 180^{\circ }\right) \) for connecting paths and cycles

In order to connect the cycles of a penalty cycle cover to a penalty tour, we cannot simply use the doubled minimum spanning tree technique like we did for subset coverage; e.g., if the penalty cycle cover consists of two distant cycles, it may be cheaper not to connect them, but select the better cycle as a tour and discard the other cycle. Instead, we double a prize-collecting Steiner tree instead of a minimum spanning tree, in which every vertex not in the tree results in a penalty (or, equivalently, every vertex in the tree provides a prize). Without loss of generality, we may assume that all cycles are disjoint: otherwise, we connect two crossing cycles at a cost of at most \((0, 360^{\circ })\), which can be charged to the merged cycle. Then the penalty for not including a cycle is the sum of penalties of all its pixels.

Lemma 22

Given a set of disjunct cycles \(\mathcal {C}\) in a graph \(G=(P,E)\) and penalties \(c: P\rightarrow \mathbb {R}^+_0\). The prize-collecting steiner tree on the complete graph over \(\mathcal {C}\) with edge weights CP and the sum of penalties \(\sum _{p\in C} c(p)\) for \(C\in \mathcal {C}\) as prize is a lower bound on a penalty tour.

Proof

Consider an optimal penalty tour \(T=p_0p_1p_2\cdots p_{n-1}p_0\) with the uncovered pixels S. We prove that we can construct a prize-collecting Steiner tree on \(\mathcal {C}\) of lower costs (including penalties). First, discard all cycles \(C\in \mathcal {C}\) that do not share a pixel with T. Their costs are also paid by T, as it is fully contained in S. For the remaining cycles \(\mathcal {C}'\), let o(C) denote the index in T of the first shared pixel and \(\mathcal {C}'=C_0, C_1,\ldots , C_{k-1}\) be ordered by o. \(p_{o(C_i)}p_{o(C_i)+1}\cdots p_{o(C_{i+1})}\) now defines a connection between \(C_i\) and \(C_{i+1}\) of costs less than or equal to \(CP(C_i, C_{i+1})\). This allows us to construct a path through all \(\mathcal {C}'\) that is at most as expensive as the touring costs of T, implying the lower bound.\(\square \)

As a result, we provide constant-factor approximation algorithms for all variants.

Theorem 23

We can establish the following approximation factors for tours.

  1. 1.

    Full tours in regular grid graphs: 6-approximation.

  2. 2.

    Full tours in generalized grid graphs: \(4\omega \)-approximation.

  3. 3.

    Subset tours in (generalized) grid graphs: \((4\omega +2)\)-approximation.

  4. 4.

    Penalty tours in (generalized) grid graphs: \((4\omega +4)\)-approximation.

These results also hold for objective functions that are linear combinations of length and turn costs.

Fig. 22
figure 22

We can compute a mesh on a polygon to obtain an irregular grid graph. With some modifications, the approximation technique can still be applied, yielding good tours in practice. The turns are smoothed using Bézier curves

Fig. 23
figure 23

Further examples of the application of the approximation technique on triangular meshes of polygons

Fig. 24
figure 24

The penalty tour approximation technique can be extended to work on meshes to compute partial coverage tours with valuable (green) and unfavourable (red) areas in a polygonal domain. The computed tour covers most of the green areas and minimizes the usage of the red areas

Proof

Starting with an approximation of the cycle cover variant, we can connect the cycle cover to a single tour with only limited additional costs.

  1. 1.

    For full tours in regular square grid graphs, greedily connecting cycles provides a tour with at most 1.5 times the turn cost of the cycle cover, while a local optimization can be exploited to limit the length to 4 times the optimum, as already proved by Arkin et al. [5].

  2. 2.

    In a cycle cover for (generalized) grid graphs, there are always at least two cycles with a distance of one; otherwise the cycle cover is already a tour. This allows iteratively merging cycles at cost at most \((2,360^{\circ })\) by using Lemma 20; the total number of merges is less than the number of cycles. Because a cycle has a cost of at least \((2, 360^{\circ })\), the additional cost is at most the cost of the cycle cover. Thus, the cost of the \(2\omega \)-approximation for a cycle cover is at most doubled.

  3. 3.

    For subset coverage, we start with a subset cycle cover approximation \(\mathcal {C}\) with a cost of at most \(2\omega \cdot OPT\). Using Lemma 21, we get a set of \(|\mathcal {C}|-1\) connecting paths with a cost of at most OPT. Applying Lemma 20 gives us a tour of cost at most \(2\omega \cdot OPT+2\cdot OPT+(|\mathcal {C}|-1)\cdot (0, 360^{\circ })\). Because \((|\mathcal {C}|-1)\cdot (0, 360^{\circ }) \le cost (\mathcal {C}) \le 2\omega \cdot OPT\), the tour is a \(4\omega +2\) approximation.

  4. 4.

    Penalty tours can be approximated in a similar manner. Start with a penalty cycle cover approximation \(\mathcal {C}\) with a cost of at most \(2\omega \cdot OPT\). Because Lemma 22 does not allow intersecting cycles, we merge all intersecting cycles at a cost of \((0, 360^{\circ })\) per merge (Lemma 20 with zero cost path). Let \(\mathcal {C}'\) be the resulting set of cycles, then \((|\mathcal {C}|-(|\mathcal {C}'|+1))\cdot (0, 360^{\circ })\) is the involved cost. Compute a 2-approximation of the prize-collecting Steiner tree on \(\mathcal {C'}\) using the algorithm of Goemans and Williamson [22], which has a cost of at most \(2\cdot OPT\), including the penalties for the removed cycles (cf. Lemma 22). Let \(\mathcal {C}''\subseteq \mathcal {C}'\) be the cycles in the prize-collecting Steiner tree. Applying Lemma 20 gives us a tour of cost at most \(2\omega \cdot OPT+2\cdot 2\cdot OPT+(|\mathcal {C}''|-1)\cdot \left( 0, 360^{\circ }\right) +(|\mathcal {C}|-(|\mathcal {C}'|+1))\cdot \left( 0, 360^{\circ }\right) \). Because \((|\mathcal {C}''|-1)\cdot \left( 0, 360^{\circ }\right) + (|\mathcal {C}|-(|\mathcal {C}'|+1))\cdot \left( 0, 360^{\circ }\right) \le |\mathcal {C}|\cdot \left( 0, 360^{\circ }\right) \le cost (\mathcal {C}) \le 2\omega \cdot OPT\), the tour is a \(4\omega +4\) approximation.

\(\square \)

3.4 Practical Application

The discussed approximation techniques can actually be extended to work on meshes, allowing to compute practical tours for complex polygonal areas. This is shown in Figs. 22, 23 and 24 and the details are given by Krupke [23, 24].

4 Conclusions

We have presented a number of theoretical results on finding optimal tours and cycle covers with turn costs. In addition to resolving the long-standing open problem of complexity, we provided a generic framework to solve geometric (penalty) cycle cover and tour problems with turn costs.

As described in [10], the underlying problem is also of practical relevance. As it turns out, our approach does not only yield polynomial-time approximation algorithms; enhanced by an array of algorithm engineering techniques, they can be employed for actually computing optimal and near-optimal solutions for instances of considerable size in grid graphs. Further details on these algorithm engineering aspects is provided in our paper [19].