Shortest path algorithms for functional environments

Shortest path algorithms for functional environments

Linear Algebra and18its Applications Discrete Optimization (2015) 217–251 466 (2015) 102–116 Contents lists at ScienceDirect Contents lists available...

797KB Sizes 0 Downloads 89 Views

Linear Algebra and18its Applications Discrete Optimization (2015) 217–251 466 (2015) 102–116

Contents lists at ScienceDirect Contents lists available at available ScienceDirect

Linear Algebra and its Applications Discrete Optimization www.elsevier.com/locate/laa www.elsevier.com/locate/disopt

✩ eigenvalue problemenvironments of Jacobi matrix Shortest path Inverse algorithms for functional with mixed data

Louis Boguchwal

Ying Wei 1 article

Department of Mathematics, Nanjing University of Aeronautics and Astronautics,

bstract i n fNanjing o 210016, PRaChina

Article history: This research generalises classic shortest path algorithms to network environments in Received 6 January 2015 by rfunctions, a r t i c l e iwhich n f oarc-costs are governed a b s t a c t rather than fixed weights. We show that Received in revised form 20 the asymptotic efficiency of our algorithms is identical to their classic counterparts. September 2015 Previous results, sinceInKnuth in 1976, requireeigenvalue several restrictive on this paper, the inverse problem ofassumptions reconstructing Accepted 21 September Article 2015 history: in the network. In contrast, our algorithms require only Received 16 January the 2014functions permitted a Jacobi matrix from its eigenvalues, its leading principal monotonicity. We present examples that this is theoflargest class of Accepted 20 September 2014 submatrix and illustrating part of the eigenvalues its submatrix Available online 22 October 2014 functions to which classic algorithms can be generalised. Applications of this Keywords: is considered. The necessary and sufficient conditions for Submitted by Y. Weiwork include critical path extensions to solve sequential decision-problems, and Shortest path algorithms Combinatorial optimisation MSC: Networks 15A18 Sequential decision-problems 15A57 Generalised flow

1. Introduction

the existence and uniqueness of the solution are derived. generalised network flow with nonlinear gain functions. Furthermore, a numerical algorithm and some numerical examples are given. © 2015 Elsevier B.V. All rights reserved. © 2014 Published by Elsevier Inc.

Keywords: Jacobi matrix Eigenvalue Inverse problem Submatrix

Since their invention in the 1950s, shortest path algorithms have been applied to transportation, telecommunications, and sequencing problems [1]. The average person encounters these algorithms almost daily, when seeking directions on the internet or on GPS devices. Phone companies solve shortest path problems when routing data traffic between various geographical locations. Shipping companies solve shortest path problems to efficiently deliver goods. Shortest path problems also emerge in less traditional settings, such as project management and DNA sequencing [1]. Standard scheduling problems can be formulated as classic shortest and longest path problems to minimise overall project completion-times [2]. For example, the critical path method has become pervasive across timedependent applications over the past fifty years, such as project-management and industrial engineering [3]. However, some decision-makers lose sight of their objectives. This paper will demonstrate how a decisionE-mail address: [email protected]. maker could apply extensions of classic shortest path algorithms to actually minimise or maximise a project’s 1 Tel.: +86 13914485239. objective, z, by optimising the sequence of constituent tasks in the project. This research generalises classic shortest path algorithms to network environments where the length of an http://dx.doi.org/10.1016/j.laa.2014.09.031 0024-3795/© 2014 Published by Elsevier Inc. arc is governed by a function. We refer to these general environments as functional environments throughout ✩

This work is based on research done for a master’s thesis at the London School of Economics and Political Science. E-mail address: [email protected].

http://dx.doi.org/10.1016/j.disopt.2015.09.006 1572-5286/© 2015 Elsevier B.V. All rights reserved.

218

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

this work. The cost of a path from a node i to another node j is in terms of some variable of interest z, where the cost from s to itself is initial value z0 . Arcs in the classic environment have static costs, whereas arcs in the functional environment have dynamic costs. These costs are represented by functions f : R → R, denoted as fij (z) ∀(i, j) ∈ A, where (i, j) is an arc in arc-set A. We signify the node-set by N . Formal notation is established in Section 1.2. Traversing an arc changes the value of variable z. If z = zi at node i, traversing arc (i, j) implies that zj = fij (zi ).

(1.1) 1

Thus, cost zj = fij (z) depends on cost zi . Formally, we say that the cost of arc (i, j) is governed by function fij (z). But for brevity’s sake, we say that “arc (i, j) is governed by fij (z)”. This generalises the classic shortest path problem, where fij (z) = cij + z. The functional shortest path problem is to find a minimum cost path from some s ∈ N to some t ∈ N in this dynamic environment. We develop several algorithms to solve the problem, dependent upon network structure and the classes of functions permitted. First, we solve the functional shortest path problem over acyclic networks in which arcs are governed by monotonically increasing functions. Next, we extend that algorithm to solve the problem over acyclic networks in which arcs are governed by monotonic functions. Then we extend the algorithm further to account for networks of arbitrary structure in which arcs are governed by monotonically increasing functions. Finally, we explore networks of arbitrary structure in which arcs are governed by monotonic functions. This paper is organised as follows. We first explore applications of this work. Next, we provide an overview of classic shortest path algorithms and results. Then we formally introduce the functional environment. We extend the classic label-setting and label-correcting algorithms to solve the shortest and longest path problems in the above settings in Sections 3–6. Notably, our algorithms only require that the functions fij (z) governing arcs (i, j) ∈ A are monotonic, bereft of further restrictions. We also demonstrate that the computational complexity of the algorithms developed is no greater than, and in fact identical to, their classic counterparts. Finally, we discuss future research and conclude. 1.1. Applications This research is motivated by sequential decision-problems and network flow problems. We briefly describe these connections here, and in greater detail in Sections 1.1.1 and 1.1.2, respectively. Each application is based on the meaning attributed to a network in the generalised functional environment. This work was ultimately inspired by one-party sequential decision-problems. We do not consider strategic interactions, as in game theory. If other parties are involved in the decision-problem, we take their actions as given and perfectly predictable. We can represent the outcome associated with a decision with the functions fij (z) on the arcs, given the state of our objective prior to executing the decision. For example, consider a company seeking to allocate its revenue with the objective of maximising its funds over time. If the company currently has $z in revenue and chooses decision (i, j), then we could model the resulting revenue as fij (z). Using the functional environment, we can characterise the revenue of the company as decisions are executed. In context of network flow, we can interpret the functions fij (z) on arcs to illustrate violations of conservation-of-flow. For example, if we send z gallons of oil through a pipe from i to j, then the function fij (z) represents the amount of oil actually reaching j. This interpretation can be applied to both generalised maximum flow and generalised minimum cost flow problems. 1.1.1. Extending critical path This research provides a framework to solve sequential decision-problems, which are often solved using dynamic programming methods. Since our algorithms generalise classic shortest path methods, they 1 Technically, this is the cost of the entire path from s to j.

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

219

Table 1 A list of generic decisions A, B, C with time-commitments for each, in months. Decision C is only possible if decision B is completed immediately before. No other decisions exhibit dependency. Decision

Time-commitment

Dependency

A B C

1.5 3 6

– – B

indirectly generalise dynamic programming methods. Additionally, our algorithms generalise critical path methods [3,4]. Critical path methods2 are applied to optimise project completion-times in the face of dependencies amongst constituent activities. Typical critical path methods are concerned with the length of the path from the first activity to the last activity in an acyclic graph, which corresponds to the total project completion-time. In contrast, we consider projects with literal objectives beyond project-completion. Thus, our formulation involves an objective function carried along each arc in the network. Ultimately, we aim to optimise the objective function associated with a possible path in our project-network. Recall that typical critical path models assume that all project activities, both critical and non-critical, must be completed. Specifically, a non-critical activity has non-zero float-time,3 but is still required for the project. In contrast, the decision-maker in our situation need not select all activities to achieve the project goal. Additionally, our decision-maker could even repeat activities. In our sequential decision-problem, activities are simply decisions to influence an outcome, rather than “one-shot”. Thus, our decision-maker must select the activities and their order in the project. Here, the influence of an activity on the objective function changes with when that activity commences and the prior objective value. Similar to classic critical path frameworks, we consider activity dependencies. Specifically, the availability of future decisions could depend on the completion of past decisions. For example, investment in research and development may be cost-prohibitive unless an investment in new technology and equipment is made first. We note two types of dependencies: • Consecutive: E.g., if B depends on A, then B can be selected if and only if A was completed immediately before. • Non-consecutive: E.g., if B depends on A, then B can be selected if and only if A was completed any number of decisions before. We present real-world example problems involving non-uniform time-commitments and dependencies. First, we present a table of three generic decisions and their time-commitments, in months. Next, we show a network representation of possible permissible decision-paths. Finally, we present a table of applications that this generic problem could represent. Using Table 1, we can construct a network to represent feasible decision paths, shown in Fig. 1. Assume a time-horizon of 12 months and that the initial value of our variable of interest is z0 . The function associated with each decision is the same, regardless of arc. For example, fs,4 (z) = f1,2 (z) = fB (z). Observe that some decisions are repeated (e.g., B occurs on both arc (6, 7) and (7, 8)). This should not alarm the reader, as it is reasonable to repeat a decision, such as hiring more employees after reaping the benefits of a recent newly-hired cohort. The decision-paths differ in their constituent number of decisions, as shown in Table 2. Fig. 1 provides an example of an abstract sequential decision-problem, bereft of an application. We provide sample applications to fill in this abstract framework in Table 3. The network describes possible decisionpaths, starting from node s, before any decisions have been selected, and ending at node t, after decisions 2 Critical path is often referred to as CPM, CPA, PERT. 3 I.e., that activity is not on the critical path.

220

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

Fig. 1. Network of decision-paths. Notice that all decision paths have total time-commitments of 12 months, given the information provided in Table 1. This network also obeys the dependency outlined in Table 1.

Table 2 Feasible decision-paths and their number of decisions. This is the same as the number of arcs in a decision-path. We characterise paths by the order of their constituent arcs. Decision path

Number of decisions

A–B–C–A B–A–B–B–A B–C–B B–C–A–A

4 5 3 4

Table 3 Real-world applications fitting the framework developed in Table 1 and Fig. 1. Decision

Revenue allocation, company investment

Production planning

Agricultural planning

Population management of an endangered species

A

Invest in non-liquid assets (e.g., holding bonds until they mature).

Hire more people

Grow and sell crops.

B

Invest in new equipment

Invest in new (or more) equipment.

Raise and sell chicken.

C

Invest in Research and Development

Produce more than before, aiming to capture expected increases in demand. New (more efficient) equipment is needed to produce more

Produce and sell eggs.

Change laws to prevent environmental threats (e.g., poaching, deforestation). Protect and restore natural habitats through environmental projects. Change food supply and predator-density within an ecosystem. An ecosystem cannot be changed until it is protected. Otherwise there would be nothing to protect.

Research and Development Depenis cost-prohibitive unless the dency Explanation company has new equipment.

Need chickens to lay eggs before you can sell eggs.

have been selected. The variable we would like to optimise, z, changes as a consequence of each decision we make. Each arc in the network represents a decision. Traversing an arc equates to selecting its corresponding decision. The outcome of a decision is determined by the function associated with that decision (e.g., fA (z) for decision A). Fig. 1 is a directed acyclic graph, following the intuition that once a decision is made it is final, so back-tracking along the graph is not permitted. 1.1.2. A foundation for generalised flow This research provides an alternative framework for representing generalised network flow problems. Modern investigations of network flow began with the seminal work of Lester Randolph Ford and Delbert Ray Fulkerson [5,6]. In a network flow problem, the objective is either to send the maximum amount of some commodity from an origin to a destination, or to cheaply transport the commodity throughout the network to satisfy the supply and demand of all locations. These problems are classically known as “maximum flow” and “minimum cost flow”, respectively. Both problems are often constrained by capacities along arcs. For example, a pipe’s flow cannot exceed that pipe’s capacity. In their original form, these problems assume “conservation-of-flow” on all arcs, meaning that flow is neither lost nor gained as it travels along a path.

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

221

This is not always realistic. For example, freight may damage or spoil in transit [7]. “Generalised flow” refers to problems such as these that violate conservation-of-flow. Typically, these violations are represented by multiplying inflows by non-negative linear factors. For example, if we send 10 units of flow from i and only 8 units make it to j, our linear factor is 0.8. Work that takes generalised flow beyond linear flow factors includes [8], which considers concave monotonically increasing flow functions. In contrast, the functional network environment permits arbitrary monotonic functions. We propose two examples that could utilise this representation: shipping spoilage and pipe flow loss. First, consider perishable goods that spoil in-transit, where spoilage rates are more complex than simply an expected proportion of the total shipped. For example, a farmer shipping apples from orchard to grocery expects some apples to damage in-transit. Spoilt apples cannot be sold. Define “apple yield” to be the proportion of applies shipped that can be sold. Suppose this farmer has two types of apples: Grade A and Grade B. √ We could model overall spoilage rate with a function such as fij (z) = 10 z, where z is the shipment size. Thus, net spoilage rate depends on total shipment size. Note that the functions could be modified, depending on the conditions corresponding to the shipment route (e.g., temperature or rugged terrain). We could express these factors as parameters modified for each arc, treated as constants on a particular arc. Thus, in this spoilage example single-variable functions remain useful. Now consider oil flowing through pipes, where some flow is lost as it moves through a pipe. Typically, generalised flow models of this phenomenon assume leaky pipes. This context is often not realistic. Instead, we assume quality pipes (i.e., no holes or leakage), where fluid loss is a result of the laws of physics. Specifically, we assume that oil is lost because some fluid sticks to the pipe surface as it flows. The amount of fluid sticking to the pipe is determined by the flow’s friction factor. Unlike the typical generalised flow problem concerning oil flow, this problem is both realistic and interesting because of the diverse flow functions that arise, many of which are nonlinear and non-concave. Analogous to the shipping example, many variables can be interpreted as constants, thereby allowing us to maintain single-variable functions. E.g., for a particular pipe, the material of the pipe can be taken as a constant. For more information on pipe flow, including specific equations4 corresponding to the above discussion, see [9]. We can represent a generalised flow problem using the functional network environment if the functions fij (z) are interpreted as nonlinear flow functions. This interpretation extends typical generalised flow involving linear gain factors, which can be easily solved by reducing the problem to classic shortest path.5 Note that while the functional network environment is related to generalised network flow, there are key differences. First, optimal routing problems in the functional network environment lack capacity constraints. Next, the algorithms developed in this research only produce one path. To optimise flow along a network, the commodity often flows along many paths, not just one. These differences correspond to the relationships between classic shortest path and classic maximum flow. These differences also exist when comparing the functional environment to minimum cost flow settings. Unlike the maximum flow problem, in the minimum cost flow problem we aim to send some commodity throughout a network from suppliers to demanders of that commodity for minimum cost. Each node has some supply or demand. In typical network environments, the cost of an arc associated with a flow xij is the unit-cost cij multiplied by the flow along the arc: cij xij , a linear function [1]. The analogous cost in the functional environment is cij fij (z), where the monotonic function fij (z) describes the flow. Future research is required to solve the minimum cost flow problem in the functional environment, even for these monotonic cost functions. 4 In the interest of brevity, we do not provide a primer on pipe flow, nor do we provide specific flow equations. 5 This problem can be translated to a shortest path problem because the objective is to minimise the product of the gain factors. Thus, take the negative log of the gain factors. Then the goal is to minimise the sum of the negative logs.

222

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

1.2. Classic shortest path algorithms We first introduce some notation and pose the classic shortest path problem. Then we classify existing algorithms based on how they solve the problem. Let G = (N, A) be a directed network, where N is the set of nodes and A is the set of arcs. Assume |N | = n and |A| = m. Define distinguished nodes s, t ∈ N to be the source and sink nodes, respectively. Further, let cost cij be given for each arc (i, j) ∈ A. We assume there is a path from s to all other nodes i ∈ N . The classic shortest path problem is to find the minimum cost path from s to t. We say that if v ∈ N , succ(v) ⊆ N is the set of nodes j ∈ N such that (v, j) ∈ A. We refer to succ(v) as the “successor set of v” for the remainder of this work. Similarly, we say that if v ∈ N , pred(v) ⊆ N is the set of nodes j ∈ N such that (j, v) ∈ A. We refer to pred(v) as the “predecessor set of v”. Modern systematic treatment of shortest path problems began with the work of Lester Randolph Ford in 1956 [5]. Since then, shortest path problems have been classified into three core categories, based upon network structure: (1) Acyclic networks with arbitrary arc-costs6 (2) Networks in which cycles are permitted, but arcs have non-negative length (3) Networks in which both cycles and arbitrary arc-costs are permitted, but negative cycles are forbidden. In7 each category, one can consider the “single-source shortest path problem” or the “all-pairs shortest path problem”. In the single-source shortest path problem, we seek the minimum cost path from a unique source-node s to all other nodes i ∈ N . In the all-pairs problem, however, we seek the minimum cost path between all pairs of nodes in the network. Label-setting algorithms can be used to solve problems in categories (1) and (2), whereas label-correcting algorithms are needed to solve problems in category (3). Label-setting algorithms are methods that declare one distance label optimal in each iteration. These algorithms place nodes into two sets: permanent and temporary. Permanent nodes have optimal distance labels, which will not change in later iterations. On the other hand, temporary nodes bear distance labels that might be subsequently improved. An additional node is designated as permanent in every iteration. In contrast, label-correcting algorithms consider all distance labels to be temporary until the final iteration. These algorithms apply to networks in which both cycles and negative arc-costs are permitted. In the absence of negative cycles, these algorithms terminate if no violations are found. That is, they either solve the shortest path problem, or terminate upon the detection of a negative cycle. Although label-correcting algorithms can solve all three classes of shortest-path problems, label-setting algorithms are computationally more efficient and used whenever possible. Define the distance label d(i) to be the currently known distance from s to i at the present iteration of some shortest path algorithm. The label d(i) is an upper-bound on the actual shortest path distance to i. Distance labels d(i) are updated iteratively. If an algorithm correctly solves the shortest path problem, then labels d(i) are optimal upon termination. Before discussing specific shortest path algorithms, we first present the optimality conditions that inspired their development. Suppose we are given a path P from s to j, and a set of distance labels d(·) for all i ∈ N . Then we can check the optimality of P against the following conditions: d(s) = 0

(1.2)

d(j) ≤ d(i) + cij

∀(i, j) ∈ A

(1.3)

d(j) = d(i) + cij

∀(i, j) ∈ P.

(1.4)

6 By arbitrary, we mean negative, zero, or positive length, as opposed to irrational possibilities. 7 Terminology, definitions, properties, and lemmata in the remainder of this section are drawn verbatim from chapters 4 and 5 of [1], unless otherwise stated.

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

223

As in [1], we refer to condition (1.4) as “sub-path cost optimality”. We now introduce the notion of sub-path optimality presented in [1]. Lemma 1.5. If P = s − i1 − i2 − · · · − ik is a shortest path from s to ik , then the sub-path s − i1 − i2 − · · · − ie from s to ie is also a shortest path for all e ∈ {1, 2, . . . , k − 1}. Classic shortest path algorithms efficiently check optimality conditions (1.2)–(1.4). Rather than brute force testing, they exploit sub-path and sub-path cost optimality to minimise the number of checks. If a node violates its optimality conditions, the algorithm updates the node to satisfy those conditions before progressing. The algorithm terminates when all conditions are satisfied. To solve the shortest path problem for an acyclic network,8 nodes are examined in their topological order. When examining node i, the algorithm checks each outgoing arc (i, j) to test if d(j) > d(i) + cij . If so, distance label d(j) is updated accordingly, such that d(j) = d(i) + cij . By the time the algorithm considers node i the distance label d(i) is optimal. This label-setting algorithm runs in O(m) time, which is the fastest possible running time for an acyclic network because every arc must be checked [1]. If we permit cycles in G, but forbid negative arc-costs, the above algorithm does not apply. In this environment we can solve the shortest path problem using Dijkstra’s algorithm [10], which is also labelsetting. Dijkstra’s algorithm differs from the one above in the way nodes are selected to become permanent. At each iteration, a node in the temporary set with minimum distance label is selected to become permanent. Ties in cost between two temporary nodes are broken arbitrarily. As the algorithm progresses, updates are made to temporary nodes. Dijkstra’s algorithm runs in O(n2 ) time. Label-correcting algorithms address the limitations of the above two label-setting algorithms. Ford originally explored these algorithms in [5]. Bellman9 proposed an efficient way to select arcs that violate their optimality conditions [11]. He developed what is now referred to as the first-in-first-out (henceforth referred to as “FIFO”) method of updating. We outline Bellman’s label-correcting algorithm below: • Store a LIST of nodes i1 , i2 , . . . , ik , which contains only the source-node s at initialisation. • In a given iteration, the algorithm explores the node in the first position of LIST. When the algorithm examines node i, it tests the optimality conditions of arcs (i, j) emanating from i. All nodes j with distance labels violating their optimality conditions are updated and subsequently added to LIST. • When LIST is updated to become LIST = LIST ∪ {j}, j is appended to the end, to follow the FIFO discipline. • Since nodes j were updated, their adjacencies k along arcs (j, k) might also violate their respective optimality conditions. That is, distance labels on nodes k could potentially improve. Hence, these nodes are added to LIST. • If a negative cycle is detected, then the algorithm terminates and no optimal solutions exist. • If LIST is empty, then the algorithm terminates and all distance labels are optimal. This algorithm runs in O(nm) time, and is the fastest known shortest path algorithm for networks that contain cycles and negative arc-costs. Thus far, we have considered the shortest path problem involving a single source. In this scenario we are looking for the shortest path from one distinguished node s ∈ N to all other nodes i ∈ N \ {s}. A generalisation of the single-source problem is the “all-pairs shortest path problem”, in which we wish to 8 Negative arc-costs are permitted. 9 In his paper “On a Routing Problem”, Bellman applies dynamic programming to solve shortest path problems. He solves and approximates his dynamic programming recursive equations. However, there is no mention of label-correcting algorithms or first-in-first-out at all. Despite Bellman’s credit as cited in [1], we could not identify who originally proposed the FIFO approach.

224

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

determine the shortest path between every pair of nodes i, j ∈ N . The most efficient method known to solve this problem is the Floyd–Warshall algorithm [12]. The algorithm integrates dynamic programming and label-correcting algorithms. Define dkij to be length of the shortest path from node i to node j using a proper or improper subset of nodes 1, 2, . . . , k −1. Observe that the ultimate solution to the all-pairs shortest 2 1 path problem is a set of distance labels dn+1 ij . Starting with dij , the algorithm computes dij . In general, to k+1 k determine dij for all node pairs i, j the algorithm uses dij for all node pairs i, j. Specifically, the algorithm uses the following property to compute dk+1 [12]: ij = min(dkij , dkik + dkkj ). dk+1 ij

(1.6)

To detect negative cycles, the Floyd–Warshall algorithm tests whether d[i, i] < 0 for some i ∈ N at each iteration. If so, then the negative cycle is reported and the algorithm terminates. This algorithm runs in O(n3 ) time. 2. The functional environment In 1976, Donald Knuth applied context-free grammar machinery to shortest path problems, which generalised Dijkstra’s algorithm [13]. We adapt the definitions of context-free grammar described in [14]. Define G = (T , N , S, R), where T is a set of terminal symbols, N is a set of non-terminal symbols, S ∈ N is a distinguished start symbol, and R is a production function from N → T . Specifically, the production function maps a non-terminal symbol A to a string of non-terminal and terminal symbols g(A) : A → g(A). Note that terminal symbols cannot be replaced with non-terminals. We elaborate upon the relationship between shortest path problems and context-free grammar analyses in Section 2.1. Definition 2.1. The four-tuple G is a context-free grammar. Knuth implicitly worked with hypergraphs, in which the concept of an arc (i, j) generalises to a hyperarc (I, j), where I ⊆ N . That is, together, a set of nodes I points to a single node j. Note that set I need not be uniform in size across all hyperarcs. Knuth was the first to explore shortest path problems in the functional environment. Ordinarily, arc-costs are fixed attributes that represent distances, times, or other costs. We are concerned with dynamic costs governed by functions. We refer to this setting as the functional environment and the generalised network environment throughout this paper. 2.1. Formal development In the functional environment, each arc (i, j) is governed by some function fij (z), where z is a variable of interest to be optimised. We assume that the domain of all functions fij (z) is R, and that the initial value of z is z0 . At node s ∈ N, z = z0 . In the classic environment, zs = z0 = 0. The optimal value of z at a node k is the shortest path distance from s corresponding to a particular path P from s to k. This distance corresponds to the initial condition z0 , and the composition of functions fij (z) governing each arc (i, j) ∈ P from s to k: f(k−1)k ◦ · · · ◦ f12 ◦ fs1 (z0 )

(2.2)

where 1, 2, . . . , (k − 1) are the intermediary nodes between s and k in P . Algorithmically, the input to function fxy (z) along arc (x, y) is the current distance label. Fig. 2 depicts an example path from a node u to another node w in this generalised network environment. If z = zu at u, this path implies10 that zw = fvw (fuv (zu )) at w. 10 In other words, this quantity is the cost from u to w.

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

225

Fig. 2. Assume the value of variable z at node u is zu , given the current path from source-node s. Then the value of z at node v is zv = fuv (z) = fuv (zu ). Similarly, the value of z at node w is zw = fvw (z) = fvw ◦ fuv (zu ) = fvw (zv ).

Given this network environment, we are looking for the shortest path from a source-node s to another distinguished sink-node t. We represent this problem in Formulation 1, a mixed-integer program in which some constraints are dynamically-defined. There are n + m decision-variables, namely zi ∀i ∈ N and xij ∀(i, j) ∈ A. Solutions to this problem specify both a path and its cost. First, we must select the constituent arcs in the path: we decide whether a particular arc (i, j) shall be in some path P from s to t. These binary decisions are represented by indicator variables xij ∈ {0, 1} ∀(i, j) ∈ A. Variable xij = 1 if arc (i, j) is selected, and xij = 0 otherwise. Once an arc (i, j) is selected, the cost of path P from s to j can be computed. We represent this cost with continuous variables zj ∀j ∈ N . The variable zt signifies the cost of path P from s to t. Hence, the objective function of this optimisation problem is to minimise this cost. Input: Graph G = (N, A), nodes s, t, initial value z0 , functions fij (z) ∀(i, j) ∈ A Output: Path P from s to t of minimum cost minimise zt subject to  xij ≤ 1 i:(i,j)∈A



xij −

j:(i,j)∈A



xki

k:(k,i)∈A

  for i = s 1, = 0, for all i ∈ N \ {s, t}  −1, for i = t

zs = z0 zj =



xij · fij (zi ) + M · (1 −

i:(i,j)∈A



xij ) ∀j ∈ N

i:(i,j)∈A

& xij ∈ {0, 1} ∀(i, j) ∈ A, zi ∈ R ∀i ∈ N , domain of all functions fij (z) is R

Formulation 1: Mathematical programming representation of the shortest path problem for functional environments. We refer to the number of incoming and outgoing arcs from a node as its in-degree and out-degree, respectively. The first set of constraints requires that the in-degree of any node can be at most 1. The piecewise-defined flow constraints require that in-degree(s) = out-degree(t) = 0.

(2.3)

Further, these constraints ensure that in-degree(i) = out-degree(i) = 1 ∀i ∈ P

(2.4)

if i is in the path from s to t, and in-degree(i) = out-degree(i) = 0 ∀i ̸∈ P

(2.5)

226

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

otherwise. In the functional environment, the cost of a path from node s to node j cannot be computed until some cost from s to i is known, where (i, j) ∈ A. The in-degree and flow constraints enforce this arc-selection rule by disallowing some outgoing arc (i, j) from node i unless some incoming arc (k, i) has already been chosen. Then, zs = z0 by definition of s. Finally, we relate the indicator variables xij to the impact on path cost zj . For ease, we deconstruct this final constraint. Define parameter M to be suitably large.11 The first set of constraints implies that  xij ∈ {0, 1}. (2.6) i:(i,j)∈A

In other words, Eq. (2.6) indicates whether node j is on the path from s to t. If j is not on the path, we set zj = M . In effect, this sets zj = ∞. However, if j is on the path,12 we set zj = fij (zi ). The dynamic constraint of the mixed-integer program sets zj equal to these quantities depending on whether arc (i, j) is selected. Additionally, we restrict our attention to functions with R as their domain.13 The classic shortest path problem is a special case of the above formulation, for cost functions fij (z) = cij + z

∀(i, j) ∈ A

zs = z0 = 0.

(2.7) (2.8)

Recall that even this case is not solvable in general, as the shortest path problem is not mathematically decidable for graphs containing negative cycles. The constraints in Formulation 1 that do not involve variables zi are effectively identical to their classic counterparts. In both mathematical programs, the in-degree and out-degree of all nodes in the path from s to t are restricted to result in one connected path. The difference between the two mathematical programming formulations is the cost-function. In the functional environment, we define the cost functions in the constraints. We present the s − t shortest path formulation for ease, but the algorithms presented in subsequent sections actually solve the shortest paths problem, and output a shortest path from s to all other nodes i ∈ N \ {s}. In contrast to the functional shortest path problem on a graph, Knuth solved the problem on a hypergraph. In his environment, productions of the context-free grammar G dictate the structure of its associated hypergraph. Fig. 3 illustrates the parallel between context-free grammars and hypergraphs. Let h, i, j, k be non-terminal symbols involved in the production h → f (i, j, k). Set I for the corresponding hyperarc as I = {i, j, k}, and h is the single target node. Fig. 3 depicts the hyperarc associated with this production. In functional environments on graphs, the cost of an arc (l, u) is dynamically-defined by a function flu (z) of the cost to l, zl . Similarly, in functional environments on hypergraphs, the cost of hyperarc ({i, j, k}, h) is dynamically-defined by a function of the costs to nodes i, j, and k: fIh (zi , zj , zk ) = f{i,j,k}h (zi , zj , zk ).

(2.9)

The initial condition in a context-free grammar hypergraph environment is represented by productions that map a non-terminal symbol to a constant terminal symbol, such as 7: E → 7.

(2.10)

Based on how production function R is defined, and whenever non-terminal symbol h is encountered, the substitution f{i,j,k}h (zi , zj , zk ) can be made. This replacement generates a new string of terminal and 11 For a shortest path problem, M should exceed the cost of any path. i.e. M ≫ z ∀i ∈ N . For a longest path problem, define i M ≪ zi ∀i ∈ N . 12 This computation of z is possible, since i is on the path. j 13 We discuss functions with arbitrary domains in Section 6.5.

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

227

Fig. 3. An example hyperarc. Nodes i, j, and k constitute set I, which is directed towards node h.

Fig. 4. Example hyperpath comprised of hyperarcs ({i, j, k}, h) and ({h, l}, t).

non-terminal symbols, which can also be replaced, based upon other productions inherent to the contextfree grammar G. Eventually, these substitutions lead to a string consisting entirely of terminal symbols, which are constants. Together, these substitutions constitute a particular hyperpath, comprised of hyperarcs corresponding to each substitution made. Fig. 4 features an example hyperpath, made up of hyperarcs ({i, j, k}, h) and ({h, l}, t). Suppose we are given the following productions: i→5

(2.11)

j→3

(2.12)

k→7

(2.13)

l → 1.

(2.14)

Tracing the path backwards from t corresponds to a composition of cost functions. These compositions reveal the following production substitutions: t → f{h,l}t (zh , zl )

(2.15)

t → f{h,l}t (f{i,j,k}h (zi , zj , zk ), 1)

(2.16)

t → f{h,l}t (f{i,j,k}h (5, 3, 7), 1)

(2.17)

where 5, 3, 7, and 1 are terminal symbols. The cost of this hyperpath is derived from substitution (2.17), namely f{h,l}t (f{i,j,k}h (5, 3, 7), 1)

(2.18)

228

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

Fig. 5. Counterexample, using monotonically increasing functions of one variable z, to demonstrate that Dijkstra’s algorithm cannot solve the shortest path problem unless functions are superior.

To determine the cost of a particular hyperpath, some sink node t must be selected. Then, the hyperpath is essentially traced backwards until some source-node s is reached. Here, nodes s and t represent terminal and non-terminal symbols, respectively. Starting from a non-terminal symbol, the “grammar problem” is to find the “minimum cost derivation of a terminal string” given the context-free grammar and corresponding compositions of functions [15]. Knuth generalised Dijkstra’s algorithm to solve the grammar problem only when hyperarcs are governed by superior functions, a subset of monotonically increasing functions. Definition 2.19. A function g(x1 , . . . , xk ) is a superior function if and only if it is monotonically increasing in each variable, and g(x1 , . . . , xk ) ≥ max(x1 , . . . , xk ). While Knuth was the first to generalise both shortest path problems and methods to the functional environment, he makes highly restrictive assumptions about the functions fij (z) permitted in the network. His algorithm cannot solve the shortest path problem even when functions are restricted to be monotonically increasing, rather than superior. 2.2. More general environments A natural question to ask is whether there exist shortest path algorithms that solve the problem for more general environments. The proof-of-correctness of Dijkstra’s algorithm reveals that the method cannot be generalised beyond the superior function environment, even for graphs. Suppose that Dijkstra’s algorithm could solve the shortest path problem for a monotonically increasing environment, i.e., a network in which all arcs are governed by functions that need only be monotonically increasing. We direct the reader’s attention to the counterexample shown in Fig. 5. Consider the network shown in Fig. 5. Let nodes s, l ∈ PERM , and nodes i, k ∈ TEMP. Observe that both i and k are reachable from s in the current iteration of Dijkstra’s algorithm. Suppose that fli (d(l)) = d(i) = 10

(2.20)

flk (d(l)) = d(k) = 11

(2.21)

in the current iteration. Hence, the algorithm selects node i to become permanent in this iteration because it has the minimum distance label among nodes in T EM P . If arc (k, i) is governed by function fki (z) = z − 11

(2.22)

then the path from s to i via l and k is of lesser cost than the path to i directly from permanent nodes fki ◦ flk (d(l)) = 0 < fli (d(l)) = 10.

(2.23)

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

229

Observe that the proof-of-correctness breaks down because there exists a shorter path to a temporary node through another temporary node. Such situations disappear if we require both monotonicity and f (z) ≥ z. This inequality is exactly Knuth’s additional condition for superior functions. Similarly, he also does not address monotonically decreasing functions. In related work, Ramalingam and Reps developed shortest path algorithms to solve the “dynamic grammar problem” on graphs in [15]. This shortest path problem is identical to the grammar problem, except modifications in the network are permitted as the algorithm progresses. Specifically, arc-costs can be changed and arcs can be inserted or deleted between distance updates on nodes. Ramalingam and Reps’ algorithm allows for an arbitrary number of structural changes to the network between iterations. Note that changes to both arc-costs and network structure may occur simultaneously between distance updates. These network modifications correspond to external changes in the system. In addition to solving the dynamic grammar problem, they extend Knuth’s work to include weakly superior functions and strict weakly superior functions.14 Definition 2.24. A function g(x1 , . . . , xk ) is a weakly superior function if and only if it is monotonically increasing in each variable, and g(x1 , . . . , xi , . . . , xk ) < xi ∀i ∈ [1, k]. Definition 2.25. A function g(x1 , . . . , xk ) is a strict weakly superior function if and only if it is monotonically increasing in each variable, and g(x1 , . . . , xi , . . . , xk ) ≤ xi ∀i ∈ [1, k]. Ramalingam and Reps broadened our understanding of the functional environment, but only trivially extended the classes of functions permitted in the network for which the shortest path problem is polynomialtime solvable. In 2010 the problem posed in Fig. 5 became solvable, utilising methods developed in [16]. The authors of [16,17] consider a hypergraph15 in which the distance between nodes can be defined using various metrics, including functional composition. These papers feature the latest and most general extensions of shortest path algorithms. After characterising optimal hyperpaths, the authors discuss generalised superior and generalised inferior functions, which are simply monotonically increasing and monotonically decreasing functions, respectively. They generalise the classic shortest path algorithm for acyclic networks discussed in Section 1.2 to solve minimisation problems for monotonically increasing environments, and maximisation problems for monotonically decreasing environments. We restrict our attention to graphs, rather than hypergraphs, and demonstrate that classic shortest path algorithms can be extended to solve either minimisation or maximisation problems for monotonic environments. Specifically, we generalise the algorithm to simultaneously solve the shortest and longest path problems in which some arcs are governed by monotonically increasing functions, while others are governed by monotonically decreasing functions. 3. Monotonically increasing environments on acyclic networks We first consider the shortest path problem on an acyclic network G = (N, A) in which each arc (i, j) ∈ A is governed by a monotonically increasing function fij (z). We then extend this algorithm to monotonic environments in Section 4. Both methods are label-setting algorithms, inspired by the one for acyclic networks described in Section 1.2. 14 We are aware that the names are unintuitive, as “strict” would correspond to a strict inequality. Further, the inequalities are reversed in comparison to Knuth’s superior function definition. However, these are the verbatim definitions of weakly superior and strict weakly superior functions from [15], respectively. 15 We remark that Knuth is credited for first applying shortest path algorithms to hypergraphs, even though he did not explicitly discuss hypergraphs in his seminal work.

230

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

3.1. Optimality conditions Assume that all functions fij (z) are monotonically increasing. Then fij (d1 (i)) ≤ fij (d2 (i))

(3.1)

provided d1 (i) ≤ d2 (i). In general, to minimise a particular function fij (zi ), zi must be minimum. This result implies that sub-path optimality holds. If s − i1 − i2 − · · · − ik is a shortest path from s to ik , then s − i1 − i2 − · · · − ie is a shortest path from s to ie ∀e ∈ {1, . . . , k − 1}. For if there were a shorter path than the one currently known from s to some ie , then the distance to ik could be decreased, by the above monotonicity property. In these environments, sub-path cost optimality also holds. If the set of distance labels d(·) corresponds to a shortest path P , then d(j) = fij (d(i))

∀(i, j) ∈ P.

(3.2)

The algorithm presented exploits these properties to solve the shortest path problem. Let P denote a shortest path from s to j. Then the following conditions are both necessary and sufficient for optimality: d(s) = z0

(3.3)

d(j) ≤ fij (d(i)) ∀(i, j) ∈ A

(3.4)

∀(i, j) ∈ P.

(3.5)

d(j) = fij (d(i))

These optimality conditions are generalisations of their classic counterparts discussed in Section 1.2, where fij (z) = cij +z. Intuitively, these conditions provide a certificate of optimality. If they were not satisfied, then some update in the path from s to j could be made to decrease d(j), thereby contradicting the optimality of d(j). We formally prove correctness below. Lemma 3.6. If a set of distance labels d(·) satisfies conditions (3.3)–(3.5), then d(·) is optimal and the shortest path problem is solved. Proof. Let i1 − i2 − · · · − ik be an arbitrary directed path P from s to j, where s = i1 and j = ik . We demonstrate that if P satisfies conditions (3.4) and (3.5), then P is an optimal path. The conditions in (3.4) imply that d(j) = d(ik ) ≤ fik−1 ik (d(ik−1 )), d(ik−1 ) ≤ fik−2 ik−1 (d(ik−2 )), .. . d(i2 ) ≤ fi1 i2 (d(i1 )) = fsi2 (d(s)) = fsi2 (z0 ). The last equality is a substitution of s = i1 . Taken together, these equations yield, by monotonicity, d(j) = d(ik ) ≤ fik−1 ik ◦ fik−2 ik−1 ◦ · · · ◦ fsi2 (z0 ). We have shown that d(j) is a lower bound on the cost of any directed path from s to j. Since we have found a particular path P that has cost d(j), it must also be an upper bound on the shortest path distance from s to j. Therefore, P is a shortest path. The inequality conditions were necessary to bound the cost of all paths from s to j, and the equality conditions were necessary to show that P itself is optimal. Condition (3.3) is analogous to forbidding negative cycles in the classic environment, which is discussed at length in Section 5.1.  Observe that the monotonicity of functions fij (z) was necessary to establish the final bounding inequality. Thus, this proof can be generalised to the monotonic environment, and no further.

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

231

3.2. The algorithm Initially, d(s) = z0 and d(i) = ∞ ∀i ∈ N \ {s}. Also, pred(i) = ∅ ∀i ∈ N . Note that pred(s) = ∅ at every iteration through to termination, by definition of source-node. Recall that if G is acyclic, then there exists a topological ordering of the nodes. Our algorithm examines nodes in their topological order. At each iteration when node i is considered, the algorithm scans all outgoing arcs (i, j) ∈ A to check the conditions described in Section 3.1. For every node j ∈ succ(i) such that d(j) > fij (d(i))

(3.7)

d(j) = fij (d(i))

(3.8)

the algorithm updates d(j) to become

and sets pred(j) = i. Upon termination, d(i) is optimal for all i ∈ N . The shortest path from s to i can be found by tracing the optimal predecessor nodes backwards from i. We present Algorithm 1, which is an adaptation of the algorithm presented in [1]. Input: Graph G = (N, A), nodes s, t, initial value z0 , functions fij (z) ∀(i, j) ∈ A Output: Paths from s to all other i ∈ N of minimum cost begin Acyclic, Monotonically Increasing d(s) = z0 ; d(i) = ∞ ∀i ∈ N \ {s}; pred(i) = ∅ ∀i ∈ N ; Find a topological ordering of the nodes 1, 2, . . . , n; k = 1; while k ≤ n do Pick node i such that order(i) = k; for all nodes j ∈ succ(i) do if d(j) > fij (d(i)), set d(j) = fij (d(i)) and pred(j) = i; end; k = k + 1; end; end;

Algorithm 1: Label-setting shortest path algorithm to solve the problem for monotonically increasing environments and acyclic networks. Notice that Algorithm 1 solves the shortest path problem for monotonically decreasing environments as well. The algorithm can also be modified to solve the longest path problem for monotonically increasing environments. At initialisation d(i) = −∞ instead of d(i) = ∞ ∀i ∈ N \{s}. The only necessary modification to the algorithm itself is the updating rule: if d(j) < fij (d(i)), set d(j) = fij (d(i)) and pred(j) = i. 3.3. Complexity and correctness The “while loop” iterates over the topological ordering of the nodes, meaning the loop runs for n iterations. However, the running-time of Algorithm 1 does not depend on the number of “while loop” iterations. Instead,

232

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

the complexity of the algorithm depends on the number of updating conditions to be checked. Optimality conditions, as noted in Section 3.1, are defined with respect to arcs (i, j) ∈ A, rather than nodes i ∈ N . The existence of a topological ordering implies that an algorithm must make the appropriate updates to ensure a particular arc’s16 optimality exactly once, since the graph is acyclic. Thus, a total of m optimality conditions must be checked, one for each arc (i, j) ∈ A. For each arc examined, if a distance label update is made, then the algorithm performs two constant-time operations. First, the actual distance label is updated. Next, the predecessor node is updated. Note that a particular distance label is updated at most once per iteration. Since all arcs are examined, the algorithm above has complexity O(m). Asymptotically, there is no computational cost for solving the shortest17 path problem for monotonically increasing environments compared to its classic weighted counterpart. The proof of correctness provided in [1] applies. We present the proof below. Theorem 3.9. Algorithm 1 solves the shortest path problem. Proof. To prove correctness, we must show that when a node i is considered, its distance label d(i) is optimal. We demonstrate this by induction. Base case: By definition, the source-node has order 1. Thus, d(s) = z0 . Hence, the distance label on node s is optimal. Inductive hypothesis: Suppose the algorithm examined nodes 1, . . . , k, and that d(i) is optimal for all i ∈ {1, . . . , k}. Inductive step: Now the algorithm considers node (k + 1). Let path P = s − 1 − 2 − · · · − r − (k + 1) be a shortest path from s to (k + 1). Then by sub-path optimality, the path s − 1 − 2 − · · · − r is a shortest path from s to r. Since the nodes are topologically ordered and there exists an arc (r, k + 1) ∈ A, we can conclude that order(r) < order(k + 1). Hence, r ∈ {1, . . . , k}. By the inductive hypothesis, d(r) is optimal. When the algorithm considered r the following update was made: d(k + 1) = frk+1 (d(r)). Therefore, the distance label d(k + 1) is optimal and the algorithm is correct.



Remark 3.10. The same argument applies to the longest path problem, since sub-path optimality also holds for longest paths. 4. Monotonic environments on acyclic networks 4.1. Optimality conditions We now extend the algorithm presented in Section 3.2 to environments in which arcs (i, j) ∈ A are governed by monotonic functions.18 Since either monotonically increasing or monotonically decreasing functions are permitted in the network, fij (d1 (i)) ≤ fij (d2 (i))

(4.1)

16 An arc’s optimality must only be checked once, whereas the distance label on a node j might be updated several times, if there are multiple paths to j. 17 Or longest. 18 That is, a network in which some arcs are governed by monotonically increasing functions and others are governed by monotonically decreasing functions.

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

233

provided d1 (i) ≤ d2 (i), and fij (z) is monotonically increasing, and fij (d2 (i)) ≤ fij (d1 (i))

(4.2)

provided d1 (i) ≤ d2 (i), and fij (z) is monotonically decreasing. In general, to minimise a particular function fij (zi ), zi must be minimum if fij (z) is monotonically increasing, and maximum if fij (z) is monotonically decreasing. A priori, it is unclear how the minimum distance label d(j) for some j ∈ N will be achieved. The label might be realised via a minimum d(i) and a monotonically increasing function fij (z) along arc (i, j), or a maximum d(l) and a monotonically decreasing function flj (z) along arc (l, j). These properties imply sub-path and sub-path cost optimality for both shortest and longest paths. We adapt and modify the shortest path optimality conditions stated in Section 3.1. As expected, the longest path optimality conditions are obtained by reversing the inequalities and updating rules. A shortest path algorithm for a monotonic environment must store twice as many predecessors and distance labels as Algorithm 1. At each iteration, each node j ∈ N has two distance labels: dmin (j) and dmax (j). These labels signify the known distances of the minimum and maximum cost paths from s to j, respectively. Thus, in order to trace the shortest and longest paths back from j to s, we must store a predecessor node for each path. We denote pred min (j) and pred max (j) as the predecessor nodes of j corresponding to the shortest and longest paths from s to j, respectively. Note that dmin (j) = dmax (j)

(4.3)

pred min (j) = pred max (j)

(4.4)

are possible when there is a unique path19 from s to j. Further, observe that this algorithm stores one, and not two, corresponding predecessor graphs. In addition to storing the predecessor node pred(j), we must also store whether the optimal predecessor of j uses its minimum or maximum value. Hence, when the algorithm makes a distance label update, the predecessor node is set to some imin or imax . These predecessor labels represent that i is the predecessor of j using dmin (i) or dmax (i), respectively. For example, one possible update is pred min (j) = imax .

(4.5)

The optimality conditions shown in (4.6)–(4.12) correspond to the shortest and longest path problems, respectively. Notice that not all conditions apply to all arcs. Denote the set of arcs governed by monotonically increasing functions as Ainc . Similarly, denote the set of arcs governed by monotonically decreasing functions as Adec . Thus, A = Ainc ∪ Adec . Refer to particular arcs in Ainc and Adec as “monotonically increasing arcs” and “monotonically decreasing arcs”, respectively. Before stating the algorithm, we direct the reader to Remark 4.13. Given these optimality conditions: dmin (s) = dmax (s) = z0 dmin (j) ≤ fij (dmin (i))

(4.6) ∀(i, j) ∈ Ainc

(4.7)

dmin (j) ≤ fij (dmax (i)) ∀(i, j) ∈ Adec

(4.8)

dmin (j) = fij (dmin (i))

or

dmin (j) = fij (dmax (i)) ∀(i, j) ∈ P

(4.9)

dmax (j) ≥ fij (dmin (i)) ∀(i, j) ∈ Adec

(4.10)

dmax (j) ≥ fij (dmax (i))

∀(i, j) ∈ Ainc

(4.11)

dmax (j) = fij (dmin (i))

or

dmax (j) = fij (dmax (i)) ∀(i, j) ∈ P.

(4.12)

19 This can occur when there is a unique path in general over the whole network G, or when there is only one path known at a particular iteration.

234

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

Remark 4.13. The algorithm for monotonic environments on acyclic networks simultaneously solves both the shortest and longest path problems, since minimum and maximum distance labels are stored for each i ∈ N at every iteration. Let Pmin and Pmax be directed shortest and longest paths from s to j, respectively. Lemma 4.14. If Pmin and Pmax satisfy optimality conditions (4.6)–(4.12), then Pmin and Pmax are shortest and longest paths, respectively. Further, dmin (·) and dmax (·) are optimal. Proof. This lemma and its corresponding proof are direct extensions of Lemma 3.6.



Extrapolating from the algorithm and discussion presented in Section 3.2, the following initialisations are made: dmin (s) = dmax (s) = z0 , dmin (i) = ∞ ∀i ∈ N \ {s}, dmax (i) = −∞ ∀i ∈ N \ {s}, and pred min (i) = pred max (i) = ∅ ∀i ∈ N . Note that pred min (s) = pred max (s) = ∅ at every iteration through to termination, by definition of source-node. As in Algorithm 1, the nodes are again examined in their topological order. At each iteration when node i is considered, the algorithm must test each of dmin (j) and dmax (j) against fij (dmin (i)) and fij (dmax (i)). Thus, the algorithm performs four checks for each j ∈ succ(i): (1) (2) (3) (4)

if if if if

dmin (j) > fij (dmin (i)), set dmin (j) = fij (dmin (i)) and set pred min (j) = imin dmin (j) > fij (dmax (i)), set dmin (j) = fij (dmax (i)) and set pred min (j) = imax dmax (j) < fij (dmin (i)), set dmax (j) = fij (dmin (i)) and set pred max (j) = imin dmax (j) < fij (dmax (i)), set dmax (j) = fij (dmax (i)) and set pred max (j) = imax .

For dmin (j) and dmax (j), the order in which fij (dmin (i)) and fij (dmax (i)) are computed is irrelevant because the algorithm performs both checks in sequence. 4.2. The algorithm We now introduce the shortest path algorithm for monotonic environments on acyclic networks, Algorithm 2. Upon termination, Algorithm 2 yields optimal solutions to both the shortest and longest path problems. The shortest and longest paths themselves are found by tracing predecessors pred min (i) and pred max (i) backwards to s, respectively. 4.3. Complexity and correctness Algorithm 2 is a generalisation of Algorithm 1. Hence, the complexity arguments discussed in Section 3.3 apply. The main differences between the two algorithms are storage requirements as well as constant-time operations. Notice that the algorithms differ in the number of constant-time operations performed for each arc. Where Algorithm 1 checks one optimality condition for each arc (i, j) ∈ A and potentially makes one update, Algorithm 2 checks four optimality conditions for each arc (i, j) ∈ A and potentially makes four updates. Also note that the algorithm presented here requires twice as much storage as the one shown in Section 3. In monotonic environments, each node bears two distance labels and two predecessor labels, instead of one. Therefore, this algorithm also has computational complexity O(m). Asymptotically, there is no computational cost for solving the shortest and longest path problems for monotonic environments compared to monotonically increasing environments and, more strikingly, the classic weighted network environment. The proof of correctness is expressed in Theorem 4.15.

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

235

Input: Graph G = (N, A), nodes s, t, initial value z0 , functions fij (z) ∀(i, j) ∈ A Output: Paths from s to all other i ∈ N of minimum and maximum cost begin Acyclic, Monotonic dmin (s) = z0 ; dmax (s) = z0 ; dmin (i) = ∞, dmax (i) = −∞ ∀i ∈ N \ {s}; predmin (i) = ∅ ∀i ∈ N ; predmax (i) = ∅ ∀i ∈ N ; Find a topological ordering of the nodes 1, 2, . . . , n; k = 1; while k ≤ n do Pick node i such that order(i) = k; for all nodes j ∈ succ(i) do if dmin (j) > fij (dmin (i)), set dmin (j) = fij (dmin (i)) and set predmin (j) = imin ; if dmin (j) > fij (dmax (i)), set dmin (j) = fij (dmax (i)) and set predmin (j) = imax ; if dmax (j) < fij (dmin (i)), set dmax (j) = fij (dmin (i)) and set predmax (j) = imin ; if dmax (j) < fij (dmax (i)), set dmax (j) = fij (dmax (i)) and set predmax (j) = imax ; end; k = k + 1; end; end;

Algorithm 2: Label-setting shortest path algorithm to solve the problem for monotonic environments and acyclic networks. Theorem 4.15. Algorithm 2 solves the shortest and longest path problems. Proof. By applying the minimisation properties discussed in Section 4.1, the proof of correctness is a simple extension of the one provided in Section 3.3.  5. Monotonically increasing environments on cyclic networks Thus far, we have shown that the shortest path problem on acyclic networks comprised of monotonic arcs can be solved using a generalised label-setting algorithm. Now we turn our attention to networks of more general structure, i.e., ones in which cycles are permitted. Solving the shortest path problem therefore requires label-correcting algorithms. As above, we first propose an algorithm for monotonically increasing environments, which inspires the one for monotonic environments. These algorithms are both inspired by the classic FIFO label-correcting algorithms discussed in [1]. 5.1. Harmful cycles Before describing the algorithms, we discuss situations in which the shortest walk problem has no finite solution. Harmful cycles are the analogue to negative cycles in the classic network environment explored in Section 1.2.

236

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

Fig. 6. Negative cycle. Notice that regardless of where traversal begins, the cost of the walk to any node in this cycle can be decreased indefinitely. Hence, initial costs to nodes in the cycle have no effect on unbounded quantity.

Fig. 7. A cycle C that is harmful depending on the starting point and cost z.

Definition 5.1. Let C = j − 2 − 3 − · · · − k be a cycle in G, where j is the starting point20 and z is the cost of the path to j prior to traversing C. If fkj ◦ · · · ◦ f23 ◦ fj2 (z) < z, then C is harmful 21 with respect to node j, cost z. The triple (C, j, z) depicts whether cycle C is harmful with respect to node j, cost z. We refer to the set of harmful triples as H. Using this notation, we express harmfulness in terms of whether (C, j, z) ∈ H or (C, j, z) ̸∈ H. Definition 5.2. Let C be a cycle in G. If ∃z ∈ R and a starting point j on the cycle such that (C, j, z) ∈ H, then C is a harmful cycle. Definitions 5.1 and 5.2 illustrate that harmfulness is a characteristic specific to both the starting point and its associated cost. While harmful cycles are similar in nature to their classic counterparts, there are three critical differences. We discuss the first two here, and the third in Section 7.2. If C is a negative cycle, it is a negative cycle with respect to starting points j ∈ C, and all costs z ∈ R. Put another way, the starting point j and its cost d(j) prior to traversal make no difference in classifying C as a negative cycle. Negative cyclicity is an invariant property in the classic network environment, but breaks down in functional environments for harmful cycles, as demonstrated via counter-examples. For comparison, we first provide a negative cycle from the classic network environment in Fig. 6. The harmful cycle C depicted in Fig. 7 illustrates the specificity of harmfulness. Suppose the starting point is i, and that d(i) = 3. Traversing C yields the following costs with respect to i: i : 3 → 10 → 24 → . . . . The cost associated with node i increases with each traversal of C. These costs show that (C, i, 3) ̸∈ H. In other words, C is harmless with respect to node i, cost 3. Now suppose d(i) = −10 and that i is still the 20 I.e., the repeated node for each traversal of cycle C. 21 When solving the longest path problem, a harmful cycle is one in which the inequality in this definition is reversed. That is, fkj ◦ · · · ◦ f23 ◦ fj2 (z) > z.

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

237

starting point. Now traversing C yields the following costs: i : −10 → −16 → −28 → . . . . These costs show that C implies unbounded solutions to the shortest walk problem with respect to node i. Thus, (C, i, −10) ∈ H. Even from the same starting point, the harmfulness of C depends on cost z. We now change the starting point to node k. Suppose d(k) = 3. Traversing C yields the following costs: k : 3 → 2 → 0 → .... These costs show that C implies unbounded solutions to the shortest walk problem with respect to node k. Thus, (C, k, 3) ∈ H, revealing that the harmfulness of C changes when the starting point changes, even for the same z. We have shown that in contrast to negative cycles, the harmfulness of a cycle C depends entirely upon the starting point and its cost, prior to traversing the cycle. 5.2. The algorithm The optimality conditions used in the algorithm presented here are identical to those discussed in Section 4.1, i.e., the ones for monotonic environments. Also, initialisations are identical to those in Algorithm 1. We apply the FIFO label-correcting methods discussed in Section 1.2, store a LIST of nodes with distance labels that might improve, and examine nodes in the order they enter LIST. When a node i is considered, all nodes j ∈ succ(i) are checked for updates. If a particular j is updated, then that node is added to LIST. This FIFO method explores arcs (i, j) ∈ A in passes, but only examines arcs that potentially improve node distance labels. For instance, if during one pass a label d(i) is unchanged, then with certainty no j ∈ succ(i) will be updated.22 The algorithm terminates when LIST is empty. In the classic network setting, a cycle is either negative for all z ∈ R, or for no z ∈ R. Fig. 6 illustrates this property, which implies an algorithmic dichotomy: label-correcting algorithms either solve the shortest path problem or report a negative cycle. If none are reported, then the graph contains no negative cycles. In other words, if G contains a negative cycle, then shortest path solutions are always affected. There is a third possibility in the functional environment. While the graph may contain a harmful cycle C, it might never be detected. If the label-correcting algorithm does not produce z for which a cycle C is harmful, then the algorithm solves the shortest path problem. This implies the algorithm’s third termination possibility: There are harmful cycles in G, but the shortest path problem is solved. However, when a harmful cycle does affect shortest path solutions, the algorithm must detect it. We apply an analogous technique to the predecessor graph method discussed in [1]. At each iteration, if a node i’s label d(i) is updated, then its label pred(i) is also updated. We can use these predecessor labels to construct a predecessor graph of arcs (pred(j), j). The cycle-detection component of our algorithm is proven below. Lemma 5.3. If the algorithm detects a directed cycle in the predecessor graph, then that cycle is harmful in the actual graph G. Proof. Let C = 1 − 2 − · · · − (k − 1) − k − 1 be a cycle found in the predecessor graph. This cycle implies that pred(1) = k, pred(2) = 1, . . . , pred(k) = k − 1. 22 That is, no j ∈ succ(i) will be updated based upon i. Of course, some j ∈ succ(i) might be updated based upon another incoming arc (k, i) if k is updated at some later iteration.

238

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

These predecessors imply that d(2) = f12 (d(1)), d(3) = f23 (d(2)), . . . , d(k) = fk−1,k (d(k − 1)). Before this cycle was traversed, all nodes i ∈ {1, 2, . . . , k} had distance labels d(i) greater than those provided by the cycle. Denote d(1) as the distance label on node 1 prior to traversing C, and d′ (1) the distance label after traversing C. Since pred(1) = k, d′ (1) = fk1 ◦ · · · ◦ f23 ◦ f12 (d(1)) < d(1). Therefore, d′ (1) − d(1) = fk1 ◦ · · · ◦ f23 ◦ f12 (d(1)) − d(1) < 0. Hence, traversing cycle C decreases the distance label on node 1, and thus, C is a harmful cycle.



Remark 5.4. Lemma 5.3 prompts a harmful cycle-detection algorithm: search for harmful cycles by identifying cycles in the predecessor graph. This method is formally explored in Lemma 5.8. We present the label-correcting algorithm for monotonically increasing environments below. Input: Graph G = (N, A), nodes s, t, initial value z0 , functions fij (z) ∀(i, j) ∈ A Output: Paths from s to all other i ∈ N of minimum cost begin Label-Correcting, Monotonically Increasing d(s) = z0 ; d(i) = ∞ ∀i ∈ N \ {s}; pred(i) = ∅ ∀i ∈ N ; LIST = {s}; while LIST ̸= ∅ do Remove the first element i from LIST ; for all nodes j ∈ succ(i) do if d(j) > fij (d(i)), set d(j) = fij (d(i)) and pred(j) = i; if the predecessor graph contains a cycle, terminate; if j ∈ / LIST , set LIST = LIST ∪ {j}; end; end; end;

Algorithm 3: Label-correcting shortest path algorithm to solve the problem for monotonically increasing environments and networks of general structure.

5.3. Complexity and correctness Algorithm 3 has the same computational complexity as the standard FIFO label-correcting algorithm, namely O(nm). Using a similar argument made in [1], we argue the computational efficiency for a slower version of the above algorithm that checks all arcs for updates in every pass. Then we remark that in practice

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

239

the algorithm is faster because only arcs corresponding to nodes in LIST need to be checked, in the order they entered LIST. Next, we explore the worst-case running-time associated with searching for harmful cycles. We elaborate upon the argument provided in [1], which only requires a search every αn iterations of the “for loop: for all nodes j ∈ succ(i)” for some constant α. However, if the harmful cycle-detection method is deployed in every iteration of the “for loop”, we demonstrate that the worst-case running-time of Algorithm 3 is O(max(n2 , nm)), which is the same as its classic counterpart. Effectively, this algorithm explores arcs (i, j) ∈ A for updates in passes. During a particular pass, the algorithm checks all arcs one-at-a-time. If no updates are made in a particular pass, then the set of distance labels d(·) is optimal. Theorem 5.5. The algorithm performs at most n − 1 passes through the arc-set. Proof. We use induction to show that at the end of the kth pass, the algorithm has computed shortest path distances to all nodes for which there is a shortest path k arcs or fewer from s. Base case: Trivially true. Inductive hypothesis: Assume that at the end of the kth pass, the algorithm has computed shortest path distances to all nodes for which there is a shortest path k arcs or fewer from s. Thus, d(j) is optimal if there exists a shortest path from s to j consisting of k or fewer arcs. Inductive step: Now consider a node l for which there is a shortest path from s consisting of k + 1 arcs and not fewer. Denote this path as s − i1 − i2 − · · · − ik − l. By sub-path optimality, the path s − i1 − i2 − · · · − ik is a shortest path from s to ik . By the inductive hypothesis, d(ik ) is optimal. Since d(ik ) is optimal, the update to node l using arc (ik , l) in the next pass updates d(l) to optimality. By definition of a path, a shortest path consists of no more than n − 1 arcs. Since we have shown the theorem holds for all k ∈ N, we set k = n − 1 to obtain the required result.  Corollary 5.6. Since each pass requires several constant-time operations for each arc, Algorithm 3 has complexity O(nm). This is the same asymptotic efficiency as the standard FIFO label-correcting algorithm. Remark 5.7. The algorithm presented is faster in practice because, in a given pass, only a subset of the arc-set needs to be checked for updates. That is, only arcs emanating from nodes appended to LIST need to be examined. Lemma 5.8. Checking for harmful cycles requires O(n) time. Proof. We adapt a negative cycle detection method from [1] to check for harmful cycles that requires O(n) time. By Lemma 5.3, we only need to find a directed cycle in the predecessor graph to locate a harmful cycle in the actual graph. Thus, this procedure searches for a directed cycle in the predecessor graph. First, mark the source-node and leave all other i ∈ N unmarked. Then investigate each unmarked node in the predecessor graph. When an unmarked node i is considered, this method marks i, and then traces the predecessors of i until a node already marked is reached. If i is reached again in the same iteration, then we have found a directed cycle. This method must consider at most all nodes in the case of an acyclic predecessor graph. Further, once a node is marked, it will not be considered again. Therefore, this cycle-detection algorithm runs in O(n) time. 

240

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

Lemma 5.9. If the harmful cycle detection procedure is performed once after every αn distance updates, for some constant α > 0, then the sub-routine does not increase the computational cost of Algorithm 3. Proof. By Lemma 5.8, harmful cycle-detection requires O(n) time. Let α be some constant such that α > 0. Now, suppose the predecessor graph is checked for cycles once every αn distance updates.23 At most, each iteration of the “for loop” yields a distance update. This case results in the worst-case running-time of Algorithm 3. Thus, assume that the algorithm checks for harmful cycles every αn iterations of the “for loop”. Notice that α is a constant, and not a function of n. Therefore, as n increases, the predecessor graph is checked for cycles less frequently, even for small α. Asymptotically, checking for harmful cycles does not affect the computational efficiency of Algorithm 3.  Remark 5.10. We are not concerned that the above detection method does not immediately reveal harmful cycles. Even if the method finds a cycle in the predecessor graph many iterations after its appearance, the harmful cycle is nevertheless detected. The gains in computational complexity are worth the delay in harmful cycle-detection. Remark 5.11. By definition of harmfulness, a cycle could appear in the predecessor graph in one iteration of the “for loop”, and disappear before the algorithm deploys the cycle-detection subroutine. Then this finitely harmful triple (C, j, z) would never be discovered. Practically speaking, this is not problematic. Harmful cycles can be detected with greater precision if α is set to be sufficiently small.24 Lemma 5.12. Alternatively, if the harmful cycle-detection method is deployed every iteration of the “for loop”, then the computational complexity of Algorithm 3 is O(max(n2 , nm)). Proof. If the algorithm checks the predecessor graph for cycles at every iteration of the “for loop”, then the “for loop” has asymptotic running-time O(n2 ). By Theorem 5.5 and Corollary 5.6, Algorithm 3 has worst case running-time O(nm), without the harmful cycle-detection method. Thus, if n < m, then the algorithm runs in O(nm) time. But if n > m, then the algorithm runs in O(n2 ) time. Therefore, the complexity of Algorithm 3 is O(max(n2 , nm)).  Remark 5.13. If the predecessor graph is checked at every iteration of the “for loop”, then the algorithm discovers harmful cycles immediately. Theorem 5.14. Algorithm 3 solves the shortest path problem or reports a harmful cycle. Proof. The algorithm acts in a FIFO discipline to update arcs that violate their optimality conditions until they hold for all (i, j) ∈ A. Since the algorithm terminates when the optimality conditions are satisfied or upon the discovery of a harmful cycle, it solves the shortest path problem. Further, the proof of correctness is a consequence of Theorem 5.5.  Theorem 5.15. The shortest path problem on an arbitrary graph G in the functional environment can be classified into three mutually-exclusive categories: 23 Of course, αn must be a non-negative integer, so technically the predecessor graph is checked every ⌈αn⌉ iterations. 24 Infinite harmfulness is defined in Section 7.2, but we make a note here in light of this remark. By definition of infinite harmfulness,

infinitely harmful triples are detected for any non-negative value of α.

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

241

(1) G has a finite shortest path solution and contains no harmful cycles (2) G has unbounded shortest walk solutions and contains at least one harmful cycle (3) G has a finite shortest path solution and contains at least one harmful cycle. Proof. The correctness of Algorithm 3, proven by Theorem 5.14, demonstrates that the shortest path problem on an arbitrary graph G in the general functional environment can be classified into the aforementioned three mutually-exclusive categories.  6. Monotonic environments on cyclic networks 6.1. Optimality conditions We now extend the algorithm presented in Section 5.2 to monotonic environments.25 The arguments used to derive the optimality conditions in Section 4.1 apply and, consequently, the optimality conditions are the same. To solve the shortest path problem on G, an algorithm must store both the minimum and maximum distance labels dmin (i) and dmax (i) ∀i ∈ N . Just as in Section 4.1, an algorithm must also store the predecessors responsible for the minimum and maximum distance labels, namely pred min (i) and pred max (i). Since both the minimum and maximum distance labels are stored for every node i ∈ N , this label-correcting algorithm solves both the shortest and longest path problems simultaneously. At initialisation, dmin (s) = dmax (s) = z0 , dmin (i) = ∞ ∀i ∈ N \ {s}, dmax (i) = −∞ ∀i ∈ N \ {s}, and pred min (i) = pred max (i) = ∅ ∀i ∈ N . Note that pred min (s) = pred max (s) = ∅ at every iteration through to termination, by definition of source-node. Here we generalise the FIFO label-correcting algorithm presented in Section 5.2. At each iteration, when a node i is removed from LIST for consideration, the algorithm must test each of dmin (j) and dmax (j) against fij (dmin (i)) and fij (dmax (i)) for optimality. The following tests are performed for each j ∈ succ(i): (1) (2) (3) (4)

if if if if

dmin (j) > fij (dmin (i)), set dmin (j) = fij (dmin (i)) and set pred min (j) = imin dmin (j) > fij (dmax (i)), set dmin (j) = fij (dmax (i)) and set pred min (j) = imax dmax (j) < fij (dmin (i)), set dmax (j) = fij (dmin (i)) and set pred max (j) = imin dmax (j) < fij (dmax (i)), set dmax (j) = fij (dmax (i)) and set pred max (j) = imax .

6.2. Harmful cycles In monotonically increasing environments, a harmful cycle decreases26 the cost of the path to some node i ∈ N . If a cycle increases the distance label d(i) in the shortest path problem, it is harmless. However, in monotonic environments this is not necessarily the case. Suppose we have a node i in some cycle C such that d(i) increases upon traversal. Now consider some node j ∈ succ(i), where j ̸∈ C. If fij (z) is a monotonically decreasing function, then fij (z) is minimised by maximising the input z. Thus, traversal increases d(i), which decreases d(j). Hence, C is a harmful cycle27 with respect to j. We formally define harmfulness in monotonic environments below. Definitions 5.1 and 5.2, which describe harmfulness in a monotonically increasing environment, apply. Definition 6.1 illustrates a new way in which a cycle C can be harmful in a monotonic environment. We prove its validity in Theorem 6.7. 25 I.e., arcs (i, j) ∈ A are governed by monotonic functions. 26 Decreases with respect to the shortest path problem. A harmful cycle increases d(i) in the longest path problem. 27 That is, C is a harmful cycle in context of the shortest path problem.

242

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

Definition 6.1. Let C be a cycle in G, where j is the starting point and z is the cost of the path to j prior to traversing C. If there exists a node l ̸∈ C reachable from j such that • Node l is incident to a monotonically decreasing arc (a, l) ∈ Adec • Arc (a, l) is on a path from j to l then C is a harmful cycle with respect to node l, starting point j, cost z if and only if FC (z) > z, where the function FC (z) is the composition of functions corresponding to cycle C and initial cost z. In light of Definition 6.1, the quadruple (C, j, z, l) depicts whether C is harmful with respect to starting point j, node l, cost z in a monotonic environment. Distinguish between nodes j and l, where j is the starting point of cycle C, and l is any node in N . Just as in monotonically increasing environments, we can express the harmfulness of C with (C, j, z, l) ∈ H or (C, j, z, l) ̸∈ H. Definition 6.2. Let C be a cycle in G. If ∃z ∈ R, a starting point j, and a node l for which (C, j, z, l) ∈ H, then C is a harmful cycle. Unlike monotonically increasing environments, detection of a cycle in the predecessor graph does not necessarily imply a harmful cycle. Intuitively, if a cycle is found that decreases distance label dmin (i), then such a cycle is harmful in the monotonic environment. On the other hand, if a cycle is found that increases dmax (i), then the cycle is harmful if and only if some monotonically decreasing arc is traversed as the algorithm progresses. We refer to the monotonic direction of a function to discuss whether that function is monotonically increasing or monotonically decreasing. Theorem 6.7 inspires a method to check for harmful cycles in a monotonic environment. Lemma 6.3. If f1 (z) is an arbitrary, monotonically increasing function, and f2 (z) is an arbitrary, monotonically decreasing function, then the following hold: (1) (2) (3) (4)

g1 (z) = f1 ◦ f2 (z) g2 (z) = f2 ◦ f1 (z) g3 (z) = f1 ◦ f1 (z) g4 (z) = f2 ◦ f2 (z)

is is is is

monotonically monotonically monotonically monotonically

decreasing decreasing increasing increasing.

Proof. Let a, b ∈ R such that a < b. Then f1 (a) < f1 (b) and f2 (a) > f2 (b), by definition of monotonically increasing and monotonically decreasing functions, respectively. g1 (z): Since f2 (z) is a monotonically decreasing function, f2 (a) > f2 (b). Now substitute these values into f1 (z), a monotonically increasing function, to obtain f1 (f2 (a)) and f1 (f2 (b)). Since f1 (z) is monotonically increasing, we can conclude that f1 (f2 (a)) > f1 (f2 (b)). Hence, g1 (z) is a monotonically decreasing function. The monotonic direction of remaining cases g2 (z) through g4 (z) can be shown using analogous techniques.  Now, define the sign of an arc (i, j) and of a walk W . Definition 6.4. Let (i, j) ∈ A. The sign of (i, j) is as follows:  +1, if and only if (i, j) ∈ Ainc sign((i, j)) = −1, if and only if (i, j) ∈ Adec .

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

243

Definition 6.5. Let W be a walk in G. The sign of W is as follows:  sign(W ) = sign((i, j)). (i,j)∈W

Lemma 6.6. Let W be a walk containing l monotonically decreasing arcs. Then l (mod 2) determines sign(W ). Proof. By Lemma 6.3, augmenting an existing composition with an additional monotonically increasing function does not change the monotonic direction of that composition, whereas a monotonically decreasing function does. Thus, sign((i, j)) · sign(W ) = sign(W ), sign((i, j)) · sign(W ) = −sign(W ),

if (i, j) is a monotonically increasing arc if (i, j) is a monotonically decreasing arc

for some walk W and arc (i, j) appended to W . Therefore, adding an arbitrary number of monotonically increasing arcs to W does not change sign(W ). Further, each monotonically decreasing arc added to W does change sign(W ). Then sign(W ) can be determined exclusively from l (mod 2). If l is even, then sign(W ) = +1. If l is odd, then sign(W ) = −1.  Define FW (z) for a walk W in the same way that FC (z) is defined for a cycle C. That is, the function FW (z) corresponds to the composition of functions fij (z) for all (i, j) ∈ W . Theorem 6.7. For any walk W in G, sign(W ) indicates the monotonic direction of FW (z). Proof. Let W be a walk in G from arbitrary node q to arbitrary node r. Apply Lemma 6.6 to obtain sign(W ). Observe, there exists an equivalent arc (q, r) in some other graph G′ , governed by function fqr (z) = FW (z). Thus, sign((q, r)) = sign(W ). By definition of sign((i, j)), sign((q, r)) represents the monotonic direction of function fqr (z) = FW (z).  Corollary 6.8. By Theorem 6.7, if C is a cycle with starting point j bearing cost z = d(j), and W is a walk from j to some other node k, then determining the harmfulness of C with respect to walk W is mathematically decidable. Corollary 6.9. If traversals over C increase d(j), and sign(W ) = −1, then the quadruple (C, j, z, W ) ∈ H. Corollary 6.10. Let C be defined as in 6.9. Then from starting point j, the first time a monotonically decreasing arc is encountered an algorithm can immediately declare walk W harmful. Theorem 6.7 and Corollaries 6.8–6.10 imply that as the generalised label-correcting algorithm progresses, a harmful cycle can be detected in one of two ways: (1) A cycle C that decreases28 the cost of a walk from s to some i ∈ N is detected. (2) A cycle C that increases29 the cost of a walk from s to some i ∈ N is detected, and some arc (k, l) governed by a monotonically decreasing function fkl (z) is reachable from i. 28 If the ultimate goal is to solve the longest path problem, then a harmful cycle can be detected if the algorithm finds a cycle that increases the cost of a walk from s to some i ∈ N . 29 If the ultimate goal is to solve the longest path problem, then a harmful cycle can be detected if the algorithm finds a cycle that decreases the cost of a walk from s to some i ∈ N , and some arc (k, l) governed by a monotonically increasing function fkl (z) is reachable from i.

244

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

These conditions inspire the harmful cycle detection sub-routines within the generalised label-correcting algorithm for a monotonic environment. Before running the generalised label-correcting algorithm for a monotonic environment, run a pre-processing graph search routine. First, locate all arcs (i, j) ∈ A that are governed by monotonically decreasing functions. Then, run a search algorithm30 to find all nodes k for which nodes i are reachable. Nodes k are stored in a lookup array. This array indicates that if a particular node k is in a cycle that increases the distance label dmax (k), then the cycle is harmful.31 Therefore, if a cycle is detected in the predecessor graph such that the distance label dmax (k) increases after traversal compared to its value when it was discovered by the algorithm, and some node i is reachable from k, then we can conclude that the cycle is harmful. We refer to the pre-processing search component of this sub-routine as “harmful search”. We refer to the query as “harmful check”. If Harmful Check = True, then the cycle is deemed harmful, and the algorithm terminates. 6.3. The algorithm We present the label-correcting algorithm for a monotonic environment below. This algorithm is a generalisation of Algorithm 3. 6.4. Complexity and correctness In addition to the analogous arguments provided in Sections 6.1 and 6.2, we provide an alternative proof of correctness. Lemma 6.11. Distance labels dmin (s) = z0 and dmax (s) = z0 are optimal, if and only if the shortest path problem on graph G contains no harmful cycles that affect shortest path distances. Proof. We prove the lemma for the shortest path problem by analysing dmin (s). The proof for the longest path problem, which investigates dmax (s), is identical in nature. At initialisation, dmin (s) = z0 . Recall that there exists a path from s to all other i ∈ N , by assumption throughout this work. Suppose, by contradiction, that dmin (s) is not optimal. Therefore, there exists a walk W = i1 − i2 − · · · − ik from s to itself, where s = i1 = ik . By definition of cycle, W is a cycle. By assumption, W is harmless with respect to node s, cost z = z0 . Since dmin (s) = z0 is not optimal, W must be a walk of cost fik−1 i1 ◦ fik−2 ik−1 ◦ · · · ◦ fi2 i3 ◦ fi1 i2 (z0 ) < z0 . Hence, W is harmful, by definition of harmful cycle. This contradicts our earlier assumption that W was harmless with respect to node s, cost z = z0 . Therefore, dmin (s) = z0 is optimal.  Theorem 6.12. Algorithm 4 correctly solves the shortest path problem for monotonic environments. Thus, the algorithm either solves the shortest path problem, or reports a harmful cycle. Proof. If a harmful cycle C affects shortest path distances, Algorithm 4 detects C and terminates, by construction of the algorithm and Theorem 6.7. Alternatively, assume that G contains no harmful cycles that affect shortest path distances. Suppose the algorithm failed to solve the shortest path problem. Then there exists a node ik ∈ N for which dmin (ik ) 30 Either of breadth-first or depth-first search. 31 I.e., the cycle is harmful with respect to node k, which means the cycle is harmful overall and the algorithm must terminate.

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

245

Input: Graph G = (N, A), nodes s, t, initial value z0 , functions fij (z) ∀(i, j) ∈ A Output: Paths from s to all other i ∈ N of minimum and maximum cost begin Label-Correcting, Monotonic begin Harmful Search end; dmin (s) = z0 ; dmax (s) = z0 ; dmin (i) = ∞, dmax (i) = −∞ ∀i ∈ N \ {s}; predmin (i) = ∅ ∀i ∈ N ; predmax (i) = ∅ ∀i ∈ N ; LIST = {s}; while LIST ̸= ∅ do Remove the first element i from LIST ; for all nodes j ∈ succ(i) do if dmin (j) > fij (dmin (i)), set dmin (j) = fij (dmin (i)) and set predmin (j) = imin ; if dmin (j) > fij (dmax (i)), set dmin (j) = fij (dmax (i)) and set predmin (j) = imax ; if dmax (j) < fij (dmin (i)), set dmax (j) = fij (dmin (i)) and set predmax (j) = imin ; if dmax (j) < fij (dmax (i)), set dmax (j) = fij (dmax (i)) and set predmax (j) = imax ; if a cycle C is detected in the predecessor graph then if traversal decreases dmin (i) for some i ∈ C, then terminate; if traversal increases dmax (i) for some i ∈ C and Harmful Check = True, then terminate; if j ∈ / LIST , set LIST = LIST ∪ {j}; end; end; end;

Algorithm 4: Label-correcting shortest path algorithm to solve the problem for monotonic environments and networks of general structure. is not optimal. Specifically, there exists a path P ′ of lesser cost from s to ik than the path P reported by the algorithm. Then, either the algorithm incorrectly assigned the predecessor to node ik , or some other node ik−1 ∈ N for which (ik−1 , ik ) ∈ A also has a sub-optimal distance label dmin (ik−1 ), by sub-path optimality. By construction of the algorithm, the former is impossible. Therefore, some node ik−1 ∈ N for which (ik−1 , ik ) ∈ A also has a sub-optimal distance label dmin (ik−1 ). Thus, some node ik−2 ∈ N for which (ik−2 , ik−1 ) ∈ A also has a sub-optimal distance label dmin (ik−1 ), by sub-path optimality. Continue tracing path P ′ backwards in this way. Eventually, we reach node i1 = s. By the same logic as above, dmin (s) = z0 is sub-optimal. But this contradicts Lemma 6.11. Therefore, the algorithm must have found the shortest path from s to ik , implying a path P ′ with lesser cost than P cannot exist. Hence, Algorithm 4 correctly solves the shortest path problem for monotonic environments.  The only differences between this algorithm and the version applied to monotonically increasing environments are the number of constant time computations performed for each node removed from LIST . More optimality conditions must be tested because the algorithm stores both dmin (i) and dmax (i) for all nodes i ∈ N .

246

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

Additionally, harmful cycle detection does not increase the computational complexity of the algorithm. Detection when a cycle is found in the predecessor graph still takes O(n) time. The procedure for cycledetection in a predecessor graph is shown in Lemma 5.8. Therefore, this label-correcting algorithm, surprisingly, has the same computational complexity as its classic counterpart, namely O(nm). 6.5. Functions with arbitrary domains Thus far, we have assumed that the domain of all functions fij (z) is R. This assumption forbids even √ some monotonic functions, such as fij (z) = z. The domain of this function is {z ∈ R|z ≥ 0}. It is possible √ for the cost of a path from s to some node i to be zi < 0. In this case, fij (zi ) = z is undefined. A non-real quantity cannot be compared to a real quantity, in terms of size. Thus, the shortest path problem cannot be solved. We refer to a path leading to an undefined cost as a terminating path, since such a path implies the termination of a shortest path algorithm. If an algorithm is solving the problem and discovers a path P of cost c(P ) ̸∈ R, then the algorithm should terminate and report the path.32 Just as finite shortest path solutions can coexist with harmful cycles, finite solutions can also coexist with terminating paths. √ Suppose there exists an arc (i, j) ∈ A governed by fij (z) = z. Since the domain of this function is not all of R, a path through this arc is a terminating path. However, if the distance label on node i is non-negative during the progression of a shortest path algorithm, the terminating path would never be detected. Thus, an arbitrary graph G = (N, A) governed by arbitrary functions has two additional shortest path termination possibilities beyond those stated in Theorem 5.15: (1) G contains at least one terminating path and has no shortest path solution (2) G contains at least one terminating path and has a finite shortest path solution. To detect a terminating path in an algorithm, every arc (i, j) ∈ A could have not only a function fij (z) associated with it, but also a domain βij (z). Before checking optimality conditions,33 the algorithm must verify that dmin (i), dmax (i) ∈ βij (z). If one of dmin (i), dmax (i) ̸∈ βij (z), then the algorithm terminates and reports the terminating path. 7. Future research In this section, we discuss extensions of the generalised shortest path algorithms developed in this work. First, we explore the classes of functions for which the generalised shortest path problem remains unsolved. Next, we describe further classifications and analyses of harmful cycles. Then we discuss shortest path problems in which an arc can be selected for a specified amount of time. Next, we further enrich Formulation 1 by introducing additional “threshold constraints”. Finally, we discuss extensions to hypergraph environments. 7.1. Arbitrary functions This research presents generalised algorithms that solve shortest path problems for monotonic environments over real domains. It remains an open question whether there exist polynomial-time algorithms to solve 32 The algorithm should report the path and the corresponding arc costs responsible for the termination. 33 This assumes that there are optimality conditions to check, which implies, in the context of this paper, that G is governed by monotonic functions.

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

247

Fig. 8. A graph G containing only one non-monotonic arc for which the optimality conditions discussed in this work do not apply.

Fig. 9. A non-monotonic arc (i, j). Function fij (z) has one critical point.

Fig. 10. The monotonic conversion of arc (i, j). Functions fij1 (z) and fij2 (z) represent the monotonically increasing and decreasing parts of fij (z), respectively.

the shortest path problem when functions fij (z) are non-monotonic. When this is the case, the above machinery does not apply because monotonicity is required to derive and prove optimality conditions (4.7)–(4.12). The following example illustrates that the classic optimality conditions in Section 1.2 cannot be extended to non-monotonic functions. Let G be defined as shown in Fig. 8, and suppose zs = z0 = −3. Investigating the two possible paths from s to k reveals that d(k) = 8 is optimal, by way of path s–j–k. However, the shortest path from s to t reveals that d(t) = −14 is optimal, by way of path s–i–k–t. Path s–j–k is not a sub-path of s–i–k–t, and the optimality conditions do not hold, even in the presence of just one non-monotonic arc. Beyond monotonic functions, one could next consider functions with one critical point, where the first derivative is zero. An intuitive approach would be to convert this non-monotonic environment into a monotonic one. For each arc (i, j) governed by a function fij (z) with one critical point, construct two copies of node j: j1 and j2 . Then construct two new arcs emanating from i: (i, j1 ) and (i, j2 ). Now, define fij1 (z) and fij2 (z) to be the monotonically increasing and decreasing parts of fij (z), respectively. By the discussion in Section 6.5, each of (i, j1 ) and (i, j2 ) inherently has an interval associated with it. Figs. 9 and 10 show an example of this conversion process, which allows us to apply the algorithms developed in this work. The conversion requires construction of two new arcs and two new nodes for each non-monotonic function fij (z). Additionally, this conversion requires construction of new arcs from each new node to all existing nodes in succ(j). In the worst case, there are exponentially many arcs to construct, depending on network structure and where the non-monotonic arcs occur. Consequently, the shortest path problem in such environments remains unsolved. The same argument applies for functions containing two or more critical points, implying even worse computational complexity. For functions containing infinitely many critical points, such as sin(z), the conversion method never terminates.

248

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

Thus, the complexity of the shortest path problem where functions have even a single critical point remains unresolved. 7.2. Harmful cycle extensions In the classic environment, the shortest path problem is not polynomial-time solvable only if there exists a negative cycle in the network. Whereas, in the functional environment, infinitely many traversals of some harmful cycle C could imply either bounded or unbounded solutions to the shortest walk problem.34 The true parallel to negative cycles must result in a decrease in cost upon each traversal, for infinite traversals. We refer to this analogue as an Infinitely Harmful Cycle. In contrast, if only a finite number of traversals around a cycle results in successive decreases in cost, we refer to it as a Finitely Harmful Cycle. Note that harmfulness is specific to a cycle, a start-node in the cycle, and the initial cost35 of the start node. Thus, the same cycle could be harmless,36 finitely harmful, or infinitely harmful for different initial costs and start-nodes. The label-correcting algorithm developed in this work can only detect harmfulness for the specific instance of the cycle encountered. In other words, there is no way to determine whether a given cycle is harmful short of traversing it and analysing the changes in cost. That is, classifying a cycle as finitely or infinitely harmful remains an open question. Further, we have not provided a direct method to check a graph G for harmful cycles. Recall that if there is a finite solution to the shortest path problem in the functional environment, there might or might not be harmful cycles in G. The algorithms developed in this research cannot tell the difference between the two situations. 7.3. Temporal aspects Now suppose the decision-maker has control over not only the actions selected, but also temporal aspects of the problem. Consider a problem in which the duration of implementation is now a continuous decisionvariable, rather than given. Denote this temporal decision-variable as tij ∀(i, j) ∈ A. In this environment, the cost of an arc is governed by some function of time and the variable of interest, denoted fij (zi , tij ), where tij is the amount of time arc (i, j) is traversed. Now, when an arc (i, j) is selected, the decision-maker must also specify the duration of arc-traversal. A path along this network corresponds to a selected sequence of actions and implementation durations. We represent this decision-problem as a mathematical program in Formulation 2. This formulation is a generalisation of the one explored throughout this paper, provided in Formulation 1. By definition, tij ≥ 0, since traversing an arc for negative time makes no sense. The parameters γij and mij are lower and upper bounds on tij , respectively. If arc (i, j) is selected, then it must be traversed for some positive amount of time. This minimum duration is represented by γij . If the constraints involving γij were not in place, an optimal path P could contain an arc that is traversed for zero time, which violates the concept of a path.37 The next set of constraints not only provides an upper bound to the time each arc is traversed, but also ensures that an arc can be traversed for more than one time unit, if selected. Together, these two sets of constraints imply that tij = 0 if (i, j) is not selected. The final constraint reflects an ultimate deadline T . If all actions must be deployed by some deadline, then by definition the sum of all implementation durations cannot exceed that deadline. In temporal functional environments each node bears a time-stamp that denotes the time in which the shortest path reaches that node. Formulation 2 inherently assumes that the amount of time, rather than 34 The boundedness of solutions depends on the function resulting from the composition of functions in the cycle. 35 Distance label. 36 I.e., neither infinitely nor finitely harmful. 37 This also violates the concept of a walk.

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

249

Input: Graph G = (N, A), nodes s, t, initial value z0 , functions fij (z) ∀(i, j) ∈ A Output: Path P from s to t of minimum cost minimise zt subject to  xij ≤ 1 i:(i,j)∈A



xij −

j:(i,j)∈A



xki

k:(k,i)∈A

  for i = s 1, = 0, for all i ∈ N \ {s, t}  −1, for i = t

zs = z0 tij ≥ γij · xij ∀(i, j) ∈ A tij ≤ mij · xij ∀(i, j) ∈ A 

zj =

xij · fij (zi , tij ) + M · (1 −

i:(i,j)∈A

 (i,j)∈A



xij ) ∀j ∈ N

i:(i,j)∈A

tij ≤ T

& xij ∈ {0, 1} ∀(i, j) ∈ A, zi ∈ R ∀i ∈ N , tij ≥ 0 ∀(i, j) ∈ A

Formulation 2: Shortest path problem in the functional environment as a mathematical program, including temporal decision-variables. the actual time-stamps themselves, affects the cost of the path from s to j. This is not necessarily the case. If the actual times in which each node in P is reached affect the cost of the path, then fij (z) would be a function of zi and the time-stamps on i and j. In such cases, the time-stamps are additional continuous decision-variables. In other words, if arc (i, j) is in some optimal path P , then the time-stamp on node j must follow that of i. The temporal dimension also gives rise to individual start and end considerations. Depending on the situation, a decision-maker might be unable to implement an action before or after particular times. Observe that time-lags do not further complicate the decision-problem. If the action represented by arc (i, j) does not take immediate effect, the time-lag can be incorporated into the solution. For example, if tij = 3 in an optimal solution, but there is a time-lag of 2 time-units, then in practice the decision-maker should set tij = 5. The same concept can be applied if the action does not lose effect immediately. The optimisation problem posed in this research involves only discrete choices. However, continuous variables enter the problem if a decision-maker also has control over how long an action can be implemented. These temporal aspects provide avenues for future shortest path research. 7.4. Threshold constraints Some sequential decision-problems require that z ∈ [a, b] for each node in a path, for lower and upper bounds a and b, respectively. Specifically, not only must an optimal solution optimise z over all permissible sequences, but also maintain a “tolerable level” z at each step. Constraint (7.1) reflects this upper bound

250

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

requirement. zj ≤ b ∀j ∈ N.

(7.1)

Similarly, Constraint (7.2) provides a tolerable lower bound for z. zj ≥ a

∀j ∈ N.

(7.2)

7.5. Extensions to hypergraphs While this research extends shortest path algorithms to solve the problem for broader classes of cost functions, it does not apply to hypergraph environments. The cost zj = fij (zi ) depends on cost zi only, should arc (i, j) be selected. Whereas, in hypergraph environments, cost zj depends on numerous costs. If I = ({u, v, q, r}, j) is a hyperarc terminating at node j, then zj = fIj (zI ) = f (zu , zv , zq , zr )

(7.3)

where zu , zv , zq , zr are the costs to nodes u, v, q, and r, respectively. In some sense, hypergraph environments imply multi-variable functions, since costs depend on several node distance labels. However, notice that even in the hypergraph environments discussed in [16,17] the problem is single-objective. That is, costs are in terms of one variable of interest z. “Multi-variable functions” in hyperarc environments involve multiple quantities of z, rather than several distinct variables of interest. Thus, typical hypergraph environments do not provide methods to solve the shortest path problem when there are several variables of interest, which could reflect the effects of several parameters on some objective function. 8. Conclusion Since Knuth in 1976, mathematicians and computer-scientists have generalised shortest path algorithms to functional environments. However, those algorithms require several restrictive assumptions on functions permitted in the network. In contrast, this research extends both classic label-setting and label-correcting shortest path algorithms while requiring only monotonicity. Classic algorithms cannot be further extended, since the underlying optimality conditions that inspire all known shortest path algorithms inherently require monotonicity. To solve the problem to optimality without requiring monotonicity, entirely new conditions, and thus algorithms, are necessary. Nevertheless, many outcome-oriented decision-problems can be solved in polynomial-time by representing them as functional shortest path problems involving monotonicity. References [1] R. Ahuja, T. Magnanti, J. Orlin, Network Flows: Theory, Algorithms, and Applications, Prentice Hall, Upper Saddle River, New Jersey, 1993, pp. 93–165. [2] P. Brucker, Scheduling Algorithms, Springer-Verlag, Heidelberg, Germany, 2007. [3] J. Kelley, M. Walker, Critical-path planning and scheduling, in: Proceedings of the Eastern Joint Computer Conference, 1959, pp. 160–173. [4] J. Kelley, Critical-path planning and scheduling: Mathematical basis, Oper. Res. 9 (3) (1961) 296–320. [5] L.R. Ford, Network flow theory. Report P-923, RAND Corporation, Santa Monica, CA, 1956. [6] L.R. Ford, D.R. Fulkerson, Flows in Networks, Princeton University Press, Princeton, NJ, 1962. [7] K.D. Wayne, Generalized maximum flow algorithms (Doctoral Dissertation), Cornell University, 1999. [8] L. V´ egh, Concave generalized flows with applications to market equilibria, Math. Oper. Res. 39 (2) (2014) 573–596. [9] http://www.pipeflowcalculations.com/pipe-valve-fitting-flow/flow-in-pipes.php. [10] E.W. Dijkstra, A note on two problems in connexion with graphs, Numer. Math. 1 (1959) 269–271. [11] R. Bellman, On a routing problem. Report P-1000, RAND Corporation, Santa Monica, CA, 1956. [12] R.W. Floyd, Algorithm 97: Shortest path, Commun. ACM 5 (1962) 345. [13] D. Knuth, A generalization of Dijkstra’s algorithm, Inform. Process. Lett. 6 (1) (1976) 177–201.

L. Boguchwal / Discrete Optimization 18 (2015) 217–251

251

[14] J. Berstel, L. Boasson, Context-free languages, in: J. Van Leeuwen (Ed.), Handbook of Theoretical Computer Science, Volume B: Formal Models and Semantics, MIT Press, Cambridge, MA, 1994, pp. 59–102. [15] G. Ramalingam, T. Reps, An incremental algorithm for a generalization of the shortest path problem. Technical report 1087, University of Wisconsin–Madison, Madison, Wisconsin, 1992. [16] G. Ausiello, G.F. Italiano, L. Laura, U. Nanni, F. Sarracco, Classification and traversal algorithmic techniques for optimization problems on directed hypergraphs. Technical report 18, Universit` a di Roma La Sapienza, Rome, Italy, 2010. [17] G. Ausiello, G.F. Italiano, U. Nanni, Hypergraph traversal revisited: Cost measures and dynamic algorithms, Lecture Notes in Comput. Sci. 1450 (1998) 1–16.