This project implements a Genetic Algorithm, which is a heuristic optimization method inspired by evolutionary mechanisms such as selection, crossover, and mutation. The algorithm is specifically designed to solve the Traveling Salesman Problem (TSP), where the goal is to find the shortest route that visits all cities and returns to the starting point.
The program provides two mutation methods for individuals in the population:
The transposition mutation method performs a transposition operation on an individual's path. It randomly selects two positions in the path and swaps the elements at those positions.
The insertion mutation method randomly selects two positions in an individual's path and inserts the element at one position to the other position, shifting the elements accordingly.
The program uses the Order Crossover (OX) method for crossover. This method combines genetic material from two parent individuals to create offspring individuals. The crossover process involves selecting two parent individuals, determining crossover points, and creating new individuals by combining genetic material from the parents.
The program employs the Elitism Selection method. This method selects the best individuals from the population based on their fitness values and includes them in the next generation. The selection process ensures that the best individuals have a higher chance of being selected for the next generation.
The initial population is generated using the nearest neighbor algorithm. This algorithm selects the nearest unvisited city as the next city to be added to the path, iteratively constructing an initial solution.
To use the program, follow these steps:
- Run the
Mainclass to start the application. - In the main menu, choose the option to read the graph from a file.
- Optionally, you can set various configurations by selecting the corresponding menu options. These configurations include:
- Setting the stopping condition for the algorithm.
- Setting the population size.
- Setting the mutation probability.
- Setting the crossover probability.
- Selecting the desired mutation method.
- Once you have configured the necessary parameters, you can proceed to run the Genetic Algorithm by selecting the appropriate option from the menu.
- The algorithm will execute, and you will see the progress and output displayed in the console.
- Optionally, you can choose to test the best cost found every 10 seconds for a duration of 100 seconds.
- To exit the program, select the "Exit" option from the menu.