• Aucun résultat trouvé

An electronic algorithm to find the optimal solution for the travelling salesman problem

N/A
N/A
Protected

Academic year: 2021

Partager "An electronic algorithm to find the optimal solution for the travelling salesman problem"

Copied!
12
0
0

Texte intégral

(1)

HAL Id: hal-01348442

https://hal.archives-ouvertes.fr/hal-01348442

Preprint submitted on 23 Jul 2016

HAL is a multi-disciplinary open access archive for the deposit and dissemination of sci- entific research documents, whether they are pub- lished or not. The documents may come from

L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des établissements d’enseignement et de

the travelling salesman problem

M Sghiar

To cite this version:

M Sghiar. An electronic algorithm to find the optimal solution for the travelling salesman problem.

2016. �hal-01348442�

(2)

An electronic algorithm to find the optimal solution for the travelling salesman problem

July 23, 2016 M.Sghiar msghiar21@gmail.com

9 Allée capitaine J.B. Bossu, 21240, Talant, France Tel : (France) 0033669753590

Abstract:

I give here an electronic algorithm of the order O(n3) which is a generaliza- tion of the atomic algorithm found in [6] and allows us to find the optimal hamiltonian cycles.

If the atomic algorithm (see [6] and [5] ) was inspired by the movement of the particles in the atom, the electronic algorithm is inspired by the resistor in the electrical circuit.

Keywords : Graph, Hamilton cycles, P=NP, the travelling sales- man problem, TSP

(3)

Introduction

The travelling salesman problem (TSP), which is an NP-hard problem in combinatorial optimization (see [1] , [2] , [3] and [4] ), important in operations research and theoretical computer science, asks the following question: Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city?

In the articles [5] and [6], I was interested to find the Hamiltonian cycles in a graph - not necessarily optimal-. And inspired by the movement of the particles in the atom, I demonstrated (in [5] and [6]) the exsitence of a ploynomial algorithm of the order O(n3) for finding Hamiltonian cycles in a graph.

This algorithm I called Atomic algorithm (See [6]), joins other several meth- ods to find the Hamiltonian cycles like the Monte Carlo method, Dynamic programming, or DNA computing.

And to prevent memory overflow and the slow execution of the program, I suggested in [6] the use of servers: Each point xi in the graph will be considered as a server, and each server xi will communicate with each other server xj with which it is connected . And finally the server x0 will receive and display the Hamiltonian cycles if they exist.

But I found that the full of memory is caused by the fact that each server send all the list he received, hence the idea to limit the amount that will send each server, and delete as and as the list that do not serve for anything.

This idea was great, since I no longer have the problem of memory overflow and the program runs faster : thus only in ten minutes, with a non- powerful computer, I was able to find a Hamiltonian cycle for thousand cities: You can test it with the below improved Feynman code.

(4)

And to find an optimal solution to the TSP problem, the solution to find all Hamiltonian cycles and choose the cycle that have the shortest distance would take time hugely although servers operate simultaneously. Hence the need to seek other way to find the optimal solutions.

Thinking of the servers, we immediately think of antennas, microwave , fre- quencies .... in short, we think to the field of electronics. Hence the idea: If we saw servers or nodes of the graph as a node in an electrical circuit, and the "distances" between vertices as a resistor values in a circuit, then more the resistor’s value is low and more the current passes quickly, so the particle or its energy will move faster by taking the shortest route.

Improved of the Feynman code that gives a Hamiltonian cycles

1

2 from scipy import *

3 import numpy as np

4 import random

5 import time

6 start = time . time ()

7

8 # The Feynman code in Python :

9 # Written by sghiar July 21 , 2016 at 21:25 p . m ..

10 # This code allows you to find the Hamilton cycle if it exists .

11

12 # Skip Code

13

14 # We define the Feynman function F .

15

16 def F (j , T ) :

17

18 l = len ( T )

(5)

19 U =[ l +1]

20 U =[0]*( l +1)

21 U [0]= T [0] -1

22 for i in range (1 , l ) :

23 U [ i +1]= T [ i ]

24 U [1]= j

25 return U

26 27 28 29 30

31 # We define the function R .

32

33 def R ( T ) :

34 l = len ( T )

35 U =[]

36 for i in range (l -1) :

37 U . append ( T [ i +1])

38 return U

39 40 41

42 # We define the distance function in a Hamiltonia n cycle .

43

44 def D ( T ) :

45 D =0.0

46 l = len ( T )

47

48 for i in range (0 , l -1) :

49 D = D +( G [ T [ i ]][ T [ i +1]])

50 return D

51 52 53

54 # We construct the graph G :

55 56 57

58 print ( " number of cities = " )

(6)

59

60 n = input ()

61

62 G = np . eye (n , n ) #

63 64 65

66 for i in range ( n ) :

67 for j in range ( n ) :

68 G [ i ][ j ]=1

69 # G [ i ][ j ]= input ()

70 # print " G [ " ,i , " ][ " ,j , " ] "

71 # G [ i ][ j ]= input ()

72 # if i <= j :

73 # G [ i ][ j ]= random . randint (0 ,1)

74 # else : G [ i ][ j ]= G [ j ][ i ]

75 # print " G [ " ,i , " ][ " ,j , " ]= " ,G [ i ][ j ]

76 77 78 79 80 d ={}

81

82 d [0]=[[ n ,0]]

83 84

85 for j in range ( n ) :

86 if G [0][ j ]!=0 and 0!= j :

87 d [ j ]=[[ n -1 , j ,0]]

88 d [0]=[]

89 # print d [ j ]

90 else :

91 d [ j ]=[[0 , j ]]

92 # print d [ j ]

93 94 95 L =[]

96 H =[]

97

98 for k in range (0 , n **2) :

99

(7)

100 if len ( H ) != 0 :

101

102 print H

103 print ( " Time : " , time . time () - start )

104 break

105

106 print (k , " Time : " , time . time () - start )

107 print " The program is looking for the Hamiltonie n cycles ... "

108

109 if k % n ==0:

110

111 for T in d [ k % n ] :

112 if T [0] == 0 :

113 H . append ( T )

114

115 else :

116 pass

117

118 del d [0]

119 d [0]=[]

120 121

122 elif k % n !=0 and len ( d [ k % n ]) >0:

123 l = len ( d [ k % n ])

124 T = d [ k % n ][ l -1]

125 for j in range (0 , n ) :

126

127 if T [0] <=0 or ( j in R ( T ) and j !=0) :

128 pass

129 else :

130 if G [ k % n ][ j ]!=0 and ( k % n ) != j :

131 d [ j ]+=[ F (j , T ) ]

132 else :

133 pass

134 d [ k % n ]. remove ( T )

135 136 137 138

139 # Hamiltoni a ns Cycles :

(8)

140 141

142 if len ( H ) !=0:

143 for elt in H :

144

145 print ( " There exist the Hamiltonia n cycles " )

146 print ( R ( elt ) ," Is one Hamiltonie n cycle , Its distance is : " , D ( elt ) )

147

148 else :

149 print ( " No Hamiltonia n cycles " )

150

151 print len ( H )

152 print ( " Time : " , time . time () - start )

153 # End of code

An electronic algorithm to find the optimal so- lution for the travelling salesman problem

This algorithm is almost similar to the Feynaman algorithm (See [5] ) to a slight change near :

Let G be a graph on E = {x0,· · · , xn−1}, where G[xi][xj]= 1 or 0, and the

"distance" between xi and xj is noteddij.

we can reduce to the case where dij is a nonzero positive : dij 0, ∀i, j

We note {d1,· · · , dl}=Si,j{dij}. withdidj if ij.

As we have seen in the introdution, thinking of the servers, we immediately think of antennas, microwave , frequencie .... in short, we think to the field of electronics. Hence the idea: If we saw servers or nodes of the graph as a node in an electrical circuit, and the "distances" between vertices as a resistor

(9)

values in a circuit, then more the resistor’s value is low and more the current passes quickly, so the particle or its energy will move faster by taking the shortest route.

And there is a link between time and the "distance" :

tij = 1 υijdij

Where υij is the speed of the electons in the electrical circuit.

ωij =υij 1 dij Where ωij is the frequency.

Otherwise seen :The server i communicate with the server j with the fre- quency ωij.

Time progresses, the server x0 sends the energy to other servers, the other servers will send it in turn to others. But as the exchange between two servers xi and xj occurs at a frequency ωij:

To a factor, let υij = 1.

We shall have :

tij =dij and

ωij = 1 dij

We start with thehigh frequencies: in other words by the smallest resistor value.

We first see the smallest resistor valueds0betweenx0andxisuch asG[x0][xi] =

(10)

1.

In the step i=1 (mod l) :

x0 will give its energy to other points xi through the resistors ds0.

And as in the Feynman algorithm, we construct the Feynman vector for the point xi:

F(xi) =

Exi

xi ...

x0

And we construct the Feynman matrix for the point xi:

M(F, x0) =

Exi · · · xi · · · ... · · · x0 · · ·

In this step, those points xi will have Exi =n−1 as energy value.

In the step i=2 (mod l) :

Among the pointsxi related tox0 we choose the minimum resistor valueds1. such that ds1 ds0 if it exist, else we choose the minimum resistor value ds1. such that ds1ds0

Each point xi linked to a resistor with value ds1 will give its energy to other points through the resistor ds1.

In the step i+1 (mod l) :

We continue this process and as the energy decreases; the algorithm, as the Feynaman algorithm, will stop, and will display the Hamiltonian cycle with a shorter distance (if the Hamiltonian cycles exist).

Example :

(11)

We can check this technique for example for the Graph G on the basis E = {a, b, c, d} with : G(x, y)=1, ∀x, y ∈ E, and with the distances : d(a,c)=3, d(a,b)=d(a, d)=d(b,d)=1, d(b, c)=2, d(c,d)=4.

We check that acbda is the first hamiltonian cycle that we find and that it have a minimal distance 7. The other cycle with the distance 8 will be found after because it do not have a minimum distance, and the cycle with the distance 9 will not be found for the same reason.

NOTE :

1- The above improved Feynman algorithm indicates whether the Hamilto- nian cycles exist.

2- If the Hamiltonian cycles exist, the electronic algorithm allows us to find the optimals Hamiltonian cycles.

3- The electronic algorithm is also of the order O(n3) like the Feynman algorithm.

4- The electronic algorithm is a generalization of the Atomic algotithm.

5- With this way I could find by hand the optimals Hamiltonian cycles for some graphs of a small size. : See the example above.

References

[1] Lizhi Du. A polynomial time algorithm for hamilton cycle. IMECS, I:17–19, March 2010. Hong Kong.

[2] L.Lovasz. Combinatorial problems and exercises. Noth-Holland, Amster- dam, 1979.

(12)

[3] D.S.Johnson M.R.Garey. Computers and intractability:a guid to the the- ory of np-completeness. Freeman,San Francisco, 1979.

[4] R.Diestel. Graph theory. Springer, New York, 2000.

[5] M. Sghiar. Algorithmes quantiques, cycles hamiltoniens et la k-coloration des graphes. Pioneer Journal of Mathematics and Mathematical Sciences, 17-Issue 1:51–69, May 2016.

[6] M. Sghiar. Atomic algorithm and the servers’ s use to find the hamiltonian cycles. International Journal of Engineering Research and Applications (IJERA), ISSN: 2248-9622, 6-Issue 6:23–30, jun 2016.

M.Sghiar msghiar21@gmail.com 9 Allée capitaine J.B. Bossu, 21240, Talant, France Tel : (France) 0033669753590

Références

Documents relatifs

Step 3; Identify the solution to the original problem: this is done by finding an Euler cycle or circuit associated with the optimal solution of step 2, (Hère, one may use the

Study, Vol. CROWDER, Validation of Subgradiant Optimization, Math. LAURIÈRE, Un Algorithme pour les Problèmes de Recouvrements, R.A.I.R.O., Vol. KARP, The Travelling Salesman

Polyominoes, tiling the plane by translation, theorem of Beauquier- Nivat, pseudo-square, pseudo-hexagon, enumeration of special classes of polyominoes.. 1 Laboratoire

It solves the blank node labeling problem by encoding the complete context of a blank node, including the RDF graph structure, into the data used to calculate the hash value..

Because this problem is an NP- hard problem there is not a known deterministic efficient (polinomial) method. Non- deterministic methods are in general more efficient but an

For the electronic measurement of currents : DC, AC, pulsed..., with a galvanic isolation between the primary circuit (high power) and the secondary circuit (electronic

In the second part of this section, the experimental results are presented when the system is controlled by the two control laws developed in section 3.2 and 3.3 with

Considering the P ||C max problem, LPT heuristic give the upper bound value UB max = 323 and the lower bound is LB max = 318. Applying FFD function with capacity 322 and the 10