From 0521525e1f17a002fe807124d3a46ac648607aa2 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 7 Feb 2023 23:33:00 +0100 Subject: [PATCH] cec2020: implement Hybrid1 func --- bench/cec2020/benchFunctions.go | 35 +++++++++++++++++++++++++++++++- bench/cec2020/helperFunctions.go | 24 ++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/bench/cec2020/benchFunctions.go b/bench/cec2020/benchFunctions.go index ecc6d41..01b951e 100644 --- a/bench/cec2020/benchFunctions.go +++ b/bench/cec2020/benchFunctions.go @@ -103,7 +103,40 @@ func RosenbrockGriewank(x []float64) float64 { } // Hybrid1 is the "Hybrid Function 1" of CEC2020. -func Hybrid1(x []float64) float64 { return 0 } +func Hybrid1(x []float64) float64 { + nx := len(x) + fnx := float64(nx) + + f1 := SchwefelModified + f2 := Rastrigin + f3 := HighConditionedElliptic + + // percentages. + p := []float64{0.3, 0.3, 0.4} + gnx := make([]float64, len(p)) + gnxsum := 0.0 + + for i := 0; i < len(p)-1; i++ { + gnx[i] = math.Ceil(p[i] * fnx) + gnxsum += gnx[i] + } + + gnx[len(p)] = fnx - gnxsum + + z := newOpt(nx) + mz := make([]float64, nx) + + for i := range x { + mz = append(mz, x[i]*z[i]) + } + + // results. + r1 := f1(mz) + r2 := f2(mz) + r3 := f3(mz) + + return gnx[0]*r1 + gnx[1]*r2 + gnx[2]*r3 +} // Hybrid2 is the "Hybrid Function 2" of CEC2020. func Hybrid2(x []float64) float64 { return 0 } diff --git a/bench/cec2020/helperFunctions.go b/bench/cec2020/helperFunctions.go index 80a1889..883ec8c 100644 --- a/bench/cec2020/helperFunctions.go +++ b/bench/cec2020/helperFunctions.go @@ -140,3 +140,27 @@ func newXopt(n int, mu0 float64) []float64 { return xopt } + +// newOpt returns a slice of optimal float64 values. +func newOpt(n int) []float64 { + uniformDist := &distuv.Uniform{ + Src: rand.NewSource(uint64(time.Now().UnixNano())), + Min: SearchRange.Min(), + Max: SearchRange.Max(), + } + + tmpvec := make([]float64, n) + xopt := make([]float64, n) + + for i := 0; i < n; i++ { + tmpvec = append(tmpvec, uniformDist.Rand()) + + xopt = append(xopt, 0.5*uniformDist.Mean()) + + if tmpvec[i] < 0 { + xopt[i] *= -1 + } + } + + return xopt +}