Click here to Skip to main content
12,453,672 members (87,943 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

27.8K views
3 bookmarked
Posted

Simple C genetic algorithm example

, 3 Oct 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Simple C genetic algorithm example
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)

Share

About the Author

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

You may also be interested in...

Pro
Pro

Comments and Discussions

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