libprima / prima

PRIMA is a package for solving general nonlinear optimization problems without using derivatives. It provides the reference implementation for Powell's derivative-free optimization methods, i.e., COBYLA, UOBYQA, NEWUOA, BOBYQA, and LINCOA. PRIMA means Reference Implementation for Powell's methods with Modernization and Amelioration, P for Powell.
http://libprima.net
BSD 3-Clause "New" or "Revised" License
292 stars 36 forks source link

Wrap the objective & constraint function evaluation and catch exceptions if any #90

Open zaikunzhang opened 10 months ago

zaikunzhang commented 10 months ago

This is related to

https://github.com/libprima/prima/issues/80

In general, we should keep in mind that function evaluations may fail or return exceptional values. A robust and reliable solver must handle such cases properly.

The capability of handling such cases can be tested by the TOUGH test. The following is a MATLAB implementation of such a test. https://github.com/libprima/prima/blob/main/matlab/tests/private/tough.m

The MATLAB interface of PRIMA handles exceptions and exceptional values as follows.
https://github.com/libprima/prima/blob/main/matlab/interfaces/private/evalobj.m https://github.com/libprima/prima/blob/main/matlab/interfaces/private/evalcon.m

In this way, the function evaluations are wrapped using a try ... catch ... so that exceptions will be taken care of. The solvers will not crash even if the function evaluation fails.

Is it possible to do similar things in C? I understand that C does not have a native try ... catch ....

jschueller commented 10 months ago

no, but it can be done when using prima is used with a c++ objective function