├── .github ├── imgs │ └── firefly_logo.png ├── templates │ ├── FEATURE_REQUEST.md │ ├── ISSUE_TEMPLATE.md │ └── PULL_REQUEST.md └── workflows │ └── test.yml ├── .gitignore ├── CHANGELOG.md ├── CITATION.cff ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── Problems.md ├── README.md ├── examples └── run.py ├── fireflyalgorithm ├── __init__.py ├── __main__.py ├── cli.py ├── fireflyalgorithm.py └── problems.py ├── poetry.lock ├── pyproject.toml └── tests ├── __init__.py ├── test_firefly.py └── test_problems.py /.github/imgs/firefly_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firefly-cpp/FireflyAlgorithm/121b1852a5ae3951034aa49e119d0fd44f1525f9/.github/imgs/firefly_logo.png -------------------------------------------------------------------------------- /.github/templates/FEATURE_REQUEST.md: -------------------------------------------------------------------------------- 1 | ### Feature Request 2 | 3 | **About**: 4 | **Title**: 5 | 6 | **Is your feature request related to a problem? Please describe.** 7 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 8 | 9 | **Describe the solution you'd like** 10 | A clear and concise description of what you want to happen. 11 | 12 | **Describe alternatives you've considered** 13 | A clear and concise description of any alternative solutions or features you've considered. 14 | 15 | **Additional context** 16 | Add any other context or screenshots about the feature request here. -------------------------------------------------------------------------------- /.github/templates/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Bug Report 2 | 3 | **About**: 4 | **Title**: 5 | 6 | **Steps to reproduce** 7 | Tell us how to reproduce the bug. 8 | 9 | **Expected behavior** 10 | Tell us what should happen. 11 | 12 | **Actual behavior** 13 | Tell us what happens instead. 14 | 15 | **System configuration** 16 | 17 | - OS: 18 | - Python version: -------------------------------------------------------------------------------- /.github/templates/PULL_REQUEST.md: -------------------------------------------------------------------------------- 1 | ### Summary 2 | 3 | Provide a general description of the code changes in your pull 4 | request... were there any bugs you had fixed? If so, mention them. If 5 | these bugs have open GitHub issues, be sure to tag them here as well, 6 | to keep the conversation linked together. 7 | 8 | ### Other Information 9 | 10 | If there's anything else that's important and relevant to your pull 11 | request, mention that information here. This could include 12 | benchmarks, or other information. 13 | 14 | Thanks for contributing to Firefly Algorithm! -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: fireflyalgorithm 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ${{ matrix.os }} 13 | strategy: 14 | matrix: 15 | os: [ubuntu-latest, windows-latest, macos-latest] 16 | python-version: ['3.9', '3.10', '3.11', '3.12'] 17 | defaults: 18 | run: 19 | shell: bash 20 | 21 | steps: 22 | - uses: actions/checkout@v3 23 | - name: Set up Python ${{ matrix.python-version }} 24 | uses: actions/setup-python@v3 25 | with: 26 | python-version: ${{ matrix.python-version }} 27 | - name: Get full Python version 28 | id: full-python-version 29 | run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))") 30 | - name: Install poetry 31 | run: | 32 | curl -sL https://install.python-poetry.org | python - -y 33 | - name: Update path 34 | if: ${{ matrix.os != 'windows-latest' }} 35 | run: echo "$HOME/.local/bin" >> $GITHUB_PATH 36 | - name: Update Windows path 37 | if: ${{ matrix.os == 'windows-latest' }} 38 | run: echo "$APPDATA\Python\Scripts" >> $GITHUB_PATH 39 | - name: Configure poetry 40 | run: poetry config virtualenvs.in-project true 41 | - name: Set up cache 42 | uses: actions/cache@v3 43 | id: cache 44 | with: 45 | path: .venv 46 | key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }} 47 | - name: Ensure cache is healthy 48 | if: steps.cache.outputs.cache-hit == 'true' 49 | run: timeout 10s poetry run pip --version || rm -rf .venv 50 | - name: Install dependencies 51 | run: poetry install 52 | - name: Run tests 53 | run: poetry run pytest 54 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | .vscode 132 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [0.4.2](https://github.com/firefly-cpp/FireflyAlgorithm/tree/0.4.2) (2023-12-04) 4 | 5 | [Full Changelog](https://github.com/firefly-cpp/FireflyAlgorithm/compare/0.4.1...0.4.2) 6 | 7 | **Merged pull requests:** 8 | 9 | - Contribution guide [\#20](https://github.com/firefly-cpp/FireflyAlgorithm/pull/20) ([lahovniktadej](https://github.com/lahovniktadej)) 10 | 11 | ## [0.4.1](https://github.com/firefly-cpp/FireflyAlgorithm/tree/0.4.1) (2023-11-10) 12 | 13 | [Full Changelog](https://github.com/firefly-cpp/FireflyAlgorithm/compare/0.4.0...0.4.1) 14 | 15 | **Closed issues:** 16 | 17 | - Create Problems.md [\#18](https://github.com/firefly-cpp/FireflyAlgorithm/issues/18) 18 | 19 | **Merged pull requests:** 20 | 21 | - Add Test Function definitions [\#19](https://github.com/firefly-cpp/FireflyAlgorithm/pull/19) ([zStupan](https://github.com/zStupan)) 22 | 23 | ## [0.4.0](https://github.com/firefly-cpp/FireflyAlgorithm/tree/0.4.0) (2023-11-06) 24 | 25 | [Full Changelog](https://github.com/firefly-cpp/FireflyAlgorithm/compare/0.3.4...0.4.0) 26 | 27 | **Closed issues:** 28 | 29 | - Enhance tests [\#16](https://github.com/firefly-cpp/FireflyAlgorithm/issues/16) 30 | - Provide Command Line Interface \(CLI\) [\#13](https://github.com/firefly-cpp/FireflyAlgorithm/issues/13) 31 | - Add installation instructions for Arch Linux [\#11](https://github.com/firefly-cpp/FireflyAlgorithm/issues/11) 32 | 33 | **Merged pull requests:** 34 | 35 | - Add tests [\#17](https://github.com/firefly-cpp/FireflyAlgorithm/pull/17) ([zStupan](https://github.com/zStupan)) 36 | - Added a Command Line Interface [\#15](https://github.com/firefly-cpp/FireflyAlgorithm/pull/15) ([zStupan](https://github.com/zStupan)) 37 | - Improve workflows [\#14](https://github.com/firefly-cpp/FireflyAlgorithm/pull/14) ([firefly-cpp](https://github.com/firefly-cpp)) 38 | - Add instructions for install FireflyAlgorithm in Arch Linux [\#12](https://github.com/firefly-cpp/FireflyAlgorithm/pull/12) ([carlosal1015](https://github.com/carlosal1015)) 39 | 40 | ## [0.3.4](https://github.com/firefly-cpp/FireflyAlgorithm/tree/0.3.4) (2022-12-13) 41 | 42 | [Full Changelog](https://github.com/firefly-cpp/FireflyAlgorithm/compare/0.3.3...0.3.4) 43 | 44 | **Merged pull requests:** 45 | 46 | - logo add [\#10](https://github.com/firefly-cpp/FireflyAlgorithm/pull/10) ([rhododendrom](https://github.com/rhododendrom)) 47 | 48 | ## [0.3.3](https://github.com/firefly-cpp/FireflyAlgorithm/tree/0.3.3) (2022-10-31) 49 | 50 | [Full Changelog](https://github.com/firefly-cpp/FireflyAlgorithm/compare/0.3.2...0.3.3) 51 | 52 | ## [0.3.2](https://github.com/firefly-cpp/FireflyAlgorithm/tree/0.3.2) (2022-07-12) 53 | 54 | [Full Changelog](https://github.com/firefly-cpp/FireflyAlgorithm/compare/0.3.1...0.3.2) 55 | 56 | **Merged pull requests:** 57 | 58 | - Rename project name in pyproject.toml [\#9](https://github.com/firefly-cpp/FireflyAlgorithm/pull/9) ([firefly-cpp](https://github.com/firefly-cpp)) 59 | 60 | ## [0.3.1](https://github.com/firefly-cpp/FireflyAlgorithm/tree/0.3.1) (2022-06-05) 61 | 62 | [Full Changelog](https://github.com/firefly-cpp/FireflyAlgorithm/compare/0.3...0.3.1) 63 | 64 | ## [0.3](https://github.com/firefly-cpp/FireflyAlgorithm/tree/0.3) (2022-03-12) 65 | 66 | [Full Changelog](https://github.com/firefly-cpp/FireflyAlgorithm/compare/0.2...0.3) 67 | 68 | **Closed issues:** 69 | 70 | - python-fireflyalgorithm fails to build with Python 3.11.0a2. [\#6](https://github.com/firefly-cpp/FireflyAlgorithm/issues/6) 71 | - fireflyalgorithm fails to build with Python 3.11 [\#4](https://github.com/firefly-cpp/FireflyAlgorithm/issues/4) 72 | 73 | **Merged pull requests:** 74 | 75 | - Add test [\#8](https://github.com/firefly-cpp/FireflyAlgorithm/pull/8) ([firefly-cpp](https://github.com/firefly-cpp)) 76 | - Fix build error for python 3.11 [\#7](https://github.com/firefly-cpp/FireflyAlgorithm/pull/7) ([zStupan](https://github.com/zStupan)) 77 | - Enabled python3.11 support. [\#5](https://github.com/firefly-cpp/FireflyAlgorithm/pull/5) ([zStupan](https://github.com/zStupan)) 78 | - Update README [\#3](https://github.com/firefly-cpp/FireflyAlgorithm/pull/3) ([zStupan](https://github.com/zStupan)) 79 | 80 | ## [0.2](https://github.com/firefly-cpp/FireflyAlgorithm/tree/0.2) (2021-09-10) 81 | 82 | [Full Changelog](https://github.com/firefly-cpp/FireflyAlgorithm/compare/0.0.5...0.2) 83 | 84 | ## [0.0.5](https://github.com/firefly-cpp/FireflyAlgorithm/tree/0.0.5) (2021-09-10) 85 | 86 | [Full Changelog](https://github.com/firefly-cpp/FireflyAlgorithm/compare/0.0.4...0.0.5) 87 | 88 | **Merged pull requests:** 89 | 90 | - Update FA and switch to poetry [\#2](https://github.com/firefly-cpp/FireflyAlgorithm/pull/2) ([zStupan](https://github.com/zStupan)) 91 | 92 | ## [0.0.4](https://github.com/firefly-cpp/FireflyAlgorithm/tree/0.0.4) (2021-02-03) 93 | 94 | [Full Changelog](https://github.com/firefly-cpp/FireflyAlgorithm/compare/0.0.3...0.0.4) 95 | 96 | ## [0.0.3](https://github.com/firefly-cpp/FireflyAlgorithm/tree/0.0.3) (2021-02-03) 97 | 98 | [Full Changelog](https://github.com/firefly-cpp/FireflyAlgorithm/compare/0.0.2...0.0.3) 99 | 100 | ## [0.0.2](https://github.com/firefly-cpp/FireflyAlgorithm/tree/0.0.2) (2021-01-19) 101 | 102 | [Full Changelog](https://github.com/firefly-cpp/FireflyAlgorithm/compare/0.0.1...0.0.2) 103 | 104 | **Merged pull requests:** 105 | 106 | - Sort optimization [\#1](https://github.com/firefly-cpp/FireflyAlgorithm/pull/1) ([lukapecnik](https://github.com/lukapecnik)) 107 | 108 | ## [0.0.1](https://github.com/firefly-cpp/FireflyAlgorithm/tree/0.0.1) (2020-11-18) 109 | 110 | [Full Changelog](https://github.com/firefly-cpp/FireflyAlgorithm/compare/0.1...0.0.1) 111 | 112 | ## [0.1](https://github.com/firefly-cpp/FireflyAlgorithm/tree/0.1) (2020-11-18) 113 | 114 | [Full Changelog](https://github.com/firefly-cpp/FireflyAlgorithm/compare/170394dc2648db570d75873af470157dd2c18c25...0.1) 115 | 116 | 117 | 118 | \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* 119 | -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | abstract: Implementation of Firefly Algorithm in Python 2 | authors: 3 | - family-names: Fister Jr. 4 | given-names: Iztok 5 | orcid: 0000-0002-6418-1272 6 | - affiliation: '@poviolabs' 7 | family-names: "Pe\u010Dnik" 8 | given-names: Luka 9 | orcid: 0000-0002-3897-9774 10 | - family-names: Stupan 11 | given-names: "\u017Diga" 12 | orcid: 0000-0001-9847-7306 13 | cff-version: 1.2.0 14 | date-released: '2023-12-25' 15 | doi: 10.5281/zenodo.10430919 16 | license: 17 | - MIT 18 | repository-code: https://github.com/firefly-cpp/FireflyAlgorithm/tree/0.4.4 19 | title: 'firefly-cpp/FireflyAlgorithm: 0.4.4' 20 | type: software 21 | version: 0.4.4 22 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Firefly Algorithm 2 | :+1::tada: First off, thanks for taking the time to contribute! :tada::+1: 3 | 4 | ## Code of Conduct 5 | This project and everyone participating in it is governed by the [Firefly Algorithm Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to [iztok.fister1@um.si](mailto:iztok.fister1@um.si). 6 | 7 | ## How Can I Contribute? 8 | 9 | ### Reporting Bugs 10 | Before creating bug reports, please check existing issues list as you might find out that you don't need to create one. When you are creating a bug report, please include as many details as possible in the [issue template](.github/templates/ISSUE_TEMPLATE.md). 11 | 12 | ### Suggesting Enhancements 13 | 14 | Open new issue using the [feature request template](.github/templates/FEATURE_REQUEST.md). 15 | 16 | ### Pull requests 17 | 18 | Fill in the [pull request template](.github/templates/PULL_REQUEST.md) and make sure your code is documented. 19 | 20 | ## Setup development environment 21 | 22 | ### Requirements 23 | 24 | * Poetry: [https://python-poetry.org/docs](https://python-poetry.org/docs) 25 | 26 | After installing Poetry and cloning the project from GitHub, you should run the following command from the root of the cloned project: 27 | 28 | ```sh 29 | poetry install 30 | ``` 31 | 32 | All of the project's dependencies should be installed and the project ready for further development. **Note that Poetry creates a separate virtual environment for your project.** 33 | 34 | ### Dependencies 35 | 36 | | Package | Version | Platform | 37 | |----------|:-------:|:--------:| 38 | | numpy | ^1.26.1 | All | 39 | 40 | #### Development dependencies 41 | 42 | | Package | Version | Platform | 43 | |---------|:--------:|:--------:| 44 | | pytest | ^7.4.3 | Any | 45 | 46 | ## Development Tasks 47 | 48 | ### Testing 49 | 50 | Manually run the tests: 51 | 52 | ```sh 53 | poetry run pytest 54 | ``` -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2023 firefly-cpp 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Problems.md: -------------------------------------------------------------------------------- 1 | # Test Functions 2 | 3 | Bellow You'll find the definitions of all the test functions implemented in this package. 4 | 5 | ## Ackley 6 | ***Function name:*** `ackley` 7 | 8 | ```math 9 | f(x) = -20 e^{-0.2 \sqrt{D^{-1} \sum\nolimits_{i=1}^D x_i^2}} - e^{D^{-1} \sum\nolimits_{i=1}^D \cos(2 \pi x_i)} + 20 + e 10 | ``` 11 | 12 | **Dimensions:** $D$ 13 | 14 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 0`$ 15 | 16 | ## Alpine 1 17 | ***Function name:*** `alpine1` 18 | 19 | ```math 20 | f(x) = \sum_{i=1}^{D} \lvert {x_i \sin \left( x_i \right) + 0.1 x_i} \rvert 21 | ``` 22 | 23 | **Dimensions:** $D$ 24 | 25 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 0`$ 26 | 27 | ## Alpine 2 28 | ***Function name:*** `alpine2` 29 | 30 | ```math 31 | f(x) = \prod_{i=1}^{D} \sqrt{x_i} \sin(x_i) 32 | ``` 33 | 34 | **Dimensions:** $D$ 35 | 36 | **Global optimum:** $`f(x^*) = 2.808^D`$ for $`x_i^* = 7.917`$ 37 | 38 | ## Cigar 39 | ***Function name:*** `cigar` 40 | 41 | ```math 42 | f(x) = x_1^2 + 10^6\sum_{i=2}^{D} x_i^2 43 | ``` 44 | 45 | **Dimensions:** $D$ 46 | 47 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 0`$ 48 | 49 | ## Cosine Mixture 50 | ***Function name:*** `cosine_mixture` 51 | 52 | ```math 53 | f(x) = -0.1 \sum_{i=1}^D \cos (5 \pi x_i) - \sum_{i=1}^D x_i^2 54 | ``` 55 | 56 | **Dimensions:** $D$ 57 | 58 | **Global optimum:** $`f(x^*) = -0.1 D`$ for $`x_i^* = 0`$ 59 | 60 | ## Csendes 61 | ***Function name:*** `csendes` 62 | 63 | ```math 64 | f(x) = \sum_{i=1}^D x_i^6 \left( 2 + \sin \frac{1}{x_i}\right) 65 | ``` 66 | 67 | **Dimensions:** $D$ 68 | 69 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 0`$ 70 | 71 | ## Dixon-Price 72 | ***Function name:*** `dixon_price` 73 | 74 | ```math 75 | f(x) = (x_1 - 1)^2 + \sum_{i = 2}^D i (2x_i^2 - x_{i - 1})^2 76 | ``` 77 | 78 | **Dimensions:** $D$ 79 | 80 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 2^{- \frac{(2^i - 2)}{2^i}}`$ 81 | 82 | ## Griewank 83 | ***Function name:*** `griewank` 84 | 85 | ```math 86 | f(x) = \sum_{i=1}^D \frac{x_i^2}{4000} - \prod_{i=1}^D \cos(\frac{x_i}{\sqrt{i}}) + 1 87 | ``` 88 | 89 | **Dimensions:** $D$ 90 | 91 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 0`$ 92 | 93 | ## Katsuura 94 | ***Function name:*** `katsuura` 95 | 96 | ```math 97 | \prod_{i=1}^D \left(1 + i \sum_{j=1}^{32} \frac{\lvert 2^j x_i - round\left(2^j x_i \right) \rvert}{2^j} \right) 98 | ``` 99 | 100 | **Dimensions:** $D$ 101 | 102 | **Global optimum:** $`f(x^*) = 1`$ for $`x_i^* = 0`$ 103 | 104 | ## Levy 105 | ***Function name:*** `levy` 106 | 107 | ```math 108 | \begin{gather} 109 | \sin^2 (\pi w_1) + \sum_{i = 1}^{D - 1} (w_i - 1)^2 \left( 1 + 10 \sin^2 (\pi w_i + 1) \right) + (w_d - 1)^2 (1 + \sin^2 (2 \pi w_d)),\,\text{where}\\ 110 | w_i = 1 + \frac{x_i - 1}{4},\, \text{for all } i = 1, \ldots, D 111 | \end{gather} 112 | 113 | ``` 114 | 115 | **Dimensions:** $D$ 116 | 117 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 1`$ 118 | 119 | ## Michalewicz 120 | ***Function name:*** `michalewicz` 121 | 122 | ```math 123 | f(x) = - \sum_{i = 1}^{D} \sin(x_i) \sin^{2m}\left( \frac{ix_i^2}{\pi} \right) 124 | ``` 125 | 126 | **Dimensions:** $D$ 127 | 128 | **Global optimum:** $`\text{at } D=2,\,f(x^*) = -1.8013`$ for $`x^* = (2.20, 1.57)`$ 129 | 130 | ## Perm 1 131 | ***Function name:*** `perm1` 132 | 133 | ```math 134 | f(x) = \sum_{i = 1}^D \left( \sum_{j = 1}^D (j^i + \beta) \left( \left(\frac{x_j}{j}\right)^i - 1 \right) \right)^2 135 | ``` 136 | 137 | **Dimensions:** $D$ 138 | 139 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = i`$ 140 | 141 | ## Perm 2 142 | ***Function name:*** `perm2` 143 | 144 | ```math 145 | f(x) = \sum_{i = 1}^D \left( \sum_{j = 1}^D (j - \beta) \left( x_j^i - \frac{1}{j^i} \right) \right)^2 146 | ``` 147 | 148 | **Dimensions:** $D$ 149 | 150 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = \frac{1}{i}`$ 151 | 152 | ## Pinter 153 | ***Function name:*** `pinter` 154 | 155 | ```math 156 | f(x) = \sum_{i=1}^D ix_i^2 + \sum_{i=1}^D 20i \sin^2 A + \sum_{i=1}^D i \log_{10} (1 + iB^2),\, \text{where} 157 | ``` 158 | ```math 159 | \begin{align} 160 | A &= (x_{i-1}\sin(x_i)+\sin(x_{i+1})) \\ 161 | B &= (x_{i-1}^2 - 2x_i + 3x_{i+1} - \cos(x_i) + 1) 162 | \end{align} 163 | ``` 164 | 165 | **Dimensions:** $D$ 166 | 167 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 0`$ 168 | 169 | ## Powell 170 | ***Function name:*** `powell` 171 | 172 | ```math 173 | f(x) = \sum_{i = 1}^{D/4} \left[ (x_{4 i - 3} + 10 x_{4 i - 2})^2 + 5 (x_{4 i - 1} - x_{4 i})^2 + (x_{4 i - 2} - 2 x_{4 i - 1})^4 + 10 (x_{4 i - 3} - x_{4 i})^4 \right] 174 | ``` 175 | 176 | **Dimensions:** $D$ 177 | 178 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 0`$ 179 | 180 | ## Qing 181 | ***Function name:*** `qing` 182 | 183 | ```math 184 | f(x) = \sum_{i=1}^D \left(x_i^2 - i\right)^2 185 | ``` 186 | 187 | **Dimensions:** $D$ 188 | 189 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = \pm \sqrt{i}`$ 190 | 191 | ## Quintic 192 | ***Function name:*** `quintic` 193 | 194 | ```math 195 | f(x) = \sum_{i=1}^D \left| x_i^5 - 3x_i^4 + 4x_i^3 + 2x_i^2 - 10x_i - 4\right| 196 | ``` 197 | 198 | **Dimensions:** $D$ 199 | 200 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = -1\quad \text{or} \quad x_i^* = 2`$ 201 | 202 | ## Rastrigin 203 | ***Function name:*** `rastrigin` 204 | 205 | ```math 206 | f(x) = 10D + \sum_{i=1}^D \left[x_i^2 -10\cos(2\pi x_i)\right] 207 | ``` 208 | 209 | **Dimensions:** $D$ 210 | 211 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 0`$ 212 | 213 | ## Rosenbrock 214 | ***Function name:*** `rosenbrock` 215 | 216 | ```math 217 | f(x) = \sum_{i=1}^{D-1} \left[100 (x_{i+1} - x_i^2)^2 + (x_i - 1)^2 \right] 218 | ``` 219 | 220 | **Dimensions:** $D$ 221 | 222 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 1`$ 223 | 224 | ## Salomon 225 | ***Function name:*** `salomon` 226 | 227 | ```math 228 | f(x) = 1 - \cos\left(2\pi\sqrt{\sum\nolimits_{i=1}^D x_i^2} \right)+ 0.1 \sqrt{\sum\nolimits_{i=1}^D x_i^2} 229 | ``` 230 | 231 | **Dimensions:** $D$ 232 | 233 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 0`$ 234 | 235 | ## Schaffer 2 236 | ***Function name:*** `schaffer2` 237 | 238 | ```math 239 | f(x) = 0.5 + \frac{ \sin^2 \left( x_1^2 - x_2^2 \right) - 0.5 }{ \left[ 1 + 0.001 \left( x_1^2 + x_2^2 \right) \right]^2 } 240 | ``` 241 | 242 | **Dimensions:** 2 243 | 244 | **Global optimum:** $`f(x^*) = 0`$ for $`x^* = (0, 0)`$ 245 | 246 | ## Schaffer 4 247 | ***Function name:*** `schaffer4` 248 | 249 | ```math 250 | f(x) = 0.5 + \frac{ \cos^2 \left( \sin \left( \vert x_1^2 - x_2^2\vert \right) \right)- 0.5 }{ \left[ 1 + 0.001 \left( x_1^2 + x_2^2 \right) \right]^2 } 251 | ``` 252 | 253 | **Dimensions:** 2 254 | 255 | **Global optimum:** $`f(x^*) = 0.292579`$ for $`x^* = (0, \pm 1.25313) \text{or} (\pm 1.25313, 0)`$ 256 | 257 | ## Schwefel 258 | ***Function name:*** `schwefel` 259 | 260 | ```math 261 | f(x) = 418.9829D - \sum_{i=1}^{D} x_i \sin(\sqrt{\lvert x_i \rvert}) 262 | ``` 263 | 264 | **Dimensions:** $D$ 265 | 266 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 420.9687`$ 267 | 268 | ## Schwefel 2.21 269 | ***Function name:*** `schwefel221` 270 | 271 | ```math 272 | f(x) = \max_{1 \leq i \leq D} \vert x_i\vert 273 | ``` 274 | 275 | **Dimensions:** $D$ 276 | 277 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 0`$ 278 | 279 | ## Schwefel 2.22 280 | ***Function name:*** `schwefel222` 281 | 282 | ```math 283 | f(x) = \sum_{i=1}^{D} \lvert x_i \rvert +\prod_{i=1}^{D} \lvert x_i \rvert 284 | ``` 285 | 286 | **Dimensions:** $D$ 287 | 288 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 0`$ 289 | 290 | ## Sphere 291 | ***Function name:*** `sphere` 292 | 293 | ```math 294 | f(x) = \sum_{i=1}^D x_i^2 295 | ``` 296 | 297 | **Dimensions:** $D$ 298 | 299 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 0`$ 300 | 301 | ## Step 302 | ***Function name:*** `step` 303 | 304 | ```math 305 | f(x) = \sum_{i=1}^D \left( \lfloor \lvert x_i \rvert \rfloor \right) 306 | ``` 307 | 308 | **Dimensions:** $D$ 309 | 310 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 0`$ 311 | 312 | ## Step 2 313 | ***Function name:*** `step2` 314 | 315 | ```math 316 | f(x) = \sum_{i=1}^D \left( \lfloor x_i + 0.5 \rfloor \right)^2 317 | ``` 318 | 319 | **Dimensions:** $D$ 320 | 321 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = -0.5`$ 322 | 323 | ## Styblinski-Tang 324 | ***Function name:*** `styblinski_tang` 325 | 326 | ```math 327 | 328 | ``` 329 | 330 | **Dimensions:** $D$ 331 | 332 | **Global optimum:** $`f(x^*) = -39.16599 D`$ for $`x_i^* = -2.903534`$ 333 | 334 | ## Trid 335 | ***Function name:*** `trid` 336 | 337 | ```math 338 | f(x) = \sum_{i = 1}^D \left( x_i - 1 \right)^2 - \sum_{i = 2}^D x_i x_{i - 1} 339 | ``` 340 | 341 | **Dimensions:** $D$ 342 | 343 | **Global optimum:** $`f(x^*) = \frac{-D (D + 4) (D - 1)}{6}`$ for $`x_i^* = i (d + 1 - i)`$ 344 | 345 | ## Weierstrass 346 | ***Function name:*** `weierstrass` 347 | 348 | ```math 349 | f(x) = \sum_{i=1}^D \left[ \sum_{k=0}^{k_{max}} a^k \cos\left( 2 \pi b^k ( x_i + 0.5) \right) \right] - D \sum_{k=0}^{k_{max}} a^k \cos \left(\pi b^k \right) 350 | ``` 351 | 352 | **Dimensions:** $D$ 353 | 354 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 0`$ 355 | 356 | ## Whitley 357 | ***Function name:*** `whitley` 358 | 359 | ```math 360 | f(x) = \sum_{i=1}^D \sum_{j=1}^D \left[\frac{(100(x_i^2-x_j)^2 + (1-x_j)^2)^2}{4000} - \cos(100(x_i^2-x_j)^2 + (1-x_j)^2)+1\right] 361 | ``` 362 | 363 | **Dimensions:** $D$ 364 | 365 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 1`$ 366 | 367 | ## Zakharov 368 | ***Function name:*** `zakharov` 369 | 370 | ```math 371 | f(x) = \sum_{i = 1}^D x_i^2 + \left( \sum_{i = 1}^D 0.5 i x_i \right)^2 + \left( \sum_{i = 1}^D 0.5 i x_i \right)^4 372 | ``` 373 | 374 | **Dimensions:** $D$ 375 | 376 | **Global optimum:** $`f(x^*) = 0`$ for $`x_i^* = 0`$ 377 | 378 | 379 | # References 380 | 381 | [1] P. Ernesto and U. Diliman, [“MVF–Multivariate Test Functions Library in C for Unconstrained Global Optimization,”](http://www.geocities.ws/eadorio/mvf.pdf) University of the Philippines Diliman, Quezon City, 2005. 382 | 383 | [2] M. Jamil and X.-S. Yang, [“A literature survey of benchmark functions for global optimisation problems,”](https://arxiv.org/abs/1308.4008) International Journal of Mathematical Modelling and Numerical Optimisation, vol. 4, no. 2, p. 150, Jan. 2013, doi: 10.1504/ijmmno.2013.055204. 384 | 385 | [3] J. J. Liang, B. Y. Qu, and P. N. Suganthan, [“Problem definitions and evaluation criteria for the CEC 2014 special session and competition on single objective real-parameter numerical optimization,”](http://bee22.com/manual/tf_images/Liang%20CEC2014.pdf) Computational Intelligence Laboratory, Zhengzhou University, Zhengzhou China and Technical Report, Nanyang Technological University, Singapore, vol. 635, no. 2, 2013. 386 | 387 | [4] S. Surjanovic and D. Bingham, Virtual Library of Simulation Experiments: Test Functions and Datasets. Retrieved November 7, 2023, from https://www.sfu.ca/~ssurjano/. 388 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |
3 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
20 |
21 |
22 |
23 |
24 |
25 |
28 |
29 |
32 | 📋 About • 33 | 📦 Installation • 34 | 🚀 Usage • 35 | 📚 Reference Papers • 36 | 📄 Cite us • 37 | 🔑 License 38 |
39 | 40 | ## 📋 About 41 | 42 | This package implements a nature-inspired algorithm for optimization called Firefly Algorithm (FA) in Python programming language. 🌿🔍💻 43 | 44 | ## 📦 Installation 45 | 46 | To install FireflyAlgorithm with pip, use: 47 | ```sh 48 | pip install fireflyalgorithm 49 | ``` 50 | To install FireflyAlgorithm on Fedora, use: 51 | ```sh 52 | dnf install python-fireflyalgorithm 53 | ``` 54 | To install FireflyAlgorithm on Arch Linux, please use an [AUR helper](https://wiki.archlinux.org/title/AUR_helpers): 55 | ```sh 56 | $ yay -Syyu python-fireflyalgorithm 57 | ``` 58 | To install FireflyAlgorithm on Alpine Linux, use: 59 | ```sh 60 | $ apk add py3-fireflyalgorithm 61 | ``` 62 | 63 | ## 🚀 Usage 64 | 65 | ```python 66 | from fireflyalgorithm import FireflyAlgorithm 67 | from fireflyalgorithm.problems import sphere 68 | 69 | FA = FireflyAlgorithm() 70 | best = FA.run(function=sphere, dim=10, lb=-5, ub=5, max_evals=10000) 71 | 72 | print(best) 73 | ``` 74 | 75 | ### Test functions 📈 76 | 77 | In the `fireflyalgorithm.problems` module, you can find the implementations of 33 popular optimization test problems. Additionally, the module provides a utility function, `get_problem`, that allows you to retrieve a specific optimization problem function by providing its name as a string: 78 | 79 | ```python 80 | from fireflyalgorithm.problems import get_problem 81 | 82 | # same as from fireflyalgorithm.problems import rosenbrock 83 | rosenbrock = get_problem('rosenbrock') 84 | ``` 85 | 86 | For more information about the implemented test functions, [click here](Problems.md). 87 | 88 | ### Command line interface 🖥️ 89 | 90 | The package also comes with a simple command line interface which allows you to evaluate the algorithm on several popular test functions. 🔬 91 | 92 | ```shell 93 | firefly-algorithm -h 94 | ``` 95 | 96 | ```text 97 | usage: firefly-algorithm [-h] --problem PROBLEM -d DIMENSION -l LOWER -u UPPER -nfes MAX_EVALS [-r RUNS] [--pop-size POP_SIZE] [--alpha ALPHA] [--beta-min BETA_MIN] [--gamma GAMMA] [--seed SEED] 98 | 99 | Evaluate the Firefly Algorithm on one or more test functions 100 | 101 | options: 102 | -h, --help show this help message and exit 103 | --problem PROBLEM Test problem to evaluate 104 | -d DIMENSION, --dimension DIMENSION 105 | Dimension of the problem 106 | -l LOWER, --lower LOWER 107 | Lower bounds of the problem 108 | -u UPPER, --upper UPPER 109 | Upper bounds of the problem 110 | -nfes MAX_EVALS, --max-evals MAX_EVALS 111 | Max number of fitness function evaluations 112 | -r RUNS, --runs RUNS Number of runs of the algorithm 113 | --pop-size POP_SIZE Population size 114 | --alpha ALPHA Randomness strength 115 | --beta-min BETA_MIN Attractiveness constant 116 | --gamma GAMMA Absorption coefficient 117 | --seed SEED Seed for the random number generator 118 | ``` 119 | 120 | **Note:** The CLI script can also run as a python module (python -m fireflyalgorithm ...). 121 | 122 | 123 | ## 📚 Reference Papers 124 | 125 | I. Fister Jr., X.-S. Yang, I. Fister, J. Brest, D. Fister. [A Brief Review of Nature-Inspired Algorithms for Optimization](http://www.iztok-jr-fister.eu/static/publications/21.pdf). Elektrotehniški vestnik, 80(3), 116-122, 2013. 126 | 127 | I. Fister Jr., X.-S. Yang, I. Fister, J. Brest. [Memetic firefly algorithm for combinatorial optimization](http://www.iztok-jr-fister.eu/static/publications/44.pdf) in Bioinspired Optimization Methods and their Applications (BIOMA 2012), B. Filipic and J.Silc, Eds. 128 | Jozef Stefan Institute, Ljubljana, Slovenia, 2012 129 | 130 | I. Fister, I. Fister Jr., X.-S. Yang, J. Brest. [A comprehensive review of firefly algorithms](http://www.iztok-jr-fister.eu/static/publications/23.pdf). Swarm and Evolutionary Computation 13 (2013): 34-46. 131 | 132 | ## 📄 Cite us 133 | 134 | Fister Jr., I., Pečnik, L., & Stupan, Ž. (2023). firefly-cpp/FireflyAlgorithm: 0.4.3 (0.4.3). Zenodo. [https://doi.org/10.5281/zenodo.10430919](https://doi.org/10.5281/zenodo.10430919) 135 | 136 | ## 🔑 License 137 | 138 | This package is distributed under the MIT License. This license can be found online at