2023-02-01 23:26:37 +01:00
|
|
|
// Copyright 2023 wanderer <a_mirre at utb dot cz>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
package cec2020
|
|
|
|
|
2023-02-06 21:48:55 +01:00
|
|
|
import "math"
|
|
|
|
|
2023-02-01 23:26:37 +01:00
|
|
|
// void sphere_func (double *, double *, int , double *,double *, int, int); // Sphere
|
|
|
|
// void ellips_func(double *, double *, int , double *,double *, int, int); // Ellipsoidal
|
|
|
|
// void bent_cigar_func(double *, double *, int , double *,double *, int, int); // Discus
|
|
|
|
// void discus_func(double *, double *, int , double *,double *, int, int); // Bent_Cigar
|
|
|
|
// void dif_powers_func(double *, double *, int , double *,double *, int, int); // Different Powers
|
|
|
|
// void rosenbrock_func (double *, double *, int , double *,double *, int, int); // Rosenbrock's
|
|
|
|
// void schaffer_F7_func (double *, double *, int , double *,double *, int, int); // Schwefel's F7
|
|
|
|
// void ackley_func (double *, double *, int , double *,double *, int, int); // Ackley's
|
|
|
|
// void rastrigin_func (double *, double *, int , double *,double *, int, int); // Rastrigin's
|
|
|
|
// void weierstrass_func (double *, double *, int , double *,double *, int, int); // Weierstrass's
|
|
|
|
// void griewank_func (double *, double *, int , double *,double *, int, int); // Griewank's
|
|
|
|
// void schwefel_func (double *, double *, int , double *,double *, int, int); // Schwefel's
|
|
|
|
// void katsuura_func (double *, double *, int , double *,double *, int, int); // Katsuura
|
|
|
|
// void bi_rastrigin_func (double *, double *, int , double *,double *, int, int); // Lunacek Bi_rastrigin
|
|
|
|
// void grie_rosen_func (double *, double *, int , double *,double *, int, int); // Griewank-Rosenbrock
|
|
|
|
// void escaffer6_func (double *, double *, int , double *,double *, int, int); // Expanded Schaffer's F6
|
|
|
|
// void step_rastrigin_func (double *, double *, int , double *,double *, int, int); // Noncontinuous Rastrigin's
|
|
|
|
// void happycat_func (double *, double *, int , double *,double *, int, int); // HappyCat
|
|
|
|
// void hgbat_func (double *, double *, int , double *,double *, int, int); // HGBat
|
|
|
|
//
|
|
|
|
// // New functions Noor Changes
|
|
|
|
// void sum_diff_pow_func(double *, double *, int , double *,double *, int, int); // Sum of different power
|
|
|
|
// void zakharov_func(double *, double *, int , double *,double *, int, int); // ZAKHAROV
|
|
|
|
// void levy_func(double *, double *, int , double *,double *, int, int); // Levy
|
|
|
|
// void dixon_price_func(double *, double *, int , double *,double *, int, int); // Dixon and Price
|
2023-02-04 20:36:57 +01:00
|
|
|
|
|
|
|
// BentCigar is the "Bent Cigar Function" of CEC2020.
|
2023-02-06 21:48:55 +01:00
|
|
|
func BentCigar(x []float64) float64 {
|
|
|
|
var sum float64
|
|
|
|
|
|
|
|
for i := 1; i < len(x); i++ {
|
|
|
|
sum += math.Pow(x[i], 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (1000000 * sum) + math.Pow(x[0], 2)
|
|
|
|
}
|
2023-02-04 20:36:57 +01:00
|
|
|
|
|
|
|
// Schwefel is the "Shifted and Rotated Schwefel's Function" of CEC2020.
|
2023-02-06 23:26:19 +01:00
|
|
|
func Schwefel(x []float64) float64 {
|
|
|
|
return SchwefelModified(x)
|
|
|
|
}
|
2023-02-04 20:36:57 +01:00
|
|
|
|
|
|
|
// LunacekBiRastrigin is the "Shifted and Rotated Lunacek bi-Rastrigin Function" of CEC2020.
|
2023-02-07 23:00:30 +01:00
|
|
|
// ref: https://al-roomi.org/benchmarks/unconstrained/n-dimensions/229-lunacek-s-bi-rastrigin-function.
|
2023-02-07 22:54:15 +01:00
|
|
|
func LunacekBiRastrigin(x []float64) float64 {
|
|
|
|
var sum0 float64
|
|
|
|
|
|
|
|
var sum1 float64
|
|
|
|
|
|
|
|
var sum2 float64
|
|
|
|
|
|
|
|
nx := len(x)
|
|
|
|
fnx := float64(nx)
|
|
|
|
s := 1 - (1 / ((2 * math.Sqrt(fnx+20)) - 8.2))
|
|
|
|
d := 1.0
|
|
|
|
mu0 := 2.5
|
|
|
|
mu1 := -math.Sqrt((math.Pow(mu0, 2) - d) / s)
|
|
|
|
xhat := make([]float64, nx)
|
|
|
|
xopt := newXopt(nx, mu0)
|
|
|
|
|
|
|
|
for i := range x {
|
|
|
|
xhat = append(xhat, 2*x[i])
|
|
|
|
|
|
|
|
if xopt[i] < 0 {
|
|
|
|
xhat[i] *= -1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range x {
|
|
|
|
sum0 += math.Pow(xhat[i]-mu0, 2)
|
|
|
|
|
|
|
|
sum1 += math.Pow(xhat[i]-mu1, 2)
|
|
|
|
|
|
|
|
zi := math.Pow(100, 0.5*((float64(i)-1)/fnx-1)) * xhat[i]
|
|
|
|
|
|
|
|
sum2 += (1 - math.Cos(2*math.Pi*zi))
|
|
|
|
}
|
|
|
|
|
|
|
|
return math.Min(sum0, (d*fnx)+(s*sum1)) + 10*sum2
|
|
|
|
}
|
2023-02-04 20:36:57 +01:00
|
|
|
|
|
|
|
// RosenbrockGriewank is the "Expanded Rosenbrock's plus Griewank's Function"
|
|
|
|
// of CEC2020.
|
2023-02-06 23:23:28 +01:00
|
|
|
func RosenbrockGriewank(x []float64) float64 {
|
|
|
|
var sum float64
|
|
|
|
|
|
|
|
nx := len(x)
|
|
|
|
|
|
|
|
for i := range x {
|
|
|
|
f := []float64{x[i], x[(i+1)%nx]}
|
|
|
|
|
|
|
|
sum += Griewank([]float64{Rosenbrock(f)})
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
2023-02-04 20:36:57 +01:00
|
|
|
|
|
|
|
// Hybrid1 is the "Hybrid Function 1" of CEC2020.
|
|
|
|
func Hybrid1(x []float64) float64 { return 0 }
|
|
|
|
|
|
|
|
// Hybrid2 is the "Hybrid Function 2" of CEC2020.
|
|
|
|
func Hybrid2(x []float64) float64 { return 0 }
|
|
|
|
|
|
|
|
// Hybrid3 is the "Hybrid Function 3" of CEC2020.
|
|
|
|
func Hybrid3(x []float64) float64 { return 0 }
|
|
|
|
|
|
|
|
// Composition1 is the "Composition Function 1" of CEC2020.
|
|
|
|
func Composition1(x []float64) float64 { return 0 }
|
|
|
|
|
|
|
|
// Composition2 is the "Composition Function 2" of CEC2020.
|
|
|
|
func Composition2(x []float64) float64 { return 0 }
|
|
|
|
|
|
|
|
// Composition3 is the "Composition Function 3" of CEC2020.
|
|
|
|
func Composition3(x []float64) float64 { return 0 }
|