2023-01-12 23:35:51 +01:00
|
|
|
// Copyright 2023 wanderer <a_mirre at utb dot cz>
|
2022-06-15 00:26:35 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
package bench
|
|
|
|
|
2023-01-19 19:55:41 +01:00
|
|
|
import "log"
|
|
|
|
|
2022-06-15 00:26:35 +02:00
|
|
|
type funcParams struct {
|
|
|
|
min float64
|
|
|
|
max float64
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
2022-06-21 23:34:32 +02:00
|
|
|
// Neighbourhood is the number of neighbouring values that are to be
|
|
|
|
// generated as part of e.g. Stochastic Hill Climbing algo.
|
2022-06-15 00:26:35 +02:00
|
|
|
Neighbourhood = 10
|
2022-07-07 16:40:37 +02:00
|
|
|
// MaxNeighbourVariancePercent covers an arbitrary task requirement: pick
|
|
|
|
// neighbours from max n percent of search space.
|
|
|
|
MaxNeighbourVariancePercent = 10
|
2022-06-15 00:26:35 +02:00
|
|
|
// MaxFES is the maximum number of allowed function evaluations.
|
|
|
|
MaxFES = 10000
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// Dimensions to compute for (spatial complexity..?).
|
2022-07-17 11:57:40 +02:00
|
|
|
Dimensions = []int{5, 10, 20}
|
2022-06-15 00:26:35 +02:00
|
|
|
|
2023-01-19 20:11:22 +01:00
|
|
|
// DimensionsGA are used with Genetic Algorithms (such as DE, see algo/de).
|
|
|
|
DimensionsGA = []int{10, 30}
|
|
|
|
|
2022-06-28 23:04:31 +02:00
|
|
|
// SchwefelParams is a struct holding the min, max allowed value of inputs
|
|
|
|
// passed to the Schwefel function.
|
2022-06-15 00:26:35 +02:00
|
|
|
SchwefelParams = funcParams{min: -500.0, max: 500.0}
|
2022-06-28 23:04:31 +02:00
|
|
|
// DeJong1Params is a struct holding the min, max allowed value of inputs
|
|
|
|
// passed to the De Jong 1st function.
|
|
|
|
DeJong1Params = funcParams{min: -5.0, max: 5.0}
|
|
|
|
// DeJong2Params is a struct holding the min, max allowed value of inputs
|
|
|
|
// passed to the De Jong 2nd function.
|
|
|
|
DeJong2Params = funcParams{min: -5.0, max: 5.0}
|
2022-12-27 00:56:54 +01:00
|
|
|
// RastriginParams is a struct holding the min, max allowed value of inputs
|
|
|
|
// passed to the Rastrigin function.
|
|
|
|
RastriginParams = funcParams{min: -5.12, max: 5.12}
|
2022-06-15 00:26:35 +02:00
|
|
|
)
|
|
|
|
|
2022-06-15 23:27:05 +02:00
|
|
|
// Min returns the non-exported "min" field of a funcParams struct.
|
2022-06-17 01:54:30 +02:00
|
|
|
func (f *funcParams) Min() float64 {
|
|
|
|
return f.min
|
2022-06-15 23:27:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Max returns the non-exported 'max' field of a funcParams struct.
|
2022-06-17 01:54:30 +02:00
|
|
|
func (f *funcParams) Max() float64 {
|
|
|
|
return f.max
|
2022-06-15 23:27:05 +02:00
|
|
|
}
|
2023-01-19 19:55:41 +01:00
|
|
|
|
2023-02-04 22:17:41 +01:00
|
|
|
// NewfuncParams returns a pointer to a fresh instance of funcParams.
|
|
|
|
// nolint: revive
|
|
|
|
func NewfuncParams(min, max float64) *funcParams {
|
|
|
|
return &funcParams{min: min, max: max}
|
|
|
|
}
|
|
|
|
|
2023-01-19 19:55:41 +01:00
|
|
|
// GetGAMaxFES calculates the value of MaxFES for Genetic Algorithms. This is
|
|
|
|
// an arbitrary specification where MaxFES is 5000xD.
|
|
|
|
func GetGAMaxFES(dim int) int {
|
|
|
|
if dim <= 0 {
|
|
|
|
log.Fatalln("dim has to be greater than 0, got:", dim)
|
|
|
|
}
|
|
|
|
|
|
|
|
return dim * 5000
|
|
|
|
}
|