Unsupported constraints in saving JuMP models

Are there certain types of JuMP constraints that are not amenable for saving under specific formats?

Recently I have converted an ILP from Python to Julia, where I’ve found building the model is significantly faster! I’m having trouble with the simplest maneuver, which is to save the optimized model:

### HELPER FXNS ###
function neighbours(k, K)
    return vcat( max(1, k-33):max(0, k-4), min(k+4, K):min(k+33, K-1)  )
end
    
### ILP DIMENSIONS ###
I= 1
J = 800
K = 67
T1=400
T2=25
N = 2 
penalty = 1000
    
### CREATE MODEL ###
model = Model(Gurobi.Optimizer)
    
### VARIABLES ###
@variable(model, r_i_j[1:I, 1:J], base_name="r_i_j", binary=true)
@variable(model, y_i_k[1:I, 1:K], base_name="y_i_k", binary=true)
s_j_k =  rand([0, 1, 2], J, K)
@expression(
    model,
    z_i_k[i=1:I, k=1:K],
    sum(r_i_j[i,j]*s_j_k[j,k] for j in 1:J_probe),
)

### CONSTRAINTS ###
@constraint(model, 
        [i in 1:I], 
        sum(y_i_k[i, :]) <= 100
)
    
@constraint(
    model,
        [k=1:ceil(Int, K/34)],
        sum(y_i_k[:, (1+(k-1)*34):min(k*34, K)]) <=1,
)

@constraint(
    model,
    [i=1:I, k=1:K-33],
    sum(y_i_k[i,k:(k+33)]) <=1
)

@constraint(
    model, 
    [i=1:I, k=1:K],
    sum(r_i_j[i, j] * y_i_k[i, k] * s_j_k[j, k] for j in 1:J) >= T1 * y_i_k[i, k],
)
    
@constraint(
    model,
    [i=1:I, k=1:K, l=neighbours(k, K)],
    z_i_k[i,l]*y_i_k[i,k] <= T2
    
)
@objective(
    model,
    Min,
    sum(r_i_j) + (N-sum(y_i_k))*penalty
)

optimize!(model)
write_to_file(model, "test.mps")

throwing the error:

MathOptInterface.UnsupportedConstraint{MathOptInterface.ScalarQuadraticFunction{Float64},MathOptInterface.GreaterThan{Float64}}: MathOptInterface.ScalarQuadraticFunction{Float64}-in-MathOptInterface.GreaterThan{Float64} constraint is not supported by the model.

I’m wondering if either (1) I am saving the model using the wrong format, or (2) I am writing a constraint in a fashion that conflicts with any format? This is a bit hard to figure out as a beginner to Julia! Additionally, do not hesitate to point out if I have missed anything on the “Make it easier to help you” thread.

2 Likes

Recently I have converted an ILP from Python to Julia, where I’ve found building the model is significantly faster!

This suggests that your Python code can probably be improved.

I am writing a constraint in a fashion that conflicts with any format

The MPS writer doesn’t support quadratic constraints at present.

Why do you need to write it to file? If necessary, you can use the Gurobi file writer:

model = direct_model(Gurobi.Optimizer())  # <-- Make sure to use `direct_model`
# ... build model etc...
Gurobi.GRBwrite(backend(model), "test.mps")

do not hesitate to point out if I have missed anything on the “Make it easier to help you”

This is a good question :slight_smile:

1 Like