Created: 2011-07-15 01:20
Updated: 2017-03-11 19:28
License: mit


YARGAL: Yet Another Ruby Genetic Algorithm Library

YARGAL is a very simplistic Genetic Algorithm Library written in Ruby. Currently YARGAL uses Fitness Proportionate Selection coupled with a single-point crossover operator. Elitism is also employed to preserve the best chromosomes from the previous population.
YARGAL stands for YetAnotherRubyGeneticAlgorithmLibrary.

How do I use it?

It's easy to get started with YARGAL

Create a Chromosome class that extends ChromosomeBase

class MyChromosome < ChromosomeBase

	def self.random()
	... code to generate a new random chromosome ...

	def calc_fitness
	... code to set / return a fitness value for this chromosome ...

	def mutate!
	... code to mutate your chromosome ...


If all this seems to confusing. Take a look at the mystery_word.rb example in the examples directory.

Intialize and configure the GA Engine

The GAEngine itself is configured with the class of your chromosome and a simple hash of all the options you'd like to set. For example:

@ga = GA.new(MyChromosome, {:population_size => 100, :mutation_rate => 50})

Call GA.evolve() to start evolving a population

Finally you call GA.evolve!() with a parameter indicating the number of iterations that you'd like to perform for example:


Future Improvements

This code is very basic right now. I would like to improve it in a variety of ways by adding different selection algorithms, different crossover operators and potentially turning the library into a true rubygem.


This code is pre-alpha state and was developed for my own enjoyment. Enjoy!

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more