Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sometimes fatal indexing error in OPF with additional nonlinear constraints #77

Closed
Segama opened this issue Aug 9, 2019 · 1 comment
Assignees
Labels

Comments

@Segama
Copy link

Segama commented Aug 9, 2019

When the number of non-linear constraints is bigger than (2nb + 2nl) an error is shown on the command window:

image

We made up a case with two buses and one line, just to check the performance of the an optimization problem with a lot of non-linear constraints and we got the error message. As it's show in the command window, the optimization problem was already solved, so the problem was easily correct. We add few lines into the function ipoptopf_solver and it seems to work fine for the cases we have tried:

image

This is the environment we're using:

image

The following example is a simple test that we created to reproduce the error, we used the matpower case9 to prove the error, but if a bigger case is used there won't be any problem.

clc,clear

mpc = loadcase(case9);
mp = mpoption;
mp.opf.ac.solver = 'IPOPT';

mpc = add_userfcn(mpc, 'ext2int', @userfcn_error_ext2int);
mpc = add_userfcn(mpc, 'formulation', @userfcn_error_formulation);

res = runopf(mpc,mp);

function mpc = userfcn_error_ext2int(mpc, mpopt, args)
% Not use for the example 
end
function om = userfcn_error_formulation(om, mpopt, args)
n = 20;         % number of non-linear constraints
%% x
x0 = ones(n,1);
xmin = 2*ones(n,1);
% xmax = 
%% y 
y0 = zeros(n,1);
ymin = y0;
% ymax =
%% variables
om.add_var('X',n,x0,xmin,[]);
om.add_var('Y',n,y0,ymin,[]);
%% constraints
fcn = @(x)f_fcn(x);
hess = @(x, lambda)f_hess(x, lambda);
om.add_nln_constraint('xy', n, 'true', fcn, hess, {'X','Y'});   % x_i = (y_i)^2
end
%% --------------  Jacobian and Hessian for equations --------------
function [g, dg] = f_fcn(x)
[x, y] = deal(x{:});
n = length(x);
if nargout == 1
    g = x - y.^2;
else
    g = x - y.^2;
    m1 = eye(n);
    m2 = - 2*diag(y);
    dg = [m1 m2];
end
end
function d2H = f_hess(x, lambda)
[X, Y] = deal(x{:});
n = length(X);

m0 = zeros(n);
m1 = -2*eye(n);

d2H = [ m0 m0;
        m0 m1];
end 

I hope everything is clear.

Sergio.

@rdzman rdzman changed the title Problem related with fcn ipoptopf_solver sometimes fatal indexing error in OPF with additional nonlinear constraints Aug 16, 2019
@rdzman rdzman self-assigned this Aug 16, 2019
@rdzman rdzman added the bug label Aug 16, 2019
@rdzman
Copy link
Member

rdzman commented Aug 16, 2019

Thanks, @Segama, for bringing this to our attention. The fix was slightly different from what you proposed and was needed for the other OPF solvers as well as IPOPT.

@rdzman rdzman closed this as completed in 1548a9c Aug 16, 2019
rdzman added a commit that referenced this issue Aug 21, 2019
Was failing for fmincon and knitro on R2019a.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants