Skip to content

Commit

Permalink
Updated to ACOTSP 1.03
Browse files Browse the repository at this point in the history
  • Loading branch information
A. Wilke committed Feb 5, 2014
1 parent 208c71d commit 4016950
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ACOTSPJava
==========

A Java implementation of ACO algorithms for the TSP
A Java implementation of ACO algorithms for the TSP



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



Project information
-------------------

The code is based on the ACOTSP project of Thomas Stuetzle:
ACO algorithms for the TSP
http://iridia.ulb.ac.be/~mdorigo/ACO/aco-code/public-software.html
Usage
-----

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

- Download the file
http://archive.apache.org/dist/commons/cli/binaries/commons-cli-1.2-bin.tar.gz
- Copy the file 'commons-cli-1.2.jar' to your project directory
- Add the library
In Eclipse: Right-click on jar-file -> 'Build Path' -> 'Add to Build Path'



Contact information
Project information
-------------------

The code is based on the ACOTSP project of Thomas Stuetzle:
ACO algorithms for the TSP, version 1.03
http://www.aco-metaheuristic.org/aco-code



Contact
-------

Adrian Wilke
http://adrianwilke.de/
13 changes: 8 additions & 5 deletions src/de/adrianwilke/acotspjava/LocalSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static void two_opt_first(int[] tour)
int pos_c1, pos_c2; /* positions of cities c1, c2 */
int i, j, h, l;
int help;
boolean improve_node, improvement_flag;
boolean improvement_flag;
int h1 = 0, h2 = 0, h3 = 0, h4 = 0;
int radius; /* radius of nn-search */
int gain = 0;
Expand Down Expand Up @@ -147,7 +147,6 @@ static void two_opt_first(int[] tour)
// DEBUG ( assert ( c1 < Tsp.n && c1 >= 0); )
if (dlb_flag && dlb[c1])
continue;
improve_node = false;
pos_c1 = pos[c1];
s_c1 = tour[pos_c1 + 1];
radius = Tsp.instance.distance[c1][s_c1];
Expand All @@ -164,7 +163,6 @@ static void two_opt_first(int[] tour)
h2 = s_c1;
h3 = c2;
h4 = s_c2;
improve_node = true;
gotoExchange = true;
break;
}
Expand Down Expand Up @@ -198,7 +196,6 @@ static void two_opt_first(int[] tour)
h2 = c1;
h3 = p_c2;
h4 = c2;
improve_node = true;
gotoExchange = true;
break;
}
Expand All @@ -207,7 +204,13 @@ static void two_opt_first(int[] tour)
}
}

if (improve_node || gotoExchange) {
if (!gotoExchange) {
/* No exchange */
dlb[c1] = true;
continue;
}

if (gotoExchange) {
gotoExchange = false;
improvement_flag = true;
dlb[h1] = false;
Expand Down
4 changes: 2 additions & 2 deletions src/de/adrianwilke/acotspjava/Tsp.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ static int ceil_distance(int i, int j)
{
double xd = instance.nodeptr[i].x - instance.nodeptr[j].x;
double yd = instance.nodeptr[i].y - instance.nodeptr[j].y;
double r = Math.sqrt(xd * xd + yd * yd) + 0.000000001;
double r = Math.sqrt(xd * xd + yd * yd);

return (int) r;
return (int) Math.ceil(r);
}

static int geo_distance(int i, int j)
Expand Down

0 comments on commit 4016950

Please sign in to comment.