Skip to content

joeylmaalouf/genetic-algorithm-package

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Genetic Algorithm Package

Contains a generalizable genetic algorithm written in Python.

Installation

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

Stars

Watchers

Forks

Packages

No packages published