https://github.com/beeceej/ga-tsp
Genetic algorithim to solve the Travelling Salesman problem, written in mostly functional style Java
https://github.com/beeceej/ga-tsp
Last synced: 8 months ago
JSON representation
Genetic algorithim to solve the Travelling Salesman problem, written in mostly functional style Java
- Host: GitHub
- URL: https://github.com/beeceej/ga-tsp
- Owner: beeceej
- License: mit
- Created: 2018-02-27T00:00:28.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-27T01:04:09.000Z (over 8 years ago)
- Last Synced: 2025-03-23T10:46:24.432Z (about 1 year ago)
- Language: Java
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Genetic Algorithm - TSP
This project heavily uses Java 8 features like Streams, First Class(ish) functions, map, reduce, bind(flatmap), etc.
The Travelling Salesman problem can be stated as:
```
Given locations (A(x,y), B(x,y), ... ) with distinct locations on a directed acyclic graph,
find the least costly path (in this case distance) to traverse from starting point A to end point.
```
my (loose) interpretation of a genetic algorithm eventually converges upon an optimal solution by:
`-> Begin with a randomly generated seed Population of size N`
`-> For M generations, perform random mutations on the traversal order, keeping only the most efficient routes (only routes with distance < than average)`
`-> After M generations, we will have converged upon a near optimal solution in much less time than exhaustive search`
A naive solution would be to calculate distance on every pass, but this can be amortized by pre-computing distances and retrieving them for amortized O(1) look up.
I've only implemented pair look up, but this could be further implemented by adding look ups for A -> B -> C ... etc.