From the GA standpoint, I should point out that you're "cheating" -- both cheating yourself, and the underlying algorithm. There are two problems: first-off, you're not allowing your best individuals to mutate, which is cheating yourself; that is, your better solutions don't get the benefit of genetic mutation. Secondly, you're using the knowledge that none of your "genes" (letters) are related in your mutation criteria, and just mutating those which are "wrong." This makes the process far less random, nearly to the point of eliminating any and all "genetics" from the process. Said another way, your above algorithm will probably go faster with a population size of one, and running for a thousand generations, than with 1000 individuals for one generation. On a similar note, you also only seem to be running one generation.

Those are my nitpicks from my point of view as a meddler in genetic programming. From a perl point of view, you've good solid code. Some of your lines are vaguely C-ish (use of parens in print("foo")), as are your loops, but that's a stylistic thing. You're not using warnings, which might be less forgivable, though. :) In your char_replace function, you're using map when you only need to generate one character -- it looks strange. You also re-evaluate the fitness there, but don't use it.

Update: I now see where you're re-running the generations. I'll point out that the way you're currently going about it is strange -- it means that only the first generation gets the percent that passes through unmodified -- a strange thing to do. I suppose what it boils down to is that I simply don't understand the meta-code that you're using to run your GA. It doesn't agree with the model that I understand, that's all.

perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'


In reply to Re: Genetic Algorithms by Chmrr
in thread Genetic Algorithms by illsorted

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.