solving the traveling salesman problem and establishing p = np

10
7/26/2019 Solving the Traveling Salesman Problem and Establishing P = NP http://slidepdf.com/reader/full/solving-the-traveling-salesman-problem-and-establishing-p-np 1/10 Solving the Traveling Salesman Problem and establishing P = NP Marc Mad April 4, 2016 1) Introduction: This paper will demonstrate a solution for the traveling salesman problem and as a consequence why P is equal to NP. 2.1)Brief description of the Traveling Salesman Problem (TSP):  You have n cities and have to find the shortest path to visit all and come back to the start city, passing only one time in every city. To do it you just know the distances between the cities. This problem is classified as NPhard. !ut also can be NP complete. "f the question is to check if there is a path that go in all cities once and came back to the start smaller than a given number. 2.2) Solving the TSP: NPhard version #$et a matri% with the values& #'um the numbers of the matri% lines, generating one sum per line (The line has the distance from one city to others)& #*ind the cities that have the + biggest sums and connect the cities with it other. (.g. -!-)& #The previous step will generate rows (.g. -!& -& !)& #*or every ne%t city (that will be the biggest remaining sum, coming from the sums made in the second step)/ for all the already generated rows/ sum the distance from the actual city to both of the row cities and subtract the row si0e ($enerating a cost). get the row with the smallest cost delete this row and add 1 new ones, from the actual city to the cities that were forming the deleted row. NPcomplete version #2ust do the steps from the NPhard version and at the end sum the the path to see if it is smaller than the given number.

Upload: marc-marc

Post on 02-Mar-2018

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Solving the Traveling Salesman Problem and Establishing P = NP

7/26/2019 Solving the Traveling Salesman Problem and Establishing P = NP

http://slidepdf.com/reader/full/solving-the-traveling-salesman-problem-and-establishing-p-np 1/10

Solving the Traveling Salesman

Problem and establishing P = NPMarc Mad

April 4, 2016

1) Introduction:

This paper will demonstrate a solution for the traveling salesman problem and as a consequencewhy P is equal to NP.

2.1)Brief description of the Traveling Salesman Problem (TSP): 

You have n cities and have to find the shortest path to visit all and come back to the start city,passing only one time in every city. To do it you just know the distances between the cities.This problem is classified as NPhard.!ut also can be NP complete. "f the question is to check if there is a path that go in all cities onceand came back to the start smaller than a given number.

2.2) Solving the TSP:

NPhard version

#$et a matri% with the values&

#'um the numbers of the matri% lines, generating one sum per line (The line has the distance fromone city to others)&

#*ind the cities that have the + biggest sums and connect the cities with it other. (.g. -!-)&

#The previous step will generate rows (.g. -!& -& !)&

#*or every ne%t city (that will be the biggest remaining sum, coming from the sums made in thesecond step)/

for all the already generated rows/

sum the distance from the actual city to both of the row cities and subtract the rowsi0e ($enerating a cost).

get the row with the smallest cost delete this row and add 1 new ones, from the actual cityto the cities that were forming the deleted row.

NPcomplete version

#2ust do the steps from the NPhard version and at the end sum the the path to see if it is smallerthan the given number.

Page 2: Solving the Traveling Salesman Problem and Establishing P = NP

7/26/2019 Solving the Traveling Salesman Problem and Establishing P = NP

http://slidepdf.com/reader/full/solving-the-traveling-salesman-problem-and-establishing-p-np 2/10

2.) !T"# page that solves the Traveling Salesman Problem:

3456TYP html7

3html7

3head7

38head7

3body7

3h973b7'alesman38b738h97

3h17:ake a better path.38h17

3button onclick;<find!estPath()<7*ind your way38button7

38br738br7

3p id;<result=ere<738p7

3script7

88edit the <distancias< to inform the distances

8#>%>#8var distancias;??>>>, 99, 9@, 9A, 11, 1B, +>, @CD,

?99, >>>, 1B, 99, 1B, 1C, C@, C>D,

?9@, 1B, >>>, 9>, 9@, +C, 1>, @@D,

?9A, 99, 9>, >>>, 9C, 9@, +9, C9D,

?11, 1B, 9@, 9C, >>>, 9>, 9C, +ED,?1B, 1C, +C, 9@, 9>, >>>, 1F, 11D,

?+>, C@, 1>, +9, 9C, 1F, >>>, +CD,

?@C, C>, @@, C9, +E, 11, +C, >>>DD&

88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

8#9A%9A#88#var distancias ; ??>>>, 99, 9@, 9A, 11, 1B, +>, @C, 1@, +1D,

  ?99, >>>, 1B, 99, 1B, 1C, C@, C>, +E, C>D,

  ?9@, 1B, >>>, 9>, 9@, +C, 1>, @@, 99, 1+D,

  ?9A, 99, 9>, >>>, 9C, 9@, +9, C9, 1A, C+D,  ?11, 1B, 9@, 9C, >>>, 9>, 9C, +E, E, C9D,

  ?1B, 1C, +C, 9@, 9>, >>>, 1F, 11, 1B, @BD,

  ?+>, C@, 1>, +9, 9C, 1F, >>>, +C, 9+, @AD,

  ?@C, C>, @@, C9, +E, 11, +C, >>>, CC, >AD,

  ?1@, +E, 99, 1A, E, 1B, 9+, CC, >>>, +@D,

  ?+1, C>, 1+, C+, C9, @B, @A, >A, +@, >>>DD&#8

8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

8#+9%+9#88#var distancias ; ??>>>>>>>> , @CF9.@1 , @AB9.@F ,@+B1.>1 , @C9E.C@ , C@>C.++ , CBAC.>+ ,+>@9.F+ , CCFF.C9 , @1EA.F+ , C>C1.E9 ,@B+A.9C , +EBA.F9 , +FE+.9C , @AC+.9F ,

Page 3: Solving the Traveling Salesman Problem and Establishing P = NP

7/26/2019 Solving the Traveling Salesman Problem and Establishing P = NP

http://slidepdf.com/reader/full/solving-the-traveling-salesman-problem-and-establishing-p-np 3/10

EC+1.>B , @@9>.A@ , @CA@.>A , @[email protected] ,+11E.>1 , @C99.CA , CAB1.C@ , 1CF@.@C ,@9++.11 , +BC9.1A , +11+.F@ , +1>F.B1 ,1+AF.AB , E9A>.@F , C1E+.F+ , @[email protected],

?@CF9.@1, >>>>>>>> , [email protected]> , B1F.+@ , 9@[email protected] ,

BCC.CA , [email protected] , [email protected] , F11C.>B , 991E.F1, E>F.99 , C@>.E+ , 1>A9.19 , +9A>.A9 , @C9.C+ ,BF+.>C , E>1.++ , 99BB.@+ , 99>B.>A , +C19.A> ,9AFA.1@ , 1@@C.F+ , +C>F.EC , 9C9F.C@ ,+A+C.>F , +C+C.1> , ++B1.A+ , +@A+.AF ,EFA.+F , 1CF1.C@ , >F9.1>D,

?@AB9.@F, [email protected]> , >>>>>>>> , 19EE.AA , 1F1C.A9 ,[email protected] , 1B+.@1 , 91CA.FF , EA1B.+F , [email protected] ,9C>B.C+ , [email protected]@ , 9FC9.F9 , 9BFA.AB ,BAA.CF , 9FBA.A> , F+F.F9 , 1C1B.>F , 1C9F.EE ,1+BB.B> , 1+A>.A@ , 9+BE.@@ , 1FCE.F1 ,99>.+@ , 9>@E.F1 , 1C99.B9 , 1+@E.+A , 1>[email protected], 9@AC.>1 , 91FA.11 , 199E.9FD,

?@+B1.>1, B1F.+@ , 19EE.AA , >>>>>>>> , @FF.>@ , BF+.1+ ,9BCF.1> , 1C11.+1 , FFB1.F@ , 1A9A.CF ,>9B.C9 , 9ABE.AB , ++FF.CC , +F11.C@ , 91F+.1+, 9@+>.@A , 9EAE.@@ , 1F1.CC , 1E1.CF , +B1>.E9, 9CC.9+ , +19E.B> , +F>>.E1 , 11F>.1B ,+E>@.1> , +BC9.BB , +B91.1F , +FCC.9A ,

9+FA.F1 , +9F9.EE , @F.9ED,

[email protected]@, 9@[email protected] , 1F1C.A9 , @FF.>@ , >>>>>>>> ,9+EE.E+ , 1CBA.BF , 1>+>.E1 , >9F9.>9 ,1@F>.@B , 91B@.+9 , [email protected]@ , +>AB.>9 ,C9EE.C+ , 9>1C.CF , 1A11.CE , 19>C.9> ,[email protected] , [email protected] , C+9F.99 , [email protected] , +EBA.>C ,CAF+.AC , 1>+>.+E , C9CE.@@ , C++A.+C ,C+AF.C1 , +BBF.A> , 9BA1.B+ , +EE1.A+ ,E++.>@D,

?C@>C.++, BCC.CA , [email protected] , BF+.1+ , 9+EE.E+ , >>>>>>>>, 91BA.9@ , 9CFC.1E , E>+9.E> , [email protected] ,1E+.9+ , 9+>F.C@ , 1CC+.F> , 1FBB.>A , FF+.99 ,9B91.+E , 9++B.@9 , 99CC.BF , 99+A.FE ,1BEF.F> , 9AE>.@> , 1++1.9+ , 1>1A.>E ,9E>B.@> , 1F>9.BB , 1B>9.91 , [email protected]@ ,1F>E.@F , 9E9C.FF , 1+9C.F> , B@@.FED,

?CBAC.>+, [email protected] , 1B+.@1 , 9BCF.1> , 1CBA.BF ,91BA.9@ , >>>>>>>> , 9AEC.C9 , EABC.99 ,

+E1.1E , 911F.F9 , 9C@>.9F , 9F9>.C1 , 9BBA.A>, [email protected] , 9F>@.A1 , F99.AC , 11AC.A1 , 19B9.1@, 1+E>.1> , 1A>E.CC , 9C11.AC , 1E11.>C ,

Page 4: Solving the Traveling Salesman Problem and Establishing P = NP

7/26/2019 Solving the Traveling Salesman Problem and Establishing P = NP

http://slidepdf.com/reader/full/solving-the-traveling-salesman-problem-and-establishing-p-np 4/10

CAE.@C , 9>BB.+> , 1+>A.>> , 1++A.+B , 1FAA.@B, 9CFC.@> , 9+1C.1C , 9BAA.CED,

?+>@9.F+, [email protected] , 91CA.FF , 1C11.+1 , 1>+>.E1 ,9CFC.1E , 9AEC.C9 , >>>>>>>> , @+F9.CA ,9C91.CA , [email protected]+ , [email protected] , BF1.>C , 9++C.BB

, 9C9A.E1 , 1FF1.B> , 9F+E.EE , 1E9E.@> ,1EA1.+> , [email protected] , 1@+1.AB , BC9.B> , 9@F>.19, 91>B.B9 , 9++B.+B , 9@1+.>1 , 9CB9.+9 ,9E+B.B9 , 1CCE.CA , BBA.B> , 1+BC.@CD,

?CCFF.C9, F11C.>B , EA1B.+F , FFB1.F@ , >9F9.>9 ,E>+9.E> , EABC.99 , @+F9.CA , >>>>>>>> ,E1E+.99 , EBFE.E1 , F@@9.9E , [email protected]+ ,C99E.BB , EE>B.@B , F>9A.+B , EFEC.E9 ,[email protected] , FBE9.F1 , +>EC.EA , F>B>.E+ ,CEFC.9B , C9F+.A1 , @BEE.>@ , [email protected]+ ,+>@9.1+ , +>>A.@+ , C+AB.A9 , F@+C.9E ,CFF1.+A , FFE@.>+D,

[email protected]+, 991E.F1 , [email protected] , 1A9A.CF , 1@F>.@B ,[email protected] , +E1.1E , 9C91.CA , E1E+.99 , >>>>>>>>, 9+B9.FF , 9+9B.99 , 9BF9.@F , [email protected] ,FF>.CE , 9@@C.CC , @AB.B> , 11FB.AC , 11EF.CC ,1E1B.CA , [email protected] , 9E+9.C9 , 1BCB.1+ ,+AC.FF , 1AB1.C9 , 1EC9.CE , 1@>E.E@ , +A+>.C@, 91F9.1C , 9@[email protected] , 9B@>.CAD,

?C>C1.E9, E>F.99 , 9C>B.C+ , >9B.C9 , 91B@.+9 , 1E+.9+ ,911F.F9 , [email protected]+ , EBFE.E1 , 9+B9.FF ,>>>>>>>> , [email protected] , 1@@>.AC , 1BA+.B> ,E9F.1+ , [email protected]+ , 99CF.99 , [email protected]> , 9A19.1E, +99C.9E , B+F.++ , 1CAE.A1 , +A1C.>A ,9EAF.@1 , 1>FA.++ , +91F.@E , +ABE.+@ ,+AA+.@A , [email protected] , 1+EB.FA , F>B.@>D,

?@B+A.9C, C@>.E+ , [email protected]@ , 9ABE.AB , [email protected]@ ,

9+>F.C@ , 9C@>.9F , [email protected] , F@@9.9E ,9+9B.99 , [email protected] , >>>>>>>> , +9E9.E1 ,+CCE.>E , BCB.AF , @1E.+C , >AB.>B , 9+C+.>9 ,9++>.9B , +FB>.CA , 911A.AA , 1>>A.9B ,+B9F.+C , 9E1+.>F , ++@F.+A , +>99.+B ,[email protected] , +BC1.C@ , 1FE.9B , 1FFB.AE , 9ACA.E+D,

?+EBA.F9, 1>A9.19 , 9FC9.F9 , ++FF.CC , +>AB.>9 ,1CC+.F> , 9F9>.C1 , BF1.>C , [email protected]+ , 9BF9.@F, 1@@>.AC , +9E9.E1 , >>>>>>>> , +EF.B9 ,11E9.+E , [email protected] , 1C1E.AA , +@>9.FA ,

+@EF.@+ , E@>.+C , +CB1.EC , C91.99 , [email protected] ,9F11.EB , C1E.E+ , EFA.19 , [email protected] , 9CA9.1A ,+9B+.AA , @>@.1+ , ++CE.1+D,

Page 5: Solving the Traveling Salesman Problem and Establishing P = NP

7/26/2019 Solving the Traveling Salesman Problem and Establishing P = NP

http://slidepdf.com/reader/full/solving-the-traveling-salesman-problem-and-establishing-p-np 5/10

?+FE+.9C, +9A>.A9 , 9BFA.AB , +F11.C@ , C9EE.C+ ,1FBB.>A , 9BBA.A> , 9++C.BB , C99E.BB ,[email protected] , 1BA+.B> , +CCE.>E , +EF.B9 , >>>>>>>>, [email protected]@ , +F@@.1@ , 1E>C.11 , +B+1.>A ,+B9>.EE , @@1.1C , +>CA.FA , @F+.>> , 9+1B.AE ,

9B+1.+C , 9FB.@@ , @@>.E> , CB9.>A , [email protected] ,[email protected] , F9A.+C , +E>B.CAD,

?@AC+.9F, @C9.C+ , BAA.CF , 91F+.1+ , 9>1C.CF , FF+.99 ,[email protected] , 9C9A.E1 , EE>B.@B , FF>.CE , E9F.1+ ,BCB.AF , 11E9.+E , [email protected]@ , >>>>>>>> , 9CAC.91, @FF.1C , 9@+1.B9 , [email protected] , 1>FB.E@ ,9C9+.C9 , 1A1E.+1 , 1BE>.+@ , 9A9E.9A ,1@A@.>E , 1>B1.>@ , 1>@A.E+ , 1BBE.F+ ,9AFC.>F , 9B@+.F1 , [email protected]+D,

?EC+1.>B, BF+.>C , 9FBA.A> , 9@+>.@A , 1A11.CE ,9B91.+E , 9F>@.A1 , 1FF1.B> , F>9A.+B ,9@@C.CC , [email protected]+ , @1E.+C , [email protected] , +F@@.1@, 9CAC.91 , >>>>>>>> , [email protected] , 9F@@.@B ,9F@1.>B , C9@+.19 , 9EC+.A> , +9>9.@1 ,C+CB.CE , 9>CC.>> , +ECE.C@ , [email protected]> ,C99C.>9 , C+B9.FC , +1B.FA , +AEA.9A , 9C>F.C>D,

?@@9>.A@, E>1.++ , F+F.F9 , 9EAE.@@ , 19>C.9> , 9++B.@9, F99.AC , 9F+E.EE , EFEC.E9 , @AB.B> , 99CF.99

, >AB.>B , 1C1E.AA , 1E>C.11 , @FF.1C , [email protected], >>>>>>>> , 9>F>.BB , 9>E>.>1 , +AF>.1A ,[email protected]> , 1999.+@ , ++91.C1 , >9C.@@ , 1@>9.+B, +ABA.F+ , +A+B.CE , ++FC.F+ , FF+.1A ,9BBE.>+ , 9@@9.9+D,

?@CA@.>A , 99BB.@+ , 1C1B.>F , 1F1.CC , [email protected] ,99CC.BF , 11AC.A1 , 1E9E.@> , [email protected] ,11FB.AC , [email protected]> , 9+C+.>9 , +@>9.FA ,+B+1.>A , 9@+1.B9 , 9F@@.@B , 9>F>.BB ,>>>>>>>> , 9C.19 , C991.@B , 91B.@E , +CC9.9A ,

+B11.1B , 1@C+.9B , +BA+.>B , [email protected] ,CABB.C1 , +>E1.@C , 9E9C.>A , +CA+.F9 ,+1>.1@D,

?@[email protected] , 99>B.>A , 1C9F.EE , 1E1.CF , [email protected] ,99+A.FE , 19B9.1@ , 1EA1.+> , FBE9.F1 ,11EF.CC , 9A19.1E , 9++>.9B , +@EF.@+ ,+B9>.EE , [email protected] , 9F@1.>B , 9>E>.>1 ,9C.19 , >>>>>>>> , CAB>.+> , 91A.BC , +C1F.9C ,+BA>.@C , 1@+9.AB , +>>B.>C , C999.F9 ,CA>@.19 , +>CB.A@ , 9EAB.E@ , ++>B.B9 ,+9>.EFD,

Page 6: Solving the Traveling Salesman Problem and Establishing P = NP

7/26/2019 Solving the Traveling Salesman Problem and Establishing P = NP

http://slidepdf.com/reader/full/solving-the-traveling-salesman-problem-and-establishing-p-np 6/10

?+11E.>1 , +C19.A> , 1+BB.B> , +B1>.E9 , C+9F.99, 1BEF.F> , 1+E>.1> , [email protected] , +>EC.EA ,1E1B.CA , +99C.9E , +FB>.CA , E@>.+C , @@1.1C ,1>FB.E@ , C9@+.19 , +AF>.1A , C991.@B ,CAB>.+> , >>>>>>>> , CA+C.AF , 9A+B.@@ ,>@>.+F , 1+>A.+> , F+9.9B , 9+.CA , E9.+F , 9A>B.9E, +>C9.CA , 91A+.A@ , +BA1.@1D,

[email protected] , 9AFA.1@ , 1+A>.A@ , 9CC.9+ , [email protected] ,9AE>.@> , 1A>E.CC , 1@+1.AB , F>B>.E+ ,[email protected] , B+F.++ , 911A.AA , +CB1.EC , +>CA.FA, 9C9+.C9 , 9EC+.A> , [email protected]> , 91B.@E ,91A.BC , CA+C.AF , >>>>>>>> , ++C9.EE , +>E>.>9, 1C1A.F+ , +>AF.CF , CACF.C+ , CA9B.1B ,+>9E.@A , 9CB1.C1 , ++AA.A@ , 9BB.AFD,

?CAB1.C@ , 1@@C.F+ , 9+BE.@@ , +19E.B> , +EBA.>C, 1++1.9+ , 9C11.AC , BC9.B> , CEFC.9B ,9E+9.C9 , 1CAE.A1 , 1>>A.9B , C91.99 , @F+.>> ,1A1E.+1 , +9>9.@1 , 1999.+@ , +CC9.9A ,+C1F.9C , 9A+B.@@ , ++C9.EE , >>>>>>>> ,9E9F.EA , 9+E9.@F , C>A.9C , [email protected]+ , B>>.+F ,9FB1.+9 , 1>>C.+> , 9F+.++ , +9>A.11D,

?1CF@.@C , +C>F.EC , 1FCE.F1 , +F>>.E1 , CAF+.AC, 1>1A.>E , 1E11.>C , 9@F>.19 , C9F+.A1 ,1BCB.1+ , +A1C.>A , +B9F.+C , [email protected] ,

9+1B.AE , 1BE>.+@ , C+CB.CE , ++91.C1 ,+B11.1B , +BA>.@C , >@>.+F , +>E>.>9 , 9E9F.EA, >>>>>>>> , 1FE+.BA , 9CBB.EC , >E9.1C ,B99.EB , 1+1.B1 , CA19.FB , 9F>B.@C , [email protected]>D,

?@9++.11 , 9C9F.C@ , 99>.+@ , 11F>.1B , 1>+>.+E ,9E>B.@> , CAE.@C , 91>B.B9 , @BEE.>@ , +AC.FF ,9EAF.@1 , 9E1+.>F , 9F11.EB , 9B+1.+C ,9A9E.9A , 9>CC.>> , >9C.@@ , 1@C+.9B , 1@+9.AB, 1+>A.+> , 1C1A.F+ , 9+E9.@F , 1FE+.BA ,>>>>>>>> , 9>9A.BA , 1+B9.BB , 1++C.@B ,

1>F9.>+ , 9@FA.+@ , 911@.@E , 111F.B>D,

?+BC9.1A , +A+C.>F , 9>@E.F1 , +E>@.1> , C9CE.@@, 1F>9.BB , 9>BB.+> , 9++B.+B , [email protected]+ ,1AB1.C9 , 1>FA.++ , ++@F.+A , C1E.E+ , 9FB.@@ ,1@A@.>E , +ECE.C@ , 1@>9.+B , +BA+.>B ,+>>B.>C , F+9.9B , +>AF.CF , C>A.9C , 9CBB.EC ,9>9A.BA , >>>>>>>> , F+F.+C , EFA.CB , 9F9A.BE ,[email protected]> , @>E.@1 , +ECB.B1D,

?+11+.F@ , +C+C.1> , 1C99.B9 , +BC9.BB , C++A.+C, 1B>9.91 , 1+>A.>> , 9@1+.>1 , +>@9.1+ ,1EC9.CE , +91F.@E , +>99.+B , EFA.19 , @@>.E> ,

Page 7: Solving the Traveling Salesman Problem and Establishing P = NP

7/26/2019 Solving the Traveling Salesman Problem and Establishing P = NP

http://slidepdf.com/reader/full/solving-the-traveling-salesman-problem-and-establishing-p-np 7/10

1>B1.>@ , [email protected]> , +ABA.F+ , [email protected] ,C999.F9 , 9+.CA , CACF.C+ , [email protected]+ , >E9.1C ,1+B9.BB , F+F.+C , >>>>>>>> , EE.>> , 9AB1.C+ ,+>@C.AB , 919+.AB , [email protected],

?+1>F.B1 , ++B1.A+ , 1+@E.+A , +B91.1F , C+AF.C1

, [email protected]@ , 1++A.+B , 9CB9.+9 , +>>A.@+ ,1@>E.E@ , +ABE.+@ , [email protected] , [email protected] , CB9.>A ,1>@A.E+ , C99C.>9 , +A+B.CE , CABB.C1 ,CA>@.19 , E9.+F , CA9B.1B , B>>.+F , B99.EB ,1++C.@B , EFA.CB , EE.>> , >>>>>>>> , 99C9.+F ,+>AC.C9 , [email protected]> , +>>@.+ED,

?1+AF.AB , +@A+.AF , 1>[email protected] , +FCC.9A , +BBF.A>, 1F>E.@F , 1FAA.@B , 9E+B.B9 , C+AB.A9 ,+A+>.C@ , +AA+.@A , +BC1.C@ , 9CA9.1A ,[email protected] , 1BBE.F+ , C+B9.FC , ++FC.F+ ,+>E1.@C , +>CB.A@ , 9A>B.9E , +>9E.@A ,9FB1.+9 , 1+1.B1 , 1>F9.>+ , 9F9A.BE , 9AB1.C+, 99C9.+F , >>>>>>>> , CAE1.CB , 9BE9.E@ ,+F+C.9ED,

?E9A>.@F , EFA.+F , 9@AC.>1 , 9+FA.F1 , 9BA1.B+ ,9E9C.FF , 9CFC.@> , 1CCE.CA , F@+C.9E ,91F9.1C , [email protected] , 1FE.9B , +9B+.AA , [email protected], 9AFC.>F , +1B.FA , FF+.1A , 9E9C.>A , 9EAB.E@, +>C9.CA , 9CB1.C1 , 1>>C.+> , CA19.FB ,

9@FA.+@ , [email protected]> , +>@C.AB , +>AC.C9 ,CAE1.CB , >>>>>>>> , 1FEB.@F , 9+9@.@BD,

?C1E+.F+ , 1CF1.C@ , 91FA.11 , +9F9.EE , +EE1.A+, 1+9C.F> , 9+1C.1C , BBA.B> , CFF1.+A ,9@[email protected] , 1+EB.FA , 1FFB.AE , @>@.1+ , F9A.+C ,9B@+.F1 , +AEA.9A , 9BBE.>+ , +CA+.F9 ,++>B.B9 , 91A+.A@ , ++AA.A@ , 9F+.++ , 9F>B.@C, 911@.@E , @>E.@1 , 919+.AB , [email protected]> ,9BE9.E@ , 1FEB.@F , >>>>>>>> , +9+1.@ED,

?@[email protected] , >F9.1> , 199E.9F , @F.9E , E++.>@ , B@@.FE ,9BAA.CE , 1+BC.@C , FFE@.>+ , 9B@>.CA ,F>B.@> , 9ACA.E+ , ++CE.1+ , +E>B.CA , [email protected]+, 9C>F.C> , 9@@9.9+ , +1>.1@ , +9>.EF , +BA1.@1, 9BB.AF , +9>A.11 , [email protected]> , 111F.B> ,+ECB.B1 , [email protected] , +>>@.+E , +F+C.9E ,9+9@.@B , +9+1.@E , >>>>>>>>D,D&#8

88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

var g ; A&

var j ; A&

var t ; A&

var l ; A&

Page 8: Solving the Traveling Salesman Problem and Establishing P = NP

7/26/2019 Solving the Traveling Salesman Problem and Establishing P = NP

http://slidepdf.com/reader/full/solving-the-traveling-salesman-problem-and-establishing-p-np 8/10

var i ; A&

var n ; A&

var p ; A&

var u ; A&

var s ; A&

var b ; A&

function find!estPath()

G

var sums ; ?D&

var sums1 ; ?D&

var finalHows ; ?D&

var *! ; ?D&

var time9A ; ?D&

for(p ; A& p3distancias.length& pII)

G

s ; A&

for(u ; A& u3distancias.length& uII)

G

s I; Number(distancias?pD?uD)&

J

sums.push(s)&

J

sums1 ; sums.slice()&

sums1.sort(function(a, b)Greturn baJ)&

finalHows.push(?sums.inde%6f(sums1?AD)D)&

finalHows?AD.push(sums.inde%6f(sums1?9D))&

finalHows.push(?sums.inde%6f(sums1?9D)D)&

finalHows?9D.push(sums.inde%6f(sums1?1D))&

finalHows.push(?sums.inde%6f(sums1?1D)D)&

finalHows?1D.push(sums.inde%6f(sums1?AD))&

for (n;+& n3distancias.length& nII)

G

*! ; ?D&

time9A ; ?D&

t ; sums.inde%6f(sums1?nD)&

Page 9: Solving the Traveling Salesman Problem and Establishing P = NP

7/26/2019 Solving the Traveling Salesman Problem and Establishing P = NP

http://slidepdf.com/reader/full/solving-the-traveling-salesman-problem-and-establishing-p-np 9/10

for (g;A& g3n& gII)

G

 j ; finalHows?gD?AD&

l ; finalHows?gD?9D&

*!.push(Number(distancias?tD?jD)INumber(distancias?tD?lD)

Number(distancias?jD?lD))&

J

time9A ; *!.slice()&

time9A.sort(function(a, b)Greturn abJ)&

finalHows.push(?sums.inde%6f(sums1?nD)D)&

finalHows?nD.push(finalHows?*!.inde%6f(time9A?AD)D?9D)&

finalHows?*!.inde%6f(time9A?AD)D?9D ; t&

J

document.getlement!y"d(<result=ere<).inner=T:K;finalHowsI< this has <IfinalHows.lengthI< rows<&

window.alert(finalHows)&

J

8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

38script7

38body738html7

2.$)%&plaining the !T"# page:

*irst set the array with the distances (Note that the array starts with city A distance to other citiesinside the first ? D, city 9 inside the second, city two inside the third and so on and when from n to nuse a big number, this way when it sums will get a high result and not consider it.)

'um the numbers of the array square brackets, generating one sum result for every square

bracket&

$enerates an array in descending order using these sums&

onnect the cities of the + first elements in this array with it other. (.g. A91A)&

The previous step will generate paths (.g. A,9& 9,1 e 1,A)&

*or every ne%t city from the array made with the square !rackets sums/ get all the alreadygenerated paths, sum the distance from the actual city to both of the path cities and subtract thepath si0e ($enerating a cost for it path) and get the path with the smallest cost delete this path andadd 1 new ones, from the actual city to the cities that were forming the deleted path.

The result will be pairs of numbers, those are the paths that form the best way. *or e%emple/

A,9,C,+,9,1,1,C,+,A, here the best way is from A to 9, C to +, 9 to 1, 1 to C and + to A.Note that the code can run faster if used a better sorting algorithm.

Page 10: Solving the Traveling Salesman Problem and Establishing P = NP

7/26/2019 Solving the Traveling Salesman Problem and Establishing P = NP

http://slidepdf.com/reader/full/solving-the-traveling-salesman-problem-and-establishing-p-np 10/10

)P ' P

"n short P stands for polynomial time and in this class are the problems that are easy to solve andcheck, NP stands for non polynomial time and this class contains the problems that are easy tocheck and hard to solve and the P vs NP question asks if all problems that can have the solutionchecked in polynomial time can be solved in polynomial time.

Thus is possible to say that P ; NP because it has already been proved that all the problems in theNP class can be reduced to the ones in the NP6:PKT class. 'o if one NP6:PKTproblem, the traveling salesman problem, is solved in polynomial time then all the NP class can besolved in polynomial time and if a problem can be solved and checked in polynomial time thisproblem is classified as P.

$) onclusion:

"t has already been established that any NP problem can be reduced to a NPcomplete problem inpolynomial time. Thus the solution above shows that all the NP class of problems is solvable in

polynomial time, what means NP is equal to P.