|
General Details
|
|
Scheme
|
|
Posted 115 Days Ago
|
|
280 Views
|
|
Received 1 Rating
|
|
Genetic Algorithm for solving the N-Queens problem
Description
Here's a my first working genetic algorithm. It was inspired by a great article by closure:
http://www.coderprofile.com/coding-article/109/n-queens-series-part-i-only-the-fittest-survive
The program returns a list of co-ordinates representing the positions of the queens. For example, ((3 . 2) (1 . 3) (0 . 1) (2 . 0)) is a solution for N=4.
If you want to play around with it, just change the parameters at the top of the program. The programs runs in acceptable time for a problem size of 4 and 5. After that it really slows down. I don't know if I coded this wrong, or if it's just the algorithms limitation. If you want to see some run statistics, just turn the STATS flag to #t. It will then show you the average fitness of the population (out of 100%) as well as when a mutation occurs.
The population limit is the constant amount of chromosomes in a population.
The cross-over-rate determines how many times a cross-over occurs per generation. The default of 2 means that 4 new chromosomes are during each cycle.
The mutation rate is the chance that a chromosome will be mutated. Setting this to 100 will mean that every chromosome gets mutated at every generation. Avoid that high of a value. I've found that values under 5 are best.
If you guys have coded a GA before, could you look this over to make sure I did it right. This is my first attempt at something like this, so I'm not confident that I did it correctly.
Source Code
Comments
| Please login to post comments. |
More "Scheme" Source Codes By This Author
Recently Posted "Scheme" Source Codes
Recently Rated "Scheme" Source Codes
|