├── src ├── Ant.java ├── Route.java ├── Constant.java ├── AntAlgorithm.java ├── canReachCity.java └── Main.java └── README.md /src/Ant.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yaochenkun/TSP-antcolony-algorithm/HEAD/src/Ant.java -------------------------------------------------------------------------------- /src/Route.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yaochenkun/TSP-antcolony-algorithm/HEAD/src/Route.java -------------------------------------------------------------------------------- /src/Constant.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yaochenkun/TSP-antcolony-algorithm/HEAD/src/Constant.java -------------------------------------------------------------------------------- /src/AntAlgorithm.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yaochenkun/TSP-antcolony-algorithm/HEAD/src/AntAlgorithm.java -------------------------------------------------------------------------------- /src/canReachCity.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yaochenkun/TSP-antcolony-algorithm/HEAD/src/canReachCity.java -------------------------------------------------------------------------------- /src/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main 3 | { 4 | public static void main(String[] args) 5 | { 6 | AntAlgorithm AA=new AntAlgorithm(); 7 | AA.run(); 8 | AA.printRoute(); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TSP-AntColonyAlgorithm 2 | An implementation of TSP(Traveling Salesman Problem) by Ant Colony Algorithm in Java. 3 | ## Details 4 | * Solve TSP in Java. 5 | * Adopt Object-Oriented. 6 | * Divide into 5 Classes: __AntAlgorithm__, __Ant__, __City__, __Road__ and __Constant__. 7 | * Verify respectively in 3 different size of cities: 10 cities, 20 cities and 31 cities. 8 | 9 | ## Classes 10 | * __AntAlgorithm__: controls the whole algorithm's life cycle including initing all the ants, choosing the next city and simulating the round trip for each ant, updating pheromone for each road. 11 | * __Ant__: portrays the serveral actions of ant such as initing the birthplace, choosing the next city, arriving the next city. 12 | * __City__: contains the id of city, the sum of visibility and pheromone with weight, and the possibility to be choosed by one ant. 13 | * __Road__: contains the distance and the pheromone of each road. 14 | * __Constant__:contains the data of map, the initial value of pheromone(C), the max number of round trips, the number of ants, the flow-rate of pheromone and so on. 15 | 16 | ## For More 17 | If you want to learn more information about this implementation, please visit the following three sites(but a pity only in Chinese): 18 | * [use Ant Colony Algorithm to solve TSP(1)-Summary](http://yaochenkun.site/index.php/2016/12/11/ant_article/) 19 | * [use Ant Colony Algorithm to solve TSP(2)-Core Code](http://yaochenkun.site/index.php/2016/12/12/ant2_article/) 20 | * [use Ant Colony Algorithm to solve TSP(3)-Verification](http://yaochenkun.site/index.php/2016/12/12/ant3_article/) 21 | --------------------------------------------------------------------------------