gugarosa / opytimizer

🐦 Opytimizer is a Python library consisting of meta-heuristic optimization algorithms.
https://opytimizer.readthedocs.io
Apache License 2.0
604 stars 41 forks source link

[NEW] Constrained optimization #10

Closed ogencoglu closed 4 years ago

ogencoglu commented 4 years ago

Hi, thanks for the work.

Any plans to add functionality to define constraints for the optimization? For instance, inequalities or any arbitrary non-linear constraints on the inputs and/or on the outputs?

gugarosa commented 4 years ago

Hello @ogencoglu ! I hope everything is alright with you!

First of all, thank you for appreciation on the library. Currently, the only constraints that we have are variable ones, which can be defined by playing with the lower and upper bounds of the task.

For instance, if x_1 <= 10 and x_2 >= 20, one can define the lower and upper bound as following:

lb = [-INF or large negative number, 20]
ub = [10, INF or large positive number]

Regarding function-based constraints, you could probably use the pre_evaluation_hook argument on the start() method of Opytimizer class. Essentially, it is a callable argument and its idea is to perform any kind of calculation prior to the evaluation of the function being optimized. Therefore, one can code and define any own function-based constraints, linear or non-linear.

Both methods would work out for the inputs. Considering the outputs, I will have to take a deeper look into it, maybe a post_evaluation_hook might fulfill the needs and enable users to custom design whatever they need.

If you have any ideas or possible solutions, please let me know, so we can go ahead and try to implement them!

Thank you and best regards, Gustavo.

ogencoglu commented 4 years ago

Thanks for the swift reply.

I understand that a custom check can be implemented. However, such checks does not mean the optimization is driven by such constraints which is what I am after.

For instance, forcing the optimization to satisfy arbitrary rules inherently such as x_1 + x_5 = 5, not just a validation check.

Best!

gugarosa commented 4 years ago

Perfect, understood! I will take a deeper look into it to find the best way to implement it.

Meanwhile, I will leave this issue open and ask if could you give me some more examples on how you are intending to constrain your optimization problem, please?

Just so I can get a bigger picture of the problem and see the most feasible way to rework some classes and workflows.

Best regards, Gustavo.

gugarosa commented 4 years ago

An naïve method for constraints have been added. We will be updating it regularly as soon as we perform our initial tests.

Please check the following for usage: examples/applications/constrained_single_objective_optimization.py.

Best regards, Gustavo.