Coder Social home page Coder Social logo

fpoyer / ga Goto Github PK

View Code? Open in Web Editor NEW

This project forked from juanmf/ga

0.0 1.0 0.0 213 KB

A Generic implementatin of Genetic Algorithms. So far only one strategy for each Genetic operatr is implemented. Feel free to contribute if you need more.

Java 100.00%

ga's Introduction

ga

A Generic implementation of Genetic Algorithms. So far only one strategy for each Genetic operator is implemented.

Also, an example use case is implemented so as to see the process running out of the box.

Customizing

To solve a given problem, you need to implement a representation of it's structure by implementin/subclassing the following I¿interfaces/classes:

  juanmf.ga.structure.Individual // In the example, Team
  juanmf.ga.structure.Gen // In the example, Player
  juanmf.ga.fitness.FitnessMeter // or subclass abstract juanmf.ga.implementation.BasicFitnessMeter
  juanmf.ga.structure.IndividualFactory // In the example, inner class of Team
  juanmf.ga.structure.PopulationFactory // In the example, inner class of Team

The example Then expose individualFactory, populationFactory and fitnessMeter beans as follows.

    /**
     * Make sure @ComponentScan("pkg") includes this class' pkg so that these beans
     * get registered.
     */
    @Configuration
    public class Config {

        @Bean(name="individualFactory")
        public IndividualFactory getIndividualFactory() {
            return new Team.TeamFactory();
        }

        @Bean(name="populationFactory")
        public PopulationFactory getPopulationFactory() {
            return new Team.TeamPopulationFactory();
        }

        @Bean(name="fitnessMeter")
        public FitnessMeter getFitnessMeter() {
            return new TeamAptitudeMeter();
        }
    }

Then run the project

$ mvn compile exec:java

And whatch the evolution process in console.

meetStopCondition: Current Best: 1310: Historical Best: 0
Selection individuals: 5806
meetStopCondition: Current Best: 1310: Historical Best: 1310
Selection individuals: 5931
...
Mutating at gen:14. individual:/*individual toString output*/
...
// X generations after last time the best changed.
meetStopCondition: Current Best: 2116: Historical Best: 2116
Selection individuals: 9921
meetStopCondition: Current Best: 2116: Historical Best: 2116
/*individual toString output of the best Individual in the last generation*/ 

Crossing Strategies

Currently only Reduces Surrogate method is used for Crossing, in two flavors, single thread and non-blocking multi-thread(@Primary). Multi-thread is preferred because it's marked with @Primary annotation, feel free to change it if you want to try the single threaded.

Feel free to contribute other strategies you might find of interest.

BasicFitnessMeter

It implements a default stop condition, if the best didn't improve in last 100 generations, it's meetStopCondition() returns true.

Selection Strategy

Stochastic universal sampling method is used.

ga's People

Contributors

juanmf avatar

Watchers

 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.