diff --git a/bench/bench.go b/bench/bench.go new file mode 100644 index 0000000..e1c4157 --- /dev/null +++ b/bench/bench.go @@ -0,0 +1,59 @@ +// Copyright 2022 wanderer +// SPDX-License-Identifier: GPL-3.0-or-later + +package bench + +import "math" + +type funcParams struct { + min float64 + max float64 +} + +const ( + Neighbourhood = 10 + // MaxFES is the maximum number of allowed function evaluations. + MaxFES = 10000 +) + +var ( + // Dimensions to compute for (spatial complexity..?). + Dimensions = []int{5, 10, 20} + + SchwefelParams = funcParams{min: -500.0, max: 500.0} + DeJong1Params = funcParams{min: -5.0, max: 5.0} + DeJong2Params = funcParams{min: -5.0, max: 5.0} +) + +// 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.Floor(val) + } + + 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.Pow(val, 2) + } + + return res +}