Modeling the 0-1 Knapsack Problem in Cargo Flow Adjustment

China’s railway network is one of the largest railway networks in the world. By the end of 2016, the total length of railway in operation reached 124,000 km and the annual freight volume exceeded 3.3 billion tons. However, the structure of network does not completely match transportation demand, i.e., there still exist a few bottlenecks in the network, which forces some freight flows to travel along non-shortest paths. At present, due to the expansion of the high-speed railway network, more passengers will travel by electric multiple unit (EMU) trains running on the high-speed railway. Therefore, fewer passenger trains will move along the regular medium-speed lines, resulting in more spare capacity for freight trains. In this context, some shipments flowing on non-shortest paths can shift to shorter paths. And consequently, a combinatorial optimization problem concerning which origin-destination (O-D) pairs should be adjusted to their shortest paths will arise. To solve it, mathematical models are developed to adjust freight flows between their shortest paths and non-shortest paths based on the 0-1 knapsack problem. We also carry out computational experiments using the commercial software Gurobi and a greedy algorithm (GA), respectively. The results indicate that the proposed models are feasible and effective.


Introduction
China's railway network is one of the largest railway networks in the world.By the end of 2016, the total length of railway in operation reached 124,000 km and the annual freight volume exceeded 3.3 billion tons.Typically, all the shipments travel along their pre-specified paths.However, these paths do not remain unchanged.In fact, they need to be adjusted in the following situations: (1) When new high-speed railways are built and a number of passenger flows are diverted to them.
Hence, the regular medium-speed lines will have more spare capacity for freight trains.(2) When some existing lines are rebuilt for capacity expansion so that more shipments can flow on them.(3) When a new line shortening the distance between two nodes on the opposite sides of a circle is built.(4) When natural disasters happen or track maintenance is carried out, reducing the capacity of railway lines.For example, annual spring maintenance lasting for around 25 days is conducted on the Datong-Qinhuangdao railway, which is known as the most famous coal-transport corridor in China.During the period, the available service time of the line will decrease by 4 h each day, which translates into a decline of coal transportation of about 200,000 tons per day.In other words, there will be a decrease of 5 million tons in total for the whole maintenance period.
For the first three situations, namely, (1), ( 2) and (3), shipments flowing on the non-shortest paths should be diverted to their shortest paths; while in situation (4), a part of shipments should shift to longer paths.The freight flow adjustment problem arising in these cases can be formulated as a typical combinatorial optimization problem.
As for the cargo flow adjustment problem, most previous studies have been devoted to flow assignment models.Lin et al. [1] studied the problem of finding the feasible path set for each O-D pair in a railway network.Du and Ji [2] analyzed the marginal cost and benefit of diverting car flows from one railway to its parallel line by taking the Beijing-Guangzhou railway and Beijing-Kowloon railway as an example.Ye et al. [3] calculated the shortest path of a car flow and discussed the impact of the Xinyi-Changxing railway on flow adjustment.Su and Chen [4] presented a multi-objective 0-1 programming model and converted it into a single objective formulation.He successfully achieved the adjustment of freight flow between the Baoji-Zhongwei railway and the Baoji-Lanzhou railway.Tian et al. [5] studied the car flow distribution problem and adopted artificial arcs to deal with infeasible flows.Zhao et al. [6] investigated the freight empty car allocation problem with dynamic demands, and formulated a stage-based optimization model.To address the real-time traffic management problem and car scheduling problem, Corman et al. [7] developed a new tabu search scheme and designed a computational experiment based on practical size instances from a dispatching area of the Dutch railway network.Sadykov et al. [8] considered a variant of the freight railcar flow problem.They formulated the problem as a multi-commodity flow problem in a large space-time graph and proposed three approaches for the linear programming relaxation of the formulation.Borndörfer et al. [9] investigated the freight train routing problem from a strategic perspective, calculating the routes in a macroscopic transportation network of Deutsche Bahn AG.The above literature mainly focuses on freight flow path optimization from the perspective of the whole railway network.In fact, changes of structure or capacity often occur in partial network, so fine-tuning is valuable for rail operators.However, there is little work devoted to this issue.Many researchers have studied in-depth the problem of passenger flow assignment problem.Zhou et al. [10] analyzed the distribution characteristics of the components of travel time, and proposed an estimation method of the path-selecting proportion.Han et al. [11] established a stochastic user equilibrium model for solving the passenger flow assignment problem in a schedule-based rail transit network.Fu et al. [12] proposed a train stop scheduling approach combining a passenger flow assignment procedure.Nguyen et al. [13] presented a new graph theoretic framework for the passenger assignment problem that encompassed simultaneously the departure time and the route choice.Cominetti and Correa [14] analyzed a Wardrop equilibrium model for passenger assignment in general transit networks, including the effects of congestion over the passengers' choices.
As this paper proposes an applicable method to adjust freight flows between parallel railways based on the 0-1 knapsack problem, some related studies should be noted for this problem.Pisinger [15] defined the classical knapsack problem and gave an overview of exact solution approaches.He also pointed out that the previous benchmark tests were limited to a few highly constructed instances, which did not show the full characteristics of the knapsack problem.Poirriez et al. [16] presented a new approach for solving the unbounded knapsack problem and proposed an efficient and robust hybrid algorithm.Frenkel et al. [17] studied the effect of free and direct products on the time complexity of knapsack-type problems in groups, which were the natural generalizations of the classic knapsack and related problems to arbitrary (non-commutative) groups.He showed that free products in certain sense preserve the time complexity of knapsack-type problems, while direct products may amplify it.Rooderkerk and Heerde [18] developed a robust approach to optimize retail assortments and proposed a novel, efficient and real-time heuristic for addressing this 0-1 knapsack problem.In the following sections, the knapsack problem and flow adjustment problem (FAP) are described in detail.

The Unbounded Knapsack Problem
As a typical non-deterministic polynomial-time hard (NP-hard) problem, the unbounded knapsack problem (UKP) is defined as follows: We are given a set of n types O = {o 1 , o 2 , ..., o n } of items without quantity restriction.Items of the same type share a common weight w i and a common value ϕ i .The problem is to choose a subset of these items aiming to maximize their overall value, while their overall weight does not exceed a given capacity c.Without loss of generality, it should be assumed that all values and weights are positive, all weights are smaller than the capacity c, and the overall weight of all items exceeds c.The model of UKP problem can be formulated as follows: where x i represents the number of items of type o i included in the knapsack.

The 0-1 Knapsack Problem
The 0-1 knapsack problem is one of the most extensively studied combinatorial optimization problems.The objective of this problem is to maximize the total value of items in the knapsack, and the constraint is to ensure the sum of the weights is less than or equal to the knapsack capacity.There is only one item of each type and only two options for each item, i.e., included in the knapsack or not.Each item cannot be put into the knapsack more than once or be partially included in the knapsack.Similar problems have arisen in other fields, e.g., information encryption, decision-making in engineering projects and cargo loading.The 0-1 knapsack problem can be formulated as follows: where y i denotes whether the item of type o i is included in the knapsack.

Flow Adjustment Models Based on the 0-1 Knapsack Problem
To describe in detail the method of adjusting freight flows between parallel railways, we construct a simplified regional railway network consisting of 6 stations and 6 links, as shown in Figure 1.There are two paths from station 1 to station 6, i.e., path A: 1→2→5→6 and path B: 1→2→3→4→5→6; path A is the shorter one., ,..., ,..., { } 1 2 , ,..., ,..., where i A f is the numerical value of shipment i traveling along path A, and j B f denotes the numerical value of shipment j flowing on path B. Notations used in our models are described as Table 1.

c′ Δ
Capacity reduction of path A.
Average speed of freight trains.

Decision Variables Representation
and 0 otherwise.
and 0 otherwise.

Models for Flow Adjustment from Non-Shortest Path to the Shortest Path
Let us assume that a high-speed railway was built along path A recently.In this context, some passenger flows will be gradually diverted from the regular medium-speed line to this new highspeed railway.Therefore, fewer passenger trains will travel along path A, resulting in more spare capacity for freight trains.Consequently, some shipments can be adjusted from path B to path A. If we regard the spare capacity of path A as a knapsack and the shipments on path B as different types of items, the flow adjustment problem is equivalent to a 0-1 knapsack problem.When we simply take Let F A be the set of all shipments traveling along path A, and F B contains all shipments flowing on path B. We assume that F A consists of shipments while F B comprises n shipments, so the two sets can be expressed by: where f i A is the numerical value of shipment i traveling along path A, and f j B denotes the numerical value of shipment j flowing on path B.
Notations used in our models are described as Table 1.
Average speed of freight trains.

Decision Variables Representation
x k B→A decision variable.x k B→A equals 1 if shipment f k B is adjusted to path A; and 0 otherwise.
A is adjusted to path B; and 0 otherwise.

Models for Flow Adjustment from Non-Shortest Path to the Shortest Path
Let us assume that a high-speed railway was built along path A recently.In this context, some passenger flows will be gradually diverted from the regular medium-speed line to this new high-speed railway.Therefore, fewer passenger trains will travel along path A, resulting in more spare capacity for freight trains.Consequently, some shipments can be adjusted from path B to path A. If we regard the spare capacity of path A as a knapsack and the shipments on path B as different types of items, the flow adjustment problem is equivalent to a 0-1 knapsack problem.When we simply take the unit transportation cost of each freight flow into consideration, the FAP can be formulated as follows: (FAP-1) The objective function ( 9) seeks to maximize the overall cost savings.The constraint (10) ensures that the total volume of adjusted shipments is smaller than the spare capacity ∆c.
In model FAP-1, transportation time cost is not considered.In fact, the time sensitivities of different commodities are quite different, for example, bulk commodities (e.g., coal, ore and oil) are not sensitive to transportation time, whereas high-value commodities (e.g., industrial equipments and fresh foods) are very sensitive.Therefore, it is necessary for us to take into account the time cost of different shipments.In other words, parameters representing time cost should be introduced.The objective function can be re-formulated by: The second term in formula (12) denotes the overall time cost savings.For simplicity, the generalized unit transportation cost µ k B is defined as follows: In this manner, the modified flow adjustment model considering transportation time cost can be expressed below: (FAP-2) Subjectto It should be noted that, although model FAP-1 is similar to model FAP-2, and function ( 9) can be converted to function (14) by simply replacing λ with µ k B , there is an essential difference between these two models.

Models for Flow Adjustment from the Shortest Path to Non-Shortest Path
In this section, we assume that the annual track maintenance is going to be conducted on path A. During this period, there will be a substantial reduction of freight capacity ∆c of path A. As a result, some shipments should shift to the non-shortest path B. Without loss of generality, let us assume that the spare capacity of path B is larger than ∆c .Apparently, the essence of this problem is to divert a number of flows from path A to path B with the objective of minimizing the operation cost.Similarly, this kind of problem can be regarded as a variant of the 0-1 knapsack problem. (FAP-3) Note that, constraint ( 10) is different from constraint (18) which ensures that the overall volume of adjusted flows is no smaller than the capacity reduction ∆c .
If we consider both time costs and transportation costs of different commodities, another modified flow adjustment model (FAP-4) can be expressed by: (FAP-4) In model FAP-1 and FAP-3, we only consider the transportation cost, while in model FAP-2 and FAP-4, time cost is taken into account so as to produce a more practical flow adjustment plan.

Computational Experiments
In this section, numerical experiments are conducted to test the feasibility of models using the optimization software Gurobi.For comparison, a greedy algorithm, which is widely used in rail transportation practice, is implemented.

Computational Experiments Based on Flow Adjustment Models
To test the feasibility and efficiency of our models, several computational experiments are designed.

Computational Experiments for Model FAP-1 and FAP-2
We make the following assumptions: the spare freight capacity of path A is ∆c = 20 million tons per year; the length of path A is l A = 726 km and that of path B is l B = 837 km; the unit transportation cost is λ = 0.1 ¥/ton-km.There are 30 shipments (the volume is virtual) moving on path B, whose volume and generalized transportation cost µ k B are shown in Table 2.

Computational Experiments Based on the Greedy Algorithm
The greedy algorithm is a heuristic algorithm which makes the locally optimal choice at each stage aiming at finding a global optimum.In many problems, a greedy strategy does not in general produce an optimal solution, but may yield locally optimal solutions approximating a global optimal solution in a reasonable time.Greedy algorithms can produce optimal solutions on some mathematical problems which have following properties: (1) The greedy choice property.
We can make whatever choice seems best at the moment and then solve the sub-problems that arise later.The choice made by a greedy algorithm may depend on the choice made so far, but not on future choices or all the solutions to the sub-problem.
(2) An optimal substructure.A problem exhibits an optimal substructure if an optimal solution to the problem contains optimal solutions to the sub-problem.Some literature which is closely related to greedy algorithms should be noted.Rao et al. [19] proposed an optimization algorithm, combining a greedy selection scheme, to produce solutions with succinct atomic representations for signal reconstruction problems.Davis and Impagliazzo [20] defined an abstract model that captured the intrinsic power and limitations of greedy algorithms for various graph optimization problems.Cerrone et al. [21] applied carousel greedy, an enhanced greedy algorithm which sought to overcome the traditional weaknesses of greedy approaches, to a variety of well-known problems in combinatorial optimization.

Applying the Greedy Algorithm to Model FAP-1 and FAP-2
In rail transportation, the greedy algorithm is widely used and its flowchart is shown in Figure 2. In rail transportation, the greedy algorithm is widely used and its flowchart is shown in Figure 2. According to the flowchart previously mentioned, we adopt the greedy algorithm to adjust shipments from path B to path A. Based on the data in Table 2, the computational result (denoted as Solution GA-1) is expressed by: { } We find that the total volume of these shipments is 19,930 thousand tons, decreasing by 70,000 There are two situations that should be taken into account, i.e., adjusting flows from non-shortest path to the shortest path and the other way around.We respectively propose two models (a basic model and a modified model) for each situation.The objective functions of two basic models (FAP-1 and FAP-3) are to maximize cost savings and to minimize operation cost growth, respectively.With consideration of transportation time cost, basic models are then modified to be more reasonable and practical.To test the feasibility and effectiveness of FAP models, computational experiments are conducted by using Gurobi.The results show that these models can efficiently address the flow adjustment problem and produce satisfactory solutions.For comparison, the greedy algorithm widely used in rail transportation is also applied to the instances.Computational results illustrate that FAP models outperform the greedy algorithm in solution quality.For future research work, researchers can focus on efficient solution approaches for the flow adjustment problem when the freight capacities of several paths change simultaneously.

Figure 1 .
Figure 1.A simplified railway network.Let A F be the set of all shipments traveling along path A, and B F contains all shipments flowing on path B. We assume that
sought to overcome the traditional weaknesses of greedy approaches, to a variety of well-known problems in combinatorial optimization.4.2.1.Applying the Greedy Algorithm to Model FAP-1 and FAP-2

Figure 2 .
Figure 2. Flowchart of the greedy algorithm.

Figure 2 .
Figure 2. Flowchart of the greedy algorithm.

Table 1 .
Notations and their representations.
A lLength of path A. B l Length of path B. c Δ Spare capacity of path A.

Table 1 .
Notations and their representations.
∆cSpare capacity of path A.∆c Capacity reduction of path A.

Table 2 .
Shipments on path B.

Table 3 .
Shipments on path A.