Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Train Marshalling Problem Joe Ryan University of Ballarat joint work with Elias Dahlhaus, Peter Horak and Mirka Miller.

Similar presentations


Presentation on theme: "The Train Marshalling Problem Joe Ryan University of Ballarat joint work with Elias Dahlhaus, Peter Horak and Mirka Miller."— Presentation transcript:

1 The Train Marshalling Problem Joe Ryan University of Ballarat joint work with Elias Dahlhaus, Peter Horak and Mirka Miller

2 Outline of Talk 1.Define the problem 2.TMP is NP-Complete Reduction from NMTS TMP  NMTS 3.Upper bound in terms of n 4.Conclusion

3

4 The Train Marshalling Problem The cars have different destinations, we use auxiliary rails to rearrange their order so that all cars with the same destination will be grouped together. Since, in general, there may be several trains at the station to be processed at the same time, the target is to use as few auxiliary rails as possible for each train. 1611273458910

5 1611273458910 Station 1: Cars 1,6,11 Station 2: Cars 5,10 Station 3: Cars 3,8 Station 4: Cars 2,7 Station 5: Cars 4,9 Track A Track B Track C Track D Reassemble the train from Track D followed, in order, by tracks C, B and A.

6 1856311274910 Station 1Station 2Station 5Station 3Station 4 Train Ready to Distribute Carriages

7 The Train Marshalling Problem Given a partition S of { 1,…,n } into disjoint sets S 1,…,S t, find the smallest number k = K( S ) so that there exists a permutation p(1),…,p(t) of { 1,…,t } with the property: The sequence of numbers 1,2,…,n,1,2,…,n,…,1,2,…,n, where the interval 1,2,…,n is repeated k times, contains all the elements of S p(1), then all elements of S p(2),… etc., and finally all elements of S p(t).

8 The Train Marshalling Problem n = 11 1,2,3,4,5,6,7,8,9,10,11 S = {S 1,S 2,S 3,S 4,S 5 } S 1 = {1,6,11} S 2 = {5,10} S 3 = {3,8} S 4 = {2,7} S 5 = {4,9} k = K( S ) = 4 1 2345 6 78910 11,1 2 3456 78 91011,12 34 5678 910 11,1234 5 67891011

9 Numerical Matching with Target Sums* a 1,a 2,a 3, …,a i,…,a j,…,a k,…,a n-1,a n b 1,b 2,b 3, …,b i,…,b j,…,b k,…,b n-1,b n c 1,c 2,c 3, …,c i,…,c j,…,c k,…,c n-1,c n + = + = * Garey and Johnson:- Problem SP17

10 Numerical Matching with Target Sums Instance: positive integers I : a 1,a 2,…,a n,b 1,b 2,…,b n,c 1,c 2,…c n Question: Are there permutations  1 and  2 such that for all i = 1,2,…n, a  1 (i) + b  2 (i) = c i ? Restriction a i  2, b i  2, c j  b i, c j  a i + 2.

11 The Reduction Let a 1,a 2,…,a n,b 1,b 2,…,b n,c 1,c 2,…c n be positive integers satisfying the restrictions. Let N = n  c i. To the set (train) I N = { 1,2,…,N } we assign a partition, R, of 2n elements (destinations); S 1,…,S n,T 1,…T n. Divide the train into blocks X 1,X 2,…X n and subblocks X i = D i j, j = 1,…,c i (in order).

12 The Reduction For any subblock D i j, and any destination M, D i j contains either 0 or 1 car going to M. There is a car of destination S k in D i j iff j = c i − a k +1,…,c i And a car of destination T k in D i j iff j = 1,…,b k. In any subblock, cars with S destinations precede cars with T destinations and S i (T i ) precedes S j (T j ) iff i < j.

13 The Reduction In each block there are a i cars with destination S i and b i cars with destination T i. In each block there are  a i +  b i =  c i cars. So there are N = n  c i cars in R. The first 2 subblocks in any block contain n cars of T destinations (b i > 2) and no cars of S destinations (a i +2  c j ). The last subblock is made up of n cars of S destinations (b i < c j ).

14 Example Let a 1 =2,a 2 =3,a 3 =3,b 1 =3,b 2 =4,b 3 =3,c 1 =5,c 2 =7,c 3 =6. Then train R consists of N = 3(5+7+6) = 54 cars. Recall There is a car of destination S k in D i j iff j = c i −a k +1,…,c i And a car of destination T k in D i j iff j = 1,…,b k.

15 Example Let a 1 =2,a 2 =3,a 3 =3,b 1 =3,b 2 =4,b 3 =3,c 1 =5,c 2 =7,c 3 =6. Then train R consists of N = 3(5+7+6) = 54 cars t 1 t 2 t 3 −t 1 t 2 t 3 −s 2 s 3 t 1 t 2 t 3 −s 1 s 2 s 3 t 2 −s 1 s 2 s 3 ║t 1 t 2 t 3 −t 1 t 2 t 3 −t 1 t 2 t 3 −t 2 −s 2 s 3 −s 1 s 2 s 3 −s 1 s 2 s 3 ║t 1 t 2 t 3 −t 1 t 2 t 3 −t 1 t 2 t 3 −s 2 s 3 t 2 −s 1 s 2 s 3 −s 1 s 2 s 3 3−3−5−4−3║3−3−3−1−2−3−3║3−3−3−3−3−3 Partition is T 1 = {1,4,9,19,22,25,37,40,43} T 2 = {2,5,10,15,20,23,26,28,38,41,44,48} T 3 ={3,6,11,21,24,27,39,42,45} S 1 ={12,16,31,34,49,52} S 2 ={7,13,17,29,32,35,46,50,53} S 3 ={8,14,18,30,33,36,47,51,54}

16 Claim: TMP is NP-Complete K(R)  2n−1  a 1,…,a n,b 1,…,b n,c 1,…,c n have a numerical matching. (i.e.) the conditions of NMTS are satisfied.

17 K(R)  2n−1  NMTS We have permutations  1 and  2 satisfying NMTS and need to show K(R)  2n−1. i.e. there is an order O of the 2n destinations so that the sequence J = (2n−1)I N contains all cars of the first destination of O followed by all cars of the second etc.

18 K(R)  2n−1  NMTS Let O = T  2 (n),S  1 (n),T  2 (n-1),S  2 (n-1),…,T  2 (1),S  1 (1) Choose as first car of T  2 (i) on J, the car in Then the last placed car of T  2 (i) is in Choose as first car of S  1 (i) on J, the car in Then the last placed car of S  1 (i) is in

19 Example 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54 S1S1 T1T1 S2S2 T2T2 S3S3 T3T3

20 K(R)  2n−1  NMTS Cars from the first destination are placed in the first round. Cars from the i-th destination are placed in the (i-1)-th round and the beginning of the i-th round. The last car of T  2 (1) is in So all the cars of S  1 (1) can be placed in the same ( 2n−1 )-th round. for this part

21 K(R)  2n−1  NMTS Consider the sequence J = 1,2,…,N,1,2,…,N,…,1,2,…,N (2n − 1) repetitions For destination M, let f M be the car of M placed first and l M the car of M placed last. Let J M be the interval on J from f M to l M. For each m  I N we say m is covered by M (destination) if at least 1 of the ( 2n − 1 ) occurrences of m in J belong to interval J M.

22 Example J T 3 = [3,45], J S 3 = [47,54]  [1,36] 4 is covered by both destinations T 3 and S 3 J T 3 covers 4 in the first round of J and J S 3 covers 4 in the second round of J. 46 is covered by neither of them. 40 is covered by T 3 but not by S 3. Each element of I N belongs to at most 2n−1 intervals.

23 K(R)  2n−1  NMTS Let x i = number of car of T n in D i 1 Let y i = number of car of S 1 in D i c i For i=1,..,n, x i is not covered by either i)Any T destination ( T  T n ) with f T in ii)Any S j destination with f S j in For i=1,…n, y i is not covered only by iii)Any T destination with f T in iv)Any S destination ( S  S 1 ) with f S in

24 Example Let x i = number of car of T n in D i 1 Let y i = number of car of S 1 in D i c i carnot covered bytype x 1 = 3S1S1 ii) x 2 = 21S2S2 ii) x 3 = 39S3S3 ii) y 1 = 16T1T1 iii) y 2 = 34T2T2 iii) y 3 = 52T3T3 iii)

25 K(R)  2n−1  NMTS All T destinations are of type ii) so all S destinations are of type iii). For each i there is one T with f T in X i and one S with f S in X i. Let T k be the T with f T k  X (i+1)modn Let S j be the S with f S j  X i. Then l T k < f S j. Subblock with l T k precedes subblock with f S j

26 K(R)  2n−1  NMTS T k does not cover the last c i −b k subblocks in X i. S j does not cover the first c i −a j subblocks in X i.

27 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54 TkTk SjSj c i -b k c i -a j  X1X1 T1T1 S1S1 235 X2X2 T2T2 S2S2 347 X3X3 T3T3 S3S3 336 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54 S1S1 T1T1 S2S2 T2T2 S3S3 T3T3 3−3−5−4−3║3−3−3−1−2−3−3║3−3−3−3−3−3 a 1 = 2a 2 = 3a 3 = 3 b 1 = 3b 2 = 4b 3 = 3 c 1 = 5c 2 = 7c 3 = 6

28 K(R)  2n−1  NMTS T k does not cover the last c i −b k subblocks in X i. S j does not cover the first c i −a j subblocks in X i. So c i −b k +c i −a j  c i i.e. c i  a j + b k but we can set  1 (i) = j and  2 (i) = k Then we get, for i = 1,…,n, c i  a  1 (i) + b  2 (i) However we have  a i +  b i =  c i so inequality becomes equality.

29 Take next exitContinue

30 The Upper Bound Since TMP is NP-complete, an upper bound for K(S) in terms of n may be useful. (We know that for t destinations K(S)  t−1. ) Let K n be that maximum of K(S) where S ranges over all partitions of {1,…,n}. Main result for this section K n =  n/4 + ½ 

31 Notation For S a partition of {1,…,n}, say S = {S(1), S(2),…,S(s)}, we use S(i) to denote the set containing i. If we use a number x i, y i etc. then this number is from the same set as i. So S(i) = {i, x i, y i,…} Let T −1 be the train obtained from T by reversing the cars. Then K(T) = K(T −1 ).

32 Observations For S′ = {S(i 1 ),…,S(i r )} a subset of S where | S(i 1 )  …  S(i r ) | = t then K(S)  K(S′) + K(S−S′)  K(S′) + K n-t Let S contain a destination with r cars or r destinations with a single car each. Then, K(S)  1 + K n−r

33 Observations If all numbers of S(i) are smaller than all numbers of destination S(j) then we say that S(i) and S(j) do not overlap. If |S(i)| + |S(j)| = r and S(i) and S(j) do not overlap then K(S)  1 + K n−r

34 Lemma Let S(i 1 ),…,S(i k ) be destinations of S such that |S(i 1 )| + |S(i k )| = t and all the numbers of the interval {1,…,j} belong to U = S(i 1 )  …  S(i k ). If it is possible to arrange all numbers from U into k rounds so that the last ( k-th ) round contains only numbers from the interval {1,…,j} then K(S)  k−1+K n−t

35 K n   n/4 + ½  We may assume n  5, and that n is even. From the previous observations we have – At most one destination contains a single car. For all other destinations 2  |S(i)|  3. Any two destinations with at least 4 cars in total must overlap.

36 The Proof Case 1: Let |S(1)| = |S(2)| = 2, then K(S)  1+K n−4   n/4 + ½  S(1) = {1,x 1 } differs from S(2) = {2,x 2 }, then either 1, x 1, x 2, * 2 or 2, x 2, x 1, * 1. x2x2 x1x1 1 2......

37 The Proof Case 2: If one of S(1) and S(2) is of cardinality 1, then K(S)  1+K n−4   n/4 + ½  Suppose |S(1)|=1, then there is no overlap with any destination of cardinality 3. If there is no 3 car set then |S(n−1)|=|S(n)|=2 and use K( T −1 ). If |S(2)|=1 then either |S(1)|=3 whence 2,x 1,y 1,*1 Or there is |S(i)|=3 such that S(2) and S(i) do not overlap.

38 The Proof Case 3: Let |S(1)| = |S(2)| = 3 then either K(S)  1+K n−4   n/4 + ½  or K(S)  2+K n−8   n/4 + ½  Let S(i) be the set with the smallest index after 2. If |S(i)|=1 then the 3 sets can be placed in 2 rounds with any of 1,2,…,i in the third and use Lemma. If |S(i)|=3 then the three sets can be placed in 2 rounds with 1,2,…,i in the third and use Lemma. i 1x1x1 2x2x2 y2y2 y1y1 xixi yiyi i 2x2x2 1x1x1 y1y1 y2y2 xixi yiyi

39 The Proof Case 3: Let |S(1)| = |S(2)| = 3 then either K(S)  1+K n−4   n/4 + ½  or K(S)  2+K n−8   n/4 + ½  Let S(i) be the set with the smallest index after 2. If |S(i)|=2 then we can add a dummy car to S(i) and number it n+1 (it comes at the end of the train). Call this new partition S′. Then, employing the Lemma, we have K(S)  K(S′)  2+K n+1−9  2+K n−8   n/4 + ½ 

40 The Proof Case 4: Let |S(1)| + |S(2)| = 5, then either K(S)  1+K n−4   n/4 + ½  or K(S)  2+K n−8   n/4 + ½  Let S(1), S(2) be {a 1,a 2 }, {b 1,b 2,b 3 }, then If a 2 <b 2 <b 3 use a 1,a 2,b 2,b 3,*b 1 and the Lemma If b 2 <b 3 <a 2 use b 1,b 2,b 3,a 2,*a 1 and the Lemma If b 2 <a 2 <b 3 then 4a: consider S(j) such that |S(j)|=3 and S(j)={c 1,c 2,c 3 }. Now consider U, the union of S(1), S(2), S(j) viz, 1,2,d 3,d 4,…,d 8 (in increasing order).

41 The Proof 4a: We have 1<2<d 3 <d 4 <…<d 8 and a 2 = d i, i={5,6,7} The following satisfy the assumptions of the Lemma and yield the bound; If a 2 =d 7 use b 1,b 2,b 3,*c 1,c 2,c 3,a 2,*a 1 If a 2 =d 6 use c 1,c 2,c 3,b 3,*b 1,b 2,a 2,*a 1 ( 2 cases) If a 2 =d 5 use b 1,b 2,b 3,c 2,c 3,*c 1,a 2,*a 1 b 3 <c 2 <c 3 c 1,c 2,c 3,b 3,*b 1,b 2,a 2,*a 1 c 2 <c 3 <b 3 For d 5 =a 2 <c 2 <b 3 <c 3 use previous cases on S(n−1), S(n) and consider K(S −1 ).

42 The Proof 4b: Let S(n), S(n−1) be {u 1,u 2 }, {v 1,v 2,v 3 }. Assume there is no such S(j)={c 1,c 2,c 3 }, then {b 1,b 2,b 3 } = {v 1,v 2,v 3 }. Since n is even there must be a destination with a single car, {w}. Then either 4b1: {a 1,a 2 } = {u 1,u 2 } which gives, since the sets must overlap, {b 1,b 2,b 3 } = {1,b 2,n} so we can use w, b 2, n,* 1, or

43 The Proof 4b2: { a 1,a 2 }  {u 1,u 2 } then consider i){a 1,b 1 } = {1,2}, {b 3,u 2 } = {n-1,n} and u 1 <b 2 <w<a 2 ii)Same as i) with a 2 and w interchanged. Apply Lemma to S(1), S(2), {u 1,u 2 } and {w} with i)b 1,b 2,b 3,u 2,*u 1,w,a 2,*a 1 for u 2 >b 3 u 1,u 2,b 3,*b 1,b 2,w,a 2,*a 1 for u 2 <b 3 i)a 1,a 2,w,u 2,*u 1,b 2,b 3,*b 1 The proof of the statement K n   n/4 + ½  is now complete.

44 K n =  n/4 + ½  We present a partition showing equality. Let k =  n/2  and S = {S(1),…,S(k)} where S(i) = {i, i+k}, i = 1,…,k. Let A be an arrangement of cars in K(S) rounds of I n. Then any round contains at most 4 cars and the first round contains at most 3 cars. So K(S)   (n−3)/4+1  =  n/4 + ½ 

45 Conclusion A dispatcher in a marshalling yard knows that the TMP is NP-complete and that they must assume that they need min(K n,T−1) auxiliary rails ( T is the number of destinations). To improve this bound the dispatcher needs some additional information. The minimum number of cars per destination should be readily available.

46 Conclusion Let K(n,m) = max K(s) where the train has n cars and at least m go to any one destination. Then Conjecture: K(n,m)   (m  1)d 2 /n+1/m  where d =  n/m  Putting S(i) = {i,i+d,…,i+(m−1)d}, i = 1,…,d gives K(n,m)   (m−1)d 2 /n+1/m  where d =  n/m . So that if the conjecture is true, this bound is the best possible.

47 Dĕkuji


Download ppt "The Train Marshalling Problem Joe Ryan University of Ballarat joint work with Elias Dahlhaus, Peter Horak and Mirka Miller."

Similar presentations


Ads by Google