Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Genetic Algorithm Package

Contains a generalizable genetic algorithm written in Python.

Installation

(GenAlg on PyPI)

sudo pip2 install genalg

Genetic Algorithm

(genalg/main.py)

class Population: Given problem specifications, create and run through a population of possible individual solutions until either the fitness goal or the generation limit is reached.

class Individual: Given problem specifications, randomly create a possible solution individual.

Example Usage

(examples/function-maximizer.py)
import genalg


def func_to_optimize(inputs):
  x, y, z = inputs
  return x * y / float(z)


if __name__ == "__main__":
  p = genalg.Population(
    popsize = 200,                # number of individuals in the population
    nchrom = 3,                   # number of chromosomes per individual
    chromset = range(1, 20)       # set from which to pick chromosomes
  )
  best = p.run(
    eval_fn = func_to_optimize,   # function to optimize
    fitness_goal = float("Inf"),  # maximum fitness to optimize towards
    generations = 400             # maximum generations to run for
  )
  print(best)

Credits

  • @droundy - mating options, misc. tweaks

About

A Python package implementing a generalizable genetic algorithm.

Resources

You can’t perform that action at this time.