Skip to main content

Opfunu-core: An Open-source Python Library for Optimization Benchmark Functions

Project description

opfunu-core

License: GPL v3 PyPI - Version PyPI - Implementation PyPI - Python Version PyPI - Wheel GitHub Release Date PyPI - Downloads

This library is a maintenance version, a fork of OPFUNU (Optimization Reference Functions in NUMPy). Is one of the most comprehensive Python libraries of numerical optimization reference functions. It contains all the functions from the CEC competitions of 2005, 2008, 2010, 2013, 2014, 2015, 2017, 2019, 2020, 2021, and 2022. In addition, it implements over 300 traditional functions with varying dimensions.

Citation Request

Please include these citations if you plan to use this library:

LaTeX Style

  @article{Van_Thieu_2024_Opfunu,
      author = {Van Thieu, Nguyen},
      title = {Opfunu: An Open-source Python Library for Optimization Benchmark Functions},
      doi = {10.5334/jors.508},
      journal = {Journal of Open Research Software},
      month = {May},
      year = {2024}
  }

APA Style

Van Thieu, N. (2024). Opfunu: An Open-source Python Library for Optimization Benchmark Functions. Journal of Open Research Software, 12(1), 8. https://doi.org/10.5334/jors.508

Installation and Usage

Install with pip

Install the current PyPI release:

$ pip install opfunu-core

Install from Github:

$ pip install git+https://github.com/ltsim/opfunu-core

After installation, you can import and check version of Opfunu:

$ python
>>> import opfunu
>>> opfunu.__version__

>>> dir(opfunu)
>>> help(opfunu)

>>> opfunu.FUNC_DATABASE      # List all name_based functions
>>> opfunu.CEC_DATABASE       # List all cec_based functions
>>> opfunu.ALL_DATABASE       # List all functions in this library

>>> opfunu.get_functions_by_classname("MiShra04")
>>> opfunu.get_functions_based_classname("2015")
>>> opfunu.get_functions_by_ndim(2)
>>> opfunu.get_functions_based_ndim(50)

>>> opfunu.get_name_based_functions(ndim=10, continuous=True)
>>> opfunu.get_cec_based_functions(ndim=2)

Let's go through some examples.

Examples

How to get the function and use it

1st way

from opfunu.cec_based.cec2014 import F12014

func = F12014(ndim=30)
func.evaluate(func.create_solution())

## or

from opfunu.cec_based import F102014

func = F102014(ndim=50)
func.evaluate(func.create_solution())

2nd way

import opfunu

funcs = opfunu.get_functions_by_classname("F12014")
func = funcs[0](ndim=10)
func.evaluate(func.create_solution())

## or

all_funcs_2014 = opfunu.get_functions_based_classname("2014")
print(all_funcs_2014)

How to draw 2D, 3D

Two ways if you want to draw functions that available in Opfunu.

from opfunu.cec_based import F12010
f0 = F12010()

# Visualize opfunu function using method in object
f0.plot_2d(selected_dims=(2, 3), n_points=300, ct_cmap="viridis", ct_levels=30, ct_alpha=0.7,
           fixed_strategy="mean", fixed_values=None, title="Contour map of the F1 CEC 2010 function",
           x_label=None, y_label=None, figsize=(10, 8), filename="2d-f12010", exts=(".png", ".pdf"), verbose=True)

f0.plot_3d(selected_dims=(1, 6), n_points=500, ct_cmap="viridis", ct_levels=30, ct_alpha=0.7,
           fixed_strategy="mean", fixed_values=None, title="3D visualization of the F1 CEC 2010 function",
           x_label=None, y_label=None, figsize=(10, 8), filename="3d-f12010", exts=(".png", ".pdf"), verbose=True)

## 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)

How to draw Latex

Two ways if you want to draw latex equation.

from opfunu.cec_based import F12010
from opfunu.name_based import Ackley02
from opfunu.utils.visualize import draw_latex

f0 = F12010()
f1 = Ackley02()

## Plot using function inside the object
f0.plot_latex(f0.latex_formula, figsize=(8, 3), dpi=500, title="Latex equation", exts=(".png", ".pdf"), verbose=True)
f1.plot_latex(f1.latex_formula_global_optimum, figsize=(8, 3), dpi=500, title="Global optimum", verbose=True)

## Plot using module
draw_latex(f0.latex_formula_bounds, title="Boundary for Function")
draw_latex(f1.latex_formula_dimension, title=None)

For more usage examples please look at examples folder.

Contributing

There are lots of ways how you can contribute to Permetrics's development, and you are welcome to join in! For example, you can report problems or make feature requests on the issues pages. To facilitate contributions, please check for the guidelines in the CONTRIBUTING.md file.

Official channels


  • Maintained by: LTSIM @ 2026
  • Developed by: Thieu @ 2023

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opfunu_core-1.0.5.1.1.tar.gz (12.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opfunu_core-1.0.5.1.1-py3-none-any.whl (13.0 MB view details)

Uploaded Python 3

File details

Details for the file opfunu_core-1.0.5.1.1.tar.gz.

File metadata

  • Download URL: opfunu_core-1.0.5.1.1.tar.gz
  • Upload date:
  • Size: 12.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for opfunu_core-1.0.5.1.1.tar.gz
Algorithm Hash digest
SHA256 2a39e72ce09fc9ef12ce3490f912640363937bec71e5418b41bfa821eda13df6
MD5 ae8234fb9b908c7c174c1e435d6ce67e
BLAKE2b-256 0f434b739fef80f9c83017f179e6d1a69ac93fbebc3c37e305a15e83e8d92d3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for opfunu_core-1.0.5.1.1.tar.gz:

Publisher: publish.yml on ltsim/opfunu-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opfunu_core-1.0.5.1.1-py3-none-any.whl.

File metadata

  • Download URL: opfunu_core-1.0.5.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for opfunu_core-1.0.5.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 02674bcc7c3cc858c9af77be4e47c70fc5936e781b4039d6c03e2f3ebf5b055c
MD5 1bdc9f37551e44e5ac9af72b57d3e19c
BLAKE2b-256 8862985226d8e943c50e7a7475d38e0ef824f6a49ae4a534bd71d327b1c848b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for opfunu_core-1.0.5.1.1-py3-none-any.whl:

Publisher: publish.yml on ltsim/opfunu-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page