Giter Site home page Giter Site logo

aroques / simple-ga Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 15 KB

A simple genetic algorithm that solves the one-max problem

License: MIT License

Python 100.00%
genetic-algorithm one-max crossover mutation selection recombination replacement fitness-function python3

simple-ga's Introduction

Simple Genetic Algorithm

A simple genetic algorithm that solves the one-max problem.

Initialization

A population N of randomly generated binary strings of the specified size n. The strings are generated with the probability of each bit being 1 of 0.5.

Selection

Parents are selected using binary tournament selection of k=2. So, given a population of size N, a random individual is selected. Then another random individual is selected. The more fit individual is selected as a parent. This procedure is repeated for the second parent.

Recombination

There is a 60% chance that uniform crossover will be applied to those parents to produce two new children for the 'next generation'. Uniform crossover generates the first child by randomly picking from which parent to get each bit. At the same time, the second child is created by using the bits from the other of the parent. Otherwise, there is a 40% chance that the parents will be kept in the 'new generation'.

Replacement

For a population of size N, N-2 children are generated. All but the best 2 parents are replaced with this set of children. This is called elitism replacement because we are keeping the very best individuals around each generation.

Fitness Function

The fitness function is onemax, which is the sum of 1s in the binary string.

Finding the Minimum Population Size

The population size starts at size 10. Then, the GA is ran 5 times and each time we check to see if the global optimum is present in the new generation. If the global optimum is not present in each of the 5 generations, then we then double the population size and repeat the above procedure. Once we find the smallest population size where the global optimum is present in each of the 5 generations we have found an upper bound. Next, we take the midpoint between this upper-bound and the lower-bound where it last failed. We repeat this procedure until we find a minimum population size. This procedure of finding the minimum population size to solve a problem is called bisection.

Minimum Population Sizes for Different String Sizes

String Size Run 1 Run 2 Run 3 Avg
20 11 7 13 10.33
50 21 19 17 19.00

To run this program:

python3.6 main.py

simple-ga's People

Contributors

aroques avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.