go(de): add benchMinIters param
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-01-20 15:52:45 +01:00
parent fe8e071460
commit e4be83ef08
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
2 changed files with 15 additions and 7 deletions

@ -350,15 +350,17 @@ func DojDE(wg *sync.WaitGroup, m *sync.Mutex) {
jDE := de.NewjDE()
// params:
// Generations, mutation strategy, parameter self-adaptation scheme,
// initial population size, differential weight, mutation constant,
// dimensions, bench name and a synchronisation channel.
// Generations, minimum bench iterations, mutation strategy, parameter
// self-adaptation scheme, initial population size, differential
// weight, mutation constant, dimensions, bench name and a
// synchronisation channel.
//
// -1 to disable generation limits,
// n > 0 for minimum bench iterations
// 0..17 to choose a mutation strategy,
// 0..1 to select a parameter self-adaptation scheme,
// np >= 4 as initial population size.
jDE.Init(-1, 0, 0, np, f, cr, bench.DimensionsGA, bench.FuncNames[i], ch)
jDE.Init(-1, 30, 0, 0, np, f, cr, bench.DimensionsGA, bench.FuncNames[i], ch)
go jDE.Run()
}

@ -17,6 +17,8 @@ type JDE struct {
// Generations denotes the number of generations the population evolves
// for. Special value -1 disables limiting the number of generations.
Generations int
// BenchMinIters is the number of iterations the bench function will be re-run (for statistical purposes).
BenchMinIters int
// Dimensions to solve the problem for.
Dimensions []int
// F is the differential weight (mutation/weighting factor).
@ -61,7 +63,7 @@ const (
var jDELogger = log.New(os.Stderr, " *** δ jDE:", log.Ldate|log.Ltime|log.Lshortfile)
// Init initialises the jDE algorithm, performs sanity checks on the inputs.
func (j *JDE) Init(generations, mutStrategy, adptScheme, np int, f, cr float64, dimensions []int, bench string, ch chan []stats.Stats) {
func (j *JDE) Init(generations, benchMinIters, mutStrategy, adptScheme, np int, f, cr float64, dimensions []int, bench string, ch chan []stats.Stats) {
if j == nil {
jDELogger.Fatalln("jDE needs to be initialised before calling RunjDE, exiting...")
}
@ -74,6 +76,9 @@ func (j *JDE) Init(generations, mutStrategy, adptScheme, np int, f, cr float64,
case generations == -1:
jDELogger.Println("Generations is '-1', disabling generation limits..")
case benchMinIters < 1:
jDELogger.Fatalln("Minimum bench iterations cannot be less than 1, got:", benchMinIters)
case mutStrategy < 0 || mutStrategy > 17:
jDELogger.Fatalln("Mutation strategy needs to be from the interval <0; 17>, got", mutStrategy)
@ -97,6 +102,7 @@ func (j *JDE) Init(generations, mutStrategy, adptScheme, np int, f, cr float64,
}
j.Generations = generations
j.BenchMinIters = benchMinIters
j.MutationStrategy = mutStrategy
j.AdptScheme = adptScheme
j.NP = np
@ -128,12 +134,12 @@ func (j *JDE) Init(generations, mutStrategy, adptScheme, np int, f, cr float64,
// InitAndRun initialises the jDE algorithm, performs sanity checks on the
// inputs and calls the Run method.
func (j *JDE) InitAndRun(generations, mutStrategy, adptScheme, np int, f, cr float64, dimensions []int, bench string, ch chan []stats.Stats) {
func (j *JDE) InitAndRun(generations, benchMinIters, mutStrategy, adptScheme, np int, f, cr float64, dimensions []int, bench string, ch chan []stats.Stats) {
if j == nil {
jDELogger.Fatalln("jDE is nil, NewjDE() needs to be called first. exiting...")
}
j.Init(generations, mutStrategy, adptScheme, np, f, cr, dimensions, bench, ch)
j.Init(generations, benchMinIters, mutStrategy, adptScheme, np, f, cr, dimensions, bench, ch)
j.Run()
}