travelling salesman problem with matlab programming

9
Int. J. Adv. Appl. Math. and Mech. 2(3) (2015) 258 - 266 (ISSN: 2347-2529) Journal homepage: www.ijaamm.com International Journal of Advances in Applied Mathematics and Mechanics Travelling salesman problem with MATLAB programming Article category Kirtiwant P Ghadle * , Yogesh M Muley Department of Mathematics, Dr. Babasaheb Ambedkar Marathwada University,Aurangabad - 431004, India. Received 03 February 2015; accepted (in revised version) 04 March 2015 Abstract: Travelling Salesman Problem (TSP) is very similar to the Assignment Problem (AP) except there is an additional restriction i.e. C ij = , if i = j . In TSP a salesman has to visit n cities. The objective is to select the sequence in which the cities are visited in such a way that total travelling time is minimized; many times AP does not satisfy the additional restriction, which becomes difficult to solve. In this article we present modified one’s algorithm with MATLAB programming to solve TSP. MSC: 90B06 90C05 90C08 90C90 Keywords: ROA method Assignment Problem TSP MATLAB code c 2015 IJAAMM all rights reserved. 1. Introduction MATLAB is powerful software package. The name MATLAB stands for MATrix LABoratory, it deals with matrix (array). MATLAB can be used for math computations, modeling and simulations, data analysis and processing, visualization and graphics, and algorithm development, and has many built in tools for solving problems. It is also possible to write programs in MATLAB, which are essentially groups of commands that are executed sequentially [1, 2]. MATLAB is widely used in universities and college introductory and advanced courses in applied mathematics, science and in engineering. Such as, Keng introduced the boundary element method for solving Laplaces equation using MATLAB [3].Dunn and Harman presented the Graphics User Interface (GUI) features of MATLAB in designing programs for calculus [4].Colgan reported the successful use of MATLAB in the teaching of core mathematics [5]. Also, Tonkes et al. managed to overcome several inherent difficulties involved in using MATLAB for numerical analysis to develop an innovative learning model for computational mathematics [6] . Travelling Salesman Problem is well known in operation research for minimized travelling cost/ distance. Some of linear programming concept used with MATLAB, YIN ZANG has described implementation of a primal dual infeasible - interior point algorithm for large scale linear programming under the MATLAB environment [7]. STURM has shown how to solve optimization problem with linear, quadratic and semidefiniteness constraints using MATLAB toolbox [8]. In this article, we shall illustrate TSP with MATLAB coding by using revised ones assignment problem. * Corresponding author. E-mail address: [email protected] 258

Upload: ledung

Post on 10-Feb-2017

349 views

Category:

Documents


15 download

TRANSCRIPT

Page 1: Travelling salesman problem with MATLAB programming

Int. J. Adv. Appl. Math. and Mech. 2(3) (2015) 258 - 266 (ISSN: 2347-2529)

Journal homepage: www.ijaamm.com

International Journal of Advances in Applied Mathematics and Mechanics

Travelling salesman problem with MATLAB programming

Article category

Kirtiwant P Ghadle ∗ , Yogesh M Muley

Department of Mathematics, Dr. Babasaheb Ambedkar Marathwada University,Aurangabad - 431004, India.

Received 03 February 2015; accepted (in revised version) 04 March 2015

Abstract: Travelling Salesman Problem (TSP) is very similar to the Assignment Problem (AP) except there is an additionalrestriction i.e. Ci j =∞, if i = j . In TSP a salesman has to visit n cities. The objective is to select the sequence inwhich the cities are visited in such a way that total travelling time is minimized; many times AP does not satisfythe additional restriction, which becomes difficult to solve. In this article we present modified one’s algorithmwith MATLAB programming to solve TSP.

MSC: 90B06 • 90C05 • 90C08 • 90C90

Keywords: ROA method • Assignment Problem • TSP • MATLAB code

c© 2015 IJAAMM all rights reserved.

1. Introduction

MATLAB is powerful software package. The name MATLAB stands for MATrix LABoratory, it deals with matrix(array). MATLAB can be used for math computations, modeling and simulations, data analysis and processing,visualization and graphics, and algorithm development, and has many built in tools for solving problems. It is alsopossible to write programs in MATLAB, which are essentially groups of commands that are executed sequentially[1, 2].

MATLAB is widely used in universities and college introductory and advanced courses in applied mathematics,science and in engineering. Such as, Keng introduced the boundary element method for solving Laplaces equationusing MATLAB [3].Dunn and Harman presented the Graphics User Interface (GUI) features of MATLAB in designingprograms for calculus [4].Colgan reported the successful use of MATLAB in the teaching of core mathematics [5].Also, Tonkes et al. managed to overcome several inherent difficulties involved in using MATLAB for numericalanalysis to develop an innovative learning model for computational mathematics [6] .

Travelling Salesman Problem is well known in operation research for minimized travelling cost/ distance. Someof linear programming concept used with MATLAB, YIN ZANG has described implementation of a primal dualinfeasible - interior point algorithm for large scale linear programming under the MATLAB environment [7].STURM has shown how to solve optimization problem with linear, quadratic and semidefiniteness constraintsusing MATLAB toolbox [8].

In this article, we shall illustrate TSP with MATLAB coding by using revised ones assignment problem.

∗ Corresponding author.E-mail address: [email protected]

258

Page 2: Travelling salesman problem with MATLAB programming

Kirtiwant Ghadle, Yogesh Muley / Int. J. Adv. Appl. Math. and Mech. 2(3) (2015) 258 - 266

2. Mathematical Formulation of Traveling Salesman Problem (TSP)[9]

Let 1, 2, . . . , n be the labels of the n cities and C = Ci , j be an n ×n cost matrix where Ci , j denotes the cost of trav-eling from city i to city j. Then, the general formulation of the traveling salesman problem (TSP), as described byAssignment Problem, is shown below.

If Ci , j =C j ,i , the problem is called symmetric traveling salesman problem (STSP).

3. Assignment based formulation [9]

Starting from his home, a salesman wishes to visit each of (n −1) other cities and return home at minimal cost. Hemust visit each city exactly once and it costs Ci j to travel from city i to city j. We may be tempted to formulate hisproblem as the assignment problem:

xi j =

1; if he goes form city ’i’ to city ’j’.

0; otherwise

Then the mathematical formulation of the assignment problem is,

M i ni mi z e Z (X ) =n∑

i=1

ci j xi j (1)

Subject to constraints,

n∑

j=1

xi j = 1, f o r i = 1..n

n∑

i=1

xi j = 1, f o r j = 1..n

xi j ≥ 0, f o r a l l i , j .

and xi j = 0 o r 1, f o r a l l i , j .

4. Algorithm-Revised ones assignment method (ROA) [9, 10]

• Divide each row byn∑

i=1

ai j .

• Divide each column byn∑

j=1

bi j .

• Check optimality (draw lines to covers all one) if it is equal to n then go to last step.

• If drawn lines < n , then consider all element less than 1.5 in matrix as 1, and again check optimality.

• If still drawn lines < n , then choose smallest element di from uncovered row or column and divide this di

from uncovered row or column.

• Repeat second last step until optimum solution is attained.

259

Page 3: Travelling salesman problem with MATLAB programming

Travelling salesman problem with MATLAB programming

5. MATLAB programming concept [1, 2]

Some basic commands in MATLAB Programming for Assignment Problem and TSP as follows,

1. nnmaxr: Find maximum of each row.EX.1. >> x= randi(3,3)x=

3 1 33 3 32 3 3

>>max=nnmaxr(x)max =333

2. nnminr: Find minimum of each row.

3. Size: [M, N] = size(X) for matrix X, returns the number of rows and columns in X as separate output variables.>> [M, N] =size(x) (see Ex.1)M = 3N = 3

4. length: length(X) returns the length of vector X. It is equivalent to MAX (SIZE(X)) for non-empty arrays and 0for empty ones.>> l=length(x) (see Ex.1)l = 3

5. find: [I,J] = find(X,...) returns the row and column indices instead of linear indices into X. This syntax is espe-cially useful when working with sparse matrices. If X is an N-dimensional array where N > 2, then J is a linearindex over the N-1 trailing dimensions of X.>> x= randi(3,3)x =

2 2 11 3 21 3 2>> [r c] = find(x==1)r =

2

3

1

c =

1

1

3

6. sum: S = sum(X) is the sum of the elements of the vector X. If X is a matrix, S is a row vector with the sum overeach column.>> x= randi(3,3)x =1 3 12 1 21 2 1>> s=sum(x)s = 4 6 4>> s1=sum(s)s1 = 14>> s= sum(sum(x))s = 14

260

Page 4: Travelling salesman problem with MATLAB programming

Kirtiwant Ghadle, Yogesh Muley / Int. J. Adv. Appl. Math. and Mech. 2(3) (2015) 258 - 266

7. for loop:Repeat statements a specific number of times. The general form of a ’for’ statement is:for variable = expr, statement, ..., statement END>> x= randi(3,3)x =2 2 33 1 13 1 3>> [M, N] = size(x)M = 3N = 3multiply each matrix element by 2>> for r=1:Mfor c=1:Nx(r,c)=x(r,c)*2;endend>> xx =4 4 66 2 26 2 6

8. If Condition:If conditionally execute statements.The general form of the if statement is

if expression

statements

ELSEIF expression

statements

ELSE

statements

END

9. Tic/toc: tic is used before program and toc is used after program, it is used for to find out total execution time.

6. Applications [11]

The Ashtavinayaka Yatra is the most important worship yatra in Maharashtra. Ashtavinayaka means "EightGaneshas" when translated in Sanskrit. Lord Ganesha is the Hindu God of unity, remover of obstacles, learning andprosperity.

This yatra covers the eight holy temples of Lord Ganesha which are located around Pune . Each temple has itsown individuality and mythology. The deities in each temple are distinct from each other. Some of these deitiesare described as ’Swayambhu’ figurines. This is to point to that no human created these deities; they were formedcompletely by nature.

According to Hindu Shastra, you will have to visit the Moreshwar temple at Morgaon first and then in sequence visitthe temples at Siddhatek, Pali, Mahad, Thevur, Lenyandri, Ozar, and Ranjangaon and in last visit the Moreshwartemple again. This will complete your Ashtavinayak-Yatra.

261

Page 5: Travelling salesman problem with MATLAB programming

Travelling salesman problem with MATLAB programming

By using ’Revised’ Ones Assignment Method (ROA) and MATLAB coding (see Appendix 1) the final solution obtainedwas,

262

Page 6: Travelling salesman problem with MATLAB programming

Kirtiwant Ghadle, Yogesh Muley / Int. J. Adv. Appl. Math. and Mech. 2(3) (2015) 258 - 266

The solution consist in three cycle which are (1,8),(8,4),(4,9),(9,7),(7,1) ; (2,5),(5,2) ; (3,6),(6,3) and minimumdistance is 675 km. if graph command is ignored for TSP 0.085230 seconds required to execute in MATLAB ( Intelcore i3, 4 GB RAM, 32 bit Windows 7 system).

If we again find next minimum values from column 7th, 5th and 6th , which will cover whole journey of AshtavinayakYatra in 987 km.

7. Conclusions

In this article, a new approach is used for solving TSP with MATLAB Programming. Due to additional restric-tion in TSP it is difficult to solve by using AP, even though online Assignment Problem (Hungarian Method -http://d3meta.com/hungarian/HungarianMethodSolver.html) solver fail to solve this problem. But using sometricks and ROA method in MATLAB optimum solution has found within 0.085230 seconds.

263

Page 7: Travelling salesman problem with MATLAB programming

Travelling salesman problem with MATLAB programming

References

[1] Amous Gilat,MATLAB: An Introduction with Applications, John Wiley and Sons, Inc.2004.[2] Stormy Attaway, MATLAB: A Practical Introduction to Programming and Problem Solving, Elsevier, Inc 2009.[3] Keng - Cheng Ang, Introducing the boundary element method with MATLAB, Int. J. Math. Edu. Sci. and Technol.

39(4) (2008) 505-519.[4] P. Dunn and C. Harman, Calculus demonstrations using Matlab, Int. J. Math. Edu. Sci. and Technol. 33 (2002)

584-596.[5] L. Colgan, Matlab in first - year engineering mathematics, Int. J. Math. Edu. Sci. and Technol. 31 (2000) 15-25.[6] E. Tonkes, B. Loch, and A. Stac, An innovative learning model for computation in first year mathematics, Int. J.

Math. Edu. Sci. and Technol. 36 (2005) 751-759.[7] Yin Zang, Solving large - scale linear programs by interior point methods under the MATLAB environment,

Optimization Method and Software 10 (1998) 1-31.[8] Jos. F. Sturm, Using SeDuMi 1.02, a MATLAB toolbox for optimization over symmetric cones, Optimization

Method and Software 11 & 12 (1999) 625-653.[9] Ghadle Kirtiwant P, Muley Yogesh M , Revised Ones Assignment Method for Solving Assignment Problem, Jour-

nal of Statistics and Mathematics, Volume 4, Issue 1 (2013) 147-150.[10] Hadi Basirzadeh, Ones Assignment Method for solving Assignment Problems, Applied Mathematical Sciences

6(47) (2012) 2345-2355.[11] Ghadle Kirtiwant P, Muley Yogesh M , An Application of Assignment Problem in Traveling Salesman Problem

(TSP), Int. Journal of Engineering Research and Applications 4(1) (2014) 169-172.

Appendix : TSP with MATLAB programming

Main Program:

Program for Travelling Salesman Problem by using Revised Ones Assignment method.Author :Kirtiwant P Ghadle, Yogesh M Muleyclc;tic;x=[ 1000 225 304 236 213 339 187 197 226

225 1000 140 153 15 175 84 160 110304 140 1000 152 132 41 121 190 108236 153 152 1000 143 188 70 73 63213 15 132 143 1000 166 74 145 102339 175 41 188 166 1000 157 226 144187 84 121 70 74 157 1000 81 43197 160 190 73 145 226 81 1000 90226 110 108 63 102 144 43 90 1000]

xnv=x;x1=x;minr= nnminr(x);[r c ] = s i z e (x );

for i=1:rfor j=1:c

x(i,j)=x(i,j)/minr(i);end

endx;minc=nnminr(x’)’;for i=1:r

for j=1:cx(j,i)=x(j,i)/minc(i);

endend

x;count=0;for l=1:r

for i=1:rfor j=1:c

264

Page 8: Travelling salesman problem with MATLAB programming

Kirtiwant Ghadle, Yogesh Muley / Int. J. Adv. Appl. Math. and Mech. 2(3) (2015) 258 - 266

if x(i,j)==1count = count+ 1;

endend

if count <= 1for I=i

for j=1:cif x(I,j)==1

x(I,j)= x(I,j)*10;end

for i=1:r[y c y r ] = f i nd (x ′ == 10);

l = length(yc);for m =1:l

x(yr(m),yc(m)) = 10;for j=1:cif x(yr(m),j) =10x(yr(m),j)=0;

endif x(j,yc(m)) =10x(j,yc(m))=0;

endend

continueend

x;end

x;end

endend

count=0;end

endx;

for i= 1:rfor j=1:c

if x(i,j) =0x(i,j)=1;

endend

endx;

count=0;for i=1:r

for j=1:cif x(i,j)==1

count = count+ 1;end

endif count > 1

for I=ifor j=1:cx(I,j)= x(I,j)*10;[y c y r ] = f i nd (x ′ == 10, 1);l = length(yc);for m =1:lx(yr(m),yc(m)) = 10;for j=1:cif x(yr(m),j) =10x(yr(m),j)=0;

end

265

Page 9: Travelling salesman problem with MATLAB programming

Travelling salesman problem with MATLAB programming

if x(j,yc(m)) =10x(j,yc(m))=0;

endend

continueend

x;end

x;end

endcount=0;

endx;

for i= 1:rfor j=1:c

if x(i,j) =0x(i,j)=1;

endend

endx;z=xnv.*xMinvalue=(sum(sum(z)))

plot(z)toc;

266