PyCRO-SL
About
This project is a Python implementation of the Coral Reef Optimization with Substrate Layers algorithm, both in its original version (CRO-SL) and in its probabilistic versions (PCRO-SL and DPCRO-SL). The goal is to provide an easy-to-use, versatile Python package that can be used off-the-shelf for a wide array of optimization problems. Among its features, we highlight:
- Operators included: the package includes more than 30 solution operators, such as Gaussian noise addition, BLX Alpha, Multi-point crossover, etc.
- Multiple conditions: the algorithm can be configured to stop after a given number of evaluations, generations, or time, or after reaching a given fitness value. These stopping conditions can also be combined using any logical expression.
- Parallelization: the package allows for parallelization of the fitness function evaluations, which can significantly speed up optimization.
- Automatic report: the implementation produces a graphical report at the end of each simulation, summarizing the behavior of the most important metrics.
- Dynamic variant: the algorithm has a dynamic variant, which allows it to reward the operators that perform better in the current problem.
For an explanation of how the CRO-SL algorithm works, we refer to the paper.
How to install
We recommend installing the project as a package. To do so, use the following commands:
git clone https://github.com.jperezaracil/PyCROSL.git
cd PyCROSL
pip intall -r requirements.txt
pip install -e .
Then, you can import the algorithm as a package, for example
from PyCROSL.CRO_SL import CRO_SL
How to use it
To use PyCRO-SL in your own optimization problems, take a look at our tutorial.
Parameters
To configure the hyperparameters a dictionary will have to be given to the class CRO_SL. This dictionary contains the following parameters:
- Basic hyperparameters:
popSize: maximum number of corals in the reefrho: percentage of initial occupation of the reefFb: broadcast spawning proportionFd: depredation proportionPd: depredation probabilityk: maximum attempts for larva settingK: maximum number of corals with duplicate solutionsgroup_subs: ifTrue, corals reproduce only within the same substrate, ifFalsethey reproduce within the whole population
- Dynamic variant hyperparameters:
dynamic: boolean value that determines whether to use the dynamic variant of the algorithmmethod: string that determines how to determine the probability of choosing each substrate. Possible values:"fitness": uses the fitness of the individuals of each substrate."diff": uses the difference between the fitness of the previous generation and the current one."success": uses the ratio of successful larvae in each generation.
dyn_metric: string that determines how to aggregate the values of each substrate to get the metric of each. Possible values:"best": takes the best fitness"avg": takes the average fitness"med": takes the median fitness"worse": takes the worse fitness
dyn_steps: specifies the number of times the substrates will be evaluated. Ifdyn_steps = -1, the substrates will be evaluated every generation.prob_amp: float that determines how the differences between substrate metrics affect the probability of each one. A lower value means more amplification
- Stopping conditions (you only need to include the ones that will be used!):
Neval: number of evaluations of the fitness functionNgen: number of generationstime_limit: execution time limit given in seconds (real time, not CPU time)fit_target: value of the fitness function we want to reachstop_cond: a string that determines the stopping condition. It can be simply the name of the criterion to be used (e.g.Ngen,Neval, etc), or also a logical expression that combines these different criteria (e.g.Ngen or Neval,time_limit and fit_target, etc). Must be included even if only a single criterion is used.
- Parallelization:
Njobs: the number of jobs to run in parallel. IfNjobs = 1, the algorithm will run in sequential mode.
- Display options:
verbose: shows a periodic report of the algorithm's performancev_timer: amount of time between each report
For examples of how to fill the parameters dictionary, please take a look at main.py.
Cite
If you use this implementation, please cite it as:
@article{perez2023,
title={New Probabilistic, Dynamic Multi-Method Ensembles for Optimization Based on the CRO-SL},
author={P{\'e}rez-Aracil, Jorge and Camacho-G{\'o}mez, Carlos and Lorente-Ramos, Eugenio and Marina, Cosmin M and Cornejo-Bueno, Laura M and Salcedo-Sanz, Sancho},
journal={Mathematics},
volume={11},
number={7},
pages={1666},
year={2023},
publisher={MDPI}
}
Metadata
Release files for PyCROSL 1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| PyCROSL-1.1.tar.gz | 23.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| PyCROSL-1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 48.5 kB
Release files / PyCROSL-1.1.tar.gz
| Download URL | PyCROSL-1.1.tar.gz |
|---|---|
| Size | 23.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a6898ebb547b2c92f30c015e3fa164444e0e62f55fc0fa9ae7339cb0b070cdc
|
|
BLAKE2b-256 checksum How to use checksums |
a58e029bd61f0619646094118df0d2b6139563352e319c37ebcef1d866408093
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / PyCROSL-1.1-py3-none-any.whl
| Download URL | PyCROSL-1.1-py3-none-any.whl |
|---|---|
| Size | 25.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e7b2c6b46ea04c06b02334cc23222b17cbb8ac449ed1a33ad5e4a31a3c79419c
|
|
BLAKE2b-256 checksum How to use checksums |
253a2162fc83ec09bc9120ca5f85deaa562d1ac375fec6a3b29f5d069fce754d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|