Constraint tolerance setting is not working

I'm using fmincon for optimizing a system for trajectory optimization. Recently, my optimization problem seems to go well below 1e-06 feasibility for the 'interior point' solver. For this project, I will have to perform multiple trajectory optimizations and hence want my sovler to stop < 1e-06 feasibility. When I add the option of constraint tolerance, the solver continues to further iterate. How do I tackle this problem. I found the same problem wiith StepTolerance option as well

Réponses (2)

Matt J
Matt J le 24 Avr 2025
Modifié(e) : Matt J le 24 Avr 2025

0 votes

You need to demonstrate the problem with code, but based on your description, nothing is obviously wrong as far as the constraint tolerance is concerned. Even though you may see the constraint tolerance met, it doesn't mean an optimal point has been found yet. Imagine if you had no constraints. Then the constraint tolerance would be satisfied vacuously at every iteration, but of course it would be wrong for the solver not to iterate...
I found the same problem wiith StepTolerance option as well
That, you would need to demonstrate for us.

3 commentaires

mekg_10
mekg_10 le 24 Avr 2025
Thanks for the reply Matt. I do understand that just because my constraint tolerance is met, doesn't mean I have an optimal solution. I just don't want my solver to continue to solving till my max iterations but rather stop when the my constraints tolerance is met. In my question, I've mentioned I only need a <1e-06 feasibility, I don't need my solver to keep solving till the optimal point. Is there any way to stop the optimization if the feasibility reaches this bound. Hope I've made my question clear
Yes, you can just set the objective function to a constant, e.g.,
f=@(x) 0
Then, all points will be optimal and the only criterion fmincon will use for stopping is satisfaction of the constraints.
Matt J
Matt J le 24 Avr 2025
Alternatively, you can implement your own stopping criterion via the OutputFcn option,

Connectez-vous pour commenter.

Catalytic
Catalytic le 24 Avr 2025
It is a classic mistake to define the stopping tolerances with optimoptions, but forget to pass them to fmincon, as in -
options=optimoptions('fmincon','StepTolerance',1e-6,'ConstraintTolerance',1e-6);
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon) %Forgot to give options to fmincon
I wonder if that may be why you aren't seeing your settings obeyed.

3 commentaires

Matt J
Matt J le 24 Avr 2025
If that was the reason, it's a case in point for why you always have to demonstrate your issue with code...
options = optimoptions('fmincon', 'Display','iter', 'MaxFunctionEvaluations', 1e6, 'MaxIterations', 1000, 'ConstraintTolerance', 1e-03);
lb = [-1500*ones(n,1); -1500*ones(n,1); 0*ones(n,1); -10*ones(n,1); 0*ones(n,1); -100*ones(n,1);
-0.5*pi*ones(n,1); -0.5*pi*ones(n,1); -0.5*pi*ones(n,1); -0.5*pi*ones(n,1); -0.5*pi*ones(n,1); -0.5*pi*ones(n,1); -50000*ones(n,1);
-50000*ones(n,1); -50000*ones(n,1); 0]; %lower bound of states, control variables and time
ub = [1000*ones(n,1); 1500*ones(n,1); 2000*ones(n,1); 0*ones(n,1); 0*ones(n,1); 100*ones(n,1);
0.5*pi*ones(n,1); 0.5*pi*ones(n,1); 0.5*pi*ones(n,1); 0.5*pi*ones(n,1); 0.5*pi*ones(n,1); 0.5*pi*ones(n,1); 50000*ones(n,1);
50000*ones(n,1); 50000*ones(n,1); 2000]; %upper bound of states, control variables and time
[x, fval] = fmincon(@(x) objective(x, n, D), x0, [], [], [], [], lb, ub, @(x) constraints(x, D, n, BCs), options);
@Catalytic @Matt JThis is my code snippet defining the options and calling the fmincon function. I wish forgetting to add the options was my mistake xD. Maybe I'm doing something else wrong here, please point out if so
Matt J
Matt J le 25 Avr 2025
Modifié(e) : Matt J le 25 Avr 2025
That looks alright, to me at least. But as I said in my answer, if you have such little interest in achieving the optimum of the objective, you may as well just set it to a constant.
Aside from that, a few miscellaneous remarks:
(1) It would be more readable and efficeint to use repelem instead of repeated calls to ones(n,1).
lb = [-1500; 0; -10; 0; -100; -0.5*pi; -0.5*pi; -0.5*pi; -0.5*pi; -0.5*pi; -0.5*pi; -50000;
-50000; -50000]; %lower bound of states, control variables and time
lb=[repelem(lb,n);0];
ub = [1000; 1500; 2000; 0; 0; 100;
0.5*pi; 0.5*pi; 0.5*pi; 0.5*pi; 0.5*pi; 0.5*pi; 50000;
50000; 50000]; %upper bound of states, control variables and time
ub=[repelem(ub,n);2000];
(2) Your unknown variables seem to have very different scales. It can sometimes help performance to change units to make them more comparable in scale, for example, by expressing any angles in degrees instead of radians.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Produits

Version

R2024b

Tags

Question posée :

le 24 Avr 2025

Modifié(e) :

le 25 Avr 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by