go(de): make Population more ephemeral
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-01-20 18:36:04 +01:00
parent e4be83ef08
commit 07d3d51ba7
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
2 changed files with 16 additions and 11 deletions

View File

@ -6,6 +6,7 @@
import (
"log"
"os"
"time"
"git.dotya.ml/wanderer/math-optim/bench"
"git.dotya.ml/wanderer/math-optim/stats"
@ -36,8 +37,6 @@ type JDE struct {
AdptScheme int
// NP is the initial population size.
NP int
// Population is a pointer to population
Population *Population
// BenchName is a name of the problem to optimise.
BenchName string
// ch is a channel for writing back computed results.
@ -123,12 +122,6 @@ func (j *JDE) Init(generations, benchMinIters, mutStrategy, adptScheme, np int,
j.fVect = fV
j.crVect = crV
pop := newPopulation(bench, j.NP)
pop.Init()
j.Population = pop
j.initialised = true
}
@ -158,14 +151,22 @@ func (j *JDE) Run() {
for _, dim := range j.Dimensions {
maxFES := bench.GetGAMaxFES(dim)
j.evolve(maxFES)
// create a population with known params.
pop := newPopulation(j.BenchName, j.NP, dim)
// set population seed.
pop.Seed = uint64(time.Now().UnixNano())
// initialise the population.
pop.Init()
j.evolve(maxFES, pop)
}
}
// evolve evolves a population by running the jDE (self-adapting Differential
// Evolution) algorithm on the passed population until termination conditions
// are met.
func (j *JDE) evolve(maxFES int) {}
func (j *JDE) evolve(maxFES int, pop *Population) {}
// NewjDE returns a pointer to a new, uninitialised jDE instance.
func NewjDE() *JDE {

View File

@ -38,6 +38,8 @@ type Population struct {
Population []PopulationIndividual
// Problem is the current benchmarking function this population is attempting to optimise.
Problem string
// Dimen is the dimensionality of the problem being optimised.
Dimen int
// Seed is the value used to (re)init population.
Seed uint64
}
@ -63,11 +65,13 @@ func (p *Population) Clear() {}
func (p *Population) MeanVelocity() float64 { return 0.0 }
// newPopulation returns a pointer to a new, uninitialised population.
func newPopulation(benchProblem string, np int) *Population {
func newPopulation(benchProblem string, np, dimen int) *Population {
p := &Population{}
p.Problem = benchProblem
p.Dimen = dimen
// pre-alloc.
p.Population = make([]PopulationIndividual, 0, np)