You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importopfunuimportnumpyasnp# get all the available functions accepting ANY dimensionany_dim_cec=opfunu.get_cec_based_functions(None)
print(any_dim_cec)
# get all the available separable functions accepting 2Dseparable_2d_cec=opfunu.get_cec_based_functions(
ndim=2, # dimensionseparable=True,
)
print(separable_2d_cec)
# Import specific functionf12005=opfunu.cec_based.F12005()
print(f12005.evaluate(np.array([5, 4, 5]))) # get resultsprint(f12005.bounds)
print(f12005.lb)
print(f12005.ub)
# f12005 = opfunu.cec_based.F12005(ndim=1010)# print(f12005.lb)lb= [-10, ] *15ub= [10, ] *15bounds= [lb, ub]
f12005=opfunu.cec_based.F12005(bounds=bounds)
print(f12005.lb)
# bounds = [[-10,] * 101, [10, ] * 101]# f12005 = opfunu.cec_based.F12005(bounds=bounds)# print(f12005.lb)# Plot 2d or plot 3d contours# Warning ! Only working on 2d functions objects !# Warning 2! change n_space to reduce the computing timef22005=opfunu.cec_based.F22005(ndim=2)
# opfunu.plot_2d(f22005, n_space=1000, ax=None)# opfunu.plot_3d(f22005, n_space=1000, ax=None)# Access/change the parameters of parametrics functionsprint(f22005.get_paras())
# Get the global minimum for a specific dimensionprint(f22005.f_global)
print(f22005.x_global)
# Acces/plot the latex formulaslatex=f22005.latex_formulalatex=f22005.latex_formula_dimensionlatex=f22005.latex_formula_boundslatex=f22005.latex_formula_global_optimumprint(latex) # --> f(\mathbf{x}) = exp(-\sum_{i=1}^{d}(x_i / \beta)^{2m}) - 2exp(-\prod_{i=1}^{d}x_i^2) \prod_{i=1}^{d}cos^ 2(x_i)opfunu.plot_latex_formula(latex)
## Test read file matrixf32005=opfunu.cec_based.F32005(ndim=10)
x=np.ones(10)
print(f32005.evaluate(x))
print(f32005.f_matrix)
print(f32005.x_global)
problem=opfunu.cec_based.F212005(ndim=10)
x=np.ones(10)
print(problem.evaluate(x))
print(problem.x_global)
print(problem.is_succeed(problem.x_global))
# # get all the available separable functions accepting 2Dmy_list=opfunu.get_cec_based_functions(
ndim=2, # dimensionrotated=True
)
print(my_list) # --> 41## Get all noise functionmy_list=opfunu.get_cec_based_functions(
randomized_term=True
)
print(my_list)
Example for version <= 0.8.0
All you need to do is: (Make sure your solution is a numpy 1-D array)
## For dimension_basedfromopfunu.dimension_based.benchmark2dimportFunctions# import 2-d benchmark functionsimportnumpyasnpsolution2d=np.array([-0.1, 1.5]) # Solution for 2-d benchmarkfunc2d=Functions() # create an objectprint(func2d._bartels_conn__(solution2d)) # using function in above objectprint(func2d._bird__(solution2d))
## For type_based (same as dimension_based)fromopfunu.type_based.multi_modalimportFunctions# import 2-d benchmark functionsimportnumpyasnp## For CECfromopfunu.cec.cec2014importFunctions# import cec2014 functionsimportnumpyasnpcec_sol=np.array([-0.1, 1.5]) # Solution for 2-d benchmarkcec_func=Functions() # create an objectprint(cec_func.C1(cec_sol)) # using function in above object from C1, ..., C30print(cec_func.C30(cec_sol))
## CEC-2005 or CEC-2008importnumpyasnpfromopfunu.cec.cec2005.F1importModelasf1fromopfunu.cec.cec2008.F7importModelasf7solution=np.array([0.5, 1, 1.5, 2, 3, 0.9, 1.2, 2, 1, 5])
t1=f1()
result=t1._main__(temp)
print(result)
t2=f7()
result=t2._main__(temp)
print(result)
## CEC-2010 importnumpyasnpfromopfunu.cec.cec2010.functionimportF1, F2, ..., F12,..
solution=np.random.uniform(0, 1, 1000)
result=F12(temp)
print(result)
## CEC-2013 (2 ways to use depend on your purpose)importnumpyasnpfromopfunu.cec.cec2013.unconstraintimportModelasM13fromopfunu.cec.cec2014.unconstraint2importModelasMD2problem_size=10solution=np.random.uniform(0, 1, problem_size)
obj=MD2(problem_size) # Object style solve different problems with different functionsprint(obj.F1(solution))
print(obj.F2(solution))
obj=M13(solution) # Object style solve same problem with every functionsprint(obj.F1())
print(obj.F2())
## CEC-2014 (3 ways to use depend on your purpose)importnumpyasnpfromopfunu.cec.cec2014.functionimportF1, F2, ...
fromopfunu.cec.cec2014.unconstraint2importModelasMD2fromopfunu.cec.cec2014.unconstraintimportModelasMDproblem_size=10solution=np.random.uniform(0, 1, problem_size)
print(F1(solution)) # Function stylefunc=MD(problem_size) # Object style solve different problems with different functionsprint(func.F1(solution))
print(func.F2(solution))
obj=MD2(solution) # Object style solve same problem with every functionsprint(obj.F1())
print(obj.F2())
## CEC-2015 importnumpyasnpfromopfunu.cec.cec2015.functionimportF1, F2,...
temp=np.random.uniform(0, 1, 10)
result=F1(temp)
print(result)
## CEC basic importnumpyasnpfromopfunu.cec_basic.cec2014import*problem_size=20sol=np.random.uniform(0, 1, 20)
print(F30(sol))
### CEC 2020 - engineering problem fromopfunu.cec.cec2020.constantimportbenchmark_functionasBFfromopfunu.cec.cec2020importengineeringfromnumpy.randomimportuniformforiinrange(1, 26):
out=BF(i) # Get object contain information about problemsD, g, h, xmin, xmax=out["D"], out["g"], out["h"], out["xmin"], out["xmax"]
solution=uniform(xmin, xmax) ## Create solution based on information aboveproblem="p"+str(i) ## Choice the problemfx, gx, hx=getattr(engineering, problem)(solution) ## Fitness function, constraintprint("\n=============="+problem+"=================")
print("fx:", fx)
print("gx:", gx)
print("hx:", hx)
--Theproblem1-23and25isDONE, theproblem24thisnotDONEyet.
...