Trouble using ParametricOptInterface when a parameter appears inside a min() expression in JuMP

Hi everyone!

I’m trying to extend a large (mixed-integer) linear model to handle Parameters, using the ParametricOptInterface.jl package. However, I’m running into an issue when a parameter is used inside a min() function. The solver throws the error Constraints of type MathOptInterface.ScalarNonlinearFunction-in-MathOptInterface.LessThan{Float64} are not supported by the solver.

Here’s a small minimal working example that reproduces the problem:

using JuMP
using HiGHS
using ParametricOptInterface

# Model 
function solve_knapsack_problem(optimizer::Any;
    profit::Vector{Float64},
    weight::Vector{Float64},
    capacity::Int64,
)   
    # The profit and weight vectors must be of equal length.
    n = length(weight)
    @assert length(profit) == n

    # Define the model
    model = Model(optimizer)
    set_silent(model)
    @variable(model, x[1:n], Bin)

    # Is the problem in using a parameter in the RHS?
    @variable(model, capacity in Parameter(capacity))
    @objective(model, Max, profit' * x)

    # CULPRIT
    @constraint(model, weight' * x <= min(capacity, 6))
    optimize!(model)
    assert_is_solved_and_feasible(model)

    # Check that everything is consistent
    println("Objective is: ", objective_value(model))
    println("Solution is:")
    for i in 1:n
        print("x[$i] = ", round(Int, value(x[i])))
        println(", c[$i] / w[$i] = ", value(model[:profit][i]) / weight[i])
    end

    return nothing
end

# Settings of the problem
n = 5;
capacity = 10;
profit = [5.0, 3.0, 2.0, 7.0, 4.0];
weight = [2.0, 8.0, 4.0, 2.0, 5.0];

# Define the optimizer
opt = () -> ParametricOptInterface.Optimizer(MOI.instantiate(HiGHS.Optimizer));

solve_knapsack_problem(opt; profit = profit, weight = weight, capacity = capacity)

Julia is version 1.11.3, and the loaded packages are:

  [87dc4568] HiGHS v1.20.0
  [4076af6c] JuMP v1.29.2
  [0ce4ce61] ParametricOptInterface v0.14.1

Thanks!

1 Like

Hi @leo.ch.97, welcome to the forum :smile:

Unfortunately, this is expected behaviour for now. JuMP’s “parameters” are really fixed decision variables in disguise.

As a work-around, change

@constraint(model, weight' * x <= min(capacity, 6))

to

@constraint(model, weight' * x <= capacity)
@constraint(model, weight' * x <= 6)
2 Likes

Thanks a lot for the solution!

1 Like