Last active
September 9, 2020 04:15
-
-
Save thieu1995/cb2a85f90e0e78e4d436b1b6f4019f79 to your computer and use it in GitHub Desktop.
How to call and run CEC 2013 benchmark functions from opfunu library.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Upgrade the library first | |
## pip install opfunu --upgrade | |
## Current version: 0.7.1 | |
import numpy as np | |
from opfunu.cec.cec2013.unconstraint import Model as MD1 | |
from opfunu.cec.cec2013.unconstraint2 import Model as MD2 | |
problem_size = 100 | |
solution = np.ones(problem_size) | |
## In the unconstraint way, you have to pass the problem_size to the object. and pass the solution to function called | |
obj1 = MD1(problem_size) # ==> pass the problem_size here | |
print(obj1.F1(solution)) # ==> pass the solution in function called | |
print(obj1.F2(solution)) | |
print(obj1.F3(solution)) | |
# ==> How to loop through this style of function called | |
list_functions = ["F1", "F2", "F3"] ## You can add from F1 to F28 here | |
for i in range(len(list_functions)): | |
print(obj1.__getattribute__(list_functions[i])(solution)) | |
## In the unconstraint2 way, you have to pass he solution to the object, and don't have to pass anything to function called | |
obj2 = MD2(solution) # ==> pass the solution here | |
print(obj2.F1()) # ==> don't have to pass anything here | |
print(obj2.F2()) | |
print(obj2.F3()) | |
# ==> How to loop through this style of function called | |
for i in range(len(list_functions)): | |
print(obj2.__getattribute__(list_functions[i])()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment