Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 25 lines (20 sloc) 0.427 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
package goga

import "math/rand"

type Mutator interface {
Mutate(*Individual)
}

type SimpleMutator struct {
chance float64
}

func NewSimpleMutator(chance float64) Mutator {
return &SimpleMutator{ chance }
}

func (sm *SimpleMutator) Mutate(individual *Individual) {
genes := individual.Genes // []Gene
for i := 0; i < len(genes); i++ {
drawn := rand.Float64()
if (drawn < sm.chance) {
genes[i].Mutate()
}
}
}
Something went wrong with that request. Please try again.