> testbit in a rather peculiar fashion.
>
> bool -> testbit( NUMBER, BITNUM ) -> NEW_NUMBER
>
> Using this, your mutate routine would go from this ...
>
> >define mutate(chom);
> >lvars pos;
> > 1 + random0( chom_length) -> pos;
> >
> > if population(chom)(pos) == 1 then
> > 0 -> population(chom)(pos);
> > else
> > 1 -> population(chom)(pos);
> > endif;
> >enddefine;
>
> ... to this ...
>
> define mutate( chom );
> lvars pos = random( chom_length ); ;;; random = random0 + 1
> ;;; toggle the pos'th bit.
> not( testbit( population( chom ), pos ) ) -> testbit(
> population(
> chom ), pos )
> enddefine;
Is that right? It doesn't look like you've updated chom with the new
number...
Shouldn't it be:
define mutate( chom );
lvars pos = random( chom_length ); ;;; random = random0 + 1
lvars bitvec = population(chom);
;;; toggle the pos'th bit.
not(testbit(bitvec, pos )) -> testbit(bitvec, pos) ->
population(chom);
enddefine;
[and other judicious use of fast_subscrv to speed things up of course
;-]
Ian
--
www.ianrogers.net
|