Download Locating a Railway Supply Depot

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

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

Document related concepts

Derivative wikipedia , lookup

Chain rule wikipedia , lookup

Fundamental theorem of calculus wikipedia , lookup

Function of several real variables wikipedia , lookup

Transcript
MATH 360
Sample Project:
Locating a Railway Supply Depot
A. Model Student
September 1, 2015
1
Introduction
Several factors influence the location of factories, power plants, retail stores,
and other commercial buildings. The placement of machines in a production
facility is similarly subject to a number of considerations. Final decisions are
made by balancing the pros and cons of various options. In this project we
will show that in some circumstances we can find an optimal location easily.
2
Given problem
Because of extreme weather conditions, lots of maintenance and repairs are
needed for the trains which run on the trans-Siberian railway. This maintenance is carried out at a number of sidings (repair stations) which are located
at various points along the track. Parts are scarce and it is not economical
to stock them at all the repair facilities. Instead, it is planned to implement
a “just in time” supply procedure: a Parts Distribution Center is to be built
somewhere along the track. Parts will be shipped from there to the various
repair facilities. The problem is to choose a location which will minimize the
cost of supplying the parts to the sidings.
1
Parameter
Description
x
Position along the track
xi
Position of the ith siding
n
Number of sidings
C(x)
Cost of siting a parts center at position x
Ni
Number of trips to the ith siding per year
D(x)
The total distance traveled if the parts center is at x
k
Unit cost per distance traveled
A
Left end point of the track
B
Right end point of the track
Si
The slope of the cost function at the ith siding
Table 1: Definition of all parameters used in this report. It may be very
helpful for the reader and the authors to use an additional column to define
the units of the parameters.
3
Model derivation
To solve this problem we need to translate it into mathematical terms. The
first step is to decide on a way of representing the setting for the problem.
Since the setting is a single railroad track, it is essentially one-dimensional,
so we will represent the railroad track by the x-axis. (We must select a
point to be the origin, and select our unit of measurement, but those choices
won’t affect our answers.) Then the sidings can be represented by points xi
(i = 1, 2, . . . , n) on the x-axis, where n is the number of sidings (all variables
are defined in table 1). We’ll likewise let the unknown x be the position of
the parts center. There is a certain cost C(x) associated with siting the parts
center at any point x; the problem then becomes:
Find the location x of the parts center so that the cost C(x) of
supplying parts to x1 , . . . , xn is minimized.
At one level, the problem is of a familiar type. It is a maximum/minimum
problem, and we know that calculus provides a tool for solving such problems.
However, what is the function C(x) to be minimized? This isn’t given directly
in the statement of the problem. We shall have to figure it out.
The cost of supplying parts will depend on the distance through which
they must be moved. This, in turn, will depend on the number of trips to
each siding xi , and the distance from x to xi . Lets denote by Ni the number
2
of trips to siding xi in a year. Then the total distance involved in all the
supply trips to repair station i is Ni |x − xi |.
Now, how does this determine the cost? The statement of the problem
does not say; what’s a reasonable assumption? Costs primarily associated
with transit (say, driver’s hourly wage, or fuel cost) are roughly proportional
to the distance traveled, say, C = kD. Let us assume that this is in fact how
C(x) is to be computed; that is, we make explicit the assumption that there
is a unit cost k such that total cost is k times the distance traveled.
Then the cost of maintaining the parts center at x is of the form C(x) =
k D(x) where
D(x) = N1 |x − x1 | + . . . + Nn |x − xn |
is the total distance traveled. Our problem becomes, “Find the value of x
which minimizes C(x)”.
Before trying to solve this problem, we note that we have made several
assumptions in setting up the model, and so there are several questions about
the model that we should consider. For example, is the model a realistic one?
The model depends on the distance from x to each xi , and also on the number
Ni of trips from the parts center to xi . How can we determine Ni ? We shall
return to these questions later.
At first this seems like a simple calculus problem. We know how to solve
those: just take the derivative and set it to zero, right? The problems is
that the function C(x) doesn’t have a derivative everywhere because of the
absolute value bars, so we can’t just take the derivative. However, we can
use theorems from calculus to help us solve the problem. Let’s see what see
do know about C(x).
1. Since C(x) is just a constant multiple of the function D(x), and since
k > 0, C and D will have their minima at the same point x. So it will
be enough for us to find the x which minimizes D.
2. D(x) is the sum of the functions Di (x) = Ni |x − xi | for i = 1, . . . n.
Each of these is a continuous function. Therefore, since the sum of
continuous functions is continuous, D is continuous for all values of x.
Since we know that D is continuous, a theorem from calculus tells us
that D has a minimum value on [A, B], so there really is a solution to
the problem.
3. Di (x) = Ni |x − xi | is differentiable for all x different from xi . For
example, y = 5|x − 2| is differentiable for all values of x except x = 2.
3
Further, the graph is a straight line, that is, the function is linear,
on each of the intervals (−∞, 2) and (2, ∞). Since the derivative of
a sum is the sum of the derivatives provided the derivative of each
summand exists, we see that D(x) is differentiable at every point except
x1 , . . . , x n .
4. The minimum value of D(x) occurs at one of the following:
• at one of the ends of the interval;
• at a point in the interior of the interval where the derivative is
zero;
• at a point in the interior of the interval where the derivative does
not exist.
5. Since the sum of linear functions is linear, we know that D is linear on
each of the intervals [A, x1 ], [x1 , x2 ], . . . , [xn , B] and so a minimum
value of D on such an interval occurs at one of the end points. This
means that the minimum value of D(x) on all of [A, B] occurs at one of
the points A, x1 , . . . , xn , B. To find an optimal location we can calculate
the values of D(x) at these n + 2 points and find those locations where
the value is least.
The solution we have given is a qualitative one. It uses qualitative properties of the model —continuity, differentiability, etc.— to show that the
problem has a solution and, in qualitative terms, where the solution may be
found. But how good a solution is this? There are still questions to be asked.
For example, how many solutions are there? If there are several, how do
we distinguish between them? (Maybe one is better than another for some
purposes.) How efficient is the solution? That is, how much computational
effort is required to find it? If there are only a few sidings, this isn’t really
a problem but what if many locations were involved? The solution we have
given doesn’t use any additional information we might have about the particular locations xi and costs Ni . Can we get a better solution process if we
do take these into account? In other words, can we refine the solution we
have already obtained to find a better one?
4
4
A toy problem
Let’s look at an example where there are three sidings located at 2,3, and 5
on the x-axis, and where
D(x) = 4|x − 2| + |x − 3| + 2|x − 5|.
Distance (D(x))
We have plotted this function in Figure 1.
25
20
15
10
0
1
2
3
4
5
6
7
Location (x)
Figure 1: Plot of the distance function. The distance function D(x) at siding
locations xi are shown by the points.
To see what is going on, we consider the graph of D(x) on the subintervals
(−∞, 2), (2, 3), (3, 5), (5, ∞)
of the x-axis because the absolute values change on these intervals. To the
left of x = 2, for example, |x−2| = 2−x, |x−3| = 3−x, and |x−5| = 5−x, so
that D(x) = 21 − 7x, whose graph is a straight line with slope −7. Likewise
in the the remaining intervals, we calculate D(x) = x+5, 3x−1, and 7x−21,
respectively.
Looking at the graph then shows there is exactly one location where the
minimum value occurs, namely x = 2.
5
5
The general problem
To see what is going on in the general situation where there are n locations
we look separately at each of the intervals
(−∞, x1 ), (x1 , x2 ), . . . , (xn , ∞).
First suppose x is in (−∞, x1 ). Then |x − x1 | = xi − x for each i so that
D(x) = N1 |x − x1 | + . . . + Nn |x − xn |
= N1 (x1 − x) + . . . + Nn (xn − x)
= (N1 x1 + . . . + Nn xn ) − (N1 + . . . + Nn ) x
which is the equation of a straight line with negative slope
S0 = −(N1 + . . . + Nn ) = −
n
X
Ni
i=1
Next consider (xn , ∞). Here |x − x1 | = x − xi for each i so that the
situation this time is the opposite of that which we considered before. We
get
D(x) = N1 |x − x1 | + . . . + Nn |x − xn |,
= N1 (x − x1 ) + . . . + Nn (x − xn ),
= (N1 + . . . + Nn )x − (N1 x1 + . . . + Nn xn ),
which is the equation of a straight line with positive slope
Sn = N1 + . . . + Nn =
n
X
Ni = −S0
i=1
It follows from these two cases that the minimum value must occur at
one of the points x1 , . . . , xn , rather than at the endpoints A or B.
Finally, consider one of the intervals (xr , xr+1 ) where r is 1 or 2 or . . . or
n − 1. For x in this interval, x − xi is positive for those i with i ≤ r and
negative for those i with i > r, so that here,
D(x) = {N1 (x − x1 ) + . . . + Nr (x − xr )} − {Nr+1 (x − xr+1 ) + . . . + Nn (x − xn )}
6
which is a straight line with slope
Sr = (N1 + . . . + Nr ) − (Nr+1 + . . . + Nn ).
Looking at the slopes we see that
S0 = −(N1 + . . . + Nn ),
S1 = N1 − (N2 + . . . + Nn ) = 2N1 + S0 > S0 ,
S2 = N1 + N2 − (N3 + . . . + Nn ) = 2N2 + S1 > S1 ,
and in general Sr+1 = 2Nr + Sr > Sr . This means that the slopes of the line
segments which go to making up D are strictly increasing so there are just
two possibilities:
1. There is exactly one optimal location (this happens if no Sr = 0)
2. There are exactly two adjacent station locations, say at xi and xi+1 ,
where D(x) has the same value. In this case, any location in the closed
interval [xi , xi+1 ] will give an optimal location.
By doing this further analysis we have more understanding about what
is going on in the problem. In addition, we have another way of finding the
optimal location which uses the additional information. The optimal location
occurs at xi if Si−1 < 0 and Si > 0, (or else anywhere in [xi , xi+1 ] if Si = 0).
How can we test for this?
1. Calculate N1 + . . . + Nn and set T0 = S0 /2 = −(N1 + . . . + Nn )/2; (this
takes n + 1 arithmetic operations).
2. Repeatedly add Ni ’s to get T1 , T2 , . . . until Ti ≥ 0; this is at most (n−1)
further operations. (We know Tn = Sn /2 is positive so the change must
occur among T1 , . . . , Tn−1 .)
Therefore, using this method, we can find the optimal location in at most
3n operations. Evaluating D directly at each of x1 , . . . , xn and then finding
the smallest value requires approximately 3n2 operations. If n = 10, this
gives approximately 300 operations as opposed to 30 by the other method.
When n = 100, direct calculation requires approximately 30,000 as opposed
to 300!
7
6
Discussion and Conclusions
Note that the second algorithm presented above is clearly more efficient. Furthermore, we now understand much more. For example, our decision about
which station is the optimal one doesn’t depend directly on the locations xi ;
it only depends on the values Ni and on the order in which they occur! We
wouldn’t have guessed that up front. The mathematical analysis has given
us understanding about how the system works and not just numbers.
To see this more clearly, lets test the method against a numerical search
for an optimal placement. In Figure 2 we randomly generated siding positions
and numbers of visits and plotted distance traveled as a function of position.
We used the method developed above to find the optimal location (which
can be easily seen as the minimum of the graph). The key part of the code
is the lines:
nn=0;
S[0]=-Total[nilist]; (*nilist is the list of Ni .*)
While[
S[nn]< 0,
S[nn+1]=2 nilist[[nn+1]]+S[nn];
nn=nn+1;
]
We then compared the result with one obtained by Mathematica numerically using the command ‘‘FindMinimum[dist[x],x,10 numsidings/2]’’
which looks for the minimum of the function D (defined in our code as
‘‘dist[x]’’) with a starting point at x = 10numsidings/2. The results
are identical in each case. By wrapping the ‘‘AbsoluteTiming’’ function
around the above two commands, we can compare how much actual time it
took to find the optimal location. For 100 sidings the first algorithm using
knowledge about our problem the code took 0.0003 seconds, and the Mathematica code took 0.0040 seconds. For 50000 sidings our first algorithm found
the optimal location in 0.16 seconds, and Mathematica’s FindMinimum took
2.26 seconds. This dramatic speed up is due to our taking advantage of the
nature of the problem. The FindMinimum code is designed to numerically
find the minimum for ANY function it is handed, so it must trade some
efficiency.
Finally, our model made assumptions about the cost as a function of
x. Let’s examine other potential costs to see if our numerical algorithm
8
(checking for a change in sign of the slopes on each interval) can be used. In
particular, figure 3 shows three arbitrary cost functions:
C1 (x) =
n
X
Ni |x − xi | + 2Ni ,
i=1
which represents the original cost with a start up cost,
C2 (x) =
n
X
Ni (x − xi )2 ,
i=1
which represents a cost that increases with the square of distance, and
C3 (x) =
n
X
Ni ln(|x − xi | + 1),
i=1
which represents a cost that increases with the log of the distance, e.g. once
the train is moving the cost doesn’t increase rapidly. We will not prove
any of these statements, but from inspecting the figures we can make a few
observations. First, the algorithm we defined above, may work for the first
two examples, but clearly will not for the third cost. However, if we look
carefully at the plot of C2 we see that in fact, the minimum occurs between
the point before x = 40 and x = 70. Therefore, we must carefully consider the
effect of the choice of cost function and the algorithm to minimize it before
beginning the problem. For the second example, the inter-siding distance is
a quadratic function which is easily minimized between two points (we could
develop such an algorithm). For the third example the sidings seem to always
be local minima, which would allow for simply checking the cost at all siding
locations.
In conclusion, we have established an algorithm for determining the optimal location of the depot given our cost function based on the assumption
that cost is proportional to distance traveled. We have demonstrated that
this algorithm is efficient compared to a “brute force” search using a computational tool such as Mathematica’s ‘‘FindMinimum’’, and, moreover,
yields insight into the nature of the problem. Finally, we have shown that
while successful for our cost function assumption, our algorithm will not be
successful for alternate cost functions.
9
600
500
400
300
200
10
20
30
40
50
14 000
12 000
10 000
8000
6000
50
100
150
200
260 000
240 000
220 000
200 000
180 000
160 000
140 000
120 000
0
200
400
600
800
1000
Figure 2: Plot of the distance function with randomly generated siding locations and number of visits per siding, and three different numbers of sidings.
The distance function D(x) at siding locations xi are shown by the points.
10
1100
C1 (x)
1000
900
800
700
0
20
40
60
80
Location
60 000
C2 (x)
50 000
40 000
30 000
20 000
0
20
40
60
80
Location
80
C3 (x)
75
70
65
60
55
0
20
40
60
80
Location
Figure 3: Plot of the three different distance functions with randomly generated siding locations and number of visits per siding. From top to bottom
we show cost C1 , C2 and C3 respectively. Note that the same siding locations
and siding visit counts are used in each plot.
11