Download The Train Marshalling Problem

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
The Train Marshalling
Problem
Joe Ryan
University of Ballarat
joint work with
Elias Dahlhaus, Peter Horak and Mirka Miller
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
The Train Marshalling Problem
1
2
3
4
5
6
7
8
9
10
11
• 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.
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
1
2
3
4
5
6
Track C
Track D
Reassemble the train from Track D followed,
in order, by tracks C, B and A.
7
8
9 10 11
Train Ready to Distribute Carriages
Station 1
1
6
Station 4
11
2
7
Station 3
8
3
Station 5
4
9
Station 2
10
5
The Train Marshalling Problem
Given a partition S of {1,…,n} into disjoint sets
S1,…,St, 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 Sp(1) , then all elements of Sp(2),… etc.,
and finally all elements of Sp(t) .
The Train Marshalling Problem
n = 11
1,2,3,4,5,6,7,8,9,10,11
S = {S1,S2,S3,S4,S5}
S1 = {1,6,11}
S2 = {5,10}
S3 = {3,8}
S4 = {2,7}
S5 = {4,9}
1234567891011,1234567891011,1234567891011,1234567891011
k = K(S) = 4
Numerical Matching
with Target Sums*
a1,a2,a3, …,ai,…,aj,…,ak,…,an-1,an
+
+
b1,b2,b3, …,bi,…,bj,…,bk,…,bn-1,bn
=
=
c1,c2,c3, …,ci,…,cj,…,ck,…,cn-1,cn
* Garey and Johnson:- Problem SP17
Numerical Matching
with Target Sums
Instance: positive integers
I: a1,a2,…,an,b1,b2,…,bn,c1,c2,…cn
Question: Are there permutations 1 and 2
such that for all i = 1,2,…n,
a1(i) + b2(i) = ci ?
Restriction
ai  2, bi  2, cj  bi, cj  ai + 2.
The Reduction
• Let a1,a2,…,an,b1,b2,…,bn,c1,c2,…cn be positive
integers satisfying the restrictions.
• Let N = nci.
• To the set (train) IN = {1,2,…,N} we assign a
partition, R, of 2n elements (destinations);
S1,…,Sn,T1,…Tn.
• Divide the train into blocks X1,X2,…Xn
and subblocks Xi = Dij, j = 1,…,ci (in order).
The Reduction
• For any subblock Dij, and any destination
M, Dij contains either 0 or 1 car going to M.
• There is a car of destination Sk in Dij
iff j = ci−ak+1,…,ci
• And a car of destination Tk in Dij
iff j = 1,…,bk.
• In any subblock, cars with S destinations
precede cars with T destinations and Si (Ti)
precedes Sj (Tj) iff i < j.
The Reduction
• In each block there are ai cars with
destination Si and bi cars with destination Ti.
• In each block there are ai + bi = ci cars.
• So there are N = nci cars in R.
• The first 2 subblocks in any block contain n
cars of T destinations (bi > 2) and no cars of
S destinations (ai+2  cj).
• The last subblock is made up of n cars of S
destinations (bi < cj).
Example
Let a1=2,a2=3,a3=3,b1=3,b2=4,b3=3,c1=5,c2=7,c3=6.
Then train R consists of N = 3(5+7+6) = 54 cars.
Recall
• There is a car of destination Sk in Dij
iff j = ci−ak+1,…,ci
• And a car of destination Tk in Dij
iff j = 1,…,bk.
Example
Let a1=2,a2=3,a3=3,b1=3,b2=4,b3=3,c1=5,c2=7,c3=6.
Then train R consists of N = 3(5+7+6) = 54 cars
t1t2t3−t1t2t3−s2s3t1t2t3−s1s2s3t2−s1s2s3║t1t2t3−t1t2t3−t1t2t3−t2
−s2s3−s1s2s3−s1s2s3║t1t2t3−t1t2t3−t1t2t3−s2s3t2−s1s2s3−s1s2s3
3−3−5−4−3║3−3−3−1−2−3−3║3−3−3−3−3−3
Partition is
T1={1,4,9,19,22,25,37,40,43} T2={2,5,10,15,20,23,26,28,38,41,44,48}
T3={3,6,11,21,24,27,39,42,45} S1={12,16,31,34,49,52}
S2={7,13,17,29,32,35,46,50,53} S3={8,14,18,30,33,36,47,51,54}
Claim: TMP is NP-Complete
K(R)  2n−1  a1,…,an,b1,…,bn,c1,…,cn have
a numerical matching.
(i.e.) the conditions of NMTS are satisfied.
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)IN contains all cars of the
first destination of O followed by all
cars of the second etc.
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
( i 1) mod n
1
D
i
b 2 ( i )
D
i
ci  a1 ( i ) 1
D
( i 1) mod n
c( i 1) mo d n
D
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
S1
S2
T1
T2
S3
T3
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.
1
• The last car of T2(1) is in Db 2 (1)
• So all the cars of S1(1) can
be placed in the same (2n−1)-th round.
for this part
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 fM be the car of M placed
first and lM the car of M placed last.
• Let JM be the interval on J from fM to lM.
• For each m  IN we say m is covered by M
(destination) if at least 1 of the (2n−1)
occurrences of m in J belong to interval JM.
Example
JT3 = [3,45], JS3 = [47,54][1,36]
4 is covered by both destinations T3 and S3
JT3 covers 4 in the first round of J and JS3 covers 4 in the
second round of J.
46 is covered by neither of them.
40 is covered by T3 but not by S3.
Each element of IN belongs to at most 2n−1 intervals.
K(R)  2n−1 NMTS
•
Let xi = number of car of Tn in Di1
•
Let yi = number of car of S1 in Dici
For i=1,..,n, xi is not covered by either
i) Any T destination (T  Tn) with fT in
ii) Any Sj destination with fSj in
For i=1,…n, yi is not covered only by
iii) Any T destination with fT in
iv) Any S destination (S  S1) with fS in
D2i
Dcii  a j 1
D1( i 1) mod n
Dcii
Example
•
•
Let xi = number of car of Tn in Di1
Let yi = number of car of S1 in Dici
car
x1 = 3
x2 = 21
x3 = 39
y1 = 16
y2 = 34
y3 = 52
not covered by
S1
S2
S3
T1
T2
T3
type
ii)
ii)
ii)
iii)
iii)
iii)
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 fT in Xi and
one S with fS in Xi.
• Let Tk be the T with fTk  X(i+1)modn
• Let Sj be the S with fSj  Xi.
• Then lTk < fSj.
• Subblock with lTk precedes subblock with fSj
K(R)  2n−1 NMTS
• Tk does not cover the last ci−bk subblocks in Xi.
• Sj does not cover the first ci−aj subblocks in Xi.
Tk
Sj
ci-bk
ci-aj

X1
T1
S1
2
3
5
X2
T2
S2
3
4
7
X3
T3
S3
3
3
6
a1 = 2
a2 = 3
a3 = 3
b1 = 3
b2 = 4
b3 = 3
c1 = 5
c2 = 7
c3 = 6
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
S1
S2
S3
T1
T2
T3
3−3−5−4−3║3−3−3−1−2−3−3║3−3−3−3−3−3
K(R)  2n−1 NMTS
• Tk does not cover the last ci−bk subblocks in Xi.
• Sj does not cover the first ci−aj subblocks in Xi.
So ci−bk+ci−aj  ci
i.e. ci  aj + bk
but we can set 1(i) = j and 2(i) = k
Then we get, for i = 1,…,n, ci  a1(i) + b2(i)
However we have ai + bi = ci
so inequality becomes equality.
Take next exit
Continue
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 Kn be that maximum of K(S) where S
ranges over all partitions of {1,…,n}.
• Main result for this section
Kn =  n/4 + ½ 
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 xi,
yi etc. then this number is from the same
set as i.
So S(i) = {i, xi, yi,…}
• Let T−1 be the train obtained from T by
reversing the cars. Then K(T) = K(T−1).
Observations
• For S′ = {S(i1),…,S(ir)} a subset of S
where |S(i1) …  S(ir)| = t then
K(S)  K(S′) + K(S−S′)  K(S′) + Kn-t
• Let S contain a destination with r cars or
r destinations with a single car each.
Then, K(S)  1 + Kn−r
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 + Kn−r
Lemma
• Let S(i1),…,S(ik) be destinations of S such
that |S(i1)| + |S(ik)| = t and all the numbers of
the interval {1,…,j} belong to
U = S(i1)…S(ik). 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+Kn−t
Kn   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.
The Proof
Case 1: Let |S(1)| = |S(2)| = 2, then
K(S)  1+Kn−4  n/4 + ½
S(1) = {1,x1} differs from S(2) = {2,x2}, then
either 1, x1, x2, * 2 or 2, x2, x1, * 1.
2
x2
x1
1
.
.
.
The Proof
Case 2: If one of S(1) and S(2) is of cardinality
1, then
K(S)  1+Kn−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,x1,y1,*1
Or there is |S(i)|=3 such that S(2) and S(i) do not
overlap.
The Proof
Case 3: Let |S(1)| = |S(2)| = 3 then either
K(S)  1+Kn−4  n/4 + ½ or K(S)  2+Kn−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.
2 x y
y
2
1
i
x1
2
1
1
xi
yi
2
i
x1 y1
x2
xi
y2
yi
The Proof
Case 3: Let |S(1)| = |S(2)| = 3 then either
K(S)  1+Kn−4  n/4 + ½ or K(S)  2+Kn−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+Kn+1−9  2+Kn−8  n/4 + ½
The Proof
Case 4: Let |S(1)| + |S(2)| = 5, then either
K(S)  1+Kn−4  n/4 + ½ or K(S)  2+Kn−8  n/4 + ½
Let S(1), S(2) be {a1,a2}, {b1,b2,b3}, then
If a2<b2<b3 use a1,a2,b2,b3,*b1 and the Lemma
If b2<b3<a2 use b1,b2,b3,a2,*a1 and the Lemma
If b2<a2<b3 then
4a: consider S(j) such that |S(j)|=3 and S(j)={c1,c2,c3}.
Now consider U, the union of S(1), S(2), S(j) viz,
1,2,d3,d4,…,d8 (in increasing order).
The Proof
4a: We have 1<2<d3<d4<…<d8 and a2= di, i={5,6,7}
The following satisfy the assumptions of the
Lemma and yield the bound;
If a2=d7 use b1,b2,b3,*c1,c2,c3,a2,*a1
If a2=d6 use c1,c2,c3,b3,*b1,b2,a2,*a1 (2 cases)
If a2=d5 use b1,b2,b3,c2,c3,*c1,a2,*a1 b3<c2<c3
c1,c2,c3,b3,*b1,b2,a2,*a1 c2<c3<b3
For d5=a2<c2<b3<c3 use previous cases on S(n−1),
S(n) and consider K(S−1).
The Proof
4b: Let S(n), S(n−1) be {u1,u2}, {v1,v2,v3}.
Assume there is no such S(j)={c1,c2,c3}, then
{b1,b2,b3} = {v1,v2,v3}. Since n is even there
must be a destination with a single car, {w}.
Then either
4b1: {a1,a2} = {u1,u2} which gives, since the
sets must overlap, {b1,b2,b3} = {1,b2,n} so we
can use w, b2, n,* 1,
or
The Proof
4b2: {a1,a2}  {u1,u2} then consider
i) {a1,b1} = {1,2}, {b3,u2} = {n-1,n} and u1<b2<w<a2
ii) Same as i) with a2 and w interchanged.
Apply Lemma to S(1), S(2), {u1,u2} and {w} with
i) b1,b2,b3,u2,*u1,w,a2,*a1
for u2>b3
u1,u2,b3,*b1,b2,w,a2,*a1
for u2<b3
i) a1,a2,w,u2,*u1,b2,b3,*b1
The proof of the statement Kn  n/4 + ½ is now
complete.
Kn =  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 In.
• 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 + ½ 
Conclusion
A dispatcher in a marshalling yard knows that
the TMP is NP-complete and that they must
assume that they need min(Kn,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.
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)d2/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)d2/n+1/m where d = n/m.
So that if the conjecture is true, this bound is the
best possible.
Dĕkuji