go: impl. Get{Best,Worst}Idx Population methods
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
37710c95b3
commit
3e78332869
|
@ -4,6 +4,7 @@
|
|||
package de
|
||||
|
||||
import (
|
||||
"git.dotya.ml/wanderer/math-optim/bench"
|
||||
"golang.org/x/exp/rand"
|
||||
|
||||
"gonum.org/v1/gonum/stat/distuv"
|
||||
|
@ -52,10 +53,47 @@ type Population struct {
|
|||
|
||||
// GetIndividal returns a reference to individual at position n.
|
||||
func (p *Population) GetIndividual(n uint) *PopulationIndividual { return &PopulationIndividual{} }
|
||||
func (p *Population) GetBestIdx() int { return 0 }
|
||||
func (p *Population) GetWorstIdx() int { return 0 }
|
||||
func (p *Population) SetX(n int, nuX DecisionVector) {}
|
||||
func (p *Population) SetV(n int, nuV DecisionVector) {}
|
||||
|
||||
// GetBestIdx returns the index of the best population individual.
|
||||
func (p *Population) GetBestIdx() int {
|
||||
f := bench.Functions[p.Problem]
|
||||
|
||||
bestIndividual := 0
|
||||
// the first one is the best one.
|
||||
bestVal := f(p.Population[0].CurX)
|
||||
|
||||
for i, v := range p.Population {
|
||||
current := f(v.CurX)
|
||||
|
||||
if current < bestVal {
|
||||
bestIndividual = i
|
||||
}
|
||||
}
|
||||
|
||||
return bestIndividual
|
||||
}
|
||||
|
||||
// GetWorstIdx returns the index of the worst population individual.
|
||||
func (p *Population) GetWorstIdx() int {
|
||||
f := bench.Functions[p.Problem]
|
||||
|
||||
worstIndividual := 0
|
||||
// the first one is the worst one.
|
||||
worstVal := f(p.Population[0].CurX)
|
||||
|
||||
for i, v := range p.Population {
|
||||
current := f(v.CurX)
|
||||
|
||||
if current > worstVal {
|
||||
worstIndividual = i
|
||||
}
|
||||
}
|
||||
|
||||
return worstIndividual
|
||||
}
|
||||
|
||||
func (p *Population) SetX(n int, nuX DecisionVector) {}
|
||||
func (p *Population) SetV(n int, nuV DecisionVector) {}
|
||||
|
||||
// Init initialises all individuals to random values.
|
||||
func (p *Population) Init() {
|
||||
|
|
Loading…
Reference in New Issue