Giter Club home page Giter Club logo

go-flow-ea's People

Contributors

maltekrupa avatar

Watchers

 avatar  avatar

go-flow-ea's Issues

Beginning

Facts

We start with a very basic setup to optimize a vector of bits.

Representation

Bit vector like:

type population struct {
    individuals    []individual
    maxIndividuals int
    maxFitness     int
    avgFitness     float64
}
type individual struct {
    entities   []int
    amount     int
    fitness    int
    generation int
}

Parent selection

Random

func (p *population) ParentSelection() (individual, individual) {
    // Returns two random individuals which will be the parents
    length := len(p.individuals)
    mother := rand.Intn(length)
    father := rand.Intn(length)
    for {
        if mother == father {
            mother = rand.Intn(length)
        } else {
            break
        }
    }
    return p.TwoIndividual(mother, father)
}

Recombination

1-point crossover

func (p *population) RandomOnePointCrossover(x, y individual) (individual, individual) {
    randOnePoint := rand.Intn(len(x.entities))
    if debug {
        fmt.Println("RandomOnePointCrossover -", "Split at point:", randOnePoint)
        fmt.Println("RandomOnePointCrossover -", "Mother:", x)
        fmt.Println("RandomOnePointCrossover -", "Father:", y)
    }
    tempGene1 := make([]int, 0, len(x.entities))
    tempGene2 := make([]int, 0, len(y.entities))

    tempGene1 = append(tempGene1, x.entities[:randOnePoint]...)
    tempGene2 = append(tempGene2, y.entities[:randOnePoint]...)

    tempGene1 = append(tempGene1, y.entities[randOnePoint:]...)
    tempGene2 = append(tempGene2, x.entities[randOnePoint:]...)

    retGene1 := individual{tempGene1, len(tempGene1), fitness(tempGene1), 0}
    retGene2 := individual{tempGene2, len(tempGene2), fitness(tempGene2), 0}
    if debug {
        fmt.Println("RandomOnePointCrossover -", "Child1:", retGene1)
        fmt.Println("RandomOnePointCrossover -", "Child2:", retGene2)
    }
    return retGene1, retGene2
}

Survivor selection

Greedy (Strongest set of entities wins)

func (p *population) KillWeak() {
    // fmt.Println(p.individuals)
    sort.Sort(byFitness(p.individuals))
    p.individuals = append(p.individuals[len(p.individuals)-amountOfIndividuals:])
    // fmt.Println(p.individuals)
    p.RefreshAvgFitness()
}

Where to start

Create some representation for the configuration and a boilerplate for go-flow. Since we'll need a form of input for these values, we start with a simple cli-app.

type Config struct {
    entities int
    individuals int
    targetFitness int
    seed string
}

This should be part of a component and saved at the end.

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.