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 {