cec2020: implement Hybrid1 func
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-02-07 23:33:00 +01:00
parent f7e9a42c92
commit 0521525e1f
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
2 changed files with 58 additions and 1 deletions

@ -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 }

@ -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
}