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

Gurobi seems to think there are small coefficients somewhere, or large coefficients #520

Closed
IainNZ opened this issue Aug 9, 2015 · 12 comments
Assignees
Milestone

Comments

@IainNZ
Copy link
Collaborator

IainNZ commented Aug 9, 2015

I have a fairly simple & small model, and when I solve it with Gurobi it says:

Optimize a model with 20 rows, 40 columns and 75 nonzeros
Coefficient statistics:
  Matrix range    [0e+00, 5e+02]
  Objective range [2e-01, 5e+01]
  Bounds range    [1e+00, 1e+00]
  RHS range       [7e+01, 1e+02]
Warning: Model contains large matrix coefficient range
         Consider reformulating model or setting NumericFocus parameter
         to avoid numerical issues.

However, printing the A matrix after prepConstrMatrix reveals nothing out of the ordinary, and printing the model to an LP and loading that with gurobipy also doesn't trigger the warning. Sebastien reported to me a similar message where Gurobi said it was removing variables with very small coefficients, even though he couldn't find any by printing out. Is there somewhere we could be injecting noise?

@IainNZ IainNZ changed the title Gurobi seems to think there are small coefficients somewhere Gurobi seems to think there are small coefficients somewhere, or large coefficients Aug 9, 2015
@mlubin
Copy link
Member

mlubin commented Aug 9, 2015

Try calling getconstrmatrix on the gurobi model instance?

@IainNZ
Copy link
Collaborator Author

IainNZ commented Aug 9, 2015

I just did something similar, got Gurobi.jl to do writeproblem, nothing weird. Here is JuMP's output

Maximize
 obj: 3 VAR36 + 3 VAR37 + 3 VAR38 + 3 VAR39 + 3 VAR40 + 0 VAR11 - .64 VAR16 - .21 VAR21 - .91 VAR26 - .72 VAR31 - .64 VAR12 + 0 VAR17 - .49 VAR22 - .67 VAR27 - 1.14 VAR32 - .21 VAR13 - .49 VAR18 + 0 VAR23 - .91 VAR28 - .91 VAR33 - .91 VAR14 - .67 VAR19 - .91 VAR24 + 0 VAR29 - .91 VAR34 - .72 VAR15 - 1.14 VAR20 - .91 VAR25 - .91 VAR30 + 0 VAR35 - 50 VAR6 - 50 VAR7 - 50 VAR8 - 50 VAR9 - 50 VAR10 - 1 VAR1 - 1 VAR2 - 1 VAR3 - 1 VAR4 - 1 VAR5
Subject To
 c1: 1 VAR11 = 0
 c2: 1 VAR1 - 524 VAR6 <= 0
 c3: 1 VAR36 <= 94
 c4: 1 VAR36 - 1 VAR1 - 1 VAR11 - 1 VAR16 - 1 VAR21 - 1 VAR26 - 1 VAR31 + 1 VAR11 + 1 VAR12 + 1 VAR13 + 1 VAR14 + 1 VAR15 <= 0
 c5: 1 VAR17 = 0
 c6: 1 VAR2 - 524 VAR7 <= 0
 c7: 1 VAR37 <= 95
 c8: 1 VAR37 - 1 VAR2 - 1 VAR12 - 1 VAR17 - 1 VAR22 - 1 VAR27 - 1 VAR32 + 1 VAR16 + 1 VAR17 + 1 VAR18 + 1 VAR19 + 1 VAR20 <= 0
 c9: 1 VAR23 = 0
 c10: 1 VAR3 - 524 VAR8 <= 0
 c11: 1 VAR38 <= 116
 c12: 1 VAR38 - 1 VAR3 - 1 VAR13 - 1 VAR18 - 1 VAR23 - 1 VAR28 - 1 VAR33 + 1 VAR21 + 1 VAR22 + 1 VAR23 + 1 VAR24 + 1 VAR25 <= 0
 c13: 1 VAR29 = 0
 c14: 1 VAR4 - 524 VAR9 <= 0
 c15: 1 VAR39 <= 71
 c16: 1 VAR39 - 1 VAR4 - 1 VAR14 - 1 VAR19 - 1 VAR24 - 1 VAR29 - 1 VAR34 + 1 VAR26 + 1 VAR27 + 1 VAR28 + 1 VAR29 + 1 VAR30 <= 0
 c17: 1 VAR35 = 0
 c18: 1 VAR5 - 524 VAR10 <= 0
 c19: 1 VAR40 <= 148
 c20: 1 VAR40 - 1 VAR5 - 1 VAR15 - 1 VAR20 - 1 VAR25 - 1 VAR30 - 1 VAR35 + 1 VAR31 + 1 VAR32 + 1 VAR33 + 1 VAR34 + 1 VAR35 <= 0
Bounds
 0 <= VAR1 <= +inf
 0 <= VAR2 <= +inf
 0 <= VAR3 <= +inf
 0 <= VAR4 <= +inf
 0 <= VAR5 <= +inf
 0 <= VAR6 <= 1
 0 <= VAR7 <= 1
 0 <= VAR8 <= 1
 0 <= VAR9 <= 1
 0 <= VAR10 <= 1
 0 <= VAR11 <= +inf
 0 <= VAR12 <= +inf
 0 <= VAR13 <= +inf
 0 <= VAR14 <= +inf
 0 <= VAR15 <= +inf
 0 <= VAR16 <= +inf
 0 <= VAR17 <= +inf
 0 <= VAR18 <= +inf
 0 <= VAR19 <= +inf
 0 <= VAR20 <= +inf
 0 <= VAR21 <= +inf
 0 <= VAR22 <= +inf
 0 <= VAR23 <= +inf
 0 <= VAR24 <= +inf
 0 <= VAR25 <= +inf
 0 <= VAR26 <= +inf
 0 <= VAR27 <= +inf
 0 <= VAR28 <= +inf
 0 <= VAR29 <= +inf
 0 <= VAR30 <= +inf
 0 <= VAR31 <= +inf
 0 <= VAR32 <= +inf
 0 <= VAR33 <= +inf
 0 <= VAR34 <= +inf
 0 <= VAR35 <= +inf
 0 <= VAR36 <= +inf
 0 <= VAR37 <= +inf
 0 <= VAR38 <= +inf
 0 <= VAR39 <= +inf
 0 <= VAR40 <= +inf
General
 VAR6
 VAR7
 VAR8
 VAR9
 VAR10
End

@IainNZ
Copy link
Collaborator Author

IainNZ commented Aug 9, 2015

and Gurobi.jl

Maximize
  - C0 - C1 - C2 - C3 - C4 - 50 C5 - 50 C6 - 50 C7 - 50 C8 - 50 C9
   - 0.64 C11 - 0.21 C12 - 0.91 C13 - 0.72 C14 - 0.64 C15 - 0.49 C17
   - 0.67 C18 - 1.14 C19 - 0.21 C20 - 0.49 C21 - 0.91 C23 - 0.91 C24
   - 0.91 C25 - 0.67 C26 - 0.91 C27 - 0.91 C29 - 0.72 C30 - 1.14 C31
   - 0.91 C32 - 0.91 C33 + 3 C35 + 3 C36 + 3 C37 + 3 C38 + 3 C39
Subject To
 R0: C10 = -0
 R1: C0 - 524 C5 <= -0
 R2: C35 <= 94
 R3: - C0 - 0 C10 + C11 + C12 + C13 + C14 - C15 - C20 - C25 - C30 + C35
   <= -0
 R4: C16 = -0
 R5: C1 - 524 C6 <= -0
 R6: C36 <= 95
 R7: - C1 - C11 + C15 - 0 C16 + C17 + C18 + C19 - C21 - C26 - C31 + C36
   <= -0
 R8: C22 = -0
 R9: C2 - 524 C7 <= -0
 R10: C37 <= 116
 R11: - C2 - C12 - C17 + C20 + C21 - 0 C22 + C23 + C24 - C27 - C32 + C37
   <= -0
 R12: C28 = -0
 R13: C3 - 524 C8 <= -0
 R14: C38 <= 71
 R15: - C3 - C13 - C18 - C23 + C25 + C26 + C27 - 0 C28 + C29 - C33 + C38
   <= -0
 R16: C34 = -0
 R17: C4 - 524 C9 <= -0
 R18: C39 <= 148
 R19: - C4 - C14 - C19 - C24 - C29 + C30 + C31 + C32 + C33 - 0 C34 + C39
   <= -0
Bounds
Binaries
 C5 C6 C7 C8 C9
End

@mlubin
Copy link
Member

mlubin commented Aug 9, 2015

There's cancellation happening here, leading to zero (or near zero) coefficients.

@IainNZ
Copy link
Collaborator Author

IainNZ commented Aug 9, 2015

There was cancellation in Seb's thing too. But isn't it 1-1 cancellation?

@mlubin
Copy link
Member

mlubin commented Aug 9, 2015

Yeah, not sure why gurobi would complain about coefficients that are exactly zero.

@IainNZ
Copy link
Collaborator Author

IainNZ commented Aug 9, 2015

using JuMP, Gurobi, Distributions
    n = 5
    srand(1000)
    μ = rand(50:150, n)
    σ = 0.5 * μ
    p = 3
    locs = rand(Uniform(0,1),(n,2))
    t = Matrix{Float64}(round([norm(locs[i,:]-locs[j,:]) for i in 1:n, j in 1:n],2))
    C = 50
    D = rand(5)
    m = Model(solver=GurobiSolver())
    @defVar(m, x[1:n] >= 0)
    @defVar(m, B[1:n], Bin)
    @defVar(m, y[1:n,1:n] >= 0)
    @defVar(m, S[1:n] >= 0)

    @setObjective(m, Max, p*sum(S) - sum(t.*y) - C*sum(B) - sum(x) )

    for i in 1:n
        @addConstraint(m, y[i,i] == 0)
        @addConstraint(m, x[i] <= sum(D)*B[i])
        @addConstraint(m, S[i] <= D[i])
        @addConstraint(m, S[i] <= x[i] + sum{y[j,i],j=1:n}
                                       - sum{y[i,j],j=1:n})
    end
    solve(m)

@IainNZ
Copy link
Collaborator Author

IainNZ commented Aug 9, 2015

So is this a Gurobi bug then arguably?

@mlubin
Copy link
Member

mlubin commented Aug 9, 2015

@IainNZ
Copy link
Collaborator Author

IainNZ commented Aug 9, 2015

Yeah, true, one pass to get true number of nnzs, then fill in second. Probably wouldn't hurt performance much.

@IainNZ
Copy link
Collaborator Author

IainNZ commented Aug 9, 2015

Or one pass with push!

@mlubin
Copy link
Member

mlubin commented Aug 9, 2015

one pass with sizehint! should be fine

@IainNZ IainNZ added this to the 0.10 milestone Aug 11, 2015
@IainNZ IainNZ self-assigned this Aug 14, 2015
@IainNZ IainNZ closed this as completed in 1e3cf6c Aug 14, 2015
IainNZ added a commit that referenced this issue Aug 14, 2015
Fix #520 by not adding zeros to constraint matrix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants