From 9795287dc98143eaef58a12489f2f2e063846de9 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 6 Feb 2023 15:43:00 +0100 Subject: [PATCH] cec2020: implement Happycat func --- bench/cec2020/basicFunctions.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/bench/cec2020/basicFunctions.go b/bench/cec2020/basicFunctions.go index 85c5dc3..c40b6dc 100644 --- a/bench/cec2020/basicFunctions.go +++ b/bench/cec2020/basicFunctions.go @@ -80,7 +80,28 @@ func Griewank(x []float64) float64 { func Ackley(x []float64) float64 { return 0 } // Happycat is the "Happycat Function" of CEC2020. -func Happycat(x []float64) float64 { return 0 } +func Happycat(x []float64) float64 { + var sum1 float64 + + var sum2 float64 + + var sum3 float64 + + // float64 version of the length of x. + fnx := float64(len(x)) + + for i := range x { + xipow2 := math.Pow(x[i], 2) + + sum1 += xipow2 - fnx + + sum2 += xipow2 + + sum3 += x[i] + } + + return math.Pow(math.Abs(sum1), 0.25) + (((0.5 * sum2) + sum3) / (fnx + 0.5)) +} // Discus is the "Discus Function" of CEC2020. func Discus(x []float64) float64 {