Click here to Skip to main content
Click here to Skip to main content

Simple C genetic algorithm example

By , 3 Oct 2011
Rate this:
Please Sign up or sign in to vote.
This is a simple C genetic algorithm example, it's not perfect but works fine without chaos errors in memory nor results, it is tested in fedora 14 with Valgrind-3.5.0 and compiled by gcc version 4.5.1.
 
This program finds an equation composed by addition/subtraction for the given target number.
 
An example output for target number 27:
 
binary string: 01111010011010110110101000011000 - fitness: 2
binary string: 01111010011010110110101000011000 - fitness: 2
binary string: 01111010011010110110101000011000 - fitness: 2
binary string: 01111010011010110110101000011000 - fitness: 2
binary string: 00110010101100101011011010100100 - fitness: 1
binary string: 00101010001001001011010110100110 - fitness: 0
2+24-5+6
 
To change target number, just edit line #define TARGET 27
 
The full source code has been given here: http://pastebin.com/40Y5U1sY[^].

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Adrabi Abderrahim
Technical Lead
Morocco Morocco
Adrabi!, Just another Ghost in the Shell =)

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 3 Oct 2011
Article Copyright 2011 by Adrabi Abderrahim
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid