Solver not applicable (cplex does not support quadratic equality constraints)

404 views
Skip to first unread message

Elder Jiang

unread,
Feb 14, 2021, 5:10:59 AM2/14/21
to YALMIP
Dear Professor Löfberg,

I am a beginner in using YALMIP and I have some trouble to solve 0-1 mixed integer linear programming problem.The command line window shows 'Solver not applicable (cplex does not support quadratic equality constraints)'.Could you please let me know whether it was a typo or have I made a mistake here ?Thanks a lot.
The attachment is the code file.
Best Wishes,
Elder Jiang


yalmip10.m

Johan Löfberg

unread,
Feb 14, 2021, 6:37:37 AM2/14/21
to YALMIP
As the message says, cplex does not support quadratic equalities (or bilinear which you have)

Johan Löfberg

unread,
Feb 14, 2021, 6:41:34 AM2/14/21
to YALMIP
you are multiplying binaries and continuous variables to model logic on/off behavior. Don't

Elder Jiang

unread,
Feb 14, 2021, 10:27:53 PM2/14/21
to YALMIP
Dear Professor Löfberg,

Thank you for your help! I have modified them.
But there is a new mistake,when i want to solve the problem,the command line shows 'Matlab Toolbox parameter "Display" found.'The details are as follows:
>> yalmip14
+ Solver chosen : CPLEX-IBM
+ Processing objective function
+ Processing constraints
Matlab Toolbox parameter "Display" found.
警告: Using Matlab Toolbox parameters in the CPLEX Matlab API is deprecated. They will be treated as unknown parameters in the future. 
> In handleparams
  In cplexmiqcp
  In cplexmilp
  In call_cplexibm_miqp>localSolverCall (line 159)
  In call_cplexibm_miqp (line 32)
  In call_cplexibm_qcmiqp (line 11)
  In solvesdp (line 371)
  In optimize (line 31)
  In yalmip14 (line 361) 
Calculation mistake

It is puzzling that the above problems did not occur when using cplex to solve a simple model.Could you please let me know whether it was a typo or have I made a mistake here ?Thanks a lot.
The attachment is the code file.
Thanks a lot!
yalmip14.m

Johan Löfberg

unread,
Feb 15, 2021, 1:00:50 AM2/15/21
to YALMIP
It still ran right? There are some warnings when using recent version of cplex as they are messing around with their option logic again

Elder Jiang

unread,
Feb 15, 2021, 1:23:11 AM2/15/21
to YALMIP
Not solved yet,the command window shows 'Calculation mistake'.
But there is no any other information about mistakes.

Elder Jiang

unread,
Feb 15, 2021, 1:31:51 AM2/15/21
to YALMIP
Professor ,  can i use the old version of cplex matlab api to solve the problem?

在2021年2月15日星期一 UTC+8 下午2:00:50<Johan Löfberg> 写道:

Johan Löfberg

unread,
Feb 15, 2021, 1:33:05 AM2/15/21
to YALMIP
'Calculation mistake' is something you've defined, it is not yalmip or cplex

Show the output structure from optimize which contains the diagnostic created by yalmip

Johan Löfberg

unread,
Feb 15, 2021, 1:34:12 AM2/15/21
to YALMIP
12.8,12.9,12.10 are the ones which work best as far as I canrecall (although some of them will show warnings about inconsistent options structure)

Elder Jiang

unread,
Feb 16, 2021, 5:31:30 AM2/16/21
to YALMIP
     Thanks a lot professor.The output structure from optimize shows 'Unbounded Objective Function', I've changed solver to gurobi and followed the Instructions in Debugging unbounded models,solved the problem without Objective and it worked.
     Well,In Unit commitment you said 'We start building our model based on this logic (remember, this can be vectorized, we use for-loops only to make the model easier to understand)',so can you tell me how to vectorize in building models,Is there any guidance on vectorization in the YALMIP tutorials?Thanks!

Johan Löfberg

unread,
Feb 16, 2021, 5:44:59 AM2/16/21
to YALMIP
your model is full of stuff which can/should be vectorized for readability and perfrmance

for i=1:Units
    for k=1:Horizon
        C_g=C_g+(0.283*(P_GT(i,k)/0.3+H_GB(i,k)/0.9)*t_g(i,k));
    end
end

is simply C_g = sum(sum((0.283*(P_GT/0.3+H_GB/0.9).*t_g)

standard matlab

that's completely unrelated to the unbounded objective though

Elder Jiang

unread,
Feb 17, 2021, 9:17:57 AM2/17/21
to YALMIP
Thanks professor!
I know that strict inequality is not allowed in YALMIP , so I wonder that if I can use another form to replace it,e.g.  a<=5-eps(5) to replace a<5 ?

Johan Löfberg

unread,
Feb 17, 2021, 9:59:29 AM2/17/21
to YALMIP
Of course, a<=b where b is less than immediately implies a<5 (but of course, in practice you cannot guarantee that the condition holds after solving since the solver only solves the problem up to some finite precision anyway)

Johan Löfberg

unread,
Feb 17, 2021, 10:00:01 AM2/17/21
to YALMIP
*where b is less than 5*

Elder Jiang

unread,
Feb 18, 2021, 7:16:04 AM2/18/21
to YALMIP
Sorry to bother you again professor . I've simplified and cleaned up my model , but there is another question that shows 'Dual infeasible due to empty column 'x229'.' and 'Row 'c5908' infeasible, all entries at implied bounds.' , the result info is 'Infeasible problem (CPLEX-IBM)' . I want to debug model by using method in  Debugging more complex models , so how can I structure my model into logical sets of constraints , e.g.

for k=1:Horizon
     Constraints=[Constraints,
            P_BTc(1,k)==0,
            P_BTc(3,k)==0,
            P_BTdisc(1,k)==0,
            P_BTdisc(3,k)==0,
            P_gb(:,k)>=0,
            P_gs(:,k)>=0,
            P_gb(:,k)+P_PV(:,k)+P_GT(:,k)+P_BTc(:,k)==P_gs(:,k)+L_E(:,k)+P_EC(:,k)+P_BTdisc(:,k),
            H_Rec(:,k)+H_GB(:,k)==H_AC(:,k)+H_HE(:,k)/0.9,
            H_Rec(:,k)==2.3*0.73*P_GT(:,k),
            C_EC(:,k)+C_AC(:,k)==L_C(:,k),
            C_EC(:,k)==4*P_EC(:,k),
            C_AC(:,k)==1.2*H_AC(:,k)];
end

for i=1:Nunits
    for k=1:Horizon
        GT_mode=[0<=onoff_GT(i,k)<=1,
                 P_GTmin(i)<=P_GT(i,k)<=P_GTmax(i)];
        GT_mode=[GT_mode,sum(gt_mode)==1,
                    implies(gt_mode(1),[onoff_GT(i,k)==1,P_GTmin(i)<=P_GT(i,k)<=P_GTmax(i)]);
                    implies(gt_mode(2),[onoff_GT(i,k)==0,P_GT(i,k)==0])];
        Constraints=[Constraints,GT_mode];
    end
end


Johan Löfberg

unread,
Feb 18, 2021, 7:20:36 AM2/18/21
to YALMIP
it means you effectively have something like x==1 and x==2 in the model, or x>=1 and x<=0

you simply have to start comment out/remove parts of the code to understand with which parts it becomes infeasible

Elder Jiang

unread,
Feb 18, 2021, 7:20:52 AM2/18/21
to YALMIP
BTW , is there any relation between infeasibility and 'some finite precision' you said yesterday?

Johan Löfberg

unread,
Feb 18, 2021, 7:22:23 AM2/18/21
to YALMIP
no, except that poor numerics can cause issues in various ways

Elder Jiang

unread,
Feb 18, 2021, 8:21:19 AM2/18/21
to YALMIP
I've found the part below that becomes infeasible :

%basic data
Nunits=4;
Horizon=24;
H_ex=sdpvar(Nunits,Horizon,'full');
H_HE=sdpvar(Nunits,Horizon,'full');
L_T=[3600,3600,3600,3600,3600,3600,3600,3600,4000,4200,4200,4200,4000,3600,3600,3600,3600,4000,4200,4200,4200,4000,3600,3600;
         0,0,0,0,0,0,0,0,1800,2800,3600,4000,4400,4000,4000,4000,4000,4200,4200,4000,3600,2800,0,0;
         0,0,0,0,0,0,0,0,2400,4200,4400,4200,4000,4000,4000,4000,4000,4000,2000,1000,500,0,0,0;
   7000,7000,7000,7000,7000,7000,7000,7000,7000,25000,25000,25000,25000,25000,25000,25000,25000,25000,7000,7000,7000,7000,7000,7000];
(4×24 matrix)

Constraints=[ ];
for i=1:Nunits
    for k=1:Horizon
        Constraints=[Constraints,H_HE(i,k)-H_ex(i,k)==L_T(i,k)];
    end
end

The command window shows:
+ Solver chosen : CPLEX-IBM
+ Processing objective function
+ Processing constraints
Matlab Toolbox parameter "Display" found.
Warning: Using Matlab Toolbox parameters in the CPLEX Matlab API is deprecated. They will be treated as unknown parameters in the future. 
> In handleparams
  In cplexqcp
  In cplexlp
  In call_cplexibm_miqp>localSolverCall (line 142)
  In call_cplexibm_miqp (line 32)
  In call_cplexibm_qcmiqp (line 11)
  In solvesdp (line 368)
  In optimize (line 31)
  In yalmip19 (line 346) 
Version identifier: 12.10.0.0 | 2019-11-26 | 843d4de2ae
CPXPARAM_Simplex_Display                         2
CPXPARAM_Barrier_Display                         2
Tried aggregator 1 time.
LP Presolve eliminated 96 rows and 192 columns.
All rows and columns eliminated.
Presolve time = 0.00 sec. (0.04 ticks)
+ Calling CPLEX-IBM

ans =

   NaN

I can't understand why it is infeasible . 

Johan Löfberg

unread,
Feb 18, 2021, 8:31:46 AM2/18/21
to YALMIP
that's not infeasible. cplex tells you it solves it trivially, which also yalmip reports

optimize(Constraints)

All rows and columns eliminated.
Presolve time = 0.00 sec. (0.04 ticks)

ans = 

  struct with fields:

    yalmipversion: '20200930'
    matlabversion: '9.9.0.1524771 (R2020b) Update 2'
       yalmiptime: 0.68409
       solvertime: 0.089908
             info: 'Successfully solved (CPLEX-IBM)'
          problem: 0

Elder Jiang

unread,
Feb 18, 2021, 9:47:54 AM2/18/21
to YALMIP
Thanks professor , I'm sorry I forgot to say the code I attached has already corrected by myself and the old is infeasible , though I didn't know the reason for NAN neither before.
But 'unbounded  objective function' occured , I solved the problem without Objective and it worked well( the Objective value is very close to the actual value), but to ensure the code is completely correct ,  I used the trick  'Bound the variables'  , the code is :

ops=sdpsettings('verbose',2,'warning',1,'showprogress',1,'savesolverinput',1,'savesolveroutput',1,'debug',1,'solver','cplex');
UsedInObjective = recover(depends(Cost_IES));
optimize([Constraints, -1000000 <= UsedInObjective <= 1000000] ,Cost_IES,ops)

the command window shows:
>>value(UsedInObjective)

ans =

   1.0e+06 *

    1.0000
         0
         0
    1.0000
    1.0000
         0
         0
    1.0000
    1.0000
         0
         0
    1.0000
    1.0000
         0
    0.9981
     (...)

So is there still any mistake in my code ?
BTW , use cplex or guribi have different Objective value(337450 for cplex and 381005 for gurobi) , is it normal ?

Johan Löfberg

unread,
Feb 18, 2021, 9:54:47 AM2/18/21
to YALMIP
Obviously many of the variables in your model are effectively unconstrained (.e. you are missing constraints) as many of the variables are moving to your artificial bound 10^6

If the objective differ by that much, they have either failed (have they really reported success?) or the model is insanely badly scaled causing numerical issues (which the solvers typically would inform you about) or there is a bug in one of them

Elder Jiang

unread,
Feb 20, 2021, 12:52:14 AM2/20/21
to YALMIP
There is no doubt that you are right,I found some other mistakes and modified them . But unfortunately Infeasible problem still exists . Despite using the method you said, I still can’t find the problem .Could you please give me some help ?
The attached file 'test5' is the code.Thanks !

The command window output :
>> test5
Academic license - for non-commercial use only - expires 2021-04-17
Warning for adding variables: zero or small (< 1e-13) coefficients, ignored
Gurobi Optimizer version 9.1.0 build v9.1.0rc0 (win64)
Thread count: 4 physical cores, 8 logical processors, using up to 8 threads
Optimize a model with 4560 rows, 1776 columns and 6864 nonzeros
Model fingerprint: 0xdfb5c1e8
Variable types: 1152 continuous, 624 integer (624 binary)
Coefficient statistics:
  Matrix range     [1e+00, 2e+04]
  Objective range  [0e+00, 0e+00]
  Bounds range     [1e+00, 1e+00]
  RHS range        [1e+00, 4e+04]
Presolve removed 3408 rows and 624 columns
Presolve time: 0.00s

Explored 0 nodes (0 simplex iterations) in 0.14 seconds
Thread count was 1 (of 8 available processors)

Solution count 0

Model is infeasible
Best objective -, best bound -, gap -
test5.m

Johan Löfberg

unread,
Feb 20, 2021, 3:18:32 AM2/20/21
to YALMIP
You don't seem to have digged far, because I can remove a lot of stuff from the model and it is still infeasible. When facing infeasibility, simplify simplify simplify to see what can be removed without gaining feasibility, so you just have to continue, and then start adding slacks when you cannot remove more

% Constraints
Constraints=[];

% Equipment output constraints
for k=1:Horizon
    Constraints=[Constraints,
        H_Recmin<=H_Rec(:,k)<=H_Recmax,
        H_GBmin<=H_GB(:,k)<=H_GBmax,
        C_ECmin<=C_EC(:,k)<=C_ECmax,
        C_ACmin<=C_AC(:,k)<=C_ACmax,
        H_HEmin<=H_HE(:,k)<=H_HEmax];
end

% Gas turbine Output Constraints
for k=1:Horizon
    Constraints=[Constraints,zeros(4,1)<=P_GT(:,k)<=P_GTmax];
end

% Energy balance constraints
for k=1:Horizon
    Constraints=[Constraints,
            P_gb(:,k)+P_PV(:,k)+P_GT(:,k)+P_BTc(:,k)==P_gs(:,k)+L_E(:,k)+P_EC(:,k)+P_BTdisc(:,k),
            H_Rec(:,k)+H_GB(:,k)==H_AC(:,k)+H_HE(:,k)/0.9,
            H_Rec(:,k)==2.3*0.73*P_GT(:,k),
            C_EC(:,k)+C_AC(:,k)==L_C(:,k),
            C_EC(:,k)==4*P_EC(:,k),
            C_AC(:,k)==1.2*H_AC(:,k)];
end

% Electricity purchase & sell constraints
for k=1:Horizon
    Constraints=[Constraints,zeros(4,1)<=P_gb(:,k)<=P_exmax,zeros(4,1)<=P_gs(:,k)<=P_exmax];
end

% Battery constraints
for k=1:Horizon 
    Constraints=[Constraints,zeros(Nunits,1)<=P_BTdisc(:,k)<=P_BTdiscmax,zeros(Nunits,1)<=P_BTc(:,k)<=P_BTcmax];
end

result=optimize(Constraints)

Message has been deleted

Elder Jiang

unread,
Feb 24, 2021, 11:27:50 PM2/24/21
to YALMIP
Dear Professor Löfberg,
I'm very sorry but I have to disturb you again .  I've further simplified my model but the problem still exists .  I used mosek this time but the yalmiperror code is 12 : 'Either infeasible or unbounded (MOSEK)' . I've tried your methods  but still can't find the guilty constraints. So Could you please help me find it(them) ? 
The attached file ‘Problematic_model.m’ is the Complete code.
Thanks ! 
Problematic_model.m

Johan Löfberg

unread,
Feb 25, 2021, 1:24:47 AM2/25/21
to YALMIP
Reply all
Reply to author
Forward
0 new messages