Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
thieu1995 committed Apr 26, 2024
1 parent 69b3358 commit 15a86a8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
8 changes: 4 additions & 4 deletions examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import opfunu
import numpy as np

# get all the available functions accepting ANY dimension
any_dim_cec = opfunu.get_cecs(None)
any_dim_cec = opfunu.get_cec_based_functions(None)
print(any_dim_cec)

# get all the available separable functions accepting 2D
separable_2d_cec = opfunu.get_cecs(
separable_2d_cec = opfunu.get_cec_based_functions(
ndim=2, # dimension
separable=True,
)
Expand Down Expand Up @@ -75,14 +75,14 @@ print(problem.x_global)
print(problem.is_succeed(problem.x_global))

# # get all the available separable functions accepting 2D
my_list = opfunu.get_cecs(
my_list = opfunu.get_cec_based_functions(
ndim=2, # dimension
rotated=True
)
print(my_list) # --> 41

## Get all noise function
my_list = opfunu.get_cecs(
my_list = opfunu.get_cec_based_functions(
randomized_term=True
)
print(my_list)
Expand Down
4 changes: 2 additions & 2 deletions examples/basic_use_cases_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

if __name__ == '__main__':
# get all the available functions accepting ANY dimension
any_dim_functions = opfunu.get_functions(None)
any_dim_functions = opfunu.get_name_based_functions(None)
print(any_dim_functions)

# get all the available differentiable functions accepting 2D
differentiable_2d_functions = opfunu.get_functions(
differentiable_2d_functions = opfunu.get_name_based_functions(
ndim=2, # dimension
differentiable=True,
)
Expand Down
8 changes: 4 additions & 4 deletions examples/basic_use_cases_cec.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

if __name__ == '__main__':
# # get all the available functions accepting ANY dimension
# any_dim_cec = opfunu.get_cecs(None)
# any_dim_cec = opfunu.get_cec_based_functions(None)
# print(any_dim_cec)
#
# # get all the available separable functions accepting 2D
# separable_2d_cec = opfunu.get_cecs(
# separable_2d_cec = opfunu.get_cec_based_functions(
# ndim=2, # dimension
# separable=True,
# )
Expand Down Expand Up @@ -77,14 +77,14 @@
print(problem.is_succeed(problem.x_global))

# # get all the available separable functions accepting 2D
my_list = opfunu.get_cecs(
my_list = opfunu.get_cec_based_functions(
ndim=2, # dimension
rotated=True
)
print(my_list) # --> 41

## Get all noise function
my_list = opfunu.get_cecs(
my_list = opfunu.get_cec_based_functions(
randomized_term=True
)
print(my_list)
19 changes: 19 additions & 0 deletions examples/example_with_mealpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Github: https://github.com/thieu1995 %
# --------------------------------------------------%

## Examples with Mealpy <= 2.5.4

from mealpy.bio_based import SMA
from opfunu.name_based import Ackley02

Expand All @@ -27,3 +29,20 @@
print(ackey.n_fe)
print(ackey.f_global)
print(ackey.x_global)


## Examples with Mealpy >= 3.0.0

from opfunu.cec_based import cec2017
f3 = cec2017.F32017(ndim=30)

from mealpy import GA, FloatVar

problem = {
"obj_func": f3.evaluate,
"bounds": FloatVar(lb=f3.lb, ub=f3.ub),
"minmax": "min",
}
model = GA.BaseGA(epoch=100, pop_size=50)
gbest = model.solve(problem_dict1)
print(f"Solution: {gbest.solution}, Fit: {gbest.target.fitness}")

0 comments on commit 15a86a8

Please sign in to comment.