Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CEC2017-and-CEC2022-2D-Functions-in-Python

A Python implementation of the CEC 2017 and CEC 2022 single objective optimization benchmark functions. The package currently provides only two-dimensional (2D) implementations.

Important

Due to instability, the second benchmark function was excluded from the CEC2017 implementation, resulting in an index shift of one for all subsequent functions. The indexing is based on the paper: Problem Definitions and Evaluation Criteria for the CEC 2017 Special Session and Competition on Single Objective Real-Parameter Numerical Optimization. Link

Importing module

from Functions import Functions

Creating an instance

F = Functions()

Available benchmark functions

  • Official functions (Functions natively defined in 2D according to the original paper):
    • CEC2017: C17_1 ↔ C17_9 | C17_20 ↔ C17_27
    • CEC2022: C22_1 ↔ C22_5 | C22_9 ↔ C22_12
  • Unofficial functions (Higher-dimensional functions adapted for 2D inputs; Hybrid functions)
    • CEC2017: U_C17_10 ↔ U_C17_19 | U_C17_28 ↔ U_C17_29
    • CEC2022: U_C22_6 ↔ U_C22_8
  • Adjusted CEC2022 composite functions to match the surface plots in the paper (unofficial; uses different sigma and lambda values)
    • C22_9_Alt ↔ C22_12_Alt

Tip

The functions and their optimal values can also be accessed via arrays!

F.CEC2017 | F.CEC2017_Opts - Official CEC2017 functions
F.CEC2017_Unofficial | F.CEC2017_Unofficial_Opts - Unofficial CEC2017 functions
F.CEC2022 | F.CEC2022_Opts - Official CEC2022 functions
F.CEC2022_Alt | F.CEC2022_Alt_Opts - Adjusted CEC2022 composite functions
F.CEC2022_Unofficial | F.CEC2022_Unofficial_Opts - Unofficial CEC2022 functions
F.AllFunctions | F.AllOpts - All official functions (CEC2017+CEC2022)
F.AllFunctionsWithU | F.AllOptsWithU - All official, adjusted and unofficial functions

Usage

# Specifying X and Y coordinates in the -100 <= x <= 100 search range
X = 10
Y = -20

# Determining Z axis value with the selected benchmark function
Z = F.C17_3(X, Y)
print(Z)

# Getting the global optimum value for the specific function
optimum = F.C17_3_Opt
print(optimum)

# Getting the difference between the global optimum and the calculated value Z (absolute error)
Err = abs(Z - optimum)
print(Err)

Plotting the function landscape over the full search space

from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
from Functions import Functions

F = Functions()

x = np.linspace(-100, 100, 1000)
y = np.linspace(-100, 100, 1000)
X, Y = np.meshgrid(x, y)
Z = np.empty_like(X)

for i in range(len(X[0])):
    for j in range(len(X[0])):
        Z[i,j] = F.C22_2(X[i,j],Y[i,j])

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

surf = ax.plot_surface(X, Y, Z, cmap='plasma')
fig.colorbar(surf, shrink=0.5, aspect=5)

ax.xaxis.pane.set_facecolor((1.0, 1.0, 1.0, 0.0))
ax.yaxis.pane.set_facecolor((1.0, 1.0, 1.0, 0.0))
ax.zaxis.pane.set_facecolor((1.0, 1.0, 1.0, 0.0))

ax.set_facecolor((1.0, 1.0, 1.0, 0.0))

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

ax.grid(True)
# contour

fig2 = plt.figure()
ax2 = fig2.add_subplot(111)
cf = ax2.contourf(X, Y, Z, levels=200, cmap='viridis')
cs = ax2.contour(X, Y, Z, levels=15, cmap='autumn', linewidths=0.5)
fig2.colorbar(cf)
ax2.set_xlabel("X")
ax2.set_ylabel("Y")
ax2.set_aspect('equal')
fig2.show()

print(np.max(Z))

plt.show()

Function landscapes

Function 3D Surface Landscape Contour
C17_1
C17_2
C17_3
C17_4
C17_5
C17_6
C17_7
C17_8
C17_9
C17_20
C17_21
C17_22
C17_23
C17_24
C17_25
C17_26
C17_27
U_C17_10
U_C17_11
U_C17_12
U_C17_13
U_C17_14
U_C17_15
U_C17_16
U_C17_17
U_C17_18
U_C17_19
U_C17_28
U_C17_29
C22_1
C22_2
C22_3
C22_4
C22_5
C22_9
C22_10
C22_11
C22_12
C22_9_Alt
C22_10_Alt
C22_11_Alt
C22_12_Alt
U_C22_6
U_C22_7
U_C22_8

Sources:

About

A Python implementation of the CEC 2017 and CEC 2022 single objective optimization benchmark functions. The package provides only two-dimensional (2D) implementations.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages