Skip to content

Commit 4016950

Browse files
author
A. Wilke
committed
Updated to ACOTSP 1.03
1 parent 208c71d commit 4016950

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

README.md

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ACOTSPJava
22
==========
33

4-
A Java implementation of ACO algorithms for the TSP
4+
A Java implementation of ACO algorithms for the TSP
55

66

77

@@ -16,20 +16,31 @@ https://github.com/adibaba/ACOTSPJava/
1616

1717

1818

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+
-----
2521

2622
You have to include the Apache Commons CLI library 1.2
2723
http://commons.apache.org/proper/commons-cli/
2824

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+
2931

3032

31-
Contact information
33+
Project information
3234
-------------------
3335

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+
3445
Adrian Wilke
3546
http://adrianwilke.de/

src/de/adrianwilke/acotspjava/LocalSearch.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static void two_opt_first(int[] tour)
119119
int pos_c1, pos_c2; /* positions of cities c1, c2 */
120120
int i, j, h, l;
121121
int help;
122-
boolean improve_node, improvement_flag;
122+
boolean improvement_flag;
123123
int h1 = 0, h2 = 0, h3 = 0, h4 = 0;
124124
int radius; /* radius of nn-search */
125125
int gain = 0;
@@ -147,7 +147,6 @@ static void two_opt_first(int[] tour)
147147
// DEBUG ( assert ( c1 < Tsp.n && c1 >= 0); )
148148
if (dlb_flag && dlb[c1])
149149
continue;
150-
improve_node = false;
151150
pos_c1 = pos[c1];
152151
s_c1 = tour[pos_c1 + 1];
153152
radius = Tsp.instance.distance[c1][s_c1];
@@ -164,7 +163,6 @@ static void two_opt_first(int[] tour)
164163
h2 = s_c1;
165164
h3 = c2;
166165
h4 = s_c2;
167-
improve_node = true;
168166
gotoExchange = true;
169167
break;
170168
}
@@ -198,7 +196,6 @@ static void two_opt_first(int[] tour)
198196
h2 = c1;
199197
h3 = p_c2;
200198
h4 = c2;
201-
improve_node = true;
202199
gotoExchange = true;
203200
break;
204201
}
@@ -207,7 +204,13 @@ static void two_opt_first(int[] tour)
207204
}
208205
}
209206

210-
if (improve_node || gotoExchange) {
207+
if (!gotoExchange) {
208+
/* No exchange */
209+
dlb[c1] = true;
210+
continue;
211+
}
212+
213+
if (gotoExchange) {
211214
gotoExchange = false;
212215
improvement_flag = true;
213216
dlb[h1] = false;

src/de/adrianwilke/acotspjava/Tsp.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ static int ceil_distance(int i, int j)
119119
{
120120
double xd = instance.nodeptr[i].x - instance.nodeptr[j].x;
121121
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);
123123

124-
return (int) r;
124+
return (int) Math.ceil(r);
125125
}
126126

127127
static int geo_distance(int i, int j)

0 commit comments

Comments
 (0)