From de1b2021c50892bbb0835b0adeb69f1aa1b0cff1 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 6 Feb 2023 15:30:59 +0100 Subject: [PATCH] cec2020: implement HGBat func --- bench/cec2020/basicFunctions.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/bench/cec2020/basicFunctions.go b/bench/cec2020/basicFunctions.go index 0c7a15d..3677473 100644 --- a/bench/cec2020/basicFunctions.go +++ b/bench/cec2020/basicFunctions.go @@ -32,7 +32,22 @@ func HighConditionedElliptic(x []float64) float64 { } // HGBat is the "HGBat Function" of CEC2020. -func HGBat(x []float64) float64 { return 0 } +func HGBat(x []float64) float64 { + var sum1 float64 + + var sum2 float64 + + for i := range x { + sum1 += math.Pow(x[i], 2) + + sum2 += x[i] + } + + // float64 version of the length of x. + fnx := float64(len(x)) + + return math.Pow(math.Abs(math.Pow(sum1, 2)-math.Pow(sum2, 2)), 0.5) + (((0.5 * sum1) + sum2) / (fnx + 0.5)) +} // Rosenbrock is the "Rosenbrock's Function" of CEC2020. // ref: https://infinity77.net/global_optimization/test_functions_nd_R.html#go_benchmark.Rosenbrock