nonlinear inequality constraint for fmincon()

Hey guys,
I am trying to write down the below nonlinear inequality constraint
Calculate_W_S_R(J, I, K, tr_prob, Tp, Tavg, Pf, Wrate) <= rateTh
in the form of c(x)<=0. However, when I want to define the constraint function, i.e., function[c ceq] = constraint(x), the input get more parameters than only the single variable x. Any idea how can I deal with this issue? Thanks in advance
the nonlinear inequality constraint c is a function of variable ptilda (the optimization variable which shows up in "Wrate") and some other given parameter (J, I, K, tr_prob, Tp, Tavg, Pf, ateTh). Wrate is a function of J, I, K, TB, ps, UE_A, SINR where SINR is a function of ptilda.
%%

9 Comments

I notice, by the way, that you do not pass the input x to Calculate_W_S_R . That would make your constraint constant in the inputs, which is not a constraint that is useful.
Thank you so much for your reply.
Thanks again for the note. The optimization variable is ptilda which is not an input directly. The Wrate is a function of a function of variable, i.e,
Wrate = Calculate_W_R(J, I, K, TB, ps, UE_A, SINR= Calculate_W_S(IL, JL, J, I, K, m, ptilda, p, g, f, v, np))
So, is it ok to not directly pass the optimization variable in constraint function?
function [c,ceq] = constraint(J, I, K, tr_prob, Tp, Tavg, Pf, Wrate, rateTh)
c = rateTh - Calculate_W_S_R(J, I, K, tr_prob, Tp, Tavg, Pf, Wrate);
ceq = [];
The nonlcon slot in fmincon() calls needs to receive a function handle to a function that accepts a single variable. It is not technically mandatory to pass that variable into the function to be invoked. However, if you do not pass that variable into the function, then you are dealing with one of the following situations:
  1. The function always returns the same value. If this is the case, it is ineffective as a constraint: just evaluate the result of the function once, and if the constraint is violated then do not bother doing the minimization becaus it would not be possibe for the constraint to not be violated at any location when the function is constant
  2. The function uses randomness. The return value would not always violate the constraint, so minimization could proceed. However, fmincon()'s algorithms are only defined for continuous functions, and any randomness makes the functions discontinuous
  3. The function uses shared or global variables and values stored during calls to other functions to make the decision. This is not a good design, and it will also fail subtly. fmincon() is permitted to make the nonlcon calls in any order relative to calls to the objective function, and when it is trying to find values that satisfy nonlinear equality constraints it will call the nonlcon multiple times without having called the objective function. Do not design your optimization this way: instead define a function to calculate the value from the inputs and call the function from both locations. It is valid to put a cache on a function such as that, perhaps using memoize(), to avoid re-computing if the parameters happen to be the same.
Walter, I got the following error, do you have any idea how I can solve it? I defined
[nonlcon_s ,ceq]= constraint(....);
nonlcon_a = matlabFunction(nonlcon_s, 'Vars', {ptilda});
nonlcon = @(ptilda) nonlcon_AnonymousFunction_ptilda(ptilda);
The constraint function must return two outputs; the nonlinear inequality constraints and the nonlinear equality constraints.
Error in test_Lagrangian (line 249)
[ptilda_opt,fval_ptilda,flag_ptilda] = fmincon(objfun_ptilda,ptilda0,A_ptilda,b_ptilda,[],[],lb_ptilda,ub_ptilda,nonlcon_ptilda,opts);
is it correct to do
nonlcon = @(ptilda) [nonlcon_AnonymousFunction_ptilda(ptilda), ceq];
??
Thanks in advance
If your ceq is empty then
nonlcon = @(ptilda) deal(nonlcon_AnonymousFunction_ptilda(ptilda), [])
Thank you so much. Appreciate your help.
Susan
Susan on 9 May 2019
Edited: Susan on 9 May 2019
Walter,
Is it a correct underestanding that using the global optimization toolbox we can solve even non-convex optimization problem?
Thank you very much in advance.
The tools in the global optimization toolbox help you try to solve all kinds of optimizations. They never make any promises that they will definitely solve it, but they are not restricted to searching local minima.
ga() and gamultiobj() in particular do not require that the objective be continuous to any level of derivative, and can deal with discrete problems or mixed integer.
The algorithms used by fmincon() (base MATLAB, no toolbox needed) work best with convex optimizations, but you can add non-linear constraints that have the effect of making the search area non-convex. However, it cannot handle discrete or mixed integer problems at all, and the function is required to be continuous within the regions that are not prohibitted.
Thank you so much for your helpful answer. Appreciate that

Sign in to comment.

Answers (0)

Asked:

on 23 Apr 2019

Edited:

on 22 May 2019

Community Treasure Hunt

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

Start Hunting!