Ok so I've been busy the last couple of days writing a really "quick and dirty" version of a genetic algorithm
Taken from the example at "generation5.org"
(Diophantine Equation Solver - Genetic Algorithms -)
I wrote a program that can solve the question
A + B + C + D = 30
(but it can also solve other equation given modest modifications)
This isn't meant as a learning guide (check generation5.org) for that...
But I thought it might be helpful
What it does:
Creates 5 objects of the type "Gene"
fills the A B C D values with random number ( 0 to 30)
then calculated the "fitness" and "Likelihoods"
ie. find the value (A - D) that is closest to our number 30
and then find the second closest and then "mates" them together...
There is random mutation, but this code is highly ***UNOPTIMIZED***
So please forgive the use of "cmp eax, 0" instead of "or" and other unoptimizing tricks...
Credits in the file...
Tell me what you think...
Sliver
---EDIT---
This does make use of Thomas and NAN's wonderful Object.inc set of macro's (which I have included with the example)... just in case (this was an attempt to learn it better)
Taken from the example at "generation5.org"
(Diophantine Equation Solver - Genetic Algorithms -)
I wrote a program that can solve the question
A + B + C + D = 30
(but it can also solve other equation given modest modifications)
This isn't meant as a learning guide (check generation5.org) for that...
But I thought it might be helpful
What it does:
Creates 5 objects of the type "Gene"
fills the A B C D values with random number ( 0 to 30)
then calculated the "fitness" and "Likelihoods"
ie. find the value (A - D) that is closest to our number 30
and then find the second closest and then "mates" them together...
There is random mutation, but this code is highly ***UNOPTIMIZED***
So please forgive the use of "cmp eax, 0" instead of "or" and other unoptimizing tricks...
Credits in the file...
Tell me what you think...
Sliver
---EDIT---
This does make use of Thomas and NAN's wonderful Object.inc set of macro's (which I have included with the example)... just in case (this was an attempt to learn it better)
Interesting program, the generation5 site has a lot of good info about these subjects. I'm glad to see the object model being actually used.
So what's next? x^2 + 5x = 30 ;) ?
Thomas
So what's next? x^2 + 5x = 30 ;) ?
Thomas
I should mention:
If you want to see exactly what's happening you can change the code
DEBUG_GA equ 0
to
DEBUG_GA equ 1
(in gene.asm)
If you want to see exactly what's happening you can change the code
DEBUG_GA equ 0
to
DEBUG_GA equ 1
(in gene.asm)
This reminds me a lot of the artificial life programs. One in particular, Tierra, has blocks of code "living" in a virtual environment and based on certain conditions the code will actually optimize itself, or split off into two species.
http://www.alife.org has more info.
http://www.alife.org has more info.