Problem 'Model creation failed (Model not available in objective at level 2)'

677 views
Skip to first unread message

Quincy 舒

unread,
Apr 16, 2017, 6:20:58 AM4/16/17
to YALMIP
I_line = sdpvar(length(lineParameters),2,'full');
I_line_com = sdpvar(length(lineParameters),1,'full','complex');
I_line_norm = sdpvar(length(lineParameters),1,'full');
I_contactline = sdpvar(length(contactLine)*2,1,'full');
I_sqr = sdpvar(length(contactLine)*2,1,'full');

k = binvar(length(lineParameters),1,'full');
% k is the decision variables

assign(k,lineParameters(:,6));

Constraints = [];

Constraints = [Constraints, sum(k)==numberOfNodes - 2];

for i = 2:numberOfNodes/2
    keyIn = find(keyBranch(:,2)==i);
    keyOut = find(keyBranch(:,1)==i);
    Constraints = [Constraints, sum(I_line(keyIn,1)) - sum(I_line(keyOut,1)) == real(Iload(i))];
    Constraints = [Constraints, sum(I_line(keyIn,2)) - sum(I_line(keyOut,2)) == imag(Iload(i))];
end
for i = numberOfNodes/2 + 2:numberOfNodes
    keyIn = find(keyBranch(:,2)==i);
    keyOut = find(keyBranch(:,1)==i);
    Constraints = [Constraints, sum(I_line(keyIn,1)) - sum(I_line(keyOut,1)) == real(Iload(i))];
    Constraints = [Constraints, sum(I_line(keyIn,2)) - sum(I_line(keyOut,2)) == imag(Iload(i))];
end

for i = 1:length(I_line)
    I_line_com(i,1) = I_line(i,1) + sqrt(-1)*I_line(i,2);
    I_line_norm(i,1) = norm(I_line_com(i,1),2);
    Constraints = [Constraints, (I_line_norm(i,1) <= Imax(i)*k(i)):['transmission power' num2str(i)]];
    if feasibleLine(i) == 1
        Constraints = [Constraints, k(i) == feasibleLine(i)];
    end
end
Q_Imax = zeros(length(contactLine)*2);
for i = 1:length(contactLine)
    Constraints = [Constraints, I_line_norm(contactLine(i,1)) + I_line_norm(contactLine(i,2)) <= min(Imax(contactLine(i,1)),Imax(contactLine(i,2)))];
    I_contactline(i*2-1,1) = I_line_norm(contactLine(i,1));
    I_contactline(i*2,1)   = I_line_norm(contactLine(i,2));
    Q_Imax(i*2-1,i*2-1)    = 1/Imax(contactLine(i,1));
    Q_Imax(i*2,i*2)        = 1/Imax(contactLine(i,2));
end

Objective = I_contactline'*Q_Imax*I_contactline;

options = sdpsettings('solver','gurobi');
tic;
optimize(Constraints, Objective, options)


Dear Professor

I have a problem with my code, that bothers me about a month.Initially, my model is an LP model, I could solve it with YALMIP + Gurobi. However, that problem occurs when I change the objective function to quadratic without changing any constraints.Here is my code.

I am a YALMIP & Optimization beginner, thanks for your times. I'm looking forward to receiving your reply.

Best wishes



                                                                                                                                                                                 Quincy Shu



Johan Löfberg

unread,
Apr 16, 2017, 6:34:42 AM4/16/17
to YALMIP
You cannot use norm()'*Q*norm(), it is not generally convex SOCP-representable and thus yalmip will not be able to derive a model

and btw, the assign you do is completely redundant

Quincy 舒

unread,
Apr 16, 2017, 1:55:12 PM4/16/17
to YALMIP
thank u so much, professor!
I read  "working with square roots", so I change my code

before
     I_line_com(i,1) = I_line(i,1) + sqrt(-1)*I_line(i,2);
     I_line_norm(i,1) = norm(I_line_com(i,1),2);

now
     I_line_norm(i,1) = sqrtm(I_line(i,1)^2 + I_line(i,2)^2);

When the objection is linear, the problem could be solved, and get the right answer

But when the objection is quadratic, it warns me "'Solver not applicable (gurobi)'"

So I didn't specify any solver

It warned me "'Infeasible problem (BNB)'"

I read "debugging infeasible models", but I cannot deal with the problem


I wonder why gurobi cannot solve the problem?

In my opinion, this is a QP or QCP problem


And how to deal with the infeasible problem?

Because I think it must have a feasible solution, it's truly a simple example

Johan Löfberg

unread,
Apr 16, 2017, 2:08:49 PM4/16/17
to YALMIP
if you read that article, you should have learned that sqrtm is used if you want to use a general nonlinear approach and solver, and thus impossible to use with gurobi

if appears that you think a quadratic form in norm(x) is convex and socp representable.. That is not the case. Take for instance x^2-2*x which trivially is convex, but norm(x)^2-2*norm(x) is easily seen to be non-convex and thus absolutely not socp representable

and I have no idea why you talk about infeasbility. No problem has been solved so you know nothing about feasibility.

Johan Löfberg

unread,
Apr 16, 2017, 2:10:32 PM4/16/17
to YALMIP
sorry, missed the fact that you switched to nonlinear solver and saw infeasibility. well, that is the drawback of a general nonlinear solver, and a possibly nonconvex model. the solver can get lost and think the problem is infeasible. hence, you should always try to obtain a nice structured convex model

Quincy 舒

unread,
Apr 17, 2017, 9:59:55 PM4/17/17
to YALMIP
Thank you for your help!
Reply all
Reply to author
Forward
0 new messages