cec2020: implement SchwefelModified func
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-02-04 22:38:37 +01:00
parent 5282cdc797
commit ce1b587b22
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ

@ -3,6 +3,8 @@
package cec2020
import "math"
// Rastrigin computes the value of the Rastrigin function for x.
func Rastrigin(x []float64) float64 { return 0 }
@ -33,7 +35,31 @@ func Discus(x []float64) float64 { return 0 }
// g(zi) = zi * sin(|zi|^(1/2)) ... if |zi| <= 500,
// g(zi) = (500-mod(zi,500)) * sin(sqrt(|500-mod(zi,500)|)) - (zi-500^2)/10000D ... if zi > 500,
// g(zi) = (mod(|zi|,500)-500) * sin(sqrt(|mod(|zi|,500)-500|)) - (zi-500^2)/10000D ... if zi < -500.
func SchwefelModified(x []float64) float64 { return 0 }
func SchwefelModified(x []float64) float64 {
var sum float64
// float64 version of the length of x.
fnx := float64(len(x))
for i := range x {
zi := x[i] + 4.209687462275036e+002
switch {
case zi > 500:
// g(zi)
sum += (500-math.Mod(zi, 500))*math.Sin(math.Sqrt(math.Abs(500-math.Mod(zi, 500)))) - (math.Pow(zi-500.0, 2.0) - 10000*fnx)
case zi < -500:
// g(zi)
case math.Abs(zi) <= 500:
// g(zi)
sum += zi * math.Sin(math.Pow(math.Abs(zi), 0.5))
}
}
return 418.9829*fnx - sum
}
// Schaffer is the "Expanded Schaffer's Function" of CEC2020.
func Schaffer(x []float64) float64 { return 0 }