forked from MaxHalford/eaopt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
population.go
46 lines (41 loc) · 1.14 KB
/
population.go
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package gago
import (
"log"
"math/rand"
"time"
)
// A Population contains individuals. Individuals mate within a population.
// Individuals can migrate from one population to another. Each population has a
// random number generator to bypass the global rand mutex.
type Population struct {
Individuals Individuals `json:"indis"`
Age time.Duration `json:"age"`
Generations int `json:"generations"`
ID string `json:"id"`
rng *rand.Rand
}
// Generate a new population.
func newPopulation(size int, gf GenomeFactory, id string) Population {
var (
rng = newRandomNumberGenerator()
pop = Population{
Individuals: newIndividuals(size, gf, rng),
ID: id,
rng: rng,
}
)
return pop
}
// Log a Population's current statistics with a provided log.Logger.
func (pop Population) Log(logger *log.Logger) {
logger.Printf(
"pop_id=%s min=%f max=%f avg=%f std=%f",
pop.ID,
pop.Individuals.FitMin(),
pop.Individuals.FitMax(),
pop.Individuals.FitAvg(),
pop.Individuals.FitStd(),
)
}
// Populations type is necessary for migration and speciation purposes.
type Populations []Population