Is the constraints in fmincon always held during the optimization?

I used fmincon to solve a nonlinear constraint optimization problem. In the constraint, I have both linear and nonlinear equality and inequalities. I use "sqp" as the solver for fmincon. Here I want to know, during the optimization process, whether all the equality and inequalities in my constraint are always held? Moreover, when calling fmincon, I also defined low boundary and high boundary for the variables to be optimized. Is there any difference to constrain the variables in low(and high) boundary and in the constraint function (which is used by fmincon)?
Thank you!

Antworten (1)

Matt J
Matt J am 29 Jan. 2016
Bearbeitet: Matt J am 29 Jan. 2016

0 Stimmen

In fmincon, only bounds expressed using lb,ub can be enforced at all iterations and only for certain algorithm selections. sqp is one of them. interior-point will also do this by default, although you can turn it off.
This is one reason why it may be good to use lb,ub when possible, as opposed to nonlcon to express bounds. It allows you to enforce the bounds at all iterations, if that is what you desire. More generally, it allows MATLAB to recognize that those constraints are simpler than the others and give them special, simplified handling. The same goes for A,b,Aeq,beq. It helps when MATLAB knows that constraints are linear and you should use those inputs to tell it so.

4 Kommentare

Thank you very much for your reply! It helps me understand more about fmincon! For the variables to be optimized, for the linear constraints, I can easily deal low and high boundary, A, b, Aeq, Beq. But how about some intermediate variables, which are not the direct variables I am going to optimize, but are nonlinear functions of the variables to be optimized? For example, x(1) and x(2) are the variables I'm going to optimize, and C = G(x), where G is a nonlinear function. During the optimization, I want C is always between 0 and 4000, since once C is out of this range, the physical meaning of some equations will lose and become unreal. Could you let me know how and where should I constrain this C? And is it OK to use "max" or "if-else-end" in the function which will be called by the constraint of fmincon? Thank you.
Matt J
Matt J am 29 Jan. 2016
Bearbeitet: Matt J am 29 Jan. 2016
Nonlinear constraints like Low<=G(x)<=High should be implemented using the nonlcon input argument (the 9th input argument) to fmincon.
Independently of this, whenever your objective function or constraints evaluates to a non-real value, you should over-ride it and return NaN of Inf. You can do this using appropiate if-else-end constructs. The SQP algorithm can backtrack whenever it encounters NaN or Inf.
Don't use max() to threshold your objective or constraint functions. That renders them non-differentiable.
You already asked about using max() and I already answered you; http://uk.mathworks.com/matlabcentral/answers/265614-when-using-fmincon-how-to-avoid-using-max-if-else-end-in-the-constraints#comment_338657. Nonlinear constraints, no matter how expressed, are always a problem for fmincon if they create disjoint regions. If they create "holes" then they might be a problem, depending on the optimization technique being used.
Using max() or min() or if/else in a nonlinear constraint does not necessarily render the objective non-differentiable, but that is a risk. You need to do boundary matching, so that there are no jumps at the interface between conditions. I seem to recall that it works out if you have first order continuity of the objective function for the optimization routines that do not use gradients, second order continuity for those that use gradients but not hessian, and third order continuity for those that need hessians (I am least certain about the requirements for hessians). (If your objective function does not have even first order continuity then you need to use a technique such as ga() or pso())
Matt J
Matt J am 30 Jan. 2016
Bearbeitet: Matt J am 31 Jan. 2016
During the optimization, I want C is always between 0 and 4000, since once C is out of this range, the physical meaning of some equations will lose and become unreal.
One more comment, just to add to the confusion :-)
The regions where your constraint and objective functions take on a real value must form an open set. If these functions are not defined on an open set, then they are non-differentiable, by definition. Or at least, they will be non-differentiable at certain points where fmincon may want to explore. For example,
f(x)=-cos( sqrt(x) )
is not differentiable at x=0, even though it does have a finite right-hand derivative there.
This means that the region you mentioned where "C" becomes non-real must be a closed set.

Melden Sie sich an, um zu kommentieren.

Gefragt:

Tao
am 29 Jan. 2016

Bearbeitet:

am 31 Jan. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by