Compatibility of Gurobi.jl and Interpolations.jl in Julia
AnsweredHi,
I am suing simple interpolation within a optimization problem using Gurobi.jl (in Julia).
I have a 3*3 grid value matrix Val_grid.
Then I implemented this simple code:
i_values = [1.0, 1.2, 1.3]
j_values = [1.0, 1.2, 1.3]
interp = interpolate((i_values, j_values), Val_grid, Gridded(Linear()))
Forward_model = Model(Gurobi.Optimizer)
@variable(Forward_model, x, lower_bound = 1, upper_bound = 1.3)
@variable(Forward_model, y, lower_bound = 1, upper_bound = 1.3)
@objective(Forward_model, Min, 1.5*x + 1.3*y + interp(x, y))
optimize!(Forward_model)
As it is obvious, it is a very simple optimization problem in which the objective function is not linear due to the interpolation.
When I run this code I get this error:
MethodError: no method matching (::Interpolations.GriddedInterpolation{Float64, 2, Matrix{Float64}, Gridded{Linear{Throw{OnGrid}}}, Tuple{Vector{Float64}, Vector{Float64}}})(::VariableRef, ::VariableRef)
Use square brackets [] for indexing an Array.
But I cannot use my variables as indexes. So I wanted to ask if Gurobi can work with interpolation functions or not; and what is your suggestion in my case
Thanks
-
Hi,
This is a general JuMP question as it doesn't depend on the solver.
Cross-reference: https://discourse.julialang.org/t/interpolation/106382
As discussed in the thread, this can be done using PiecewiseLinearOpt.jl.Cheers,
David0
Please sign in to leave a comment.
Comments
1 comment