62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
// Copyright 2022 wanderer <a_mirre at utb dot cz>
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package bench
|
|
|
|
import "math"
|
|
|
|
// Functions is a string-func map of function names and specific bench funcs
|
|
// for easier iterable access.
|
|
var Functions = map[string]func([]float64) float64{
|
|
"Schwefel": Schwefel,
|
|
"De Jong 1st": DeJong1st,
|
|
"De Jong 2nd": DeJong2nd,
|
|
}
|
|
|
|
var FuncNames = map[int]string{
|
|
0: "Schwefel",
|
|
1: "De Jong 1st",
|
|
2: "De Jong 2nd",
|
|
}
|
|
|
|
// Function params maps function names to their funcParams for easier iterable
|
|
// access.
|
|
var FunctionParams = map[string]funcParams{
|
|
"Schwefel": SchwefelParams,
|
|
"De Jong 1st": DeJong1Params,
|
|
"De Jong 2nd": DeJong2Params,
|
|
}
|
|
|
|
// Schwefel computes a value of the Schwefel function for x.
|
|
func Schwefel(x []float64) float64 {
|
|
var res float64
|
|
|
|
for _, val := range x {
|
|
res += val * math.Sin(math.Sqrt(math.Abs(val)))
|
|
}
|
|
|
|
return 418.9829*float64(len(x)) - res
|
|
}
|
|
|
|
// DeJong1st computes the value of the 1st De Jong function for x.
|
|
func DeJong1st(x []float64) float64 {
|
|
var res float64
|
|
|
|
for _, val := range x {
|
|
res += math.Pow(val, 2)
|
|
}
|
|
|
|
return res
|
|
}
|
|
|
|
// DeJong2nd computes the value of the 2nd De Jong function for x.
|
|
func DeJong2nd(x []float64) float64 {
|
|
var res float64
|
|
|
|
for _, val := range x {
|
|
res += math.Floor(val)
|
|
}
|
|
|
|
return res
|
|
}
|