-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python | ||
# Created by "Thieu" at 17:03, 24/05/2024 ----------% | ||
# Email: [email protected] % | ||
# Github: https://github.com/thieu1995 % | ||
# --------------------------------------------------% | ||
|
||
from opfunu import draw_2d, draw_3d | ||
|
||
## Define a custom function, for example. I will use mealpy problem as an example | ||
from mealpy import Problem, FloatVar | ||
import numpy as np | ||
|
||
# Our custom problem class | ||
class Squared(Problem): | ||
def __init__(self, bounds=None, minmax="min", data=None, **kwargs): | ||
self.data = data | ||
super().__init__(bounds, minmax, **kwargs) | ||
|
||
def obj_func(self, solution): | ||
x = self.decode_solution(solution)["my_var"] | ||
return np.sum(x ** 2) | ||
|
||
bound = FloatVar(lb=(-10., )*20, ub=(10., )*20, name="my_var") | ||
custom_squared = Squared(bounds=bound, minmax="min", data="Amazing", name="Squared") | ||
|
||
## Visualize function using utility function | ||
draw_2d(custom_squared.obj_func, custom_squared.lb, custom_squared.ub, selected_dims=(2, 3), n_points=300) | ||
draw_3d(custom_squared.obj_func, custom_squared.lb, custom_squared.ub, selected_dims=(2, 3), n_points=300) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env python | ||
# Created by "Thieu" at 16:55, 24/05/2024 ----------% | ||
# Email: [email protected] % | ||
# Github: https://github.com/thieu1995 % | ||
# --------------------------------------------------% | ||
|
||
from opfunu.cec_based import F12010 | ||
|
||
# Visualize opfunu function using method in object | ||
f0 = F12010() | ||
f0.plot_2d(selected_dims=(2, 3), n_points=300) | ||
f0.plot_3d(selected_dims=(2, 3), n_points=300) | ||
|
||
## Visualize opfunu function using utility function | ||
from opfunu import draw_2d, draw_3d | ||
|
||
draw_2d(f0.evaluate, f0.lb, f0.ub, selected_dims=(2, 3), n_points=300) | ||
draw_3d(f0.evaluate, f0.lb, f0.ub, selected_dims=(2, 3), n_points=300) |