diff --git a/bench/cec2020/benchFunctions.go b/bench/cec2020/benchFunctions.go index 5f9938f..debe818 100644 --- a/bench/cec2020/benchFunctions.go +++ b/bench/cec2020/benchFunctions.go @@ -184,7 +184,44 @@ func Hybrid3(x []float64) float64 { } // Composition1 is the "Composition Function 1" of CEC2020. -func Composition1(x []float64) float64 { return 0 } +func Composition1(x []float64) float64 { + nx := len(x) + fnx := float64(nx) + + // optimum positions. + o := newOpt(nx) + sigma := []float64{10, 20, 30} + lambda := []float64{1, 10, 1} + bias := []float64{0, 100, 200} + omega := make([]float64, nx) + funcs := []func([]float64) float64{ + Rastrigin, + Griewank, + SchwefelModified, + } + + var sum float64 + + var weights []float64 + + for i := range funcs { + wi := getWeight(x, o, sigma[i], fnx) + + weights = append(weights, wi) + + var wsum float64 + + for j := range weights { + wsum += weights[j] + } + + omega = append(omega, wi/wsum) + + sum += (omega[i] * (lambda[i]*funcs[i](x) + bias[i])) + funcs[i](x) + } + + return sum +} // Composition2 is the "Composition Function 2" of CEC2020. func Composition2(x []float64) float64 { return 0 } diff --git a/bench/cec2020/helperFunctions.go b/bench/cec2020/helperFunctions.go index d8df5a0..29993d0 100644 --- a/bench/cec2020/helperFunctions.go +++ b/bench/cec2020/helperFunctions.go @@ -191,3 +191,14 @@ func getMz(x []float64, z []float64) []float64 { return mz } + +func getWeight(x, o []float64, sigma, nx float64) float64 { + var sum float64 + + for i := range x { + sum += math.Pow(x[i]-o[i], 2) + } + + // w. + return (1 / (math.Sqrt(sum))) * math.Exp(-(sum / 2 * nx * math.Pow(sigma, 2))) +}