algorithm applied in transportation or problem university of hong kong algorithm applied in...

12
The University of Hong Kong Algorithm Applied in Transportation OR Problem Dijkstra, Dijkstra, Dijkstra, Dijkstra, Floyd Floyd Floyd Floyd and and and and Sweep&TSP Sweep&TSP Sweep&TSP Sweep&TSP Algorithm Algorithm Algorithm Algorithm Wang Ningxin BEcon&Finance 2010973011

Upload: phungkhuong

Post on 08-Jun-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Algorithm Applied in Transportation OR Problem University of Hong Kong Algorithm Applied in Transportation OR Problem Dijkstra, Floyd and Sweep&TSP Algorithm Wang Ningxin BEcon&Finance

The University of Hong Kong

Algorithm Appliedin TransportationOR ProblemDijkstra,Dijkstra,Dijkstra,Dijkstra, FloydFloydFloydFloyd andandandand Sweep&TSPSweep&TSPSweep&TSPSweep&TSPAlgorithmAlgorithmAlgorithmAlgorithm

Wang Ningxin BEcon&Finance

2010973011

Page 2: Algorithm Applied in Transportation OR Problem University of Hong Kong Algorithm Applied in Transportation OR Problem Dijkstra, Floyd and Sweep&TSP Algorithm Wang Ningxin BEcon&Finance

IntroductionIntroductionIntroductionIntroductionTransportation problem, when occur in daily life, must take cost and profit issue intoconsideration. In most of the cases, scheduling is based on two targets: the first one isto minimize the time, and the second one is to minimize the mileage.

Several mathematical methods can be used for optimal planning of transportationproblems, including linear programming from course materials. In the linearprogramming model, the objective function is to minimize the time or mileagerequired in the transportation process, while the constraints are formulated as goodsrequired to be distributed in different position.

However, though linear programming methods could be very intuitive and effective instimulation, when it comes to the real transportation problem, where we have to dealwith tens or even hundreds of distribution spots, and more detailed requisition, linearprogramming sometimes will not be as effective as expected because we have to dealwith hundreds of equations at the same time. In order to use practical mathematics tosolve complex transportation problems, algorithms based on graph theory areintroduced into operational research techniques. Different algorithms are focused ondifferent problems, thus there is no panacea for all transportation problems, eachdetailed case should be analyzed first, and then could be plugged in algorithms that fitit well. This time I’ll just talk about 3 common algorithms, including Dijkstra, Floyd,Sweep and TSP Algorithm. To illustrate their function, I also raise some examples,easy or complex for further demonstration.

1.1.1.1. DijkstraDijkstraDijkstraDijkstra AlgorithmAlgorithmAlgorithmAlgorithmDijkstra Algorithm is the most popular algorithm focused on calculating shortest pathbetween two spots, and also can be applied to calculate the shortest path from a singlespot to all other spots, if we know the distance between each pair of adjacent points.This algorithm will retain the shortest path found so far from spot S to every spot V.

Initially, the path length value of start spot S is assigned to be 0( ( ) 0d S = ) while path

lengths towards all other vertices are set to infinity to illustrate that we do not know

any of the path leading to these vertices( 1 2( ) ( ) ... ( ) 0nd V d V d V= = = = ), the shortest

path from S to nV will be stored in ( )nd V when the algorithm process ends. For

example, the shortest path from s to v can obtained by adding a path from u to v to theshortest path from s to u, The length of this path can be interpreted as

( ) ( , )d U w U V+ . If this value is smaller than the current value of ( )d V , we can use

this new value to replace the previous one, such rotation will be conducted until

Page 3: Algorithm Applied in Transportation OR Problem University of Hong Kong Algorithm Applied in Transportation OR Problem Dijkstra, Floyd and Sweep&TSP Algorithm Wang Ningxin BEcon&Finance

( )nd V can represent the shortest path between S and every single nV .Hence, Dijkstra

Algorithm is mostly adopted when there is a target to minimize the mileage.Example 1: Spot A is logistic center selling daily goods, and supplier must send theirgoods to shops in Village B. However, there aren’t direct way to B. In order to sendgoods to B, supplier must choose one of the routines shown in the picture. Given thepath length of each pair of adjacent spots, which is the best way to go to save cost ongas?

212

17

15

1820

19

171015

3723

AAAA BBBB

CCCC

DDDDEEEE

FFFF

GGGGThis question requires us to save cost on gas. Because gas consumption is based onthe distance from A to B (perhaps need to be doubled for the back way from B to A),in this question, using Dijkstra will help easily solve the problem.Create two set, set S contains the vertices that has already been added in the routine,while set V contains vertices haven’t arranged into the routine. S stands for the valueof the current shortest way

step Set S Set V

1 Taking A inside, S=A-A=0

B,C,D,E,F,GA-C=23A-D=15A-G=18

2 Taking D inside, S=A-D=15

B,C,E,F,GA-D-C=15+15=30A-D-E=15+10=25A-D-G=15+12=27A-D-F=15+17=32

3 Taking E inside, S=A-D-E=25B,C,F,G

A-D-E-B=25+17=42A-D-E-F=25+2=27

4 Taking F inside S=A-D-E-F=27B,C,G

A-D-E-F-B=27+20=47>42Change routine

Page 4: Algorithm Applied in Transportation OR Problem University of Hong Kong Algorithm Applied in Transportation OR Problem Dijkstra, Floyd and Sweep&TSP Algorithm Wang Ningxin BEcon&Finance

5 Taking B inside, S=A-D-E-B=42 C,GTill now, we have found the shortest routine from logistic center A to shops in villageB, which is 42 kilometer. We conclude that this is the mileage minimized way, and inwhich we can save most gas consumption cost.

2.2.2.2. FloydFloydFloydFloydAlgorithmAlgorithmAlgorithmAlgorithmDijkstra Algorithm offers convenient methods to calculate shortest path value fromone single spot to all other spots, which can easily be applied into B2C commerciallogistics: one big warehouse that is in charge of supply for the surrounding area.However, in some cases, when it comes to C2C commercial logistics: small suppliersare distributed in different areas, each of them can transact with others, thus,transportation can happen between every spots in the area. A logistic server may needto know the shortest path between every two spots in the whole area in order toarrange and combine the logistic service in this area to save the cost on gasconsumption.To get a detailed information of shortest path between each two spots in one area, onesuggested method is to refer to Floyd Algorithm, it is more effective than DijkstraAlgorithm in solving this kind of problem.The basic idea of Floyd Algorithm is to change the geographic information of the mapinto an adjacency matrix, in order to determine whether there is path between two

points. If the a path is connecting points iD and jD , and the path length is d, it can be

interpreted that [ , ]G i j d= , if not, set [ , ]G i j to be void. Define a matrix D, whose

entries [ , ]D i j stands for all spots that on the path between spot i and j. Initially, we

define the value of [ , ]D i j to be j, and then insert other spots, and compare the new

path length with previous ones, and let [ ] [ ] [ ] [ ]( )G i, j min G i, j , G i, k G k, j = + ,

If the value of [ , ]G i j get smaller, then let [ ],D i j k= .After all spots are inserted,

[ , ]G i j will turn out to be the shortest path, and [ ],D i j k= stands for the shortest

path.

Example 2: below is a picture of store distribution in the city. These stores are sellingdifferent goods, A post office located on Spot 51, is responsible for the city logistic. Inorder to minimize their cost, the post office decides to better plan their delivery path.To better the path, they want to know the shortest path between every two stores inthe city.

Page 5: Algorithm Applied in Transportation OR Problem University of Hong Kong Algorithm Applied in Transportation OR Problem Dijkstra, Floyd and Sweep&TSP Algorithm Wang Ningxin BEcon&Finance

Much as data are in this example, computer programming is needed. By Referring toMatlab Programming, we can get a table that exports result of the adjacent matrix asshown below, giving us the shortest path length between every two stores in the city.

1 2 3 4 5 6…

…49 50 O/51

1 0 7745 1916 5453 8998 1294…

…20306 16989 10068

2 7745 0 5829 2293 1253 9040…

…25569 22001 16296

3 1916 5829 0 3536 7082 3211…

…20705 17388 10467

4 5453 2293 3536 0 3546 6747…

…24242 20924 14004

5 8998 1253 7082 3546 0 10293…

…24316 20748 16563

6 1294 9040 3211 6747 10293 0…

…21601 18283 11363

…… …… …… …… …… …… ………

……… …… ……

Page 6: Algorithm Applied in Transportation OR Problem University of Hong Kong Algorithm Applied in Transportation OR Problem Dijkstra, Floyd and Sweep&TSP Algorithm Wang Ningxin BEcon&Finance

49 203062556

9

2070

5

2424

224316 21601

…0 3569 11722

50 169892200

1

1738

8

2092

420748 18283

…3569 0 9928

O/51 100681629

6

1046

7

1400

416563 11363

…11721 9928 0

3.3.3.3. SweepSweepSweepSweep methodmethodmethodmethod andandandand thethethethe TSPTSPTSPTSPalgorithmalgorithmalgorithmalgorithmIn discussion above, all example planning are focused on minimizing mileage.However, in some cases, time saving is also very important. To improve the efficiencyof the deliverers, careful planning based on time optimization. Especially, in somecases that locations are various, sweep method is often referred. Sweep method is aheuristic algorithm, which suggest distributing the location into different parts beforeoptimization, For example, think about the picture of stores in the city above, sincethere’re a lot of stores in the city, thus while there are some detailed information, suchas weigh of goods to be sent to specific stores, or special time limits of some goods,scanning methods can be adopted for a better planning. We can use polar coordinatesto indicate the location of all demand points, and select a starting point to define theangle of zero, in the direction of counterclockwise; we sort out goods into differentparts and finally get different routines to better plan separately. After completion ofthe city division, we apply TSP algorithm to each sub-domain to get the optimal path,that is to say, to find a shortest path from a certain starting point, passing all requiredspots to deliver goods and finally return to the original starting point. After break thewhole situation into some sub-problems, things will get much less complex to dealwith that we can use the simplest TSP method: enumeration method to solve.Example 3: Think about a question based on example 2. Assume there is only onedeliver in the post office in Spot 51, he has 100 goods to deliver to all of the stores inthe city. His maximum carrying capacity is 30kg, and the maximum volume of goodscarried by is 0.8 cubic meters. The average speed of delivering is a constant that is24km/h, and time required for handing over in each point is 3minutes. Design a bestplan for delivery that it can finish as soon as possible.

GoodNumber

Store tosend Weigh(kg) Volume(cubic

meters)Good

NumberStore to

send Weigh(kg) Volume(cubicmeters)

31 1 1.26 0.025 19 27 2.45 0.044532 2 1.15 0.0501 58 28 1.72 0.05833 3 1.63 0.0483 59 29 1.34 0.037234 4 1.23 0.0006 60 30 0.06 0.040235 5 1.41 0.0387 21 31 0.8 0.0108

Page 7: Algorithm Applied in Transportation OR Problem University of Hong Kong Algorithm Applied in Transportation OR Problem Dijkstra, Floyd and Sweep&TSP Algorithm Wang Ningxin BEcon&Finance

36 6 0.54 0.0067 3 31 1.18 0.02437 7 0.7 0.0129 61 31 0.6 0.0274100 7 1.98 0.0493 28 32 0.52 0.00238 8 0.76 0.0346 83 32 2.77 0.003439 9 2.14 0.0087 91 32 1.01 0.0340 10 1.07 0.0124 17 32 0.25 0.041299 10 1.38 0.0175 9 32 0.7 0.048196 11 0.3 0.0172 62 32 2.19 0.050341 11 1.37 0.051 92 33 2.51 0.013398 12 0.24 0.0056 63 33 1.89 0.049442 12 5.39 0.0828 24 34 3.8 0.030343 13 0.99 0.0048 64 34 1.81 0.03251 13 2.5 0.0316 65 35 1 0.00556 14 1.72 0.01 93 36 1.17 0.00244 14 1.66 0.0491 66 36 1.24 0.017745 15 0.45 0.0209 18 36 1.79 0.018497 15 4.43 0.0536 90 37 1.42 0.00246 16 2.04 0.0098 67 37 2.51 0.036130 16 1.2 0.0429 10 38 1.33 0.02197 17 1.38 0.0109 94 38 1.82 0.030847 17 1.95 0.0324 68 38 4.04 0.051595 17 0.33 0.0345 69 39 1.07 0.0442 18 0.5 0.0354 13 39 2.56 0.059548 18 2.12 0.0554 25 40 1.14 0.015587 19 1.12 0.0249 70 40 0.49 0.032949 19 6.87 0.1262 88 41 0.9 0.003885 20 0.21 0.049 71 41 0.51 0.009450 20 16.31 0.3216 15 42 2.85 0.04951 21 1.38 0.0419 72 42 10.38 0.09555 21 2.15 0.0505 73 43 1.31 0.012152 22 0.39 0.0001 12 43 0.95 0.022884 23 2.29 0.0054 16 43 1.7 0.07828 23 1.4 0.0426 74 44 1.26 0.000553 23 1.66 0.0502 11 45 1.1 0.028729 23 18.91 0.287 14 45 2.28 0.030154 24 1.24 0.0534 26 45 0.68 0.038220 24 4.93 0.142 75 45 0.98 0.0413

Page 8: Algorithm Applied in Transportation OR Problem University of Hong Kong Algorithm Applied in Transportation OR Problem Dijkstra, Floyd and Sweep&TSP Algorithm Wang Ningxin BEcon&Finance

81 25 0.79 0.0011 76 46 1.35 0.024155 25 2.41 0.0012 89 46 2.38 0.043486 25 9.29 0.288 82 46 2.12 0.049256 26 1.26 0.0059 77 47 2.12 0.02323 26 1.57 0.021 78 48 0.54 0.05424 26 1.56 0.035 27 49 1.35 0.014422 27 2.25 0.0018 79 49 28.5 0.56657 27 0.42 0.0224 80 50 1.12 0.0284

This problem is a typical NPC problem; the best exists but can’t be solved out. Inorder to find a relative suitable solution, we’re going to use the idea of programming.Firstly, we divide 50 stores into 3 different groups, f

(1).stores whose goods are extremely weight, such as 49D

(2). stores faraway from spot 51, and routine towards these stores are rare, such as

48D

(3).Other ordinary stores.Then, we use sweep method to distribute the whole city into four areas, as shownbelow:

For stores(1), we use Dijkstra Algorithm to send goods there directly and also go backdirectly, unless we can also deliver some good to stores on the same path if weightand volume permitFor stores(2) in the same area, we set delivery prior for them.When design the routine, we have find the largest circle in the graphic, and the circle

Area 2Area 1

Area3

Area 4

Page 9: Algorithm Applied in Transportation OR Problem University of Hong Kong Algorithm Applied in Transportation OR Problem Dijkstra, Floyd and Sweep&TSP Algorithm Wang Ningxin BEcon&Finance

should be within the shortest routine.

Given the maximized carrying capacity of the deliverer to be 30kg、0.8 3m .

From the table ,we can calculate the total weigh and volume of the goods:100

1

233.79ii

m m kg=

= =∑ ,100

3

1

4.5166ii

V V m=

= =∑

Hence we can first give a lower bound of delivery groups:

1233.79 7.793 8

30 30mT ⎡ ⎤ ⎡ ⎤= = = =⎡ ⎤⎢ ⎥⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥

24.5166 5.64575 6

0.8 0.8VT ⎡ ⎤ ⎡ ⎤= = = =⎡ ⎤⎢ ⎥⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥

Take 1 2max{ , } 8T T T= = , that is to say, we at least can divide 8 groups for the

deliverer.

We can use Excel to look for stores(1), and pick up 49D 、 23D 、 20D 、 42D 、 25D as stores

(1)Thus ,we’ll conduct Dijkstra Algorithm to calculate the shortest path length and to seewhether it is possible to deliver other goods on the same path. If so, do theadjustment.

After applying these ideas, we can get 8 routines for the delivery, they separatelycontains several stores

(1) 49D

(2) 21 23 32 35, , ,D D D D

(3) 20 25,D D

(4) 24 29 22 30 28 33 46 48 44 41 37 47, , , , , , , , , , ,D D D D D D D D D D D D

(5) 21 17 23 16 14 9 46 10 7 1 6 18, , , , , , , , , , ,D D D D D D D D D D D D

(6) 13 11 12 8 3 4 2 5 15 19, , , , , , , , ,D D D D D D D D D D

(7) 38 43 42 45, , ,D D D D

(8) 26 31 7 39 34 40 50 36, , , , , , ,D D D D D D D D

An graphic showing the distribution solution is here below:

Page 10: Algorithm Applied in Transportation OR Problem University of Hong Kong Algorithm Applied in Transportation OR Problem Dijkstra, Floyd and Sweep&TSP Algorithm Wang Ningxin BEcon&Finance

The blue star is where the post offie lies.

After separating all the stores into 8 different groups, we can use TSP methods tosolve them, since every single routine only contain a few stores, we can useenumeration method directly.Attention: Only stores specially mentioned is where we send goods to, other stores wejust pass by.

1、 1 51 21 36 38 43 42 42 43 38 36 21 5149 DP D D D D D D D D D D DD= − − − − − − − − − − − −

(Unload at 49D )

2、 2 51 17 38 36 21 5121 23 32 35P D D D D D DD D D D= − − − − − − − − −

(Unload at 21 23 32 35, , ,D D D D ,Unload No.5 good only when arrive at 21D Unload

No.5 good only when arrive at 23D )

3、 3 51 26 31 24 19 29 22 22 29 25 1925 20P D D D D D D D D D D DD D= − − − − − − − − − − − −

24 31 26 51D D D D− − − −

(Unload at first arrival at 20 25,D D )

4、 4 51 26 31 19 25 2224 29 30 28 33 46 48P D D D D D DD D D D D D D= − − − − − − − − − − − −

40 40 34 31 26 5144 41 37 47D D D D D DD D D D− − − − − − − − − −

Page 11: Algorithm Applied in Transportation OR Problem University of Hong Kong Algorithm Applied in Transportation OR Problem Dijkstra, Floyd and Sweep&TSP Algorithm Wang Ningxin BEcon&Finance

(Unload at 24 29 22 30 28 33 46 48 44 41 37 47, , , , , , , , , , ,D D D D D D D D D D D D )

5 51 1 7 51721 17 23 16 14 9 10 1 6 18P D D D DD D D D D D D D D D D= − − − − − − − − − − − − − −

( Unload at 21 17 23 16 14 9 10 7 1 6 18, , , , , , , , , ,D D D D D D D D D D D ,Unload No.51good

when arrive at 21D ,Unload No. 8,53,84 when arrive at 23D )

6、 6 51 18 513 11 12 8 3 4 2 15P D D D D D D D D D D D= − − − − − − − − − −

25 24 31 26 5119D D D D DD− − − − − −

(Unload at 13 11 12 8 3 4 2 5 15 19, , , , , , , , ,D D D D D D D D D D )

7、 7 51 21 43 38 36 21 5136 38 43 42P D D D D D D DD D D D= − − − − − − − − − −

(Unload at 36 38 43 42, , ,D D D D )

8、 8 51 27 31 3626 31 27 39 34 40 50 45P D D D DD D D D D D D D= − − − − − − − − − − −

21 51D D− −

(Unload at 26 31 27 39 34 40 50 45, , , , , , ,D D D D D D D D )

Routine Distance(k

m)

weigh(kg) volume(m3

)

Amount of

goods

Time

needed(mi

n)

1 23.444 29.85 0.5804 2 64.61

2 15.445 29.11 0.518 8 62.6125

3 26.834 29.01 0.6609 6 85.085

4 41.559 29.19 0.6393 18 157.9

5 31.412 28.7 0.553 20 138.53

6 37.354 29.84 0.5909 15 138.385

7 19.502 28.58 0.3999 11 81.755

8 26.586 29.12 0.5742 20 126.465

So the { }1 2 8[ , ] | [ , ] , 222.136G G i j D i j P P P km= = =∑ ……

Page 12: Algorithm Applied in Transportation OR Problem University of Hong Kong Algorithm Applied in Transportation OR Problem Dijkstra, Floyd and Sweep&TSP Algorithm Wang Ningxin BEcon&Finance

Total time needed to send all these 100 goods is 3 100 14.2556724 60Gt h= + × = .

Reference:Reference:Reference:Reference:1. www.wikipedia.com