Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unfortunately, the ideal solution usually depends on your problem domain. <a href="http://pseudofish.com/blog/2007/12/16/genetic-algorithms-in-haskell/" rel="nofollow noreferrer">This blog post</a> talks about the typeclass approach and the bitwise approach. I personally think a hybrid approach is best if you want flexibility. If there is a good bitwise mapping, you can define it, and the implementation is derived from that, otherwise you can implement the crossover and mutate manually.</p> <p>ja's method is actually not going to work. Some of your genome functions are going to need random input, which you can get by running in the state monad with a random number generator <a href="https://stackoverflow.com/questions/2926267/how-to-make-random-in-haskell-in-pure-function">like this thread</a></p> <pre><code>class Genome a where fitness :: a -&gt; Int breed :: (RandomGen g, MonadState g m) =&gt; a -&gt; a -&gt; m a mutate :: (RandomGen g, MonadState g m) =&gt; a -&gt; m a </code></pre> <p>Then you have common functions that operate on sets of genomes, regardless of implementation.</p> <pre><code>selectParents :: (Genome a, RandomGen g, MonadState g m) =&gt; [a] -&gt; m [a] selectSurvivors :: (Genome a, RandomGen g, MonadState g m) =&gt; [a] -&gt; m [a] </code></pre> <p>If you do have a good bit mapping, you can just define fixed functions on BitArrays (notice that each will have to take the fitness function as a parameter)</p> <pre><code>breed :: (RandomGen g, MonadState g m) =&gt; BitArray -&gt; BitArray -&gt; m BitArray mutate :: (RandomGen g, MonadState g m) =&gt; BitArray -&gt; m BitArray selectParents :: (RandomGen g, MonadState g m) =&gt; (BitArray -&gt; Int) -&gt; [BitArray] -&gt; m [BitArray] selectSurvivors :: (RandomGen g, MonadState g m) =&gt; (BitArray -&gt; Int) -&gt; [BitArray] -&gt; m [BitArray] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload