File tree 3 files changed +29
-15
lines changed
src/de/adrianwilke/acotspjava
3 files changed +29
-15
lines changed Original file line number Diff line number Diff line change 1
1
ACOTSPJava
2
2
==========
3
3
4
- A Java implementation of ACO algorithms for the TSP
4
+ A Java implementation of ACO algorithms for the TSP
5
5
6
6
7
7
@@ -16,20 +16,31 @@ https://github.com/adibaba/ACOTSPJava/
16
16
17
17
18
18
19
- Project information
20
- -------------------
21
-
22
- The code is based on the ACOTSP project of Thomas Stuetzle:
23
- ACO algorithms for the TSP
24
- http://iridia.ulb.ac.be/~mdorigo/ACO/aco-code/public-software.html
19
+ Usage
20
+ -----
25
21
26
22
You have to include the Apache Commons CLI library 1.2
27
23
http://commons.apache.org/proper/commons-cli/
28
24
25
+ - Download the file
26
+ http://archive.apache.org/dist/commons/cli/binaries/commons-cli-1.2-bin.tar.gz
27
+ - Copy the file 'commons-cli-1.2.jar' to your project directory
28
+ - Add the library
29
+ In Eclipse: Right-click on jar-file -> 'Build Path' -> 'Add to Build Path'
30
+
29
31
30
32
31
- Contact information
33
+ Project information
32
34
-------------------
33
35
36
+ The code is based on the ACOTSP project of Thomas Stuetzle:
37
+ ACO algorithms for the TSP, version 1.03
38
+ http://www.aco-metaheuristic.org/aco-code
39
+
40
+
41
+
42
+ Contact
43
+ -------
44
+
34
45
Adrian Wilke
35
46
http://adrianwilke.de/
Original file line number Diff line number Diff line change @@ -119,7 +119,7 @@ static void two_opt_first(int[] tour)
119
119
int pos_c1 , pos_c2 ; /* positions of cities c1, c2 */
120
120
int i , j , h , l ;
121
121
int help ;
122
- boolean improve_node , improvement_flag ;
122
+ boolean improvement_flag ;
123
123
int h1 = 0 , h2 = 0 , h3 = 0 , h4 = 0 ;
124
124
int radius ; /* radius of nn-search */
125
125
int gain = 0 ;
@@ -147,7 +147,6 @@ static void two_opt_first(int[] tour)
147
147
// DEBUG ( assert ( c1 < Tsp.n && c1 >= 0); )
148
148
if (dlb_flag && dlb [c1 ])
149
149
continue ;
150
- improve_node = false ;
151
150
pos_c1 = pos [c1 ];
152
151
s_c1 = tour [pos_c1 + 1 ];
153
152
radius = Tsp .instance .distance [c1 ][s_c1 ];
@@ -164,7 +163,6 @@ static void two_opt_first(int[] tour)
164
163
h2 = s_c1 ;
165
164
h3 = c2 ;
166
165
h4 = s_c2 ;
167
- improve_node = true ;
168
166
gotoExchange = true ;
169
167
break ;
170
168
}
@@ -198,7 +196,6 @@ static void two_opt_first(int[] tour)
198
196
h2 = c1 ;
199
197
h3 = p_c2 ;
200
198
h4 = c2 ;
201
- improve_node = true ;
202
199
gotoExchange = true ;
203
200
break ;
204
201
}
@@ -207,7 +204,13 @@ static void two_opt_first(int[] tour)
207
204
}
208
205
}
209
206
210
- if (improve_node || gotoExchange ) {
207
+ if (!gotoExchange ) {
208
+ /* No exchange */
209
+ dlb [c1 ] = true ;
210
+ continue ;
211
+ }
212
+
213
+ if (gotoExchange ) {
211
214
gotoExchange = false ;
212
215
improvement_flag = true ;
213
216
dlb [h1 ] = false ;
Original file line number Diff line number Diff line change @@ -119,9 +119,9 @@ static int ceil_distance(int i, int j)
119
119
{
120
120
double xd = instance .nodeptr [i ].x - instance .nodeptr [j ].x ;
121
121
double yd = instance .nodeptr [i ].y - instance .nodeptr [j ].y ;
122
- double r = Math .sqrt (xd * xd + yd * yd ) + 0.000000001 ;
122
+ double r = Math .sqrt (xd * xd + yd * yd );
123
123
124
- return (int ) r ;
124
+ return (int ) Math . ceil ( r ) ;
125
125
}
126
126
127
127
static int geo_distance (int i , int j )
You can’t perform that action at this time.
0 commit comments