DIFFERENT BITS
fitness in the population and to
ensure we don’t end up losing our
genetic progress though crossover
and mutation, we copy the most fit
member of the original population
to the new. After all these breeding
steps, we can dispense with the
old generation by copying the
“pop_new” array into the original
“pop” array.
• Lines 210-252
Finally, we repeat our earlier steps
to evaluate the new population and
we display the DNA of the most fit
member of the population on our LCD
screen. The last part of the loop progressively decreases the mutation rate
after we hit a threshold fitness level of 5.
So that is the genetic algorithm,
Exclusively at Jameco…
The Lowest Prices…
Guaranteed!
Save 15%-25% Save 30% or more!
Save more when a Looking for killer deals?
specific manufacturer is Jameco buyers often find
not required. Major Brand Factory Overruns from
semi’s are sourced some of the industry’s
from 5-6 specific major biggest names. That
manufacturers, plus we means savings of 30%
also offer Jameco Brand and more to you!
and Generic passives for
even greater savings.
Save 3% to 5%
Looking to save on
thousands of Name Brand
components? Jameco
offers these popular
products for 3% to 5%
below market price, and
we guarantee it!
3 Levels of Choice
3 Levels of Savings
Other Jameco Advantages:
We offer over 300 Major Manufacturers
99% of catalog products ship the same day.
Lowest prices guaranteed, or we pay 10%.
Order 24 hours a day, 7 days a week
www.Jameco.com
Or call 800-831-4242 anytime
SEMICONDUCTORS • PASSIVES • INTERCONNECTS • ELECTROMECHANICAL • POWER
implemented in 5.6K of program
space and 551 bytes of RAM on the
PIC. There is still plenty of memory
and most of the I/O pins are left to
allow you to make this code one part
of a larger program. Don’t feel limited
to evolving the phrase “hello_world;”
get creative! For instance, I can
imagine a digital clock display that is
evolving the word representations of
the time, or a robot which evolves
different greetings for different
people and objects it encounters. Or,
how about a display without a specific
goal set ahead of time that tries to
evolve new words with a fitness factor
based on how closely they resemble
existing words?
One way you could implement
this would be to make it interactive
and utilize a human judge of the
fitness of each word. This is called
interactive evolution, and we will
get into the details and try out a
practical example of this technique
next time.
Although the hello world problem
is a good illustration of genetic
algorithm techniques, it is a bit of a
toy problem because we know the
answer in advance. Typically, the
reason for employing a GA in the
first place is because the answer is
difficult to estimate, and this makes
determining a fitness measure a bit
trickier. For example, in the traveling
salesman problem we don’t know
how short the shortest route between
all the cities should be, so we can’t be
positive that we have found the best
solution. What genetic algorithms give
us is the humbling quality of mother
nature who demands only that her
children are good enough. We don’t
have to be perfect, we just have to
survive. Similarly, with the traveling
salesman problem fitness would be
measured as a function of how long
the route was. The algorithm can be
run and the settings can be tweaked
until a satisfactory solution is found,
a path with a reasonable length, or
it can be run until it plateaus and
the results don’t seem to be getting
any better.
Happy coding! SV
72 SERVO 05.2008