go(de): implement Init(),Reinit() on Population
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-01-20 18:38:29 +01:00
parent 07d3d51ba7
commit 93206b2cd1
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ

@ -3,6 +3,12 @@
package de package de
import (
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/stat/distuv"
)
type ( type (
// DecisionVector is a []float64 abstraction representing the decision vector. // DecisionVector is a []float64 abstraction representing the decision vector.
DecisionVector []float64 DecisionVector []float64
@ -51,11 +57,24 @@ func (p *Population) GetWorstIdx() int { return 0 }
func (p *Population) SetX(n int, nuX DecisionVector) {} func (p *Population) SetX(n int, nuX DecisionVector) {}
func (p *Population) SetV(n int, nuV DecisionVector) {} func (p *Population) SetV(n int, nuV DecisionVector) {}
// Init initialises all individuals. // Init initialises all individuals to random values.
func (p *Population) Init() {} func (p *Population) Init() {
uniform := distuv.Uniform{}
uniform.Src = rand.NewSource(p.Seed)
for _, v := range p.Population {
v.CurX = make([]float64, p.Dimen)
for i := 0; i < p.Dimen; i++ {
v.CurX[i] = uniform.Rand()
}
}
}
// Reinit reinitialises all individuals. // Reinit reinitialises all individuals.
func (p *Population) Reinit() {} func (p *Population) Reinit() {
p.Init()
}
// ReinitN reinitialises the individual at position n. // ReinitN reinitialises the individual at position n.
func (p *Population) ReinitN(n uint) {} func (p *Population) ReinitN(n uint) {}