Placing Labels in Road Maps: Algorithms and Complexity

A road map can be interpreted as a graph embedded in the plane, in which each vertex corresponds to a road junction and each edge to a particular road section. In this paper, we consider the computational cartographic problem to place non-overlapping road labels along the edges so that as many road sections as possible are identified by their name, i.e., covered by a label. We show that this is NP-hard in general, but the problem can be solved in O(n3)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$O(n^3)$$\end{document} time if the road map is an embedded tree with n vertices and constant maximum degree. This special case is not only of theoretical interest, but our algorithm in fact provides a very useful subroutine in exact or heuristic algorithms for labeling general road maps.


Introduction
Map labeling is a well-known cartographic application problem in computational geometry [13,16]. Depending on the type of map features, one can distinguish labeling of points, lines, and areas. Common cartographic quality criteria are that labels must be disjoint and clearly identify their respective map features [8]. Most of the previous work concerns point labeling, while labeling line and area features received 1 3 considerably less attention. In this paper we address labeling line features, namely roads in a road map.
Geometrically speaking, a road map is the representation of a road graph G as an arrangement of fat curves, i.e., curves with fixed, positive stroke width, in the plane ℝ 2 . Each road is a connected subgraph of G (typically a simple path) and each edge belongs to exactly one road. Roads may intersect each other in junctions, the vertices of G, and we denote an edge connecting two junctions as a road section. In road labeling, the task is to place the road names inside the fat curves so that all road sections are identified unambiguously but at the same time the road map is not overloaded with labels.
Chirié [1] presented a set of rules and quality criteria for label placement in road maps based on interviews with cartographers. These include that (C1) Labels are placed inside and parallel to the road shapes, (C2) Every road section between two junctions should be clearly identified, and (C3) No two road labels may intersect.
Further, he gave a mathematical description for labeling a single road and introduced a heuristic for sequentially labeling all roads in the map. Imhof's foundational cartographic work on label positioning in maps lists very similar quality criteria [3]. Edmondson et al. [2] took an algorithmic perspective on labeling a single linear feature (such as a river). While Edmondson et al. considered non-bent labels, Wolff et al. [15] introduced an algorithm for a single linear feature that places labels following the curvature of the linear feature. Strijk [10] considered static road labeling with embedded labels and presented a heuristic for selecting non-overlapping labels out of a set of label candidates. Seibert and Unger [11] considered grid-shaped road networks. They showed that in those networks it is NP-complete to decide whether for every road at least one label can be placed without any overlaps between labels. Further, they prove that the according optimization problem maximizing the number of roads having at least one label is APX-hard. Yet, Neyer and Wagner [7] introduced a practically efficient algorithm that finds such a grid labeling if possible. Maass and Döllner [5] presented a heuristic for labeling the roads of an interactive 3D map with objects (such as buildings). Apart from label-label overlaps, they also resolve label-object occlusions. Vaaraniem et al. [14] used a force-based labeling algorithm for 2D and 3D scenes including road label placement. Schwartges et al. [12] presented a simple heuristic for maximizing the number of placed road labels in interactive maps providing operations for panning, zooming and rotating the map. Finally, Schwartges et al. [9] considered the problem of labeling roads in 3-dimensional maps. In order to avoid distortion of the labels by projecting them onto the road, they used billboards instead, i.e., labels connected to their roads by short leaders.
Contribution and Outline While it is sufficient to place a single label per road to clearly identify all its road sections in grid-shaped road networks, this is not the case in general road networks. Consider the schematic example in Fig. 1. In Fig. 1a, it is not obvious whether the road section in the center belongs to Knuth St. or to Turing St. On the other hand, simply maximizing the number of placed labels, as often done for labeling point features, can cause undesired effects like unnamed roads or clumsy label placements (e.g., the unlabeled Dijkstra St. and the threefold labeled Hamming St. in Fig. 1a. In order to overcome the problems outlined, we aim for maximizing the number of labeled road sections, i.e., the number of road sections that can be clearly assigned to labels; see Fig. 1b. Further, in contrast to the approaches of Chirié [1] and Strijk [10,Ch. 9], we consider label placement in road maps globally for the entire map, applying a continuous sliding model. More precisely, as the underlying model, we introduce a new and versatile planar graph model based on criteria (C1)-(C3); see Sect. 2.
We take an algorithmic, mathematical perspective on the optimization problem of maximizing the number of labeled road sections. In Sect. 3 we show that the problem of maximizing the number of labeled road sections is NP-hard for general road graphs, even if every road is a path. For the special case that the road graph is a tree, we present a polynomial-time algorithm in Sect. 4. This special case is not only of theoretical interest, but our algorithm in fact provides a very useful subroutine in exact or heuristic algorithms for labeling general road graphs, as we demonstrated in an applied companion paper [6]. c Illustration of the road graph and relevant terms. d Graph representation of (a) with five labels and five labeled road sections. e Graph representation of (b) with five labels and eight labeled road sections, which is optimal with respect to the considered objective (Color figure online) 1 3

Model
As argued before, a road map is a collection of fat curves in the plane, each representing a particular piece of a named road. If two (or more) such curves intersect, they form junctions. A road label is again a fat curve (the bounding shape of the road name) that is contained in and parallel to the fat curve representing its road. We observe that, by being contained inside the road curves, labels of different roads can intersect only within junctions and that the actual width of the curves is irrelevant, except for defining the shape and size of the junctions. We use these observations to define the following abstract road graph model. 1 A road map M is a planar road graph G = (V, E) together with a planar embedding (G) , which can be thought of as the geometric representation of the road axes as thin curves; see Fig. 1c. We denote the number of vertices of G by n, and the number of edges by m. Observe that, since G is planar, m = O(n) . Each edge e ∈ E is either a road section, which is not part of a junction, or a junction edge, which is part of a junction. Each vertex v ∈ V is either a junction vertex incident only to junction edges, or a regular vertex incident to one road section and at most one junction edge, which implies that each regular vertex has degree at most two. A junction consists of a junction vertex v and its incident junction edges. The edge set E decomposes into a set R of edge-disjoint roads, where each road R ∈ R induces a connected subgraph of G. Without loss of generality we assume that no two road sections in G are incident to the same (regular) vertex. Thus, a road decomposes into road sections, separated by junction vertices and their incident junction edges. In realistic road networks the number of roads passing through a single junction is small and does not depend on the size of the road network. We therefore assume that each vertex in G has constant degree. We further assume that each road R ∈ R has a name (to be displayed in its label) whose length we denote by (R).
For simplicity, we identify the embedding (G) with the subset of the plane covered by (G) , i.e., (G) ⊆ ℝ 2 . We also use (v) , (e) , and (R) to denote the embeddings of a vertex v, an edge e, and a road R.
We model a label as a simple open curve ∶ [0, 1] → (G) . Unless mentioned otherwise, we consider a curve always to be simple and open, i.e., has no self-intersections and its end points do not coincide. In order to ease the description, we identify a curve in (G) with its image, i.e., denotes the set { (t) ∈ (G) | t ∈ [0, 1]} . The start point (0) of is denoted as the head h( ) and the endpoint (1) as the tail t( ) . The length of is denoted by length ( ) . The curve (partly) covers a road section r if ∩ (r) ≠ � . In that case we say that labels the road section r. For a set L of curves, (L) is the number of road sections that are labeled by the curves in L . For a single curve , we use ( ) instead of ({ }) . For two curves 1 and 2 it is not necessarily true that ({ 1 , 2 }) = ( 1 ) + ( 2 ) because they may label the same road section twice.

3
Algorithmica (2020) 82:  A label for a road R is a curve ⊆ (R) of length (R) whose endpoints must lie on road sections and not on junction edges or junction vertices. Requiring that labels end on road sections avoids ambiguous placement of labels in junctions where it is unclear how the road passes through it. A labeling L for a road map with road set R is a set of mutually non-overlapping labels, where we say that two labels and ′ overlap if they intersect in a point that is not their respective head or tail.
Following the cartographic quality criteria (C1)-(C3), our goal is to find a labeling L that maximizes the number of labeled road sections, i.e., for any labeling L ′ we have (L � ) ≤ (L) . We call this algorithmic optimization problem MaxLabeLe-dRoads. While Fig. 1d shows a sub-optimal labeling, Fig. 1e shows an optimal labeling of the same road map with respect to the considered objective function.
Note that assuming the road graph G to be planar is not a restriction in practice [6]. Consider for example a road section r that overpasses another road section r ′ , i.e., r is a bridge over r ′ , or r ′ is a tunnel underneath r. In order to avoid overlaps between labels placed on r and r ′ , we either can model the intersection of r and r ′ as a regular crossing of two roads or we split r ′ into shorter road sections that do not cross r. In both cases the corresponding road graph becomes planar. In the latter case we may obtain more independent roads created by chopping r ′ into smaller pieces.

Computational Complexity
We first study the computational complexity of road labeling and prove NP-completeness of MaxLabeLedRoads in the following sense.
Theorem 1 For a given road map M and an integer K it is NP-complete to decide if in total at least K road sections can be labeled even if M has maximum degree 4.
Proof One can argue that the decision problem is in NP by guessing which junctions are covered by which label and then using linear programming for computing the label positions. More precisely, by means of an integer linear programming formulation with binary and continuous variables one can describe MaxLabeLedRoads [6]. After guessing all binary variables contained in this formulation, a linear programming formulation remains, which can be solved in polynomial time. For the technical details of that formulation we refer to the companion paper [6].
We perform a reduction from the NP-complete pLanaR Monotone 3-sat problem [4]. An instance of pLanaR Monotone 3-sat is a Boolean formula with n variables and m clauses (disjunctions of at most three literals) that satisfies the following additional requirements: (i) is monotone, i.e., every clause contains either only positive literals or only negative literals and (ii) the induced variable-clause graph H of is planar and can be embedded in the plane with all variable vertices on a horizontal line, all positive clause vertices on one side of the line, all negative clauses on the other side of the line, and the edges drawn as rectilinear curves connecting clauses and contained variables on their respective side of the line.
We construct a road map M that mimics the shape of the above embedding of H by defining variable and clause gadgets, which simulate the assignment of truth values to variables and the evaluation of the clauses. We refer to Fig. 2 for a sketch of the construction.
Chain Gadget The basic building block is the chain gadget, which consists of an alternating sequence of equally long horizontal and vertical roads with identical label lengths that intersect their respective neighbors in the sequence and form junctions with them as indicated in Fig. 2c. Assume that the chain consists of k ≥ 3 roads. Then each road except the first and last one decomposes into three road sections split by two junctions, a longer central section and two short end sections; the first and last road consist of only two road sections, a short one and a long one, separated by one junction. (These two roads will later be connected to x3 ∨x4 ∨x5   Fig. 2c.) The label length and distance between junctions is chosen so that for each road either the central and one end section is labeled, or no section at all is labeled. For the first and last road, both sections are labeled if the junction is covered and otherwise only the long section can be labeled. We have k roads and k − 1 junctions. Each label must block a junction if it labels two sections. So the best possible configuration blocks all junctions and labels 2(k − 1) + 1 = 2k − 1 road sections.
The chain gadget has exactly two states in which 2k − 1 road sections are labeled. Either the label of the first road does not block a junction and labels a single section and all subsequent roads have their label cover the junction with the preceding road in the sequence, or the label of the last road does not block a junction and all other roads have their label cover the junction with the successive road in the sequence. In any other configuration there is at least one road without any labeled section and thus at most 2k − 2 sections are labeled. We use the two optimal states of the gadget to represent and transmit the values true and false from one end to the other.
Fork Gadget The fork gadget allows us to split the value represented in one chain into two chains, which is needed to transmit the truth value of a variable into multiple clauses. It connects to the end roads of three chain gadgets by sharing junctions.
The core of the fork, as illustrated in Fig. 3, consists of six roads r 1 , … , r 6 , where r 1 , r 2 , and r 3 are vertical line segments and r 4 , r 5 , and r 6 are horizontal line segments. We arrange these roads such that r 1 and r 2 each have one junction with r 4 and one junction with r 5 . Further, r 3 has one junction with r 4 , one with r 5 and one with r 6 . The label length of these roads is chosen so that it is exactly the length of the roads. Hence, a placed label blocks all road sections of the roads.
Further, there are three roads g 1 , g 2 , g 3 such that g 1 has one junction with r 1 , g 2 has one junction with r 2 , and g 3 has one junction with r 6 . In all three cases we place the junction so that it splits the road into a short road section that is shorter than the road's label length and a long road section that has exactly the road's label length. We call g 1 , g 2 and g 3 gates, because later these roads will be connected by junctions to the end roads of chains. To that end, these connecting junctions will be placed on the long road sections of the gates; see the purple dotted areas in Fig. 3. The fork gadget has exactly two states, in which 16 road sections are labeled. 2 In the first state the labels of r 1 , r 2 and r 3 are placed; see Fig. 3b. Hence, the labels of g 1 and g 2 label only the long road sections of g 1 and g 2 , but not the short ones. The label of g 3 labels both the long and short road section of g 3 . In the second state the labels of r 4 , r 5 , r 6 are placed; see Fig. 3c. Hence, the labels of g 1 and g 2 label the long and short road sections of g 1 and g 2 , while only the long road section of g 3 is labeled. In any other configuration fewer road sections are labeled. We use the two optimal states of the gadget to represent and transmit the values true and false from one gate to the other two gates. More specifically the gates g 1 and g 2 are connected with chains that lead to the same literal, while g 3 is connected with a chain that leads to the complementary literal.
Variable Gadget We define the variable gadgets simply by connecting chain and fork gadgets into a connected component of intersecting roads. This construction already has the functionality of a variable gadget: it represents (in a labeling that labels the maximum number of road sections) the same truth value in all of its branches, synchronized by the fork gadgets, see the blue chains and yellow forks in Figs. 2 and 4a. More precisely, we place a sequence of chains linked by fork gadgets along the horizontal line on which the variable vertices are placed in the drawing H . Each fork creates a branch of the variable gadget either above or below the line. We create as many branches above (below) the line as the variable has occurrences in positive (negative) clauses in . The leftmost and rightmost chain on the line also serve as branches. The synchronization of the different branches via the forks is such that either all top branches have their road labels pushed away from the line and all bottom branches pulled towards the line or vice versa. In the first case, we say that the variable is in the state false and in the latter case that it is in the state true. The example in Fig. 2 has one variable set to true, namely x 2 , and four variables set to false, namely x 1 , x 3 , x 4 and x 5 . Note that in case a variable occurs only in one positive and one negative clause (see x 4 in Fig. 2a), we connect the corresponding literals via a single chain without introducing forks for that variable. Clause Gadget Finally, we need to create the clause gadget, which links three branches of different variables. The core of the gadget is a single road that consists of three subpaths meeting in one junction. Each subpath of that road shares another junction with one of the three incoming variable branches. Beyond each of these three junctions the final road sections are just long enough so that a label can be placed on the section. However, the section between the central junction of the clause road and the junctions with the literal roads is shorter than the label length. The road of the clause gadget has six sections in total and we argue that the six sections can only be labeled if at least one incoming literal evaluates to true. Otherwise at most five sections can be labeled. By construction, each road in the chain of a false literal has its label pushed towards the clause, i.e., it blocks the junction with the clause road. As long as at least one of these three junctions is not blocked, all sections can be labeled; see Fig. 2b. But if all three junctions are blocked, then only two of the three inner sections of the clause road can be labeled and the third one remains unlabeled. We observe that this requires that the core of the gadget is a single road.
Reduction Obviously, the size of the instance M is polynomial in n and m. If we have a satisfying variable assignment for , we can construct the corresponding road labeling and the number of labeled road sections is six per clause and a fixed constant number K ′ of sections in the variable gadgets, i.e., at least K = K � + 6m . On the other hand, if we have a road labeling with at least K labeled sections, each variable gadget is in one of its two maximum configurations and each clause road has at least one label that covers a junction with a literal road, meaning that the corresponding truth value assignment of the variables is indeed a satisfying one. This concludes the reduction. ◻ Most roads in the reduction are paths, except for the central road in each clause gadget, which is a degree-3 star. In fact, we can strengthen Theorem 1 by using a more complex clause gadget instead that consists only of paths as described next.

Theorem 2 For a given road map M and an integer K it is NP-complete to decide if in total at least K road sections can be labeled, even if M has maximum degree 4 and all roads are paths.
Proof The clause gadget consists of twelve roads, r a , r b , r c , g a , g b , g c , a i , b i , and c i with i ∈ {1, 2} that all are paths; see Fig. 5. We choose r a , r b , and r c such that r a and r b consist of vertical segments and r c consists of horizontal segments. Going along r a from bottom to top, the junctions with the roads a 1 , a 2 , c 1 and b 1 occur in the sequence B a = (a 1 , c 2 , b 1 , a 2 ) . Going along r b from top to bottom, the junctions with the roads b 1 , b 2 , a 2 and c 1 occur in the sequence B b = (a 2 , b 1 , c 1 , b 2 ) . Going along r c from right to left, the roads b 2 , c 1 , c 2 and a 1 occur in the sequence B c = (b 2 , c 1 , c 2 , a 1 ) . Further, the label lengths of r a , r b , and r c is chosen such that exactly one label can be placed.
We now describe junctions of the roads g a , g b , g c , a i , b i , and c i with i ∈ {1, 2} . The road a 1 first intersects g a , then r a , and finally r c . Let s 1 , while the others are shorter than the label length of a 1 . More specifically, we define a 1 's label length such that a label covers the sections in either {s 1 } . We define the intersections and the label length for a 2 analogously. Further, g a intersects a 1 and a 2 in one junction, i.e., the edge of g a connecting both junction vertices is a junction edge. The label length of g a is chosen so that a label can cross g a 's only junction. The length of g a 's road sections is at least as long as g a 's label length. We call g a a gate, because later this road will be connected to the end road of a chain by a junction; see the lilac dotted square in Fig. 5a. For b 1 , b 2 , c 1 , c 2 we introduce analogous junctions and road sections, however, b 1 and b 2 intersect g b instead of g a , and c 1 and c 2 intersect g c instead of g a .
In order to label both road sections of a gate, either two labels can be placed on the road sections separately, or one label that goes through the junction. In the former case the gate is open, and in the latter case it is closed; see Fig. 5b. We observe that it only makes sense to close a gate if at least one road section of the gate does  . Hence, 33 road sections are labeled. We observe that we can place the labels of b 1 , b 2 , c 1 , c 2 such that they do not cross the junctions of g b and g c , respectively. Hence, it does not matter whether g b and g c are closed or open, i.e., it does not matter whether the corresponding literals are true or false.
We now argue that this is an optimal labeling. If s 4 increases the number of labeled road sections. In order to label at least one of the unlabeled road sections of r, we need to place a label that crosses B b or B c . Obviously, this yields a smaller number of labeled road sections than 31.
Finally, assume that all gates are closed as in Fig. 5c. Consider the same labeling as before. This time, however, we cannot label s 2 a 1 and s 2 a 2 anymore. Hence, this labeling has only 31 labeled road sections. Obviously, it cannot be improved by changing the placement of the remaining labels or adding more labels. ◻

An Efficient Algorithm for Tree-Shaped Road Maps
In this section we assume that the underlying road graph of the road map is a tree T = (V, E) . In Sect. 4.1 we present a polynomial-time algorithm to optimally solve MaxLabeLedRoads for trees; Sect. 4.2 shows how to improve its running time and space consumption. Our approach uses the basic idea that removing the vertices whose embeddings lie in a curve c ⊆ (T) splits the tree into independent parts. In  particular this is true for labels. We assume that T is rooted at an arbitrary leaf and that its edges are directed away from ; see Fig. 6. For two points p, q ∈ (T) we define d (p, q) as the length of the shortest curve in (T) that connects p and q. For . For a point p ∈ (T) we abbreviate the distance d (p, ) to the root by d p . For a curve in (T) , we call p ∈ the highest point of if d p ≤ d q , for any q ∈ . As T is a tree, p is unique. We distinguish two types of curves in (T) . A curve is vertical if h( ) or t( ) is the highest point of ; otherwise we call horizontal; see Fig. 6. Without loss of generality we assume that the highest point of each vertical curve is its tail t( ) . Since labels are modeled as curves, they are also either vertical or horizontal. For a vertex u ∈ V let T u denote the subtree rooted at u.

Basic Approach
We first determine a finite set of candidate positions for the heads and tails of labels, and transform T into a tree T � = (V � , E � ) by subdividing some of T's edges so that the resulting tree contains a vertex for every candidate position. To that end we construct for each regular vertex v ∈ V a chain of tightly packed vertical labels that starts at (v) , is directed towards , and ends when either the road ends, or adding the next label does not increase the number of labeled road sections; see Fig. 7. More specifically, we place a first vertical label 1 such that h( 1 ) = (v) ; recall that t( 1 ) is the highest point of 1 . For i = 2, 3, … we add a new vertical label i with h( i ) = t( i−1 ) , as long as h( i ) and t( i ) do not lie on the same road section and none of i 's endpoints lies on a junction edge. We use the tails of all these labels to subdivide the tree T. Doing this for all regular vertices of T we obtain the tree T ′ , which we call the subdivision tree of T. The vertices in V ′ ⧵V are neither junction vertices nor regular The next lemma proves that it is sufficient to consider canonical labelings.

Lemma 1 For any road graph T that is a tree, there exists a canonical labeling L.
Proof Let L be an optimal labeling of T. We push the labels of L as far as possible towards the leaves of T without changing the labeled road sections; see Fig. 8. More specifically, starting with the labels closest to the leaves, we move each label away from the root as far as possible while its head and tail must remain on their respective road sections. For a vertical label this direction is unique, while for horizontal labels we can choose any of the two possible directions. Then, for each label its head or tail either coincides with a leaf of T, with some internal regular vertex, or with the head of another label. Consequently, each vertical label belongs to a chain of tightly packed vertical labels starting at a regular vertex v ∈ V . Further, the head or tail of each horizontal label coincides with the end of a chain of tightly packed vertical labels or with a regular vertex of T, which proves the claim. ◻ We now explain how to construct a canonical labeling that is optimal among all possible labelings. To that end, we first introduce some notations. For a vertex u ∈ V � let L(u) denote a labeling that labels a maximum number of road sections in T using only valid labels in (T � u ) , where T ′ u denotes the subtree of T ′ rooted at u. Note that these labels may also cover the incoming road section of u, e.g., label in Fig. 8b covers the edge e ′ .
Further, the children of a vertex u ∈ V � are denoted by the set N(u); we explicitly exclude the parent of u from N(u). Further, consider an arbitrary curve in (T) and let � = ⧵{t( ), h( )} . We observe that removing all vertices of T ′ contained in ′ together with their incident outgoing edges creates several independent subtrees. We  call the roots of these subtrees (except the one containing ) children of (see Fig. 6). If no vertex of T ′ lies in ′ , the curve is contained in a single edge (u, v) ∈ E � . In that case v is the only child of . We denote the set of all children of as N( ).
For each vertex u in T ′ we introduce a set C(u) of candidates, which model potential labels with highest point (u) . If u is a regular vertex of T or u ∈ V � ⧵V , the set C(u) contains all vertical labels with highest point (u) . If u is a junction vertex, C(u) contains all horizontal labels that start or end at a vertex of T ′ and whose highest point is (u) . In both cases we assume that C(u) also contains the degenerate curve ⊥ u = (u) , which is the dummy label of u. We set N(⊥ u ) = N(u) and (⊥ u ) = 0.
For a curve we define Thus, L( ) is a labeling comprising and the labels of its children's optimal labelings. We call a label ∈ C(u) with = argmax { (L( )) | ∈ C(u)} an optimal candidate of u. Next, we prove that it is sufficient to consider optimal candidates to construct a canonical labeling.

Lemma 2
Let u be a vertex of T ′ with optimal labeling L(u), and let be an optimal candidate of u, then it is true that (L(u)) = (L( )).
Proof First note that (L(u)) ≥ (L( )) by the definition of L(u) and because both labelings L(u) and L( ) only contain labels that are embedded in (T � u ). By Lemma 1 we can assume without loss of generality that L(u) is a canonical labeling. Let be the label of L(u) with (u) as the highest point of (if it exists).
If exists, then the vertices in N( ) are roots of independent subtrees, which directly yields (L(u)) = (L( )) . By construction of C(u) we further know that is contained in C(u). Hence, is an optimal candidate of u, which implies ( ) = ( ). If does not exist, then we have Equality (1) follows from N(⊥ u ) = N(u) and the definition that ⊥ u does not label any road section. Since ⊥ u is contained in C(u), the dummy label ⊥ u is the optimal candidate . ◻ Algorithm 1 first constructs the subdivision tree T � = (V � , E � ) from T. Then starting with the leaves of T ′ and going to the root of T ′ , it computes an optimal candidate = (u) for each vertex u ∈ V � in a bottom-up fashion. By Lemma 2, the labeling L( ) is an optimal labeling of T ′ u . In particular, L( ) is the optimal labeling of T.
Due to the size of the subdivision tree T ′ we consider O(n 2 ) vertices. Implementing (u) , which computes an optimal candidate for u, naively, creates C(u) explicitly. We observe that if u is a junction vertex, C(u) may contain O(n 2 ) labels; as we assume that each vertex has constant degree, O(n 2 ) pairs of road sections of different subtrees of u can be connected by horizontal labels. Each label can be constructed in O(n) time using a breadth-first search. Thus, for each vertex u the procedure OptCandidate needs in a naive implementation O(n 3 ) time, which yields O(n 5 ) running time in total. Further, we need O(n 2 ) storage to store T ′ . Note that we do not need to store L(u) for each vertex u of T ′ , because by Lemma 2 we can reconstruct it using L( ) , where is the optimal candidate of u. To that end we store for each vertex of T ′ its optimal candidate and w(L( )).

Theorem 3 For a road map with a tree as underlying road graph with constant maximum degree, MaxLabeLedRoads can be solved in O(n 5 ) time using O(n 2 ) space.
In case that all roads are paths, Algorithm 1 runs in O(n 4 ) time, because for each u ∈ V � the set C(u) contains O(n) labels. We shortly note that besides the primary objective to label a maximum number of road sections, Chirié [1] also suggested several additional secondary objectives, e.g., labels should overlap as few junctions as possible. Our approach allows us to easily incorporate secondary objectives by changing the weight function appropriately. In particular, as the primary and secondary objectives might contradict each other, the weight function can be used to express a compromise between them. The improvements that we present in the following sections are specialized for the objective of maximizing the number labeled road sections. For instance, the red label in Fig. 8b is an e-rooted curve. We observe that in any canonical labeling each vertical label is a (u, v)-rooted curve with (u, v) ∈ E � , and each horizontal label can be composed of a (u, v 1 )-rooted curve 1 and a (u, v 2 ) -rooted curve 2 with (u, v 1 ), (u, v 2 ) ∈ E � and (u) is the highest point of ; see   The main idea of the linearization is that for each length of a possible e-rooted curve there is an e-dock in L that represents the best possible weight of an e-rooted curve with the same length. To that end, Condition (1) enforces that the function actually encodes the weights of the e-docks in L. Condition (2) ensures that L is complete in the sense that for any e-rooted curve there is an e-rooted curve ′ of the same length that ends on an e-dock of L. We observe that ′ is unique as L contains pairwise superposition-free e-docks.

Improvements on Running Time
Assume that we apply Algorithm 1 on T ′ and that we currently consider the vertex u of T ′ . Hence, we can assume that for each vertex v ≠ u of T ′ u its optimal candidate and (L(v)) is given. We first explain how to speed up OptCandidate using linearizations. Afterwards, we present the construction of linearizations.

Speeding up OptCandidate with Linearizations
Here we assume that the linearizations are given for the edges of T. Depending on the type of u we describe how to compute its optimal candidate. Case 1: u is regular. If u is a leaf, the set C(u) contains only ⊥ u . Hence, assume that u has one outgoing edge e = (u, v) ∈ E � , which belongs to a road R. Let P be the longest path of vertices in T ′ u that starts at u and does not contain any junction vertex. Note that the path is unique. Further, by construction of T ′ the last vertex w of P must be a regular vertex in V, but not in V ′ ⧵V . We consider two cases; see Fig. 9a.
If d (u, w) ≥ (R) , the optimal candidate is either ⊥ u or the e-rooted curve of length (R) that ends on (P) . By assumption and due to (L(⊥ u )) = (L(v)) , we decide in O(1) time whether (L(⊥ u )) ≥ (L( )) , obtaining the optimal candidate.
If d (u, w) < (R) , the optimal candidate is either ⊥ u or goes through a junction. Since w is regular, it has only one outgoing edge e � = (w, x) . Further, by the choice of P the edge e ′ is a junction edge in T; therefore the linearization (L, ) of e ′ is given. In linear time we search for the e-dock c ∈ L such that there is an e-rooted curve of length (R) with its head on c. To that end we consider for each e-dock c ∈ L its distance interval I(c) and check whether there is a t ∈ I(c) with t − d u = (R) . Note that using a binary search tree for finding c speeds this procedure up to O(log n) time, however, this does not asymptotically improve the total running time. The e-rooted curve then can be easily constructed in O(n) time by walking from c to u in (T).
If such an e-dock c exists, by definition of a linearization the optimal candidate is either ⊥ u or , which we can decide in O(1) time by checking whether (L(⊥ u )) ≥ (L( )) . Note that we have (L(⊥ u )) = (L(v)) and (L( )) = (c) . If c does not exist, again by definition of a linearization there is no vertical label ∈ C(u) and ⊥ u is the optimal candidate. Case 2: u is a junction vertex. The set C(u) contains horizontal labels. Let be such a label and let e 1 = (u, v 1 ) and e 2 = (u, v 2 ) be two junction edges in E covered by ; see Fig. 9b. Then there is an e 1 -rooted curve 1 and an e 2 -rooted curve 2 whose composition is . Further, we have (L( )) = (L( 1 ) ∪ L( 2 )) + ∑ v∈N(u)⧵{v 1 ,v 2 } (L(v)) . We use this as follows. Let e 1 and e 2 be two outgoing edges of u that belong to the same road R, and let (L 1 , 1 ) and (L 2 , 2 ) be the linearizations of e 1 and e 2 , respectively. We now define for e 1 and e 2 and their linearizations the operation opt-cand (L 1 , L 2 ) that returns an optimal candidate of u restricted to labels covering e 1 and e 2 .
Applying f u (t) on the boundaries of the distance intervals of the curves in L 1 , we first mirror these intervals such that they are contained in the interval Fig. 11. Thus, the curves in L 1 ∪ L 2 are mutually superpositionfree such that their distance intervals lie in We call an interval [x, y] ⊆ J a window if it has length (R) , if d u ∈ [x, y] , and if there is an e 1 -dock c 1 ∈ L 1 and an e 2 -dock c 2 ∈ L 2 with x ∈ I(c 1 ) and y ∈ I(c 2 ) ; see Fig. 11. By the definition of a linearization there is a maximal e 1 -rooted curve 1 ending on c 1 and a maximal e 2 -rooted curve 2 ending on c 2 such that length ( 1 ) + length ( 2 ) = (R) . Consequently, the composition of 1 and 2 forms a horizontal label with (L( )) = (L( 1 ) ∪ L( 2 )) + ∑ v∈N(u)⧵{v 1 ,v 2 } L(v) ; we call (L( )) the value of the window. Using a simple sweep from left to right we compute for the distance interval I(c) of each curve c ∈ L 1 ∪ L 2 a window [x, y] that starts or ends in I(c) (if such a window exists). The result of opt-cand (L 1 , L 2 ) is then the label of the window with maximum value. For each pair e 1 and e 2 of outgoing edges we apply opt-cand (L 1 , L 2 ) , which yields a label . By construction either the label with maximum ( ) or ⊥ u is the optimal candidate for u, which we can check in O(1) time. Later on we prove that we consider only linearizations of linear size. Since we assume that every vertex of T ′ has constant degree, we obtain the next lemma.

Lemma 3
For each u ∈ V � the optimal candidate can be found in O(n) time.

Construction of Linearizations
We now show how to recursively construct a linearization for an edge e = (u, v) of T. To that end we assume that we are given the subdivision tree T ′ of T and the linearizations for the outgoing edges e 1 = (v, w 1 ), … , e k = (v, w k ) of v that belong to the same road R as e. Further, we can assume that we have computed the weight (L(w)) for each vertex w in T ′ u except for u. In case that two of these vertices share the same position in (T � u ) we remove the one with less weight. Let is a junction edge. (b) e is a road section. (c) Interval representation of (b).

Fig. 12
First step of constructing a linearization: for each edge e i its linearization (L, ) is extended to a linearization (L i , i ) of the tree T i rooted at u T i be the tree induced by the edges e, e i and the edges of the subtree rooted at w i . As a first step we compute for each linearization (L, ) of each edge e i a linearization (L i , i ) for e restricted to tree T i , i.e., conceptually, we assume that T u consists only of T i 's edges.
If e is a junction edge (see Fig. 12a), we set L i ← L and determine the weight of each curve c ∈ L i as Otherwise, if e is a road section, let v 1 , … , v l be the vertices of the subdivision tree T ′ that lie on e, i.e., (v j ) ∈ (e) for all 1 ≤ j ≤ l ; see Fig. 12b-c. We assume that d (v 1 ) < … < d (v l ) , which in particular yields v 1 = u and v l = v . Let c 1 be the curve ((v 1 , v 2 )) and for 2 ≤ j < l let c j be the curve ((v j , v j+1 ))⧵ (v j ) . Hence, we have ⋃ l j=1 c j = (e) and c j ∩ c j � = � for 1 ≤ j < j ′ < l . We set We weight each curve c ∈ L i as follows. If c is contained in L, we set Otherwise, c is a sub-curve of (e) and there exists a j with c = c j . We set is an e-rooted curve that starts at (u) and ends on c. The next lemma shows that this transformation yields a linearization as desired.

(A)
The curves in L i are pairwise superposition-free. Since L contains only curves that do not superpose each other, the only curves that could superpose another curve in L i are contained in L i ⧵L . Since L i ⧵L is empty for a junction edge, we can assume that e is a road section. By construction these curves in L i ⧵L partition (e) without intersecting each other. Further, by assumption no two road sections share a common vertex and since all curves of L are contained in (T v ) , the curves in L i ⧵L cannot superpose any curve in L.
(B) The curves in L i are maximal e-docks with e (c) = (c) . First of all, all curves in L i are sub-curves of road sections: since L is a linearization, each curve of L must be a sub-curve of a road section. Further, if e is a road section, the curves L i ⧵L are sub-curves of e and otherwise, if e is a junction edge, the set L i ⧵L is empty. Next, we show that for each point p of any curve c ∈ L i there is a maximal e-rooted curve that ends at p with (L( )) = i (c) . This particularly shows that c is an e-dock as any two e-rooted curves ending on c have consequently the same weight. We distinguish the two cases that e is a road section or a junction edge.
Case: e is a road section. We distinguish the two cases that c ∈ L i ⧵L or c ∈ L . First, let c be an arbitrary curve in L i ⧵L and let be any e-rooted curve that ends on c. Obviously, must be a maximal e-rooted curve, because there is no other point in (T i ) having the same distance to as h( ) has. We show that e (c) = i (c) . Let v 1 , … , v l be the vertices of the subdivision tree T ′ that lie on e as defined above. By construction there is an edge (v j , v j+1 ) with 1 ≤ j < l and c ⊆ (v j , v j+1 ) . It holds that Hence, we obtain that c is an e-dock with weight e (c) = i (c). Now, consider a curve c ∈ L and let be any e-rooted curve that ends on c. As L is a linearization of e i , for each point p on c there must be a maximal e i -rooted curve ′ with h( � ) ∈ c . We choose ′ such that h( � ) = h( ) . Since ′ is a maximal e i -rooted curve, the curve must be a maximal e-rooted curve. Further, labels one road section more than ′ . Hence, we obtain Hence, we again obtain that c is a maximal e-dock with weight e (c) = i (c).
Case: e is a junction edge. Let c be a curve in L i and let be any e-rooted curve that ends on c. Further, let ′ be the e i -rooted sub-curve of that starts at Since ′ is a maximal e i -rooted curve, it directly follows that is a maximal e-rooted curve with respect to T i . Hence, we obtain that c is an e-dock with weight e (c) = i (c).
(C) For each e-rooted curve there is an e-dock c ∈ L with length ( ) + d u ∈ I(c) . First consider an e-rooted curve that either ends on e i or on an edge of T w i . Recall that h( ) must lie on a road section. Then there is an e i -rooted curve ′ with ′ ⊆ and h( ) = h( � ) . Hence, there is a curve c ∈ L with length ( � ) + d v ∈ I(c) . Since ′ is a sub-curve of , we also have length ( ) + d u ∈ I(c) . Now, consider an e-rooted curve that ends on e. In that case e is a road section. By construction there is a curve c ∈ L i ⧵L with length ( ) + d u ∈ I(c) . ◻ In the next step we define an operation ⊕ by means of which two linearizations (L i , i ) and (L j , j ) can be combined to one linearization (L i , i ) ⊕ (L j , j ) of e that is restricted to the subtree T i,j induced by the edges of T i and T j . Consequently, We finally prove that all e-docks are maximal and Condition (1) of a linearization is satisfied by doing an induction over the curves inserted to L. Let L k be L after the k-th insertion step. Since L 0 is empty, the condition obviously holds for L 0 . So assume that we insert c to L k obtaining the set L k+1 . Without loss of generality assume that c ∈ L i . If c does not superpose any curve in L k , the condition directly follows from the definition of c. So assume that c � ∈ L k superposes c. Since c ∈ L i , the curve c ′ is contained in (T j ) . We remove c ′ from L k and insert the curves c R , c M and c L as defined above. We prove that all three curves satisfy Condition (1).
Consider in the following the subtree T i,j of T u restricted to the edges of T i and T j . We set c R = c[I R ] and set (c R ) = i (c) , if I R ⊆ I(c) . In that case there is no e-rooted curve ⊆ (T j ) with length ( ) + d u ∈ I R , i.e., either there is no curve in (T j ) with t( ) = (u) and length ( ) + d u ∈ I R , or any curve in (T j ) with t( ) = (u) and length ( ) + d u ∈ I R ends on a junction edge. Consequently, any e-rooted curve with length ( ) + d u ∈ I R and in particular any maximal e-rooted curve with length ( ) + d u ∈ I R lies in (T i ) . Thus, the curve c R is a maximal e-dock and satisfies Condition (1). For the case I R ⊆ I(c � ) and the curve c L we can argue analogously.
So consider the curve c M . Without loss of generality we assume that i (c) ≥ (c � ) . The opposite case can be handled analogously. For any maximal e-rooted curve in (T j ) with length ( ) + d u ∈ I M it must be true that (L( )) ≤ (c M ) . Further, since c M ⊆ c and c satisfies Condition (1) with respect to T i , c M is a maximal e-port and satisfies the Condition (1) with respect to T i,j . ◻

Lemmas 4 and 5 yield that
Note that when computing optimal candidates (see Sect. 4.2.1) we are only interested in e-rooted curves that have length at most (R) , where R is the road of e. Hence, when constructing (L i , i ) for an edge e i in the first step, we discard any curve c of L i that does not allow an e-rooted curve that both ends on c and has length at most (R) ; the curve c is not necessary for our purposes. Hence, we conceptually restrict T i to the edges that are reachable from u by one label length. It is not hard to see that T ′ restricted to (T i ) contains only O(n) vertices, because each vertex of V ′ ⧵V is induced by a chain of tightly packed vertical labels, whereas each label has length (R) . Hence, T ′ restricted to (T i ) contains for each such chain at most one vertex of V ′ ⧵V . Further, the endpoints of the curves in L i are induced by the vertices of T ′ . Hence, by discarding the unnecessary curves of L i the set L i has size O(n). Altogether, by Lemma 5 and due to the constant degree of each vertex we can construct When constructing L(u) for u as described in Algorithm 1, we first build the linearization L e of each of u's outgoing edges. By Lemma 3 we can find in O(n) time the optimal candidate of u. Then, due to the previous reasoning, the linearization of an edge of T and the optimal candidate of a vertex u can be constructed in O(n) time.
Altogether we obtain the following result.

Improvements on Storage Consumption
Since T ′ contains O(n 2 ) vertices, the algorithm needs O(n 2 ) space. This can be improved to O(n) space. To that end T ′ is constructed on the fly while executing Algorithm 1. Parts of T ′ that become unnecessary are discarded. We prove that it is sufficient to store O(n) vertices of T ′ at any time such that the optimal labeling can still be constructed.
When constructing the optimal labeling of T, we build for each edge (u, v) of T its linearization based on the linearization of the outgoing edges of v. Afterwards we discard the linearizations of these outgoing edges. Since we assume that each vertex has constant degree, it is sufficient to maintain a constant number of linearizations at any time if we consider the vertices of T ′ in an appropriate order.
Hence, because each linearization has size O(n), we need O(n) space for storing the required linearizations in total. However, we store for each vertex u of T ′ the weight (L(u)) and its optimal candidate. As T ′ has size O(n 2 ) the space consumption is O(n 2 ) . In the following, we improve that bound to O(n) space.
We call a vertex v ∈ V � reachable from a vertex u ∈ V � if there is a curve ⊆ (T � u ) that starts at (u) and that is contained in the embedding of a road R with (R) ≥ length ( ) such that (v) ∈ or v ∈ N( ) ; see Fig. 15a. The set u contains all vertices of T ′ u that are reachable from u. The next lemma shows that u has linear size.

Lemma 6 For any vertex u of T ′ the set u has size O(n).
Proof Recall how T ′ is constructed: For each vertex v ∈ V we construct a chain C of tightly packed vertical valid labels that starts at (v) , is directed towards , and ends when either the road ends, or adding the next label does not increase the number of labeled road sections.
Each label of such a chain C induces one vertex of T ′ . Hence, C induces a set V C of vertices in T ′ . We show that for each chain C the set V C ∩ u contains at most two vertices. As we construct n chains in order to build T ′ the claim follows.
For the sake of contradiction assume that there is a chain C and a vertex u in T ′ such that V C ∩ u contains more than two vertices. Without loss of generality we assume that V C ∩ u contains three vertices, which we denote by v 1 , v 2 and v 3 ; see Fig. 15b. We further assume that d v 1 < d v 2 < d v 3 . By construction all labels in C lie in the embedding of the same road R C , and By definition of C there is a vertical curve ∈ (T � u ) that starts at (u) and contains v 1 , v 2 and v 3 . Let e be the outgoing edge of u in T ′ whose embedding is covered by and consider the sub-curve ′ ⊆ with length (R C ) that starts at u. By definition of u , we know for each v i with 1 ≤ i ≤ 3 that either its embedding is contained in ′ or v i ∈ N( � ) . The definition of N( � ) implies the vertices of N( � ) cannot lie on a common vertical curve in T. Hence, as v 1 , v 2 and v 3 lie on the vertical curve Reachable vertices. (b) Lemma 6. (c) Chains of label . , only v 3 can be contained in N( � ) . Hence, Assume that we apply Algorithm 1 considering vertex u. When constructing u's optimal candidate, by Lemma 6 it is sufficient to consider the vertices of T ′ u that lie in u . On that account we discard all vertices of T ′ u that lie in V ′ ⧵V , but not in u . Further, we compute the vertices of V ′ ⧵V that subdivide the incoming edge (t, u) ∈ E on demand, i.e., we compute them when constructing the optimal candidate of t. Hence, the space consumption is linear.
However, when discarding vertices of T ′ , we lose the possibility of reconstructing the labeling. We therefore annotate each vertex u ∈ V of the original tree T with further information. To that end consider a canonical labeling L of T. Let be a horizontal label of L and let e be the edge of T on which 's head is located; see Fig. 15c. Either, no other label of L ends on e, or another label ′ ends on e that belongs to a chain of tightly packed vertical labels. Analogously, we can define the chain with respect to edge e ′ on which ′ s tail is located. On that account we store for a junction vertex u ∈ V not only its optimal candidate ∈ C(u) , but also the two chains and , if they exist. Note that such a chain of tightly packed vertical labels is uniquely defined by its start and endpoint, which implies that O(1) space is sufficient to store both chains. Using a breadth-first search we can easily reconstruct these chains in linear time. For a regular vertex u ∈ V we analogously store the chain of its optimal candidate ∈ C(u) if it exists. Since is vertical, we do not need to consider its tail. For the special case that = ⊥ u , we define that is the chain of tightly packed vertical labels that ends on the only outgoing edge e of u. Summarizing, the additional information together with the optimal candidates stored at the vertices of the original tree are sufficient to reconstruct the labeling of T. Together with Proposition 1 we obtain the following result.

Conclusions
In this paper, we investigated the problem of maximizing the number of labeled road sections in a labeling of a road map. We showed that this problem is NPhard in general. For the special case of trees we introduced a dynamic programming algorithm. This algorithm utilizes the basic observation that a label passing through a vertex splits the tree into sub-instances that can be considered independently. By systematically exploring all O(n 2 ) possibilities how a label can pass through a vertex, the dynamic programming approach recursively computes an optimal solution in O(n 5 ) time. We improved that bound to O(n 3 ) by using the new concept of linearizations. Finally, we showed that by computing the necessary data structures on the fly, the approach needs linear space while maintaining O(n 3 ) running time.
The underlying road graphs of real-world road maps are rarely trees. However, in an applied companion paper [6] we show that road maps decompose into a large number of subgraphs by placing trivially optimal road labels and removing the corresponding edges from the graph. It turns out that a vast majority of the resulting subgraphs are actually trees, which we can label optimally by the algorithm proposed here. As a consequence, this means that a large fraction of all road sections in our real-world road graphs can be labeled optimally by combining this simple preprocessing strategy with our tree labeling algorithm. For the remaining subgraphs we observe that a majority are nearly trees in the sense that the cycles can be broken by removing only few edges. Hence, a future research direction points to the investigation of MAXLABELEDROADS for such tree-like graphs. In addition, the investigation of MAXLABELEDROADS for cactus graphs and graphs with bounded tree-width promises new interesting insights. Is MAXLABELEDROADS already NP-hard for these graphs, or can our dynamic programming approach be adapted accordingly?
In the presented model, we maximize the number of labeled road sections, which is a rather simple optimization function. From a cartographic point of view more complex cost functions (e.g., priority of road sections, shape of labels, etc.) may also be of interest. Hence, the question arises whether our results carry over. The NP-hardness result strongly relies on the assumption that the number of labeled road sections is maximized. As a consequence, the computational complexity of the problem cannot be directly transferred, but must be considered for each cost function individually. Still, we believe that the basic constructions of the presented gadgets may help to find NP-hardness proofs for newly considered cost functions.
In contrast to the NP-hardness proof, the basic dynamic programming approach for trees is more likely to carry over. As long as a cost-optimal labeling can be composed by a discrete and pre-defined set of label candidates, the dynamic programming idea can be used to compute it. However, the running time strongly relies on the number of label candidates to be considered. Hence, minimizing the number of label candidates a priori becomes an important research question. In particular, the question arises whether the introduced speed-up techniques (e.g., the use of linearizations) carry over.
In the last decades maps have undergone a dramatic change from static figures to dynamic visualizations in which the scale, rotation and view of the map changes over time. Accordingly, in order to obtain a temporally coherent label placement, the change of the map needs to be taken into account. While dynamic maps have been extensively investigated for labeling point features, labeling line features has hardly been considered. Hence, an interesting and important research direction is to adapt the presented model and algorithms to dynamic maps.