Warning for adding constraints: zero or small (< 1e-13) coefficients, ignored

I asked this question and it seems no one wants to help me: I am just using Gurobi 9.0 which solves non convex problems as well. I get this error:

Warning for adding constraints: zero or small (< 1e-13) coefficients, ignored
Gurobi Optimizer version 9.0.0 build v9.0.0rc2 (win64)
Optimize a model with 599 rows, 875 columns and 1929 nonzeros
Model fingerprint: 0x3713a22a
Model has 552 quadratic objective terms
Model has 141 quadratic constraints
Coefficient statistics:
  Matrix range     [5e-03, 3e+02]
  QMatrix range    [1e-03, 1e+00]
  QLMatrix range   [1e+00, 8e+03]
  Objective range  [5e+03, 5e+03]
  QObjective range [2e+00, 2e+00]
  Bounds range     [0e+00, 0e+00]
  RHS range        [7e-15, 2e+04]
Presolve removed 84 rows and 76 columns
Gurobi.GurobiError(10020, "Q matrix is not positive semi-definite (PSD)")

Stacktrace:
 [1] optimize at C:\Users\Utente\.julia\packages\Gurobi\CI8ht\src\grb_solve.jl:7 [inlined]
 [2] optimize!(::Gurobi.Optimizer) at C:\Users\Utente\.julia\packages\Gurobi\CI8ht\src\MOI_wrapper.jl:1803
 [3] optimize!(::MathOptInterface.Bridges.LazyBridgeOptimizer{Gurobi.Optimizer}) at C:\Users\Utente\.julia\packages\MathOptInterface\DmQBj\src\Bridges\bridge_optimizer.jl:239
 [4] optimize!(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}) at C:\Users\Utente\.julia\packages\MathOptInterface\DmQBj\src\Utilities\cachingoptimizer.jl:189
 [5] #optimize!#78(::Bool, ::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(optimize!), ::Model, ::Nothing) at C:\Users\Utente\.julia\packages\JuMP\MsUSY\src\optimizer_interface.jl:141
 [6] optimize! at C:\Users\Utente\.julia\packages\JuMP\MsUSY\src\optimizer_interface.jl:111 [inlined] (repeats 2 times)
 [7] general_equi_NLP(::Int64, ::Int64, ::Int64, ::Array{Float64,2}, ::Array{Float64,2}, ::Array{Float64,2}, ::Array{Float64,2}, ::Array{Float64,1}, ::Int64, ::Array{Float64,1}, ::Float64, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Int64, ::Float64, ::Array{Float64,2}, ::Array{Float64,2}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}) at .\In[8]:121
 [8] top-level scope at In[10]:1```
I apprciate if any one can help me in spoting this problem. Moreover, what does it mean in this context to say:

Gurobi.GurobiError(10020, “Q matrix is not positive semi-definite (PSD)”)

Hi there!

You have a few issues:

  1. You should pay attention to warnings like: Warning for adding constraints: zero or small (< 1e-13) coefficients, ignored. In particular, you should read: https://www.gurobi.com/documentation/9.0/refman/num_grb_guidelines_for_num.html

  2. Since you’re using Gurobi 9, and you got Gurobi.GurobiError(10020, "Q matrix is not positive semi-definite (PSD)"), I’m guessing you’re trying to solve a non-convex quadratic. You need to set the NonConvex parameter: https://www.gurobi.com/documentation/9.0/refman/nonconvex.html. For example:

    model = Model(with_optimizer(Gurobi.Optimizer))
    set_parameter(model, "NonConvex", 2)
    
2 Likes

Thank you for your suggestion. I put the model as you did before and I got that error. Now I just add set_parameter(model, "NonConvex", 2) and it doesn’t respond rather busy for long time.
image
So I do not get where it gets wrong.

Take a read of the first post of Please read: make it easier to help you. (Don’t worry about the rest of the thread.)

It’s a lot easier to help if you provide a minimal example of what you tried and what went wrong.

Did set_parameter(model, "NonConvex", 2) take a long time, or the solve itself? Note that non convex quadratics are difficult to solve, and depending on the problem size, it’s not uncommon for it to take a long time.

1 Like

I think after that the error disappeared and it just runs without any sign of providing solution.
I did not show you where the error is occurred because it didn’t have error message. It just stayed busy. If I remove that set_parameter(model, "NonConvex", 2) part, the error message is the one I posted above. Note that the problem has solution with Ipopt solver. I wanted to use Gurobi as I am thinking to solve bigger problem than before.

Please take the time to read the PSA and post an example of what code you tried.

For example, it would help us make sure you are printing the Gurobi log, i.e., don’t have OutputFlag = 0.

I would also close IJulia and restart from a new session.

Note that because the problem is non-convex, Ipopt may find a local optima. Gurobi will take much longer because it is finding the global optimum.

function general_equi_NLP(I,J,W,a,b,c,Q,gamma_S,gamma_F,beta_S,beta_F,qmax_F_i,qmin_F_i,qmax_F_j,qmin_F_j,phi,alpha,sigma_i,sigma_j,delta_i,varphi_i,varphi_j)
    m = Model(with_optimizer(Gurobi.Optimizer))
   set_parameter(m, "NonConvex", 2)

     @variables(m, begin 
          xi_i[i=1:I]
          cvar_i[i=1:I]
          eta_i[i=1:I,w=1:W]>=0
          Pi_i[i=1:I,w=1:W]
          EPi_i[i=1:I]
          qF_i[i=1:I]
          qS_i[i=1:I,w=1:W]
          mu_i[i=1:I,w=1:W]>=0
          theta_i[i=1:I,w=1:W]>=0
          numin_i[i=1:I]>=0
          numax_i[i=1:I]>=0
          var_pi_i[i=1:I,w=1:W]
          xi_j[j=1:J]
          cvar_j[j=1:J]
          eta_j[j=1:J,w=1:W]>=0
          Pi_j[i=1:J,w=1:W]
          EPi_j[j=1:J]
          qF_j[j=1:J]
          qS_j[j=1:J,w=1:W]
         mu_j[j=1:J,w=1:W]>=0
        theta_j[j=1:J,w=1:W]>=0
        numin_j[j=1:J]>=0
        numax_j[j=1:J]>=0
       var_pi_j[j=1:J,w=1:W]
       PF
       PS[w=1:W]
end)
    #Parameters
     Vgamma_S=gamma_S-beta_S.*sum(Q,dims=1)'
    tau_i=1 ./(beta_S*(1 .+delta_i)'.+c')'
    Varphi_w=1 ./(1 .+beta_S.*sum(tau_i,dims=1)')
    var_PF_i=-beta_F*(1 .+varphi_i*(I+J-1))
    var_PF_j=-beta_F*(1 .+varphi_j*(I+J-1))
    var_PS_i=Varphi_w'.*((varphi_i.*beta_S').*(sum(c.*tau_i,dims=1).-c.*tau_i)+beta_S'.*c.*tau_i -(1 .+(I-1)*varphi_i)*beta_S')
    var_PS_j=0*ones(J,W)
    var_qS_i=tau_i.*(var_PS_i-c)
    var_qS_j=-1*ones(J,W)

    
    @objective(m, Min, sum(sum(mu_i[i,w]*(eta_i[i,w]+Pi_i[i,w]-xi_i[i]) for i=1:I) for w=1:W) +
        sum(sum(mu_j[j,w]*(eta_j[j,w]+Pi_j[j,w]-xi_j[j]) for j=1:J) for w=1:W) + 
        sum(sum(eta_i[i,w]*theta_i[i,w] for i=1:I) for w=1:W) + 
        sum(sum(eta_j[j,w]*theta_j[j,w] for j=1:J) for w=1:W) + 
        sum((qF_i[i]-qmin_F_i[i])*numin_i[i] for i=1:I) + 
        sum((qF_j[j]-qmin_F_j[j])*numin_j[j] for j=1:J) + 
        sum((qmax_F_i[i]-qF_i[i])*numax_i[i] for i=1:I) + 
        sum((qmax_F_j[j]-qF_j[j])*numax_j[j] for j=1:J))
        
   @constraint(m, gap_equi, sum(sum(mu_i[i,w]*(eta_i[i,w]+Pi_i[i,w]-xi_i[i]) for i=1:I) for w=1:W) +
        sum(sum(mu_j[j,w]*(eta_j[j,w]+Pi_j[j,w]-xi_j[j]) for j=1:J) for w=1:W) +
        sum(sum(eta_i[i,w]*theta_i[i,w] for i=1:I) for w=1:W) +
        sum(sum(eta_j[j,w]*theta_j[j,w] for j=1:J) for w=1:W) +
        sum((qF_i[i]-qmin_F_i[i])*numin_i[i] for i=1:I) +
        sum((qF_j[j]-qmin_F_j[j])*numin_j[j] for j=1:J) +
        sum((qmax_F_i[i]-qF_i[i])*numax_i[i] for i=1:I) +
        sum((qmax_F_j[j]-qF_j[j])*numax_j[j] for j=1:J)>=0)
          
    @constraint(m, profit_i_def[i=1:I,w=1:W], Pi_i[i,w]==PF*qF_i[i]+PS[w]*qS_i[i,w]-a[i,w]-b[i,w]*(qF_i[i]+qS_i[i,w])-1/2*c[i,w]*(qF_i[i]+qS_i[i,w])^2)  
    @constraint(m, profit_j_def[j=1:J,w=1:W], Pi_j[j,w]==(PF-PS[w])*qF_j[j]+PS[w]*Q[j,w])  
    
    @constraint(m, expect_prof_i[i=1:I], EPi_i[i] == sum(sigma_i[i,w]*Pi_i[i,w] for w=1:W))
    @constraint(m, expect_prof_j[j=1:J], EPi_j[j] == sum(sigma_j[j,w]*Pi_j[j,w] for w=1:W))
                                    
    @constraint(m, cvar_i_def[i=1:I],cvar_i[i] == xi_i[i]-(1/(1-alpha))*sum(sigma_i[i,w]*eta_i[i,w] for w=1:W))
    @constraint(m, cvar_j_def[j=1:J],cvar_j[j] == xi_j[j]-(1/(1-alpha))*sum(sigma_j[j,w]*eta_j[j,w] for w=1:W))
    
    @constraint(m, price_F, PF == gamma_F-beta_F*(sum(qF_i[i] for i=1:I)+sum(qF_j[j] for j=1:J)))
    @constraint(m, price_S[w=1:W], PS[w] == Varphi_w[w]*(Vgamma_S[w]-beta_S[w]*sum(qF_i[i] for i=1:I)+beta_S[w]*sum(tau_i[i,w]*(b[i,w]+c[i,w]*qF_i[i]) for i=1:I)))
      
                                            
    @constraint(m, qS_i_def[i=1:I,w=1:W], qS_i[i,w] == tau_i[i]*(PS[w]-b[i,w]-c[i,w]*qF_i[i]))
    @constraint(m, qS_j_def[j=1:J,w=1:W], qS_j[j,w] == Q[j,w]-qF_j[j])
                                                                   
    @constraint(m, var_pi_def_i[i=1:I,w=1:W], var_pi_i[i,w] ==  var_PF_i[i]*qF_i[i]+PF+var_PS_i[i,w]*qS_i[i,w]+PS[w]*var_qS_i[i,w]-b[i,w]*(1+var_qS_i[i,w])-c[i,w]*(qF_i[i]+qS_i[i,w])*(1+var_qS_i[i,w]))
    @constraint(m, var_pi_def_j[j=1:J,w=1:W], var_pi_j[j,w] ==  (var_PF_j[j]-var_PS_j[j,w])*qF_j[j]+PF-PS[w]+var_PS_j[j,w]*Q[j,w])

    @constraint(m, cons_L1_i[i=1:I], sum((-(1-phi)*sigma_i[i,w]-mu_i[i,w])*var_pi_i[i,w] for w=1:W)-numin_i[i]+numax_i[i] == 0)
    @constraint(m, cons_L1_j[j=1:J], sum((-(1-phi)*sigma_j[j,w]-mu_j[j,w])*var_pi_j[j,w] for w=1:W)-numin_j[j]+numax_j[j] == 0)
   
    @constraint(m, cons_L2_i[i=1:I,w=1:W], (phi/(1-alpha))*sigma_i[i,w]-mu_i[i,w]-theta_i[i,w] == 0)
    @constraint(m, cons_L2_j[j=1:J,w=1:W], (phi/(1-alpha))*sigma_j[j,w]-mu_j[j,w]-theta_j[j,w] == 0)
                                    
    @constraint(m, cons_L3_i[i=1:I], -phi+sum(mu_i[i,w] for w=1:W) == 0)
    @constraint(m, cons_L3_j[j=1:J], -phi+sum(mu_j[j,w] for w=1:W) == 0)

    
    @constraint(m, comp1_i[i=1:I,w=1:W],0<= eta_i[i,w]+Pi_i[i,w]-xi_i[i])
    @constraint(m, comp1_j[j=1:J,w=1:W],0<= eta_j[j,w]+Pi_j[j,w]-xi_j[j])
                                    
    @constraint(m, comp2_i[i=1:I],0<= qF_i[i]-qmin_F_i[i])
    @constraint(m, comp2_j[j=1:J],0<= qF_j[j]-qmin_F_j[j])

    @constraint(m, comp4aa_i[i=1:I],0<= qmax_F_i[i]-qF_i[i])
    @constraint(m, comp4aa_j[j=1:J],0<= qmax_F_j[j]-qF_j[j])
    
    @time status = optimize!(m)
    
    return JuMP.objective_value(m), JuMP.value.(cvar_i), JuMP.value.(cvar_j), JuMP.value.(Pi_i), JuMP.value.(Pi_j), JuMP.value.(EPi_i), JuMP.value.(EPi_j), JuMP.value.(qF_i), JuMP.value.(qF_j), JuMP.value.(qS_i),JuMP.value.(qS_j),JuMP.value.(PF),JuMP.value.(PS),status
end```

This is part of the code I am working with. I can’t make it simple as I think it won’t show the where the exact problem happens. Note that instead of using @NLobjective and @NLconstraint I just states as @objective and @constraint. So with this code it doesn’t halt. I hope this shows you where the exact problem is.

You’re halfway there with the example, but we need a little more information. In particular, we don’t know what inputs you used for the function. (Number 3 in the PSA.)

To make it simpler (Number 4), try using a small value of I, J, and W (e.g., 1). Does it run? If so, you’re just solving a hard problem. If it still doesn’t run, comment out all of the constraints, and then add them in one-by-one.

The lack of printing is probably because you’re using IJulia. For some reason, it doesn’t flush the Gurobi log to the screen while it’s running.

1 Like