1 Introduction

The Shortest Path Problem (SPP) is one of the most studied problems in network optimization [15, 23, 28]. The problem comes up in practice and arises as sub-problem in many network optimization algorithms. Solution approaches for the \( SPP \) have been studied for a long time (e.g., [8, 23, 29, 44]). More recently, some improvements and computational studies have been presented by Ahuja et al. [1], Gabow and Tarjan [31] and Goldberg [34]. The reader is referred to the works of Cherkassky et al. [12] and Gallo and Pallottino [32] for detailed surveys.

In its basic formulation, the objective is to determine a minimum cost path through a network from a given source node to a destination node. Several polynomial time solution approaches have been developed in the scientific literature to address the \( SPP \) in the case there are no negative cost cycles (e.g., see [16, 23, 42]). On a network with negative arc costs, but with all cycles having non-negative costs, the best currently known time bound \(\mathcal {O}(nm)\) is achieved by the Bellman-Ford algorithm [8, 29, 44], where n and m denote the number of nodes and arcs in the network, respectively. If the arc costs are non-negative, implementations of Dijkstra’s algorithm [23] achieve better bounds. In particular, an implementation presented by Fredman and Tarjan [30] runs in \(\mathcal {O}(m+n\log n)\) time.

An interesting extension of the \( SPP \) is represented by the k shortest paths problem (\(k SPP \)), whose aim is to find a set of k shortest paths for each node by considering the first, the second and so on up to the k-th shortest path. Many solution approaches have been defined to solve the \(k SPP \) (e.g., see [36]) and its loopless counterpart (e.g., see [43, 55]). Dreyfus [25] and Yen [55] cite several additional papers on this subject going back as far as 1957.

When negative cost cycles are present in the network, the \( SPP \) is not well defined, that is, a finite optimal solution does not exist. In this case, the problem is to check whether a simple cycle, whose arc costs sum up to a negative number, is present in the network. This problem is known as Negative Cost Cycle Detection Problem (\( NCCDP \)). It is worth noting that the \( NCCDP \) is polynomial. Several procedures have been defined for the \( NCCDP \). The Bellman-Ford algorithm is one of the earliest and to date asymptotically fastest algorithm for the \( NCCDP \) [12]. Recently, Subramani [51] has introduced a new approach for the \( NCCDP \); the proposed solution strategy is based on exploiting the connections between the \( NCCDP \) and the problem of checking whether a system of difference constraints is feasible.

The scientific literature provides several works dealing with algorithms that list up all cycles in directed as well as undirected graphs in which arc costs are not considered [11, 47]. Yamada and Kinoshita [54] addressed the problem of finding all cycles in a directed graph with negative costs and they proposed a recursive algorithm. All the cited references do not solve the \( SPP \) in presence of negative cost cycles, rather they enumerate all the cycles in the network or check whether a negative cost cycle exists.

Solving the \( SPP \) in general graph means to find a shortest elementary path, i.e., a shortest path with distinct nodes. The elementarity requirement in a network with negative cost cycles has been studied in the context of branch and price algorithm for the Vehicle Routing Problem (\( VRP \)), see for instance [17]. Indeed, the pricing problem is formulated on a cyclic graph with no restriction in the cost sign. Besides the elementarity requirement, constraints on the consumption of resource along paths are introduced. The scientific literature refers to this problem as the Resource Constrained Elementary Shortest Path Problem (\( RCESPP \)). Starting with the seminal work of Beasley and Christofides [6], a variety of solution approaches have been developed to solve to optimality the \( RCESPP \) (see, e.g., [20, 22, 39]). The single-source single-destination version of the Elementary Shortest Path Problem (\( ESPP \)) can be viewed as a particular instance of the \( RCESPP \), where the resource consumption constraints are removed.

In this paper, we deal with the more general case in which an elementary shortest path must be found for all nodes and resource consumptions are not taken into account. In other words, we address the single-source all-destinations version of the \( ESPP \). In order to solve to optimality the single-source all-destinations , we define a dynamic programming approach, applying the concepts introduced by Boland et al. [10] and Righini and Salani [48] for the \( RCESPP \). In addition, an innovative method, that is, a dynamic k shortest paths algorithm, is designed. The value of k is a variable and may assume an arbitrary value for each node of the network.

An in depth analysis is carried out to evaluate the theoretical complexity of the proposed solution approaches and an extensive computational phase is conducted in order to asses the efficiency of the defined optimal solution strategies. The proposed methods are able to solve also the single-source single-destination \( ESPP \). However, it is worth observing that well-tailored solution approaches for the single-source single-destination version can be devised but this topic is out of the scope of this work. The reader is referred to [24, 38] for the latter version of the problem.

Studying the \( ESPP \) is motivated by different main issues. First, the solution approaches for the \( ESPP \) proposed in this paper, can be used to determine lower bounds on the optimal cost and to solve the dual Lagrangean problem associated with the \( RCESPP \). This information can be used to improve the performance of the state-of-the-art methods.

Secondly, the \( ESPP \) models the currency conversion problem [49]. Indeed, when the nodes represent currencies and the arcs the transactions with costs equal to exchange rates, the problem is to find the maximum product path, that is, the best exchange sequence. The problem can be easily transformed in the \( SPP \) and, since the graph can contain negative cost cycles, it can be viewed as an instance of the \( ESPP \).

In addition, the \( ESPP \) is the pricing problem when the multiple traveling salesman problem (\(m TSP \)) is solved with column-generation approaches (see, e.g. [7]). Even though the \(m TSP \) can be used to represent a great variety of real-life applications, the scientific literature has not devoted too much attention to this problem. The proposed solution approaches for the \(m TSP \) are based on either the branch and bound scheme [2, 33] or focus on the transformation of the \(m TSP \) to the \( TSP \) [45, 46]. For this reason, the \( ESPP \) as pricing problem of the \(m TSP \) has not been addressed and exact algorithms are not available.

The paper is organized as follows. The proposed solution approaches, along with their theoretical analysis are presented in Sect. 2. Section 3 is devoted to the discussion of the computational results. Section 4 presents our conclusions. The paper ends with the Appendix, where a toy example is used to show the operations executed by the proposed algorithms.

2 Proposed solution approaches

The solution approaches proposed in this paper are based on the idea to compute the minimum set of paths for each node such that an elementary shortest path is found for all nodes.

2.1 Notations and definitions

Let \(\mathcal {G=(N,A)}\) be a directed graph where \(\mathcal {N}\) is the set of n nodes, whereas \(\mathcal {A}\) denotes the set of \(m \le |\mathcal {N}\times \mathcal {N}|\) arcs. \(\mathcal {N}\) contains also the source node s. A cost \(c_{ij}\) is associated with each arc \((i,j)\in \mathcal {A}\). A cycle on node i is defined as an ordered sequence of nodes \(C_i = (i, j_1, \ldots ,j_{g},i)\), where \(j_h \ne j_k\) for all pairs \(h,k \in \{1,\ldots , g\}\) such that \(h\ne k\). It can also be viewed as a sequence of consecutive \(g+1\) arcs \(\left( (i,j_1), \ldots ,(j_{g-1},j_g),(j_g,i)\right) \in \mathcal {A}\). It is worth observing, as shown by Allender [3], that the number of cycles in a complete graph is equal to \(\tilde{C}=\sum _{\rho =1}^{n}{\frac{n!(\rho -1)!}{\rho !(n-\rho )!}}\). A path \(\pi _{si}\) from node s to node i is a sequence of nodes \(\pi _{si} = (s=i_1,\ldots ,i_l=i)\), \(l \ge 2\) and a corresponding sequence of \(l-1\) arcs such that the h-th arc in the sequence is \((i_h ,i_{h+1})\in \mathcal {A}\) for \(h = 1,\ldots ,l-1\). Thus, each path contains at least one arc. Let \(M_{\pi }(j)\) be the multiplicity of node j in path \(\pi \), that is, \(M_{\pi }(j) = \left| \{ v:1 \le v \le l, i_v = j\} \right| \). The path \(\pi \) is said to be an elementary path if \(M_{\pi }(j) = 1\), for all \(j \in \pi \). A cycle \(C_i\) on node \(i\in \mathcal {N}\) is said to be a negative cost cycle (\( NCC \)) if \(c(C_i) = \sum _{(h,k)\in C_i}c_{hk}<0\).

Let \(\pi _{sj}\) be an elementary path from node s to node j such that \(i\in \pi _{sj}\) for some \(i\in \mathcal {N} {\setminus } \{s\}\). Let \(\pi _{si} = \pi _{sj}\cup \{(j,i)\}\) be the path obtained by extending path \(\pi _{sj}\) to node i through arc \((j,i) \in \mathcal {A}\). Since \(i\in \pi _{sj}\), a cycle \(C_i=\pi _{ij}\cup \{j,i\}\) is created.

Proposition 1

Given a path \(\pi _{sj}\) and its sub-path \(\pi _{si}\), \(C_i\) is a \( NCC \) iff \(c(\pi _{si})>c(\pi _{sj})+c_{ji}, (j,i)\in \mathcal {A}\).

Proof

The cost of the path \(\pi _{sj}\) can be viewed as the sum of the cost of the sub-path \(\pi _{si}\) and the sub-path from i to j, that is \(c(\pi _{sj}) = c(\pi _{si})+c(\pi _{ij})\). It follows that

$$\begin{aligned} c(\pi _{si})>c(\pi _{sj})+c_{ji} \Leftrightarrow c(\pi _{si})>c(\pi _{si})+c(\pi _{ij})+c_{ji} \Leftrightarrow 0>c(\pi _{ij})+c_{ji} = c(C_i). \end{aligned}$$
(1)

This concludes the proof. \(\square \)

Since the directed graph \(\mathcal {G}\) is not assumed to be acyclic and the arc costs are not constrained in sign, there may be \( NCC s\) in \(\mathcal {G}\). The \( ESPP \), from the source s to all other nodes, consists in finding the paths \(\pi _{si},\; \forall i\in \mathcal {N} {\setminus } \{s\}\) such that \(c(\pi _{si})\) is minimized and \(M_{\pi _{si}}(j)=1,\; \forall j\in \pi _{si}\).

It is well known that the Bellman’s optimality principle does not apply for this problem, indeed sub-paths of the optimal path for some node may not be optimal. For more details, the reader is referred to [18].

2.2 Dynamic multi-dimensional labelling approach

The approach, presented in this section, uses the concept of critical node introduced by Kohl [41]. In particular, a node i is said to be critical if there exists a cycle \(C_i\) that is a \( NCC \). A binary variable is introduced for each critical node in order to keep track whether the node is visited. This binary variable can be viewed as a resource associated with node i, bounded to be less than or equal to one (see [6]).

Let \(S=\{i_1,i_2,\ldots ,i_{|S|}\}\), be the set of critical nodes and \(r[p],\; p=1,\ldots ,|S|\) be the binary variable associated with node \(i_p \in S\).

We denote as \(y_i = (c(\pi _{si}),r_i)\) the label that contains the cost and the resource consumptions vector of the path \(\pi _{si}\) from node s to node i. The resource consumptions vector \(r_i\) has the following form: \(r_i[p] \ge 1,\;\forall p:j_p \in \pi _{si}\) and \(r_i[p]=0,\;\forall p:j_p \not \in \pi _{si}\). In other words, the vector \(r_i\) keeps track of the nodes \(j \in S\) that are visited along the path \(\pi _{si}\).

Definition 1

Let \(y_i^{1}=(c(\pi _{si}^1),r_i^1)\) and \(y_i^{2}=(c(\pi _{si}^2),r_i^2)\) be two labels associated with node i. The label \(y_i^{2}\) is dominated by the label \(y_i^{1}\) if \(c(\pi _{si}^1) \le c(\pi _{si}^2)\), \(r_i^1[p] \le r_i^2[p]\) for \(p=1,\ldots ,|S|\) and at least one inequality is strict.

Definition 2

A label \(y_i=(c(\pi _{si}),r_i)\) associated with node i is said to be efficient or Pareto-optimal if there does not exist a label \(\bar{y}_i\) that dominates it.

Definition 3

A label \(y_i=(c(\pi _{si}),r_i)\) associated with node i is said to be feasible if \(r_i[p] \le 1, \;\forall p=1,\ldots ,|S|\).

A set D(i), containing the efficient labels to node i, and the set \(FS(i)=\{j:(i,j)\in \mathcal {A}\}\) of successor nodes, are associated with each node \(i\in \mathcal {N}\).

The main difficulty is that the set S of critical nodes must be known in advance. the enumerative procedure of Yamada and Kinoshita [54] could be executed to determine the entire set of negative cost cycles. The nodes belonging to each negative cost cycle can be used to initialize set S. However, this strategy could be inefficient, since only a sub-set of all nodes belonging to all negative cost cycles need to be considered. In addition, the procedure defined by Yamada and Kinoshita [54] is not polynomial.

If the set S is not known in advance, we can modify the solution approaches presented in [10, 48], in order to define well-tailored procedure for the \( ESPP \). In particular, starting from \(S=\emptyset \), a label-setting algorithm is executed. The search is stopped when a \( NCC \), named \(C_i\), is detected. The set S is incremented by adding node i and the label-setting algorithm is run again. The procedure terminates when no \( NCC \) is detected. This approach is similar to the general state-space augmenting algorithm proposed in [10] with the difference that the label-setting algorithm is stopped when a negative cost cycle is detected. In Algorithm 1, we describe the steps of the aforementioned procedure, whereas the truncated label-setting algorithm is depicted in Algorithm 2.

figure a
figure b

2.2.1 Correctness of the dynamic multi-dimensional labelling approach

In this section, we prove the correctness of the proposed solution approach. In particular, at the end of Algorithm 1, the label \(y_i\) with the smallest cost among those belonging to the set D(i) is associated with the least cost elementary path from s to i.

Proposition 2

At the end of Algorithm 2, one of the following two situations can occur:

  1. 1.

    a \( NCC \) is detected, that is, the stop conditions of line 13 are verified;

  2. 2.

    if the procedure is stopped by condition of line 27, then all the efficient and feasible paths from s to each other node \(i \in \mathcal {N} {\setminus } \{s\}\) are determined.

    1. (a)

      At the end of each iteration, the following conditions hold:

      1. i.

        \(D(s)=\{y_{s}^{1}\}=\{(0,0)\}\);

      2. ii.

        \(\forall j\in \mathcal {N}\), if \(D(j)\ne \emptyset \) [i.e.: \(D(j)=\{y_{j}^{1}, y_{j}^{2},\ldots , y_{j}^{\Xi }\}\)] and \(j\ne s\), then \(y_{j}^{\xi }, \xi =1,\ldots ,\Xi \) is a label related to a feasible path from node s to node j and D(j) is an efficient set.

    2. (b)

      Upon termination of the algorithm, if \(D(j)\ne \emptyset , j\in \mathcal {N}\) and \(j\ne s\), then D(j) contains the labels of all efficient and feasible paths from node s to node j.

Proof

Let us consider case 1. The conditions of line 13 derive from Proposition 1. Thus, if they are verified, then a \( NCC \) is detected. If case 1 does not occur, then all \( NCC s\) have been forbidden and the algorithm terminates when the list L is found empty, that is, case 2.

In what follows, we prove case 2.

Let us consider case 2a. Condition 2(a)i holds because, initially, \(D(s)=\{y_{s}^{1}\}=\{(0,0)\}\) and, by the rules of the algorithm, D(s) cannot change.

We prove condition 2(a)ii by induction on the iteration count. Indeed, initially, condition 2(a)ii holds, since node s is the only node for which the set D(s) is nonempty. Suppose that 2(a)ii holds for some node j at the beginning of some iteration. Let \(y_{i}^{\delta }\) be the label removed from L.

If \(i=s\) (which only occurs at the first iteration) and \(\delta =1\), then at the end of this iteration, we have \(D(j)={y_{j}^{1}}\) for all successor nodes j of s such that the corresponding path \(\pi _{sj}\) is feasible, \(D(j)=\emptyset \) for all other nodes \(j\ne s\), \(j \notin FS(i)\). Thus, the set of labels has the required property.

If \(i\ne s\), then \(y_{i}^{\delta }\) is the label of some feasible path \(\pi _{si}^\delta \) starting from s and ending to i that is not dominated by the other paths in D(i), by the induction hypothesis. If the set D(j) changes, for some node j, such that \(j \in FS(i)\), as a result of the iteration, a new feasible label \(\bar{y}_{j} = (c(\bar{\pi }_{sj}), \bar{r}_{j})\) is obtained for node j. The created label is related to the feasible path \(\pi _{sj}\) consisting of path \(\pi _{si}^\delta \) followed by the arc (ij). Finally, note that, by the rules of the algorithm, the newly created label is added to D(j) only if it is an efficient label. This completes the induction proof of 2(a)ii.

Let now consider condition 2b. Using part 2(a)ii, we have that, at each iteration, \(\forall j\in \mathcal {N}\) such that \(D(j)\ne \emptyset \), D(j) is an efficient set. Thus, the property mentioned is also satisfied when the algorithm terminates. In addition, the way in which the candidate list L is updated and the termination condition (i.e., the algorithm terminates when there are no more labels left to be scanned) guarantee that all the labels with the potential to determine a new label for at least one node are scanned during the execution of the algorithm. \(\square \)

Proposition 3

(Correctness of Algorithm 1) At the end of Algorithm 1, the label \(y_i\) with the smallest cost among those belonging to the set D(i) is associated with the least cost elementary path from s to \(i,\, \forall i\in \mathcal {N}\).

Proof

From Proposition 2, it follows that all the efficient and feasible labels \(y_i,\forall i \in \mathcal {N}\), are determined. Since the set D(i) is an efficient set, the path \(\bar{\pi }_{si} = argmin_{y\in D(i)}\{c(\pi _{si})\}\) has minimum cost among all the feasible paths from s to i, that is, \(\bar{\pi }_{si}\) is the optimal solution \(\forall i\in \mathcal {N}\). \(\square \)

2.2.2 Complexity analysis

The complexity of Algorithm 1 is \(\mathcal {O}(n2^{2n})\), in the worst case. This result is formally stated in the following lemma.

Lemma 1

In the worst case, the complexity of Algorithm 1 is \(\mathcal {O}(n2^{2n})\).

Proof

The total number of efficient labels is at most \(2^{|S|}\). Thus, at most \(2^{|S|}\) labels are selected from set L. Since each label contains \(|S|+1\) elements, the total number of operations required by the dominance check is bounded by \(|S|2^{|S|}\). Thus, the complexity of Algorithm 2 is \(\mathcal {O}(|S|2^{2|S|})\). A node i is added to the set S at each iteration of Algorithm 2. Since the cardinality of set S is n in the worst case, the complexity of Algorithm 1 is \(\mathcal {O}(n2^{2n})\). \(\square \)

The scientific literature proposes a relaxation of the elementary constraint by considering a surrogate resource \(\gamma \) which counts the number of nodes in the path.

This idea was proposed by Feillet et al. [26] and applied by Righini and Salani [48] for solving the \( RCESPP \). It is worth observing that [26, 48] consider the single-source single-destination case. In their approach, a labelling algorithm is executed and labels with \(\gamma > |\mathcal {N}|\) are declared unfeasible. At the end of the algorithm, if the path is acyclic, then it is the optimal elementary path, otherwise, the repeated nodes are added to the set S. In our algorithm, the labelling procedure (Algorithm 2) is stopped when a cycle is detected, thus the resource \(\gamma \) does not make sense. The approach to augment the set S is the same of that proposed by Boland et al. [10] and by Righini and Salani [48]. The difference is that in the latters the optimal path has to be found for a single destination. For more details, the reader is referred to [19, 22]. In [37] the authors proposed a new state-space reduction technique combined with the strategies defined in [48]. This strategy cannot be extended to the single-source all-destinations version of the \( ESPP \).

For a numerical example illustrating the operations executed by Algorithm 1 the reader is referred to the Appendix.

2.3 Labelling approach based on the k shortest paths problem

In this section, we describe a labelling approach in which the first k paths are determined for each node \(i \in \mathcal {N}\). The aim of the procedure is to determine the smallest set of paths for each node i. Under this respect, k is a variable and can take different values for each node. The main idea is to start with \(k=1\) for each node. Whenever a \( NCC \) is detected, k is incremented for a specific node and the labelling algorithm is run again. When no \( NCC \) is detected, from the set of paths associated with each node, the optimal solution is chosen.

It is worth observing that when the \(k SPP \) is solved, the paths are ranked by non-decreasing cost. In our context, it is necessary to store equivalent paths. This is necessary because paths with the same cost can have a different structure, that is, they can contain different nodes.

Let \(K_i\) be the number of best paths from node s to node i. The set \(\Pi _i\) contains the \(K_i\) paths ordered by non-decreasing cost, that is, \(c(\pi _{si}^k) \le c(\pi _{si}^{k+1}), \ \forall k=1,\ldots ,K_i-1\). For the case of q equivalent paths, that is, \(c(\pi _{si}^k) = c(\pi _{si}^{k+1}),\, k=h,\ldots , h+q\), with \(h\ge 1\) and \(h+q\le K_i\) we have that \(\pi _{si}^k \ne \pi _{si}^{p}\), \(k=h,\ldots , h+q-1\) and \(p=k+1,\ldots , h+q-1\).

Definition 4

Set \(\Pi _i,\forall \ i\in \mathcal {N}\) is said to be path-elementary, if each path \(\pi _{si}^k \in \Pi _i, k=1,\ldots , K_i\) does not contain repeated nodes.

figure c

A vector \(y_i\in \mathbb {R}^{K_i}\) is associated with each node i and stores the costs of the paths belonging to the set \(\Pi _i\), that is, \(y_i[k]\) represents the cost of path \(\pi _{si}^k\in \Pi _i\).

Every time a \( NCC \,C\) is detected, the number of paths that have to be found for each node \(i \in C\) is increased, that is, \(K_{i}=K_{i}+1,\; \forall i \in C\), and the labelling algorithm is executed again. When no \( NCC \) is detected, \(y_i[1]\) is the cost of the optimal elementary shortest path from node s to node \(i \in \mathcal {N}\).

The proposed solution approach iteratively solves the \(k SPP \) for a fixed value of \(K_i,\;\forall i \in \mathcal {N}\). The steps of the labelling procedure are depicted in Algorithm 3. It is iteratively run after that \(K_i,\ \forall i\in \mathcal {N}\), is coherently updated. The dynamic labelling solution strategy is reported in Algorithm 4.

figure d

2.3.1 Correctness of the dynamic labelling approach

In this section, we prove the correctness of the proposed solution approach. In particular, at the end of Algorithm 4, \(\pi _{si}^1\) is the least cost elementary path from s to i.

Proposition 4

At the end of Algorithm 3, we have one of the following two cases:

  1. 1.

    a \( NCC \) is detected, that is, conditions of line 9 are verified;

  2. 2.

    if condition of line 30 is verified, then all the first \(K_i\) elementary paths are determined for each node \(i\in \mathcal {N}\), that is, sets \(\Pi _i,\ \forall i\in \mathcal {N}\), are path-elementary.

    1. (a)

      At the end of each iteration, the following conditions hold:

      1. i.

        \(y_s[1]=0\);

      2. ii.

        \(\forall i\in \mathcal {N} {\setminus } \{s\}\), if \(y_{i}[k]\ne +\infty \), then \(\pi _{si}^{k}\) is an elementary path.

    2. (b)

      Upon termination of the algorithm, \(\Pi _i,\ \forall i\in \mathcal {N}\), is path-elementary.

Proof

Let us consider case 1: The first part of conditions in line 9, that is, \(y_i[k] \ne +\infty ,\;\forall k\in \{1, \ldots , K_i\}\), checks whether all the \(K_i\) paths to node i are determined. The second one checks whether it is not possible to generate at least one elementary path. The third part derives from Proposition 1, thus if it is verified for some \(\bar{k}\), a \( NCC \) is found and the algorithm terminates. It follows that the presence of a \( NCC \) is verified only if the entire set of paths from node s to the considered node i are determined. If case 1 does not occur, then the determined value \(K_i\) is sufficient to skip \( NCC s\) involving node \(i,\, \forall i \in \mathcal {N}\), and the algorithm terminates when the list L is found empty, that is, case 2.

Case 2: Let us consider case 2a. Condition 2(a)i holds because, initially, \(y_s[1]=0\) and, by the rules of the algorithm, \(y_s[1]\) cannot change.

We prove condition 2(a)ii by induction on the iteration count. Indeed, initially, condition 2(a)ii holds, since node s is the only node for which the cost is not equal to \(+\infty \). Suppose that 2(a)ii holds for some node j at the beginning of some iteration. Let i be the node removed from L.

If \(i=s\) (which only occurs at the first iteration), then at the end of this iteration, we have \(y_j[1]\ne +\infty \) for all successor nodes j of s and the corresponding path \(\pi _{sj}=\{(s,j)\}\) is elementary, and \(y_j[1]=+\infty \) for all other nodes \(j\ne s,\, j \notin FS(i)\). Thus, the set of paths has the required property.

If \(i\ne s\), then \(y_{i}[k]\) is the cost of the k-th path \(\pi _{si}^k\) starting from s and ending to i that does not contain repeated nodes, by the induction hypothesis. If \(y_j[k]\) changes, for some node \(j \in FS(i)\) and k, then a new path is obtained for node j. The created path \(\pi _{sj}^k\) consists of path \(\pi _{si}^k\) followed by the arc (ij). Finally, note that, by the rules of the algorithm, the newly created path is elementary because \(j \not \in \pi _{si}^k\). This completes the induction proof of 2(a)ii.

Let now consider condition 2b. Using part 2(a)ii, we have that, at each iteration, \(\pi _{sj}^k,\, \forall j\in \mathcal {N}\) such that \(y_j[k]\ne +\infty \) is an elementary path. Thus, the property mentioned is also satisfied when the algorithm terminates. In addition, the way in which the candidate list L is updated and the termination condition (i.e., the algorithm terminates when there are no more nodes left to be scanned) guarantee that all the nodes with the potential to determine a new path for at least one node are scanned during the execution of the algorithm. \(\square \)

Proposition 5

(Correctness of Algorithm 4) At the end of Algorithm 4, \(\pi _{si}^1\) is the optimal path from node s to node \(i,\ \forall i\in \mathcal {N}\).

Proof

The algorithm terminates when no cycle is detected. From Proposition 4, we know that if no cycles are detected, then Algorithm 3 provides the path-elementary set \(\Pi _i,\ \forall i\in \mathcal {N}\), containing the first \(K_i\) elementary paths (see part 2 of Proposition 4). Since the paths are ordered in non-decreasing order of the cost, the path \(\pi _{si}^1\) belonging to each set \(\Pi _i\) represents the least cost path. In addition, being \(\Pi _i\) path-elementary, \(\pi _{si}^1\) is the optimal path. \(\square \)

2.3.2 Complexity analysis

Let K be the highest number of paths to some node i at the end of the Algorithm 4, that is, \(K = \max _{i\in \mathcal {N}}\{|K_i|\}\). In the worst case, \(|K_i|\) is equal to the number of cycles involving node i. We know that the number of cycles \(C_i\) in a complete network is equal to \(\sum _{\rho =1}^{n-1}\prod _{\beta = 1}^{\rho }(n-\beta )\), where \(\rho \) indicates the number of nodes, different from i, included in the cycles. Since \(K_i\) is incremented for each node i included in the detected cycles C (see line 9 of Algorithm 4), \(|K_i|\) assumes, in the worst case, the following value: \(\sum _{\rho =1}^{n-1}(\rho +1)\prod _{\beta = 1}^{\rho }(n-\beta )\).

Lemma 2

In the worst case, the complexity of the Algorithm 4 is \(\mathcal {O}(n^2K^4)\).

Proof

The running time of one iteration of the inner forloop in line 14 of Algorithm 3 is \(\mathcal {O}(K)\). Since the forloops of line 13 and 14 of Algorithm 3 take \(K^2\), the number of iterations in lines 13 – 25 of Algorithm 3 is \(\mathcal {O}(K^3)\). The FS contains at most \(n-1\) elements, thus lines 8 – 27 of Algorithm 3 perform \(\mathcal {O}(nK^3)\) operations. The forloop of line 8 of Algorithm 3 is invoked nK times. Consequently, Algorithm 3 takes \(\mathcal {O}(n^2K^4)\). \(\square \)

A numerical example illustrating the operations executed by Algorithm 4 is reported in the Appendix.

3 Computational experiments

The aim of this section is to evaluate the behaviour of the proposed solution approaches and to compare them in terms of computational cost. The proposed algorithms have been coded in Java and tested by using an Intel(R) core(TM) i7 CPU M620, 2.67 GHz, ram 4.00 GB, under a Microsoft 7 operating system. In the next section, we present the considered instances and how they were generated.

3.1 Test problems

The computational results are carried out on two groups of test problems. The first one is composed of random networks, the instances belonging to the second group are derived from \( VRP \) benchmark test problems.

The test problems of the first group (i.e., fully random networks) have been generated randomly by using the Netgen generator of Klinglman et al. [40]. In particular, we consider networks with number of nodes n belonging to \(\{300, 350, 400, 450, 500\}\) and for each value of n we consider three arc densities, that is, 10, 30 and 50. With these parameters, the minimum and maximum number of arcs are 3000 and 25000, respectively. The cost \(c_{ij}, \forall (i,j)\in \mathcal {A}\) is randomly generated from the interval [0, 100].

For each network, a given number of instances have been generated, in such a way that at least a fixed number of negative cost cycles is present. The procedure used to build the test problems is detailed in what follows. Let \(\#c\) be the number of negative cost cycles and let leng be the number of arcs belonging to a given cycle. For each fully random network, we have generated 30 instances by letting \(\#c=1, \ldots , 30\). In other words, each instance has a number of cycles at least equal to \(\#c\). The value leng has been randomly chosen in the interval [2, 5].

The procedure used to build the test instances relies on the solution of the shortest path problem for each fully random network, obtaining a tree T. Let \(\pi _{ij}\) be the path from node i to node j in T. Exactly \(\#c\) cycles are chosen by selecting \(\#c\) arcs \((j,i)\in \mathcal {A} {\setminus } T\). Each cycle \(C^{\#c}_i, \#c=1, \ldots , 30\) is composed by the arcs belonging to the path \(\pi _{ij}\) and by the arc (ji). Starting from each leaf node and exploring the related branch by following only inverse arcs, the first path \(\pi _{ij}\), from which it is possible to generate a cycle with leng nodes is selected. The cost \(c_{ji}\) of arc (ji) is modified in order to obtain a new cost \(\bar{c}_{ji}=c_{ji}-c(C^{\#c}_i)-1\). It follows that evaluating the cost of the cycle \(C^{\#c}_i\) considering the new cost \(\bar{c}_{ji}\) we have \(\bar{c}(C^{\#c}_i) = -1\).

It is worth observing that the procedure described above does not ensure that exactly \(\#c\) negative cost cycles are introduced, but the value \(\#c\) indicates the minimum number of negative cost cycles present in the network.

The second group of instances are derived from Capacited \( VRP \) (\(C VRP \)) test problems taken from the scientific literature. We have considered ten sets of test problems. Each set is associated with the scientific contribution in which the corresponding test problems have been introduced for the first time.

Table 1 shows the name of each set, the paper in which the related test problems have been introduced, the number of problems and the characteristics of the instances in terms of number of nodes (i.e., the maximum and the minimum number of nodes over the networks belonging to the considered set are reported).

Table 1 Characteristics of the \(C VRP \) benchmark instances

In order to test the algorithm for the \( ESPP \) on the \(C VRP \) test problems, we have considered the related \( RCESPP \), that is, the pricing problem obtained when a branch and price approach is used to solve the \(C VRP \). First, we have modified the \(C VRP \) test problems by adding a prize at each node. As described in [48], the value of each prize can be chosen in the range [1, 20]. The cost of a path is the sum of the cost associated with the arcs minus the prizes collected at the nodes. Second, we get the \( ESPP \) instances by considering the Lagrangean relaxation of the \( RCESPP \). Indeed, given a Lagrangean multiplier, the problem is an instance of the \( ESPP \). For each \( RCESPP \) test problem we have considered 20 \( ESPP \) instances by choosing several values for the Lagrangean multiplier. These values are selected in a such way that instances with different degree of complexity are obtained: the lower the value of the Lagrangean multiplier, the more difficult the \( ESPP \) instances. As suggested in [6], the Lagrangean multiplier is set equal to \(0.1, 0.2, \ldots , 2\) for the \(1^{st}\), the \(2^{nd},\ldots ,\) the \(20^{th}\, ESPP \) instances. Thus we have tested \(4060\, ESPP \) instances.

3.2 Test codes

The codes considered in this work are named DMLA, implementing Algorithm 1 described in Sect. 2.2; and the code DLA is related to Algorithm 4, defined in Sect. 2.3.

Considering DLA, in order to select a node from L, see line 5 of Algorithm 3, we implement the FIFO strategy. In addition, at each iteration, the costs for each node are inizialized by considering the partial solutions obtained in the previous iteration. In particular, the set L contains all nodes such that at least one path has been determined in the previous iteration and the labels are those available at the end of the previous iteration. Of course, for the nodes belonging to the detected cycle, the dimension of the associated label is incremented by one. This type of initialization speeds up the search process at each iteration.

The same type of initialization is not possible for DMLA. Indeed, at each iteration, an additional resource is introduced, augmenting the dimension of each label. Since the efficiency of a solution is affected by the dimension of the associated label, a solution that in the previous iteration was dominated, with the new definition of the label could represent an efficient sub-path. For this reason, in DMLA the initialization is that reported in Algorithm 2.

3.3 Computational results

In this section, we analyze the behaviour of the proposed solution approaches. In the next section we focus on the results collected when solving the first group of instances, that is, the fully random networks. In Sect. 3.3.2, the resulting best performing algorithm on the first group of instances is tested on the second one.

3.3.1 Computational results on the fully random networks

The collected results are organized in three classes. The first one is related to the instances with \(\#c \in [1,10]\), the second class to those with \(\#c\in [11,20]\) and the results obtained on the instances with \(\#c\in [21,30]\) belong to the third class. In what follows, we present a summary of the collected computational results. A more detailed accounting of the experiments is given in [18].

Results for DMLA. The results are collected in Table 2, where the average execution time (column time) and the average number of iterations (column iter) are reported for each value of the indicator \(\#c\). It is worth observing that the column iter reports the average number of executions of Algorithm 2 in Algorithm 1. As expected, the computational results underline that the higher the number of negative cost cycles, the higher the execution time. Table 2 shows that the computational cost for solving the second and the third class of instances is 15.77 and 197.54 times higher than the execution time required to solve the instances of the first class.

Table 2 Average execution time in ms and average number of iterations obtained by DMLA when solving the first, the second and the third class of test problems

This behaviour can be justified by considering the number of iterations. Indeed, DMLA performs, on average, 8.53, 28.65 and 48.30 iterations, for the instances belonging to the first, the second and the third class, respectively. Figure 1 shows the trend of the average computational cost and the average number of iterations with respect to the indicator \(\#c\) of the number of negative cost cycles.

Fig. 1
figure 1

Average execution time and average number of iterations of DMLA as a function of the indicator \(\#c\) of the number of negative cost cycles

From Figure 1, it is clear that the computational cost grows exponentially with respect to the increase of the number of negative cost cycles, whereas, a linear trend is observed for the number of iterations. This behaviour is due to the fact that the higher the number of negative cost cycles, the higher the execution time per iteration. In particular, the time per iteration grows exponentially with the indicator \(\#c\) of the number of negative cost cycles. This trend is shown in Figure 2.

Fig. 2
figure 2

Average execution time per iteration of DMLA as a function of the indicator \(\#c\) of the number of negative cost cycles

Table 3 Average execution time in ms and average number of iterations obtained by DLA when solving the first, the second and the third class of test problems

A possible explanation of this trend can be found by considering the dimension of the state-space induced by the definition of the labels. Indeed, the state-space is composed by states associated with efficient partial solutions. The number of Pareto-optimal solutions is strongly related to the dimension of the labels. Indeed, the higher the number of negative cost cycles, the higher the dimension of the labels due to the fact that a higher number of additional node resources must be introduced. In addition, as shown in [5, 9, 21], the number of non-dominated solutions increases exponentially with the size of the labels. As a consequence, the state-space grows exponentially with the increase of the number of the negative cost cycles.

Results for DLA. In Table 3, we report the average computational cost under column time and the average number of times Algorithm 3 is called by Algorithm 4 under column iter, for each value of the indicator \(\#c\). As expected, the higher the number of negative cost cycles the higher the execution time. Indeed, the computational cost for solving the instances belonging to the second and the third class is 3.63 and 7.05 times higher than that required for the instances of the first class. This behaviour is justified by the number of iterations executed by DLA. In particular, DLA performs 3.81 and 8.59 times higher number of iterations for the second and the third class of instances, respectively, than that executed by the algorithm for solving the instances belonging to the first class.

Figure 3 shows the trend of the computational cost and the number of iterations executed by DLA.

Fig. 3
figure 3

Average execution time and average number of iterations of DLA as a function of the indicator \(\#c\) of the number of negative cost cycles

From Figure 3, it is evident that both the execution time and the number of iterations present the same trend. In particular, both parameters show a linear trend. However, the average execution time and the average number of iterations grow faster for \(\#c > 26\) than the increasing observed for \(\#c \le 26\).

Comparison The results underline that DLA behaves the best. Indeed, on average, DMLA is 88.89 times slower than DLA. However, it is worth observing that the number of iterations performed by DLA is 2.03 times higher than that of DMLA. The worst performance in terms of computational cost of DMLA is due to the average time per iteration. Indeed, the time per iteration obtained with DLA is 93.87 times lower than that of DMLA.

Table 4 Average execution time in ms and average number of iterations varying the density

Table 4 shows the performance of DMLA and DLA varying the density, that is, the ratio between the number of arcs and the number of nodes. Density does not seem to strongly affect the number of iterations executed by DMLA, that are almost the same for all three different values of density tested. In addition, the computational time of DMLA increases, on average, by the 45 % and 11 % when the density value varies from 10 to 30 and from 30 to 50, respectively. In addition, the execution time is less than doubled when the density increases from 10 to 50. The results summarized in Table 4 underline a different situation for DLA, whose performance is more affected by the density than DMLA. Indeed, when the density increases from 10 to 30 and from 30 to 50 the execution time of DLA increases more than 2 and 2.5 times, respectively. In addition, the computational time is multiplied by a factor of five when the density increases from 10 to 50.

From Figure 4, it is possible to observe that the higher the number of negative cost cycles, the higher the difference, in terms of execution time, between DLA and DMLA. More specifically, DLA is 4.85, 21.04 and 135.75 times faster than DMLA for the instances belonging to the first, the second and the third class, respectively.

Fig. 4
figure 4

Average execution time in ms of DMLA and DLA as a function of the indicator \(\#c\) of the number of negative cost cycles

The DLA behaves better than DMLA for two main reasons: 1) DMLA is strongly affected by the dimension of the label; 2) DLA takes advantage of the fact that it maintains the partial solutions at each iteration. This aspect justifies the lower computational cost per iterations.

3.3.2 Computational results on \(C VRP \) benchmark instances

In this section, we evaluate the behaviour of the best performing algorithm, that is, DLA by considering the \(C VRP \) benchmark instances. An execution time limit of one hour for each instance has been imposed.

Table 5 Results obtained on the instances derived from \(C VRP \) benchmark test problems

The results collected on the corresponding \( ESPP \) instances are summarized in Table 5. We report the name of the set under the first column, the column min \(\lambda \) reports the minimum value of the Lagrangean multiplier such that at least one instance is solved, the last three columns show the numerical results obtained. In particular, for each set, we have considered average results for each value of the Lagrangean multiplier. Under column min, we report the minimum values related to the time (in seconds), number of iterations (iter), number of distinct cycles (cycles) detected during the execution of the DLA and the percentage (%) of the instances solved, evaluated over all the average results, obtained for each value of the multiplier. Under column max the maximum values and under column mdm the medium values on all the instances associated with each set. It is worth observing that the first six sets, that is, \(F,\, A-A,\, A-B,\, A-P,\, CE\), and S contain instances associated with \(C VRP \) test problems for which the optimal solution is known. The remaining four sets are composed of instances for which the related \(C VRP \) test problems are not solved to optimality.

The average results reported in Table 5 (see row AVG) underline that on all the considered test problems, in the medium case, the \(60\,\%\) of instances are solved within the time limit of one hour. In the worst case, only the \(21\,\%\) of instances is solved, whereas \(95\,\%\) of instances are solved in the best case (see row AVG, column max of Table 5). It is worth observing that for the first six sets, at least one instances with the Lagrangean multiplier equal to 0.1 is solved (see column min \(\lambda \) of Table 5). For the remaining sets, DLA is able to solve at least one instance with the Lagrangean multiplier equal to \(0.7,\, 0.6,\, 0.6\), and 0.3 for set \(B,\, CMT,\, T\), and GWKC, respectively.

In addition, even though the best performance is observed for the first six sets of instances, the results collected on the other sets can be considered satisfactory. Indeed, the average percentage of solved problem is of 17, 44 and 87 % in the worst, medium and best case, respectively.

4 Conclusions

In this paper we have investigated the shortest path problem in presence of negative cost cycles. This study is the first attempt to provide solution methods for the single-source all-destinations shortest path problem with negative cost cycles. The scientific literature provides strategies that are able to determine the presence of negative cost cycles and algorithms for solving the elementary shortest path problem on graph with negative cost cycles in conjunction with resource consumption constraints.

Two different strategies have been devised to solve to optimality the problem under investigation. The main idea behind the proposed solution approaches is to compute, for each node, the minimum number of paths such that the shortest paths from the source node to all others nodes are determined. In addition, the two methods dynamically increase the number of paths that have to be found for some node. The main difference among the proposed approaches is related to the way in which the number of paths is incremented. In the first method, the number of paths that have to be found is determined by considering a dummy node resource that keeps trace about the visiting at the node. This results in a constrained multi-objective shortest path in which the node associated with the dummy resource can be visited only once along the paths. The second proposed approach is based on the idea behind the k shortest paths methods. In particular, the value of k is different per node and it is incremented each time a further path that passes through such a node is needed in order to avoid a negative cost cycle. The theoretical complexity of the proposed solution approaches in the worst case is derived.

The proposed optimal strategies have been evaluated empirically on a large set of test problems. In particular, we have considered two groups of instances. The first one refers to fully random networks, the second group contains the instances derived from vehicle routing problem benchmarks. Referring to the first group of instances, we have considered instances with up to 500 nodes and 25000 arcs with 30 negative cost cycles at least present in the networks. The experiments underline the superiority of the innovative strategy based on the k shortest paths problem. Indeed, it outperforms the dynamic programming based approach. In particular, the best performing algorithm is able to solve the instances based on fully random networks with 500 nodes, 25000 arcs and at least 30 negative cost cycles in about 5 seconds.

The proposed method based on the k shortest paths problem has been tested on instances derived from the vehicle routing problem benchmarks. In particular, we have considered two classes of test problems: the first one refers to those that the literature solves to optimality, the second class contains the test problems for which only near optimal solutions are known. Starting from the vehicle routing problem benchmarks we have derived several instances of the elementary shortest path problem with a different degree of difficulty. The computational results suggest that the best performing algorithm solves to optimality near to all the more difficult instances belonging to the first class within a reasonable amount of time. For the instances of the second class, the solution approach based on the k shortest paths problem does not solve the more difficult instances. However, despite to the NP-hard complexity of the problem, the numerical results are satisfactory.

From the computational results, we can conclude that the solution approach based on the k shortest paths problem is very efficient for solving the elementary shortest path problem on medium-large size fully random networks. In addition, the proposed method is able to solve in a reasonable amount of time instances derived from the vehicle routing problem benchmarks.