Skip to content

Genetic algorithm implementation for teaching support

Notifications You must be signed in to change notification settings

edielsonpf/genetic-algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

genetic-algorithm

Genetic algorithm implementation for teaching support

Quick start

import sys
import os.path
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from genetic_algorithm.ga import genetic_algorithm
from EightQueensExample import EightQueens
import matplotlib.pyplot as plt


#Genotype definition
NumIndividuals = 20
MinSymbol = 1
MaxSymbol = 8
IndividualSize = 8

#Instantiate problem object with the genotype parameters
problem = EightQueens(MinSymbol, MaxSymbol, IndividualSize)

#Algorithms parameters definition 
MaxGeneration = 2000
Target = 28
Elitism = True
MutationRate = 0.2

#Instantiate the GA algorithm
ClassHandle  = genetic_algorithm(problem,MutationRate,Elitism)

#Solve the problem
fit,generation = ClassHandle.search(NumIndividuals, MaxGeneration, Target)

#Plot the algorithm solution sequence
interaction=[i for i in range(generation)]
plt.plot(interaction,fit)
plt.show()

About

Genetic algorithm implementation for teaching support

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published