You are on page 1of 4

Stack loading and unloading problems: an application to rail freight transportation

Federico Malucelli Dipartimento di Elettronica e Informazione, Politecnico di Milano Stefano Pallottino Dipartimento di Informatica, Universit` a di Pisa
Via F. Buonarroti 2, I56127 Pisa, Italy, tel. +39-050-2212737, e.mail: pallo@di.unipi.it

Daniele Pretolani Dipartimento di Matematica e Informatica, Universit` a di Camerino


Abstract The problems of loading and unloading a stack at dierent stages has many applications, particularly in rail freight transportation. We study three particular problems of loading and unloading a stack through a sequence of handling operations; each handling operation consists in removing from the top of the stack a given subset of elements and then inserting at the top of it another subset of elements. Note that the two subsets are not necessarily disjoint. A handling operation can load new elements into the stack and/or unload previously loaded elements. It is assumed that elements have dierent types, and must be unloaded in increasing order of type. Besides the two basic problems of unloading an unsorted full stack, and loading an empty stack so that at the end of the loading it is perfectly sorted (in increasing order of type), we consider a third problem which is a combination of the former two: given an empty stack, bursts of loading operations are performed before all unloading ones. The objective is to perform the minimum number of insertions and removals of the elements. Our intention is to prove that the problems are all solvable in polynomial time and describe the algorithmic approaches. In particular the loading-unloading problem requires a solution approach which is not a trivial combination of those provided for the unloading and the loading cases. Some explicative examples prove that the optimal solution of the third problem can not be derived from the optimal solutions of the former two problems.

The Stack Loading and Unloading


We consider some problems related to the optimization of loading and unloading operations in a stack, i.e., a sequence of objects in a row in which the only allowed operations are insertions or removals from the same side of the row. This kind of model can be applied in the optimization of the classication of a freight train visiting a sequence of stations. In this operation, using dierent parallel tracks, cars are sorted in such a way that, at the end of the operation, each track contains cars with a common destination. Each line of cars with the same destination produced by the classication operation is a block, and the sequence of blocks gives the nal composition of the train [1]. Therefore we may think of having a train with a predetermined route given by a sequence of stations. Station i requires that all cars having destination i are detached from the train. Station i may also supply new cars to be added to the train having destination one of the subsequent stations in the route. It is often the case that it is not worth doing a complete classication at each station depending on the number of cars with same destination present in the train or depending on the cars that have to be attached to the train in the next stations. Indeed, if we count the number of cars that are removed and added again to the train, sometimes it is better to postpone the classication in order to minimize this number. Let us introduce the stack model and the notation. We consider a stack S = {S [1], . . . , S [n]}, that is an integer array where elements of dierent types can be inserted and removed at the top, by means of push and pop operations. The type is denoted by an integer in the interval [1, T ], without loss of generality we can assume that there exists at least one occurrence of each type. The number of elements of type t is denoted by ut . Clearly
T t=1

u t = n.

Here we consider three problems which can be solved in polynomial time [2].

The Stack Unloading Problem


We start with a full stack S where 1 is the top, that is the index of the rst non-empty element of S . The stack must be emptied in T stages from stage 1 to stage T . During stage t, all the elements of type t must be removed. This may require to pop some elements of type t > t, that must be pushed again at the end of stage t. Elements popped from the stack can be pushed in any order. The goal is to minimize the total number of push operations. A feasible unloading strategy is dened by the number of pops performed at each stage t, which allows to remove all elements of type t from the stack, assuming that the elements which need to be introduced back into the stack are pushed in non increasing order of type, that is in the most suitable way. This operation is called reordering. The measure of the overhead at stage t is dened by the number of push operations during the reordering. The simplest feasible unloading strategy

removes from the stack all elements down to the deepest one of type t and, consequently, reordering all elements of type t > t which have been removed. However if we aim at minimizing the total number of pushes it may be worthwhile, at any stage t, to remove more elements than those strictly necessary, thus anticipating some work to be done in successive stages. In the extreme case, at the rst stage we may remove all elements in order to obtain a completely ordered stack after the popped elements are pushed back into it. We present a polynomial algorithm that nds the feasible unloading strategy with the minimum number of push operations, and show its behavior with a small example.

The Stack Loading Problem


Starting with the empty stack, a set of b n batches of elements of possibly dierent types must be loaded in successive steps. At the end of the loading phase, we want the elements to appear in the stack in non-decreasing order; this means that the stack can be unloaded without performing any push. It is then allowed to pop some elements at a step i and to reinsert them, together with the elements of batch i, through a reordering operation, whose additional cost is dened by the number of pops. A feasible loading strategy is dened by the number of pops at the beginning of the steps, and its cost is the total number of pops. The simplest strategy is to perform the pops only at the beginning of the last step; however, to minimize the number of pops we can advantageously reorder the bottom of the stack at previous steps. We prove that the problem of nding a feasible loading strategy with minimum number of pops can be solved in polynomial time, and we present the algorithmic approach with a small example.

The Stack Loading+Unloading Problem


Now, let us consider the loading+unloading (L+U) case where a number of loading steps is followed by the unloading stages. This time, we assume that the reordering operations can take place during any step of the loading phase and any stage of the unloading phase. The objective is to minimize the sum of pop and push operations performed during the two phases. This may give rise to a smaller number of operations with respect to the previous two strategies. In fact, through a counter-example we show that an optimal loading strategy followed by a zero-cost unloading strategy, and a zero-cost loading sequence followed by an optimal unloading strategy are both dominated by a mixed strategy. A mixed strategy is a sequence of, possibly null, pop operations at the loading steps followed by a sequence of, possibly null, push operations at the unloading stages; its cost is the sum of the pop and push operations. We prove that nding a mixed strategy of minimum cost is a polynomial problem and give the corresponding algorithm. An illustrative example concludes the presentation. 3

References
[1] Crainic, T., J.-A. Ferland, J.-M. Rosseau, Multicommodity, multimode freight transportation: a general modeling and algorithmic framework for the service network design problem, Transportation Research B, 20B (1986) 225-242. [2] Malucelli F., S. Pallottino and D. Pretolani, The Dynamic Stack Loading and Unloading Problem, unpublished paper (2000).

You might also like