The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

    Algorithm::Evolutionary::Individual::String - A character string to be evolved. Useful mainly in word games

SYNOPSIS

    use Algorithm::Evolutionary::Individual::String;

    my $indi = new Algorithm::Evolutionary::Individual::String [a..z] 10;
                                   # Build random bitstring with length 10

    my $indi3 = new Algorithm::Evolutionary::Individual::String;
    $indi3->set( _length => 20, 
                 _chars => [A..Z] );   #Sets values, but does not build the string
    $indi3->randomize(); #Creates a random bitstring with length as above
    print $indi3->Atom( 7 );       #Returns the value of the 7th character
    $indi3->Atom( 3 ) = 'q';       #Sets the value

    $indi3->addAtom( 'k' ); #Adds a new character to the bitstring at the end

    my $indi4 = Algorithm::Evolutionary::Individual::String->fromString( 'esto es un string');   #Creates an individual from that string

    my $indi5 = $indi4->clone(); #Creates a copy of the individual

    my @array = qw( a x q W z ñ); #Tie a String individual
    tie my @vector, 'Algorithm::Evolutionary::Individual::String', @array;
    print tied( @vector )->asXML();
    
    print $indi3->asString(); #Prints the individual
    print $indi3->asXML() #Prints it as XML. See 

    my $xml=<<EOC;
<indi type='String'>
    <atom>a</atom><atom>z</atom><atom>q</atom><atom>i</atom><atom>h</atom>
</indi>
EOC
    my $indi4=  Algorithm::Evolutionary::Individual::String->fromXML( $xml );

Base Class

Algorithm::Evolutionary::Individual::Base

DESCRIPTION

String Individual for a evolutionary algorithm. Contains methods to handle strings easily. It is also TIEd so that strings can be handled as arrays.

METHODS

new

Creates a new random string, with fixed initial length, and uniform distribution of characters along the character class that is defined.

randomize

Assigns random values to the elements

addAtom

Adds an atom at the end

fromString

Similar to a copy ctor; creates a bitstring individual from a string

clone

Similar to a copy ctor: creates a new individual from another one

asString

Prints it

Atom

Sets or gets the value of the n-th character in the string

TIE methods

String implements FETCH, STORE, PUSH and the rest, so an String can be tied to an array and used as such.

length

Returns length of the string that stores the info.

asXML

Prints it as XML. See Algorithm::Evolutionary::XML for more info on this

Chrom

Sets or gets the variable that holds the chromosome. Not very nice, and I would never ever do this in C++

Known subclasses

  This file is released under the GPL. See the LICENSE file included in this distribution,
  or go to http://www.fsf.org/licenses/gpl.txt

  CVS Info: $Date: 2002/11/17 17:10:59 $ 
  $Header: /cvsroot/opeal/opeal/Algorithm/Evolutionary/Individual/String.pm,v 1.6 2002/11/17 17:10:59 jmerelo Exp $ 
  $Author: jmerelo $ 
  $Revision: 1.6 $

1 POD Error

The following errors were encountered while parsing the POD:

Around line 28:

Non-ASCII character seen before =encoding in 'ñ);'. Assuming CP1252