Skip to content

Genetic algorithm header for finding a good approximate solution to a travelling salesman problem.

Notifications You must be signed in to change notification settings

l90lpa/genetic_algorithm_TSP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

genetic_algorithm_TSP

A genetic algorithm in a header file for finding a good approximate solution to a travelling salesman style problem. The header file also include facilities for somewhat preparing the data ready to be passed into the algorithm.

0. Proposed works

  • Convert to templated format

1. Folder structure

  • GA_TSP.h:
  • main.cpp:
  • test_main-GA_TSP.cpp:

2. Dependencies

  • GA_TSP.h: utilizes C++11 features and the standard template library (STL).
  • tests/test_main-GA_TSP.cpp: utilizes the Boost Unit Test Framework.

3. Setup

3.1 Configure

Examples can be seen inside "example/main.cpp" that show the following configuration steps. Inside a relevant C++ file carry out the following:

  • Include the header file

#include "GA_TSP.h"

  • seed the pseudo random number generator using srand() and call rand() once.

srand(static_cast(time(0))); rand();

  • create a vector to hold the points (vertice).

std::vector points;

  • initialize the points with data from either a txt file.

initVetices(points, short dimensions, short numPoints, std::string fileName);

  • OR initialize the points with user input.

initVetices(points, short dimensions, short numPoints);

  • run the the genetic algorithm to obtain the best approximate solution Genome

Genome bestGenome = GA_TSP(points, short populationSize, float survivingPopulationPercent, short averageNumMutations, short numGenerations);

About

Genetic algorithm header for finding a good approximate solution to a travelling salesman problem.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages