The values you provide in mpc.user_constraints.nli should be the names of the 
functions themselves, not the names of variables that contain the function 
handles. You also need to provide any additional arguments that are needed in 
the 6th element of the cell array.

In other words, I think you want something like …

mpc.user_constraints.nli={
    {'f_cost', 1, 'nli_constraint', 'nli_constraint_hess', { }, {H, e, M}}
};

You’ll also have to modify nil_constraint_hess() to have the proper form. That 
is, the first two arguments are x and lambda, followed by whatever you provide 
in the 6th element of the cell array above.

function d2H = nli_constraint_hess(x, lambda, H, e, M)

Please have a look at the example around line 408 in t_opf_mips, to see the 
format of a working example. If you are still having trouble, feel free to 
submit an issue <https://github.com/MATPOWER/matpower/issues> that includes a 
minimal working example (MWE) 
<https://en.wikipedia.org/wiki/Minimal_Working_Example> as an attachment that I 
can use to reproduce your issue.

    Ray


> On Oct 30, 2017, at 7:34 PM, Monisha Raju <monis...@buffalo.edu> wrote:
> 
> Hello,
> 
> I'm trying to add a nonlinear cost constraint : cost = x' H x+e'x+M
> I've used the direct method to create field 
> mpc.user_constraints.nli={
> {'f_cost', 1, 'gh_fcn', 'hess_fcn', { },{ }}
> };
> where
> 
> f_fcn = @(x)f_cost(x, H, e, M);
> gh_fcn = @(x) nli_constraint(x, H, e, M);
> hess_fcn = @(lam) nli_constraint_hess(lam, H);
> 
> I've attached .m files for reference. The opf_setup evaluates fcn and hess 
> that requires nlc{6}. Even though I've added a cell { } in nlc{6} there are 
> errors and gh_fcn is said to be undefined. Could you guide me on how to 
> proceed?
> 
> These are the errors I'm getting:
> MATPOWER Version 6.1-dev, 27-Sep-2017 -- AC Optimal Power Flow
> Undefined function or variable 'gh_fcn'.
> 
> Error in opf_setup>@(x)gh_fcn(x,nlc{6}{:})
> 
> Error in opt_model/eval_nln_constraint (line 81)
>         [gk, dgk] = fcn(xx);    %% evaluate kth constraint and gradient
> 
> Error in opf_consfcn (line 54)
>     [h, dh] = om.eval_nln_constraint(x, 0); %% inequalities (branch flow 
> limits)
> 
> Error in mipsopf_solver>@(x)opf_consfcn(x,om,Ybus,Yf(il,:),Yt(il,:),mpopt,il) 
> (line 118)
> gh_fcn = @(x)opf_consfcn(x, om, Ybus, Yf(il,:), Yt(il,:), mpopt, il);
> 
> Error in mips (line 354)
>     [hn, gn, dhn, dgn] = gh_fcn(x); %% nonlinear constraints
> 
> Error in mipsopf_solver (line 121)
>   mips(f_fcn, x0, A, l, u, xmin, xmax, gh_fcn, hess_fcn, opt);
> 
> Error in opf_execute (line 70)
>       [results, success, raw] = mipsopf_solver(om, mpopt);
> 
> Error in opf (line 217)
>     [results, success, raw] = opf_execute(om, mpopt);
> 
> Error in runopf (line 75)
> [r, success] = opf(casedata, mpopt);
> 
> Error in Add_constraints (line 30)
> r = runopf(mpc, mpopt);
>  
> 
> Thank you,
> Monisha Raju
> Graduate Research Assistant
> University at Buffalo
> <Add_constraints><f_cost.m><nli_constraint.m><nli_constraint_hess.m>

Reply via email to