ibex-team / ibex-lib

IBEX is a C++ library for constraint processing over real numbers.
http://ibex-team.github.io/ibex-lib/
GNU Lesser General Public License v3.0
69 stars 51 forks source link

default optimizer with sign function #464

Closed domensta closed 4 years ago

domensta commented 4 years ago

Hi there,

I have an issue when using the default optimizer with an objective and a constraint functions using the sign function. When executing the binary of this .cpp code //////////////////////////////////

include "ibex.h"

using namespace std; using namespace ibex;

void optimize(double r1, double r2,Interval x1b,Interval x2b,Interval ub) { Variable x1; Variable x2; Variable u;

IntervalVector bounds(3);
bounds[0] = x1b;
bounds[1] = x2b;
bounds[2] = ub;

SystemFactory opt_fac;
opt_fac.add_var(x1);
opt_fac.add_var(x2);
opt_fac.add_var(u);
opt_fac.add_goal(-(-9.81*(1.1*1.2/2*(cos(1.2*x1)-cos(1.1*x1)))*cos((1.1*sin(1.2*x1)-1.2*sin(1.1*x1))/2) -0.7*(-9.81*sin((1.1*sin(1.2*x1)-1.2*sin(1.1*x1))/2)-0.7*x2+u*(1+0.15/4*sign((1.1*sin(1.2*x1)-1.2*sin(1.1*x1))/2)*sign(u))) +(-r1-r2)*(1+0.15/4*sign((1.1*sin(1.2*x1)-1.2*sin(1.1*x1))/2)*sign(u))));
opt_fac.add_ctr(x2 >0);
opt_fac.add_ctr(-9.81*sin((1.1*sin(1.2*x1)-1.2*sin(1.1*x1))/2)-0.7*x2+u*(1+0.15/4*sign((1.1*sin(1.2*x1)-1.2*sin(1.1*x1))/2)*sign(u)) > 0);
System opt_sys(opt_fac);
DefaultOptimizer optimizer(opt_sys,1e-02);
optimizer.optimize(bounds);
optimizer.report();

}

int main(){

double r1  = 1;
double r2 = 1;

optimize(r1,r2,Interval(0,12),Interval(-2,2),Interval(-11,11));

} //////////////////////////////////////////

sometimes I get the expected optimization report:


optimization successful!

f* in [-4.73561,-4.68825] (best bound)

x* = (12 ; 0.248329 ; 1.86362) (best feasible point)

relative precision on f: 0.01 [passed] absolute precision on f: 0.0473562 cpu time used: 0.00838601s number of cells: 18


and sometimes I get the following error :


IBEX has crashed because the following feature is not implemented yet: Inner projection of "sign" Please, submit a new feature request.


The only explanation I can think about is that the default optimizer implements a compo or fix point contractor that call randomly several other contractors, and one of this contractor does not work with the sign function which cause the program to crash when called at a particular position.

The objective and constraint functions expressions are a bit large but I couldn't simplify them and still having the bug occurring.

gchabert commented 4 years ago

Benoit, You almost got it, except that the operator in question is a "loup finder" that may or may not be called, depending if good enough bounds have been found meanwhile by the optimizer. Anyway, just discard the operator by using the constructor of DefaultOptimizer with the following arguments:

DefaultOptimizer optimizer(opt_sys,1e-02, OptimizerConfig::default_abs_eps_f, NormalizedSystem::default_eps_h, false, false);

Gilles