Abstract
We consider the problem of moving a connected set of railcars, which we refer to as a train, from an origin layout to a destination layout in a railyard, accounting for the special structure of the railyard network and the length and orientation of the train. We propose a novel shortest path algorithm for determining a sequence of moves that minimizes the total distance (and associated time) required to move a train from its origin to destination. A railyard network consists of a set of track sections connected via switch points, which correspond to points at which three sections of track come together, such that one pair of the track segments forms an acute angle (and the other two pairs form obtuse angles). A train’s ability to traverse a switch node depends on the train’s length and whether or not its desired route involves traversing the acute angle or an obtuse angle at the switch. The shortest route problem for a train is further complicated by the fact that a train’s position on the network at any point in time may span multiple nodes in the network. We propose an easily explained solution approach that addresses the complications associated with switch points and the train’s length to determine a shortest route from origin to destination in \({\mathcal {O}}(e + n \log n)\) operations, where n and e correspond to the number of switch nodes and edges in the network respectively.
Introduction
A typical freight rail network consists of a set of rail hubs, usually in large metropolitan areas, connected to one another via main line tracks that may span hundreds of miles between hubs. A hub facility acts as an origin point, destination point, and sorting facility for various freight railcars. Routine daily operations at a rail hub include receiving trucks that drop off intermodal freight bound for other cities via rail, offloading railcars from arriving trains for pickup by trucks for regional intermodal distribution, disassembling railcars from arriving trains from other hubs, and assembling railcars into outbound trains destined for other hubs.
The combined activities of disassembling incoming trains and assembling outbound trains require frequently moving and repositioning subsets of connected cars within the railyard using a locomotive to either push or pull the cars. We will refer to any set of connected cars that requires movement via a locomotive generically as a train. Efficient disassembly and reassembly of cars requires moving trains within the railyard network as quickly as possible. Thus, given a subset of cars that requires repositioning in the railyard network, we wish to find the shortest route from an origin location to a destination location in order to minimize total repositioning time. A fast solution procedure for these problems is necessary since repositioning cars occurs frequently.
The associated shortest route problems contain features that make them fundamentally different from classical shortest path problems on a network. These differences arise from the structure of the railyard network, the length and orientation of a train, and restrictions on movements trains face in the network. For example, a train approaching a node in the network via a given edge cannot necessarily proceed directly onto any other edge connected to the node (where we define a node in the network as a point at which three or more sections of track meet). In particular, if the section of track from which the train enters the node forms an acute angle with another section of track connected to the node, then the train cannot proceed directly onto the latter edge from the former. It may be possible, however, for the train to proceed onto a section of track connected to the node that forms an obtuse angle with the train’s direction of entry, travel entirely past the node, and then to reverse direction onto the edge forming an acute angle with the train’s original direction of entry to the node. Note that this is only possible if a sufficient amount of track exists to permit the train to fully pass the node and then reverse direction.
In addition to the complications resulting from acute angles in the railyard network, we also encounter the possibility that the length of the train may span multiple nodes in the network at the same time due its length. This requires a different characterization of the train’s position in the network than is typically used in classical shortest path problems. Moreover, a train’s original and final desired orientation in the network may differ. We define a train’s orientation based on the end of the train at which the locomotive is attached, as well as whether the locomotive is pushing or pulling the train. Thus, if we denote the end of the train with a locomotive as the positive \((+)\) end (and the other end as the negative \(()\) end), when the locomotive is pulling the railcars, the \((+)\) end is leading the direction of motion. This complication sometimes arises as a result of which end of the train a locomotive can more easily access to initiate movement, as well as the ease with which the locomotive can be disconnected from the train after moving to the train’s final layout. If, for example, the train’s final layout falls on a deadend track segment, then it is often necessary to ensure that the locomotive pushes the train onto the deadend segment (with the \(()\) end leading) so that it can easily disconnect from the train and move to another track segment without being blocked.
Motivated by the need to frequently reposition trains in the railyard network, we consider the shortest route problem for a train in a railyard network, given a train’s origin and destination positions in the network, as well as its initial and final orientation. We provide an intuitive approach for solving this problem, which results in an algorithm that is relatively easy to implement and to describe. The worstcase performance of this algorithmic approach is no worse than an implementation of Dijkstra’s classical shortest path solution algorithm using Fibonacci heaps, i.e., \({\mathcal {O}}(e + n \log n)\) for a network with n nodes and e edges (see Fredman and Tarjan [7]). We note that Enayaty Ahangar, Sullivan, Spanton, and Wang [5] recently developed an algorithm for solving problems in this class with the same worstcase complexity in terms of \({\mathcal {O}}(\cdot )\) notation. While the worstcase bound of our approach is the same when expressed as a function of the number of nodes n and edges e in the original train network, we demonstrate that our shortest route approach requires fewer total arcs in the corresponding shortest path network, which reduces the computational requirements for any instance. Our approach also permits a relatively straightforward and compact description, which facilitates ease of implementation while accounting for the fact that a train’s position can span multiple nodes.
The remainder of this paper is organized as follows. The following section discusses related literature in the area of train routing. Section 3 then formalizes the problem definition, after which Sect. 4 discusses two algorithmic approaches for its solution. Section 5 then characterizes the complexity associated with our solution approaches, while Sect. 6 provides concluding remarks.
Related literature
A large volume of literature exists dealing with the application of operations research and analytics techniques to railroad freight scheduling and routing problems. Cordeau et al. [2] provide an excellent overview and classification of work in this area. The majority of this work focuses on the flow of rail traffic between and through the various railyards comprising a nationwide or international rail network. A railcar entering the system at a railyard, or terminal, is typically classified into a block, implying that it is grouped with a set of cars that are assigned a common destination. A block’s designated destination may not correspond to the final destination of each car in the block. If the block’s destination does not correspond to a car’s destination, then the car must be reclassified at the block destination for further transport. A nonlinear mixedinteger optimization model and solution method for determining a yard’s blocking policy is provided in [1]. This multicommodity flow model specifies a finaldestinationdependent classification block for any car at a given railyard. The combined problem of scheduling train departures at each yard and assigning blocks to scheduled trains is considered in [8]. This work models the multicommodity flow problem on an expanded timespace network and applies integer programming and heuristic techniques to obtain highquality solutions. While this prior stream of work on blocking problems emphasizes larger tactical planning problems of moving freight from origin to destination via multiple railyards, we focus on operations within a railyard.
A significant body of prior work considers models that measure railyard operations performance measures, intended to characterize throughput times of cars or blocks through a railyard. Petersen [10] provides a thorough description of typical railyard activities and develops a queuing model to predict train throughput times. Turnquist and Daskin [13] refined this queuing analysis to account for individual carlevel processing times and considered the impacts of different dispatching approaches. In [3], the authors further considered the way in which different block sorting strategies influence average yard performance measures. A common approach in practice for analyzing the way in which different policies and strategies affect railyard throughput performance is to create a simulation model that accounts for random train arrivals, block sorting strategies, and departing train dispatch rules [2]. Our focus in this paper lies in addressing a problem that significantly contributes to railyard throughput performance, i.e., the most efficient movement of a connected set of cars through the railyard from an origin to a destination.
Several past works have considered the problem of simultaneously routing multiple trains through a common set of tracks and platforms such that no collisions occur and some measure of service performance is achieved (e.g., each passenger train has an arrival time and a desired departure time, and the objective is to ensure that each train departs before its desired departure time; see, e.g., [14]). In [12], the authors provide a mixedinteger optimization formulation and a metaheuristic solution approach for realtime selection of routes when different trains may desire the same track at the same time. They use an objective of minimizing targeted departure delays. For each train, their approach determines a subset of routes selected from among the existing routing alternatives available for each train. Lange and Werner [9] take a different approach by modeling train path assignments as a jobshop problem. Each track or track section is equivalent to a machine, while each train corresponds to a job; as a result, each route corresponds to an ordered set of operations performed on a set of machines. Conflicts are therefore eliminated by assigning one job (train) at a time to a machine (track).
Despite the high volume of literature on blocktotrain assignment and scheduling in rail freight, as well as in the area of routing multiple passenger trains through common tracks to adhere to a schedule, relatively little work exists that explicitly considers routing decisions within a railyard while accounting for the unique network topology and train travel restrictions inherent in a freight railyard network. Two relatively recent notable exceptions exist. Riezebos and Wezel [11] consider the problem of determining the k shortest paths for a train in a shunt yard with an objective of minimizing the number of crossovers and direction changes associated with each path. Their model treats each section of track as a node in the network with an associated direction of travel and does not account for the fact that a freight train may span multiple track sections at any given time (the application context on which they focus deals with overnight repositioning of selfpropelled coach cars). The arc costs in the associated network account for distances between track segments as well as crossover and direction change penalties. The most closely related work to ours is that of Enayaty Ahangar et al. [5], who consider the same shortest freighttrain route problem in a railyard network. We rely on a preprocessing stage they developed as our initial step, which determines, for a given train length and railyard network topology, which acuteangle turns in the network are feasible. We then propose a shortest route solution approach based on the solution of an equivalent shortest path problem, which differs from their approach. Our approach requires fewer nodes and arcs in the corresponding shortest path graph, which determines the number of computations required using common shortest path methods, such as Dijkstra’s algorithm [4]. In addition, our proposed approach arguably lends itself to a less complex description, which facilitates easier implementation. We next define this problem and describe our proposed solution approach.
Problem definition
This section defines the structure of the railyard networks we consider, as well as the constraints this network imposes on train travel. A railyard network consists of a set of tracks that are connected to one or more main tracks via lead tracks (where the main tracks lead to other railyards). Track length can span over ten thousand feet, and numerous sections of tracks are connected to one another via switch points. A switch point corresponds to a point at which three or more track sections meet, enabling an approaching train to depart the switch point via multiple directions. Figure 1 illustrates a typical railyard layout.
A railyard switch point permits a train to travel onto two different tracks. Hence, a typical switch point involves three track segments converging at a point such that the angle formed by one of the pairs of track segments is acute, while the angles formed by the other two pairs are obtuse. A crossover is essentially a pair of switches that facilitate connections between two parallel tracks. A double crossover corresponds to a pair of crossovers which permit travel between two parallel tracks regardless of travel direction (crossovers are depicted with an \(\times \) in Fig. 1.)
Physical constraints restrict a train to only depart a switch point via a track segment that forms an obtuse angle with the track segment on which it approaches the switch. In our network representation of the railyard, each switch point defines a node in the network. We assume without loss of generality that exactly three track segments meet at any node, where a track segment defines an edge in the network. If, for example, four or more edges meet at a node, we can create copies of the node with zero distance between the node and its copies, where the original node and each copy are incident to three edges (see Fig. 2). After making any required adjustments to ensure that exactly three edges meet at any node, each such node may be viewed as a connection point between two inline track segments and another segment that forms an acute angle with this line; equivalently, each node creates two supplementary angles, one of which is acute and the other obtuse.
We define a train as a car or set of cars attached to one another on the network, which must move as a single entity on the network. Given a rail network on which a train lies, we can describe the train’s layout on the network with a series of nodes that form a subpath in the network (see Fig. 3), which characterize the train’s position in the network.
The goal of the shortest train route problem is to find the shortest distance (or time) required to move a train in the network from some initial layout to some final layout (Fig. 4a, b illustrate two sample networks with initial and final locations of a train indicated).
Recall that a train approaching a switch node may continue travelling without delay onto the track segment with which its current track segment forms an obtuse angle. Whether or not it can travel back onto the other acuteangle leg depends on the train’s length and whether a sufficient amount of available track space exists to allow the entire train to pass the switch node and then reverse direction. If we let L denote the train’s length, then the railyard network must be able to accommodate a length of L on the other side of the switch node via the obtuse angle leg in order for the train to entirely pass the node, reverse direction, and then proceed onto the other acuteangle leg. We say that a switch node is backable by a train of length L if the train is able to traverse its acute angle, and we refer to such a move as a doubleback. Figure 5 illustrates a sequence of moves in which a train performs a doubleback move on an acute angle.
In [5], the authors define acuteanglefree cycles in a network. An acuteanglefree (AAF) cycle is the one that starts at a node and returns back to it without traversing an acute angle. Figure 6 demonstrates a sample AAF cycle. For example, if a train travels from node 6 to node 5, it can then visit nodes 1, 2, and 3, in that order, and return to node 5 without having traversed any acute angles. (Observe that the ability to traverse an AAF cycle without any acute angle turns may depend on the train’s direction of travel, i.e., the same cycle in Fig. 6 cannot be traversed without an acute angle turn when visiting nodes in the sequence 15321.) For networks such that all AAF cycles have length of at least L (the train’s length), Enyaty Ahangar et al. [5] provide a polynomialtime preprocessing routine that determines whether each node is backable (for networks that permit AAF cycles of any nonnegative length, they show that this preprocessing problem is \({{\mathcal {N}}}{\mathcal {P}}\)Hard). We confine our analysis to networks that do not possess such AAF cycles of length less than L, assuming therefore that we can use the algorithm in [5] to determine whether each angle in the network is backable in polynomial time for a given train of length L. The output of this preprocessing step, i.e., whether or not each node is backable, will serve as an input to our solution approach discussed in Sect. 4.
We will first present each of our solution approaches without regard for the train’s orientation, i.e., assuming only the initial and final locations of the train are specified, independent of the location of the \((+)\) and \(()\) ends within the layout. Later, we present modifications needed to account for a desired orientation of the train within its final layout position. Using this approach, a train’s desired final layout on the network can be characterized by those nodes on top of which the train will lie, plus two outer nodes that bound the outermost cars of the train (these “outer nodes” of a layout correspond to the first node the lead car of the train will reach by traveling in either direction). Suppose that in the final layout, the train covers a set of \(\eta \) nodes. For example, \(\eta \) equals two in Fig. 3. This creates at most \(\eta + 2\) candidate “final layout entry nodes" (the \(\eta \) nodes spanned by the train plus the two outer nodes). We refer to these as final layout entry nodes because the train must reach its final layout by entering one of these nodes from some node not among the final layout nodes. Thus, the train enters its final layout by traversing one of these final layout entry nodes. For example, in Fig. 4a or b, in order for the train to reach its final layout, it must enter node 4, and because the train’s final layout does not span any other nodes, node 4 is the only final layout entry node for the networks illustrated in the figures. Given a candidate final layout entry node and whether or not it is backable, we can efficiently determine whether the train’s entry to its final layout via this node is feasible.
Our solution approaches will require differentiating between the different edges incident to a given node i, and we adopt the convention used in [5] by referring to the pair of edges that form an acute angle at node i as edges 2(i) and 3(i), while the remaining edge corresponds to edge 1(i) (see Fig. 7).
Let \({\mathcal {F}}\) denote a set of feasible final layout entry nodes. We will refer to a final layout entry node i as an O (one) entry node (OEN) if it is in \({\mathcal {F}}\) and the train must achieve its final layout by entering the node via either 2(i) and 3(i) from some node not in \({\mathcal {F}}\) and subsequently exiting the node via edge 1(i); otherwise the final layout entry node is a T (two/three) entry node (TEN). Node 4 in Fig. 4 is an OEN.
Similarly to the train’s final layout, we assume without loss of generality that the train’s initial layout is defined by a set of m nodes spanned by the train, plus the two outer nodes corresponding to the first node reached by traveling in either direction. This creates at most \(m + 2\) candidate “start nodes" via which the train may begin its route. For example, in Fig. 4a or b, the train must start its route from node 1, and because the train’s layout does not span any other nodes, node 1 is the only start node for these networks. If the train must be moved into start node i by approaching via edge 2(i) or 3(i) and exiting via edge 1(i), then we will refer to that start node as an O start node (OSN); otherwise, the start node is a T start node (TSN). Note that node 1 in Fig. 4 is a TSN.
Observe that any train route through the railyard network must consist of a set of alternating directed AAF walks (where a directed AAF walk corresponds to a sequence of edges/nodes such that that no consecutive edges in the sequence form an acute angle). These AAF walks are adjoined by backable nodes at which doubleback moves are made for direction changes. As we move along a given direction, any time we reach a node, if we continue traversing an edge without doublebacking (i.e. from 1(i) to one of 2(i) or 3(i) or vice versa), then we are continuing an AAF walk in the same direction; otherwise, we switch to the opposite direction when a doubleback move is made. Note that a feasible solution exists if at least one set of consecutive AAF walks exists that is connected by backable nodes between one of the start nodes and one final layout entry node.
The problem therefore is to find the shortest route between an initial and final layout that consists of a feasible sequence of alternating and adjoining directed AAF walks in the network.
Solution approach
This section proposes two methods for obtaining the shortest route from an initial to final layout for a single train on a railyard network. We differentiate between a train’s shortest route through the rail network, which may contain doubleback moves, and the classical simple shortest path problem in a network, which is characterized by a sequence of nodes and associated arcs that provide the shortest distance between an origin node and a destination node in the network. Although the approach described in Sect. 4.1 requires greater computational time in the worst case, it is very easy to describe, understand, and implement, and its presentation lays a foundation for describing the improved method presented in Sect. 4.2.
Allshortestpaths approach
Section 4.1.1 first presents the approach without considering the train’s orientation, i.e., when orientation is unimportant, while Sect. 4.1.2 later presents modifications needed to account for the train’s orientation. We refer to the solution approaches described in Sects. 4.1.1 and 4.1.2 as allshortestpaths methods, as they determine a shortest path from every node to each reachable node in an appropriately defined subnetwork. This is not, however, equivalent to solving the wellknown allpairs shortest path problem (see, e.g., Fredman [6]), which determines the shortest directed path between every pair of nodes in a network.
Orientationfree approach
This approach uses network information on how nodes are connected to one another in the network, as well as whether direction changes are required using doubleback moves at any given node. A node j is Oreachable (OR) from node i if a path exists starting at i and exiting via 1(i), which leads to node j without making any acute angle turns, and without completely traversing any AAF cycles. Similarly, a node j is Treachable (TR) from i if a simple path exists beginning at i and exiting via 2(i) or 3(i), which leads to node j without any acute angle turns, and without completely traversing any AAF cycles. Observe that it is possible for a node to be both Oreachable and Treachable from a given node when AAF cycles exist in the network. Given any node, it is straightforward (using a recursive algorithm, such as depthfirst or breadthfirst search) to construct the subnetwork whose node set consists of all OR nodes from the node, along with all edges with both ends incident to nodes in this node set; let \(\textit{OR}(i)\) denote this subnetwork. It is similarly straightforward, for any given node, to construct the subnetwork with node set consisting of all TR nodes from the node, along with all edges with both ends incident to nodes in this node set; let \(\textit{TR}(i)\) denote this subnetwork. Examples of these subnetworks are illustrated in Fig. 8, which depicts a set of subnetworks associated with the example network shown in Fig. 4b.
Some additional discussion on the construction of subnetworks \(\textit{OR}(i)\) and \(\textit{TR}(i)\) is warranted when AAF cycles exist in the railyard network. Such cycles are not overly common in railyard networks, and typically exist for the purpose of temporary railcar storage. Despite this, we still account for the possibility of their presence in constructing a solution approach. Note that assuming a feasible route exists from the origin to destination, it is easy to show that if we are indifferent to the train’s orientation on the network, an optimal shortest train route always exists that does not completely traverse an AAF loop. In other words, a path in which the train reverses direction before entering an AAF loop always has shorter length than one that traverses that loop. For example, for the subnetwork shown in Fig. 6, any path that traverses the subpath 51235 has a path length that is strictly greater than one that stops at node 5 and reverses direction. Because of this, if train orientation is not a concern, when we apply a recursive algorithm to construct the set of Oreachable or Treachable nodes starting from some node i, if we find that we have reached some node k for a second time when following an AAF walk from node i, then this implies that we have fully traversed an AAF cycle, and we can discontinue following that particular AAF walk in the construction of \(\textit{OR}(i)\) or \(\textit{TR}(i)\) from such a node (although we do need to ensure exploring all possible AAF walks from node i in constructing the corresponding \(\textit{OR}(i)\) or \(\textit{TR}(i)\) network). When orientation is important, however, as we later discuss in Sect. 4.1.2, we cannot discontinue the exploration along an AAF walk after a second instance of a node is encountered in the subnetwork because traversal of an AAF cycle may be necessary to change the train’s orientation.
Observe that if node j is Oreachable from node i, then finding the shortest route of the train in \(\textit{OR}(i)\) from a layout in which the train exits node i via 1(i) and arrives at node j is equivalent to finding a simple shortest path from node i to j in the subnetwork \(\textit{OR}(i)\). Conversely, if node j is Treachable from i, then finding the shortest train route in \(\textit{TR}(i)\) from a layout in which the train starts at node i and moves along 2(i) or 3(i) and ends at j is equivalent to finding a simple shortest path from node i to j in the subnetwork \(\textit{TR}(i)\).
Suppose then that we first solve an allshortestpaths problem without any doubleback moves, i.e., for each node i (for a total of n nodes), we find the shortest path to each OR node in \(\textit{OR}(i)\) and to each TR node in \(\textit{TR}(i)\) and retain this information. That is, for each node in the original network, we make a list of all OR and TR nodes and their associated shortest path and distance. Using a Fibonacci heap implementation of Dijkstra’s algorithm, in the worst case, this requires \({\mathcal {O}}(en + n^2 \log n)\) computations, where n is the number of nodes in the network.
We next define a new shortest path graph. This graph is built based on the idea that every feasible path in the railyard network corresponds to a sequence of alternating doubleback moves from the train’s initial location to its final destination. This new shortest path graph contains two layers; layer T and layer O, with a copy of each node in the network in each layer. For each node i we refer to these copies as nodes iT and iO. Traversing node iT means the train exits node i via 2(i) or 3(i), while traversing iO implies that the train exits node i via 1(i).
The following provides a more explicit definition of the five types of arcs needed to connect nodes in the resulting shortest path graph. Figure 9 illustrates the shortest path network’s layers and arcs using the example shown in Fig. 4b.

1.
Source arcs Recall that we begin with at most \(m + 2\) feasible start nodes (consisting of the m nodes covered by the initial layout plus the outer nodes bounding the train) associated with an initial path. Thus, we create a source node s that connects to each valid start node, with an arc of length equal to the distance required to move the train from its initial position to the start node. If start node i is an OSN (i.e., the train enters node i via 2(i) or 3(i) and exits via 1(i)), then the source connects to the start node in layer O; if the start node is a TSN (i.e., the train enters node i via 1(i) and exits via 2(i) or 3(i)), the source connects to the start node in layer T.

2.
Sink arcs In a similar fashion to the source, we create a dummy sink node t, and for each of at most \(\eta + 2\) feasible final layout entry nodes, we create an arc from layer O to the dummy sink node if the entry node i is an OEN (i.e., the train enters node i via 2(i) or 3(i) and exits via 1(i)); otherwise, the entry node connects to the sink node from layer T. The associated arc length is the distance required for the train to reach its final position from each final layout entry node to the final train layout.

3.
T Exit arcs Consider a node i in layer T; if the node is backable, we create an arc from iT to each node \(j \ne i\) in layer O that is in \(\textit{TR}(i)\) and has the potential to accommodate a subsequent doubleback move, i.e., any node j in \(\textit{TR}(i)\) such that the shortest path from node i to j in \(\textit{TR}(i)\) enters node j via 2(j) or 3(j) (in other words, \(j \in TR(i)\) and \(i \in TR(j)\)). The corresponding arc length equals the shortest path length in \(\textit{TR}(i)\). If a final layout entry node j is in \(\textit{TR}(i)\) and cannot be used for a subsequent doubleback move after leaving node i on 2(i) or 3(i), then we connect node iT to node jT (providing a path to the sink node; observe that if node j is a final layout entry node that is not backable, then it cannot be an OEN and must be a TEN). Doing this for all i in layer T completes the set of arcs leaving nodes in layer T. Note that an arc (i, j) within layer T is only created if node j is a final layout entry node that is not backable in \(\textit{TR}(i)\) after leaving node i, and is reachable from node i after exiting on 2(i) or 3(i).

4.
O Exit arcs Consider a node i in layer O; if node i is an OSN, we create an outgoing arc from iO to any node \(j \ne i\) in layer O that is in \(\textit{OR}(i)\) and can be used for a subsequent doubleback move (i.e., such that we enter node j via 2(j) or 3(j) in \(\textit{OR}(i)\) after exiting node i). The associated arc length equals the shortest path length in \(\textit{OR}(i)\). If a final layout entry node j is in \(\textit{OR}(i)\) and cannot be used for subsequent doubleback move after leaving node i, we connect iO to node jT (providing access to the sink node).

5.
Doubleback arcs If node i is backable, we create an arc with length L (the train length) from iO to node iT. This corresponds to the added distance required along edge 1(i) for making a doubleback move. Traversing these arcs corresponds to a doubleback move. In other words, we first exit node i via 1(i) and then immediately reverse and exit node i via 2(i) or 3(i). Observe that if a node is backable, it is always possible to fully pass such a node and then reverse direction. Therefore, in the final shortest path graph, a given node can only have an arc leaving layer O and connecting to the same node index in layer T if it is indeed backable.
We call the resulting shortest path graph the OT Layered (OTL) graph. The shortest path from source node s to sink node t determines the shortest train route over the original network considering the doubleback moves. This solution consists of a start node, a sequence of nodes at which the train performs doubleback moves, and a final entry node and, by construction, a path exists in the OTL graph for each feasible path in the original train network. The length of each path in the OTL network also correctly reflects the associated path length on the original network, plus the distance required for doubleback moves. The need to compute the shortest path in \(\textit{TR}(i)\) and \(\textit{OR}(i)\) for each node i requires solving n shortest path problems, each of which requires \({\mathcal {O}}(e + n \log n)\) operations using a Fibonacci heap implementation of Dijkstra’s algorithm. Thus, the total number of operations required for solving n such problems is \({\mathcal {O}}(ne + n^2 \log n)\). The OTL graph contains \({\mathcal {O}}(n)\) nodes and \({\mathcal {O}}(n^2)\) arcs and its solution, therefore, requires \({\mathcal {O}}(n^2 + n \log n)={\mathcal {O}}(n^2)\) operations. As a result, the complexity of the overall solution approach is \({\mathcal {O}}(ne + n^2 \log n)\).
Accounting for orientation
We next consider how to extend the approach to account for the train’s orientation. When considering orientation, the location of the locomotive relative to the train becomes important, i.e., whether the locomotive pulls or pushes the train into its final location. This is particularly important in cases where the final layout lies on a deadend of a track, where it is undesirable to have the locomotive trapped behind the railcars. In Fig. 10, for the train shown in the left figure to have reached its illustrated location and orientation, the locomotive may have either pulled the railcars through node 1, or it may have pushed them through node 2. However, for the train shown on the right, the locomotive would have needed to push the railcars through node 3 to prevent becoming trapped between the railcars and the track’s deadend. We next explain how we can manipulate the OTL graph to ensure achieving not only a final train layout, but one with a desired orientation.
Assume we have a locomotive on one end of the train designated as the \((+)\) end, and suppose we create a duplicate of each node in layer O and each node in layer T. That is, for each node iO we create nodes \(iO^+\) and \(iO^\), and for each node iT, we create nodes \(iT^+\) and \(iT^\). Entry to \(iO^+\) and \(iT^+\) corresponds to node i entry with the locomotive pulling, while entry to \(iO^\) and \(iT^\) corresponds to node i entry with the locomotive pushing. A doubleback move now corresponds to traversing arc (\(iO^+\), \(iT^\)) when the locomotive pulls into the doubleback move node and pushes out of it, and to arc (\(iO^\), \(iT^+\)) when the locomotive pushes in the doubleback move node and pulls out of it. All other arcs in the graph must go from a \((+)\) node to a \((+)\) node or from a \(()\) node to a \(()\) node. In addition, if node i can subsequently be reached after departing node i (by traversing an AAF cycle), such moves correspond to arcs of the form (\(iO^+\), \(iT^+\)), (\(iO^\), \(iT^\)), (\(iT^+\), \(iO^+\)), and (\(iT^\), \(iO^\)). Traversing these arcs results in a change in direction relative to node i while maintaining either a pushing or pulling orientation. For each node i that is in \(\textit{OR}(i)\) or \(\textit{TR}(i)\), we determine the shortest path from the node back to itself in \(\textit{OR}(i)\) and \(\textit{TR}(i)\) to determine the length of these AAF loop arcs.
For a final layout entry node i, we only connect to the sink node if the entry to the node has the proper orientation. For example, if node i is a final layout entry node that must be approached using edge 1(i) and exited via 2(i) or 3(i) with the locomotive pulling, then only node \(iT^+\) connects to the sink node. If node i is a final layout entry node that must be approached using edge 2(i) or 3(i) and exited via 1(i) with the locomotive pulling, then only node \(iO^+\) connects to the sink node. Similarly, if node i is a final layout entry node that must be approached using edge 1(i) and exited via 2(i) or 3(i) with the locomotive pushing, then only node \(iT^\) connects to the sink node. And if node i is a final layout entry node that must be approached using edge 2(i) or 3(i) and exited via 1(i) with the locomotive pushing, then only node \(iO^\) connects to the sink node.
Similarly, to connect the source node to start node(s), if leading with the \((+)\) end of the train (pulling) requires approaching start node i using 1(i) (2(i) or 3(i)), then we connect the source node to \(iT^+\) (\(iO^+\)) with the corresponding path length. If leading with the \(()\) end of the train (pushing) requires approaching start node i using 1(i) (2(i) or 3(i)), then we connect the source node to \(iT^\) (\(iO^\)) with the corresponding path length. Figure 11 illustrates the orientationbased network’s layers and arcs using the example shown in Fig. 4b. Compared to Fig. 9, it is clear that the number of arcs increases to accommodate for train orientation.
This extension to permit accounting for the train’s orientation results in an OTL graph with twice the number of nodes and arcs, while maintaining the same worstcase complexity bound.
Improved approach
We next describe an approach that eliminates the need for the allshortestpaths solution and results in an improved worstcase complexity. We continue to assume without loss of generality that each node is incident to three edges, two of which form an acute angle. Given a node i, we refer to edges that form an acute angle as edges 2(i) and 3(i), and we call the remaining edge 1(i) (see Fig. 7).
For any node traversed by the train, we can identify an edge of entry and an edge of departure. Observe that entry to node i via edge 1(i) permits continuing along edge 2(i) or 3(i) without an acuteangle turn, while entry via either edge 2(i) or 3(i) permits continuing along edge 1(i) without an acuteangle turn. However, entry via 2(i) (3(i)) with a departure along edge 3(i) (2(i)) requires turning along the acute angle via a doubleback move. Note that if edge 1(i) in Fig. 7 does not connect to another node to its left, then it is not strictly necessary to define a leaf node at the end of this edge, because whether we can change direction at i is only dependent on the backability of node i, which is determined in the preprocessing stage. Such edges can be used to accommodate doubleback moves, however (in which case the train proceeds from 2(i) to 3(i), or vice versa).
We create two layers of the graph, which we will refer to as the Push and Pull layers. In general, these Push and Pull layers are independent of the direction of movement, and simply differentiate the orientation of the train. As illustrated in Fig. 12, we create four copies of each node, with two in each of the Push and Pull layers of the graph. We now have upper and lower layers as well, where the copy of node i in the upper layer corresponds to entry via edge 1(i) (call these \(iU^+\) for pulling, and \(iU^\) for pushing), while the copy of node i in the lower layer corresponds to entry via edge 2(i) or 3(i) (call these \(iL^+\) for pulling and \(iL^\) for pushing). For instance, node \(iU^+\) corresponds to the train entering node i via 1(i) with locomotive pulling the railcars.
We next define four necessary arc types to create our shortest path graph (note that we will use the notation 2(i)/3(i) to correspond to either edge 2(i) or edge 3(i)). Figure 12 illustrates the shortest path graph for the example problem illustrated in Fig. 4a, assuming all acute angles in the network are backable (the figure omits some arc directions for convenience).

1.
Source arcs Recall that we consider at most \(m + 2\) valid starting nodes. From the source node, if leading with the \((+)\) end of the train (pulling railcars) requires approaching start node i using 1(i) (2(i)/3(i)), then we connect the source node to \(iU^+\) (\(iL^+\)). Alternatively, if leading with the \(()\) end of the train (pushing) requires approaching start node i using 1(i) (2(i)/3(i)), then we connect the source node to \(iU^\) (\(iL^\)). The length of the arc equals the shortest distance required to move the train to the corresponding start node.

2.
Sink arcs For each of at most \(\eta + 2\) feasible final layout entry nodes, if the final orientation of the train requires that the locomotive approaches the entry node with the \((+)\) end of the train (pulling railcars), then we connect the entry node to the sink node only from the Pull layer. On the other hand, if the final layout must be achieved with locomotive pushing the railcars, then we connect the entry node to sink node from the Push layer. The associated arc length equals the distance required to move the train from the feasible entry node to its final position.

3.
Through arcs For each edge (i, j) in the rail network:

If edge 2(i)/3(i) equals edge 1(j), i.e., pulling into node i via 1(i) and using arc (i, j) leads to pulling into node j via 1(j), we create an arc (\(iU^+,jU^+\)). We also create arc (\(iU^,jU^\)) corresponding to travel on arc (i, j) from i to j with the locomotive pushing the railcars.

If edge 2(i)/3(i) equals edge 2(j)/3(j), we create an arc (\(iU^+, jL^+\)), which corresponds to pulling into node i via 1(i) and traveling directly to node j via 2(j)/3(j). We also create arc (\(iU^, jL^\)) corresponding to traveling on arc (i, j) from i to j with the locomotive pushing the railcars.

If edge 1(i) equals edge 2(j)/3(j), we create an arc (\(iL^+, jL^+\)) corresponding to pulling into node i via 2(i)/3(i) and traveling directly to node j via 2(j)/3(j). We also create arc (\(iL^, jL^\)) corresponding to traveling on arc (i, j) from i to j with the locomotive pushing the railcars.

If edge 1(i) equals 1(j), we create an arc (\(iL^+, jU^+\)) which represents pulling into node i via 2(i)/3(i) and traveling directly to node j via 1(j). We also create arc (\(iL^, jU^\)) corresponding to traveling on arc (i, j) from i to j with the locomotive pushing the railcars.


4.
Doubleback arcs Crosslayer arcs connecting the Pull and Push layers enable doubleback moves. Therefore, arc (\(iL^+ , jL^\)) indicates that the train pulls railcars into node i via 2(i)/3(i), makes a doubleback move resulting in an orientation change, and pushes the railcars into node j via 2(j)/3(j). Similarly, arc (\(iL^ , jL^+\)) represents the move with the reverse orientation. On the other hand, arc (\(iL^+ , jU^\)) permits pulling railcars into node i via 2(i)/3(i), making a doubleback move, and continuing via pushing into 1(j). The arc (\(iL^ , jU^+\)) corresponds to the same move with the orientation reversed.
The arcs in the graph within the Push and Pull layers now represent the lengths of the corresponding edge in the original network, while the arc lengths between layers include the length of the edge plus the train’s length L. Thus, the length of the shortest path found over this graph correctly corresponds to the associated route on the original network. An arc within the Pull (Push) layer corresponds to a simple move from one node to another without making any doubleback move, while an arc between the two layers corresponds to an acute angle turn via a backable node. As a result, the between (Push and Pull) layer arcs correspond to entering and leaving some node j via edge 2(j) or 3(j) (and, therefore, such arcs always depart the Push or Pull layer from the set of nodes in lower layers). Note that in this structure, the pull or push orientation does not change when train traverses an AAF cycle and the associated cycle arcs remain within the pull or push layer for such cycles.
We call this graph the expanded shortest path graph. Each feasible train route in the original railyard network has a corresponding path in the expanded graph, and the shortest path from the source node to the sink node in the graph thus gives the shortest train route in the original railyard network considering doubleback moves. Note that each time we jump from the left layer to the right (or vice versa), this implies that the train has changed orientation in terms of pulling or pushing, via a doubleback move at a switch node. As discussed before, this improved approach does not require the allshortestpaths solution for each node, and this results in better worstcase complexity.
Complexity
The shortest path graph associated with the improved approach contains \(4n + 2\) nodes and \(4e+2n\) arcs. Using a Fibonacci heap implementation of Dijkstra’s algorithm to compare the two approaches, the solution of this shortest path problem thus has worstcase complexity of \(O(e + n \log n)\) for the improved approach. Although the complexity of the algorithms we provided are \(O(ne + n^2 \log n)\) and \(O(e + n \log n)\) for the allshortestpaths and improved approaches respectively, the required number of nodes and arcs for the final graph are as follows:

Allshortestpaths approach: The number of nodes is \(4n + 2\), and the number of arcs is at most \(2n^2 + 2n\);

Improved approach: The number of nodes is \(4n + 2\), and the number of arcs is at most \(4e + 2n\),
where n and e denote the number of switch nodes and edges in the original network, respectively. Note that if we ignore the pulling and pushing requirements in the allshortestpaths approach, the associated numbers of nodes and arcs become \(2n + 2\) and \(n^2 + 2n\), respectively. However, as discussed in Sect. 4.1, the complexity of this approach is dominated by the need to compute shortest paths for each node’s Treachable and Oreachable subnetworks, which results in an overall complexity of \({\mathcal {O}}(ne + n^2 \log n)\).
The number of nodes and arcs of the final graph in the approach proposed in [5] are \(4m + 8n + 2\) and \(4e + 12n + 4\), respectively, where m is the total number of nodes (switch and leaf nodes). Thus, although our approach utilizes the preprocessing step introduced in [5], and both approaches solve a shortest path problem over a transformed network representation, our improved approach requires fewer nodes and arcs in the corresponding shortest path graph, which is the key to determining the required computational effort in shortest path algorithms. Figure 13 shows the reduction in the number of nodes and arcs in the corresponding shortest path graph provided by the improved approach when compared with the method in [5] (the figure assumes \(e=\frac{3n}{2}\), where n is the number of switch nodes, and that the number of leaf nodes equals 10% of the number of switch nodes). The realworld instances tested in [5] contain around 4,600 nodes. Thus, the difference in computational time and effort can be nontrivial when needing to solve problems of this type repeatedly in practice.
Discussion and conclusion
This work proposed two related approaches for constructing an expanded version of a railyard network, over which any shortest path algorithm can be applied to find the shortest feasible route of a single train from an initial position to a final location on the network. We based our analysis on a Fibonacci heap implementation of Dijkstra’s classical shortest path algorithm, although any shortest path algorithm can be utilized over the constructed networks to find the shortest feasible route solution. The proposed polynomialtime algorithms account for the geometric restrictions of the railyard network, with switch points serving as possible points for changing direction if the length of track connected to the switch node can accommodate the length of the train. We note that the proposed improved approach is easier to implement compared to previous works because it only requires accounting for the network’s switch nodes and also uses a more compact network representation. Another contribution of our approach is that it allows a train to span multiple nodes in the network at any point in time, while accounting for train orientation by distinguishing between pull and push moves and expanding the shortest path approach accordingly. Future work may include addressing the problem of determining the minimum time required to simultaneously route multiple trains on the network without collisions.
Data availability
Data sharing is not applicable to this article as no datasets were generated or analysed during the current study.
References
 1.
Bodin, L., Golden, B., Schuster, A., Romig, W.: A model for the blocking of trains. Transp. Res. Part B 14(1–2), 115–120 (1980)
 2.
Cordeau, J., Toth, P., Vigo, D.: A survey of optimization models for train routing and scheduling. Transp. Sci. 32(4), 380–408 (1998)
 3.
Daganzo, C., Dowling, R., Hall, R.: Railroad classification yard throughput: the case of multistage triangular sorting. Transp. Res. Part A 17(2), 95–106 (1983)
 4.
Dijkstra, E.: A note on two problems in connexion with graphs. Numer. Math. 1(1), 269–271 (1959)
 5.
Enayaty Ahangar, N., Sullivan, K., Spanton, S., Wang, Y.: Algorithms and Complexity Results for the SingleCut Routing Problem in a Rail Yard. Working Paper, University of Arkansas, Fayetteville, AR. https://industrialengineering.uark.edu/_resources/scrp20210603.pdf (2021)
 6.
Fredman, M.: New bounds on the complexity of the shortest path problem. SIAM J. Comput. 5(1), 83–89 (1976)
 7.
Fredman, M., Tarjan, R.: Fibonacci heaps and their uses in improved network optimization algorithms. J. ACM 34(3), 569–615 (1987)
 8.
Jha, K., Ahuja, R., Şahin, G.: New approaches for solving the blocktotrain assignment problem. Networks 51(1), 48–62 (2008)
 9.
Lange, J., Werner, F.: Approaches to modelling train scheduling problems as jobshop problems with blocking constraints. J. Sched. 21(2), 191–207 (2018)
 10.
Petersen, E.: Railyard modeling: part I. Prediction of putthrough time. Transp. Sci. 11(1), 37–49 (1977)
 11.
Riezebos, J., Wezel, W.: kshortest routing of trains on shunting yards. OR Spectr. 31(4), 745–758 (2009)
 12.
Sama, M., Pellegrini, P., D’Ariano, A., Rodriguez, J., Pacciarelli, D.: Ant colony optimization for the realtime train routing selection problem. Transp. Res. Part B 85, 89–108 (2016)
 13.
Turnquist, M., Daskin, M.: Queuing models of classification and connection delay in railyards. Transp. Sci. 16(2), 207–230 (1982)
 14.
Zwaneveld, P., Kroon, L., Romeijn, H., Salomon, M.: Routing trains through railway stations: model formulation and algorithms. Transp. Sci. 30(3), 181–194 (1996)
Author information
Affiliations
Corresponding author
Additional information
Publisher's Note
Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Rights and permissions
About this article
Cite this article
Aliakbari, M., Geunes, J. & Sullivan, K.M. The single train shortest route problem in a railyard. Optim Lett 15, 2577–2595 (2021). https://doi.org/10.1007/s1159002101761w
Received:
Accepted:
Published:
Issue Date:
Keywords
 Shortest path
 Railyard network
 Routing
 Polynomialtime algorithm