[ANN] charlie 0.5.0 Released - A genetic algorithms library.

Discussion in 'Ruby' started by Sander Land, Dec 19, 2007.

  1. Sander Land

    Sander Land Guest

    Hi all,

    I'm pleased to announce the first public release of charlie, a genetic
    algorithms library for Ruby.

    ## FEATURES:
    - Quickly develop GAs by combining several parts (genotype, selection,
    crossover, mutation) provided by the library.
    - Sensible defaults are provided with any genotype, so often you only
    need to define a fitness function.
    - Easily replace any of the parts by your own code.
    - Test different strategies in GA, and generate reports comparing them.

    ## EXAMPLE: (also at http://pastie.caboo.se/130559 with better formatting)
    This example finds the binary representation of the number 512.

    require 'rubygems'
    require 'charlie'
    class Find512 < BitStringGenotype(10) # choose a genotype, in this
    case a list of 10 bits represents a solution
    # Define a fitness function. This one returns minus the offset to
    the best solution, so a higher number is better.
    # Usually, you won't know the best solution, and will define this
    as some value that needs to be maximized.
    def fitness
    # Use the 'genes' function to retrieve the array of bits
    representing this solution.
    -(genes.map(&:to_s).join.to_i(2) - 512).abs
    end
    end
    # Finally, create an instance of a population (with the default size
    of 20) and let it run for the default number of 100 generations.
    Population.new(Find512).evolve_on_console

    ## RUBYQUIZ #142 SOLUTION:
    I know, it's a bit late. ;)

    require 'rubygems'
    require 'charlie'
    N=5
    CITIES = (0...N).map{|i| (0...N).map{|j| [i,j] } }.inject{|a,b|a+b}
    class TSP < PermutationGenotype(CITIES.size)
    def fitness
    d=0
    (genes + [genes[0]]).each_cons(2){|a,b|
    a,b=CITIES[a],CITIES
    d += Math.sqrt( (a[0]-b[0])**2 + (a[1]-b[1])**2 )
    }
    -d # lower distance -> higher fitness.
    end
    end
    pop = Population.new(TSP,20).evolve_on_console(50)

    Several other simple examples are included in the gem/tarball.

    ## INSTALLATION:
    * sudo gem install charlie

    ## Links
    * http://rubyforge.org/projects/charlie/
    * http://charlie.rubyforge.org

    ## LICENSE:
    MIT license.
     
    Sander Land, Dec 19, 2007
    #1
    1. Advertising

  2. Sander Land

    hemant Guest

    On Dec 19, 2007 11:22 PM, Sander Land <> wrote:
    > Hi all,
    >
    > I'm pleased to announce the first public release of charlie, a genetic
    > algorithms library for Ruby.
    >
    > ## FEATURES:
    > - Quickly develop GAs by combining several parts (genotype, selection,
    > crossover, mutation) provided by the library.
    > - Sensible defaults are provided with any genotype, so often you only
    > need to define a fitness function.
    > - Easily replace any of the parts by your own code.
    > - Test different strategies in GA, and generate reports comparing them.
    >
    > ## EXAMPLE: (also at http://pastie.caboo.se/130559 with better formatting)
    > This example finds the binary representation of the number 512.
    >
    > require 'rubygems'
    > require 'charlie'
    > class Find512 < BitStringGenotype(10) # choose a genotype, in this
    > case a list of 10 bits represents a solution
    > # Define a fitness function. This one returns minus the offset to
    > the best solution, so a higher number is better.
    > # Usually, you won't know the best solution, and will define this
    > as some value that needs to be maximized.
    > def fitness
    > # Use the 'genes' function to retrieve the array of bits
    > representing this solution.
    > -(genes.map(&:to_s).join.to_i(2) - 512).abs
    > end
    > end
    > # Finally, create an instance of a population (with the default size
    > of 20) and let it run for the default number of 100 generations.
    > Population.new(Find512).evolve_on_console
    >
    > ## RUBYQUIZ #142 SOLUTION:
    > I know, it's a bit late. ;)
    >
    > require 'rubygems'
    > require 'charlie'
    > N=5
    > CITIES = (0...N).map{|i| (0...N).map{|j| [i,j] } }.inject{|a,b|a+b}
    > class TSP < PermutationGenotype(CITIES.size)
    > def fitness
    > d=0
    > (genes + [genes[0]]).each_cons(2){|a,b|
    > a,b=CITIES[a],CITIES
    > d += Math.sqrt( (a[0]-b[0])**2 + (a[1]-b[1])**2 )
    > }
    > -d # lower distance -> higher fitness.
    > end
    > end
    > pop = Population.new(TSP,20).evolve_on_console(50)
    >
    > Several other simple examples are included in the gem/tarball.
    >
    > ## INSTALLATION:
    > * sudo gem install charlie
    >
    > ## Links
    > * http://rubyforge.org/projects/charlie/
    > * http://charlie.rubyforge.org
    >


    Awesome work!

    Going to check it out.. Thanks.



    --
    Let them talk of their oriental summer climes of everlasting
    conservatories; give me the privilege of making my own summer with my
    own coals.

    http://gnufied.org
     
    hemant, Dec 19, 2007
    #2
    1. Advertising

  3. Sander Land

    Ian Leitch Guest

    [Note: parts of this message were removed to make it a legal post.]

    Excellent, I've been wanting such a library for a while now. Cheers!

    On 19/12/2007, hemant <> wrote:
    >
    > On Dec 19, 2007 11:22 PM, Sander Land <> wrote:
    > > Hi all,
    > >
    > > I'm pleased to announce the first public release of charlie, a genetic
    > > algorithms library for Ruby.
    > >
    > > ## FEATURES:
    > > - Quickly develop GAs by combining several parts (genotype, selection,
    > > crossover, mutation) provided by the library.
    > > - Sensible defaults are provided with any genotype, so often you only
    > > need to define a fitness function.
    > > - Easily replace any of the parts by your own code.
    > > - Test different strategies in GA, and generate reports comparing them.
    > >
    > > ## EXAMPLE: (also at http://pastie.caboo.se/130559 with better

    > formatting)
    > > This example finds the binary representation of the number 512.
    > >
    > > require 'rubygems'
    > > require 'charlie'
    > > class Find512 < BitStringGenotype(10) # choose a genotype, in this
    > > case a list of 10 bits represents a solution
    > > # Define a fitness function. This one returns minus the offset to
    > > the best solution, so a higher number is better.
    > > # Usually, you won't know the best solution, and will define this
    > > as some value that needs to be maximized.
    > > def fitness
    > > # Use the 'genes' function to retrieve the array of bits
    > > representing this solution.
    > > -(genes.map(&:to_s).join.to_i(2) - 512).abs
    > > end
    > > end
    > > # Finally, create an instance of a population (with the default size
    > > of 20) and let it run for the default number of 100 generations.
    > > Population.new(Find512).evolve_on_console
    > >
    > > ## RUBYQUIZ #142 SOLUTION:
    > > I know, it's a bit late. ;)
    > >
    > > require 'rubygems'
    > > require 'charlie'
    > > N=5
    > > CITIES = (0...N).map{|i| (0...N).map{|j| [i,j] } }.inject{|a,b|a+b}
    > > class TSP < PermutationGenotype(CITIES.size)
    > > def fitness
    > > d=0
    > > (genes + [genes[0]]).each_cons(2){|a,b|
    > > a,b=CITIES[a],CITIES
    > > d += Math.sqrt( (a[0]-b[0])**2 + (a[1]-b[1])**2 )
    > > }
    > > -d # lower distance -> higher fitness.
    > > end
    > > end
    > > pop = Population.new(TSP,20).evolve_on_console(50)
    > >
    > > Several other simple examples are included in the gem/tarball.
    > >
    > > ## INSTALLATION:
    > > * sudo gem install charlie
    > >
    > > ## Links
    > > * http://rubyforge.org/projects/charlie/
    > > * http://charlie.rubyforge.org
    > >

    >
    > Awesome work!
    >
    > Going to check it out.. Thanks.
    >
    >
    >
    > --
    > Let them talk of their oriental summer climes of everlasting
    > conservatories; give me the privilege of making my own summer with my
    > own coals.
    >
    > http://gnufied.org
    >
    >
     
    Ian Leitch, Dec 20, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thuswise Webmaster
    Replies:
    0
    Views:
    829
    Thuswise Webmaster
    Jun 28, 2003
  2. aum
    Replies:
    1
    Views:
    350
  3. Sander Land
    Replies:
    0
    Views:
    122
    Sander Land
    Dec 26, 2007
  4. Sander Land
    Replies:
    1
    Views:
    105
    Sander Land
    Jan 12, 2008
  5. Sander Land
    Replies:
    0
    Views:
    114
    Sander Land
    Feb 12, 2008
Loading...

Share This Page