diff --git a/README.md b/README.md index b45da9b0..9c51660d 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ using JuMP, HiGHS import ParametricOptInterface as POI model = Model(() -> POI.Optimizer(HiGHS.Optimizer())) @variable(model, x) -@variable(model, p in POI.Parameter(1.0)) +@variable(model, p in MOI.Parameter(1.0)) @constraint(model, cons, x + p >= 3) @objective(model, Min, 2x) optimize!(model) diff --git a/benchmark/MOI_benchmarks.jl b/benchmark/MOI_benchmarks.jl index 60386540..c9a1e8a6 100644 --- a/benchmark/MOI_benchmarks.jl +++ b/benchmark/MOI_benchmarks.jl @@ -117,7 +117,7 @@ function generate_poi_problem(model, data::PMedianData, add_parameters::Bool) if add_parameters d, cd = MOI.add_constrained_variable( model, - POI.Parameter(data.num_facilities), + MOI.Parameter(data.num_facilities), ) end diff --git a/benchmark/run_benchmarks.jl b/benchmark/run_benchmarks.jl index 3ca572a2..fd4b2943 100644 --- a/benchmark/run_benchmarks.jl +++ b/benchmark/run_benchmarks.jl @@ -24,14 +24,14 @@ end function poi_add_parameters(N::Int) model = POI.Optimizer(MOI.Utilities.Model{Float64}()) - MOI.add_constrained_variable.(model, POI.Parameter.(ones(N))) + MOI.add_constrained_variable.(model, MOI.Parameter.(ones(N))) return nothing end function poi_add_parameters_and_variables(N::Int) model = POI.Optimizer(MOI.Utilities.Model{Float64}()) MOI.add_variables(model, N / 2) - MOI.add_constrained_variable.(model, POI.Parameter.(ones(Int(N / 2)))) + MOI.add_constrained_variable.(model, MOI.Parameter.(ones(Int(N / 2)))) return nothing end @@ -39,7 +39,7 @@ function poi_add_parameters_and_variables_alternating(N::Int) model = POI.Optimizer(MOI.Utilities.Model{Float64}()) for i in 1:Int(N / 2) MOI.add_variable(model) - MOI.add_constrained_variable(model, POI.Parameter(1)) + MOI.add_constrained_variable(model, MOI.Parameter(1.0)) end return nothing end @@ -77,7 +77,7 @@ function poi_add_saf_variables_and_parameters_ctr(N::Int, M::Int) first.( MOI.add_constrained_variable.( model, - POI.Parameter.(ones(Int(N / 2))), + MOI.Parameter.(ones(Int(N / 2))), ) ) for _ in 1:M @@ -103,7 +103,7 @@ function poi_add_saf_variables_and_parameters_ctr_parameter_update( first.( MOI.add_constrained_variable.( model, - POI.Parameter.(ones(Int(N / 2))), + MOI.Parameter.(ones(Int(N / 2))), ) ) for _ in 1:M @@ -162,7 +162,7 @@ function poi_add_sqf_variables_parameters_ctr(N::Int, M::Int) first.( MOI.add_constrained_variable.( model, - POI.Parameter.(ones(Int(N / 2))), + MOI.Parameter.(ones(Int(N / 2))), ) ) for _ in 1:M @@ -186,7 +186,7 @@ function poi_add_sqf_variables_parameters_ctr_parameter_update(N::Int, M::Int) first.( MOI.add_constrained_variable.( model, - POI.Parameter.(ones(Int(N / 2))), + MOI.Parameter.(ones(Int(N / 2))), ) ) for _ in 1:M @@ -212,7 +212,7 @@ function poi_add_sqf_parameters_parameters_ctr(N::Int, M::Int) first.( MOI.add_constrained_variable.( model, - POI.Parameter.(ones(Int(N / 2))), + MOI.Parameter.(ones(Int(N / 2))), ) ) for _ in 1:M @@ -236,7 +236,7 @@ function poi_add_sqf_parameters_parameters_ctr_parameter_update(N::Int, M::Int) first.( MOI.add_constrained_variable.( model, - POI.Parameter.(ones(Int(N / 2))), + MOI.Parameter.(ones(Int(N / 2))), ) ) for _ in 1:M @@ -288,7 +288,7 @@ function poi_add_saf_variables_and_parameters_obj(N::Int, M::Int) first.( MOI.add_constrained_variable.( model, - POI.Parameter.(ones(Int(N / 2))), + MOI.Parameter.(ones(Int(N / 2))), ) ) for _ in 1:M @@ -314,7 +314,7 @@ function poi_add_saf_variables_and_parameters_obj_parameter_update( first.( MOI.add_constrained_variable.( model, - POI.Parameter.(ones(Int(N / 2))), + MOI.Parameter.(ones(Int(N / 2))), ) ) for _ in 1:M @@ -375,7 +375,7 @@ function poi_add_sqf_variables_parameters_obj(N::Int, M::Int) first.( MOI.add_constrained_variable.( model, - POI.Parameter.(ones(Int(N / 2))), + MOI.Parameter.(ones(Int(N / 2))), ) ) for _ in 1:M @@ -399,7 +399,7 @@ function poi_add_sqf_variables_parameters_obj_parameter_update(N::Int, M::Int) first.( MOI.add_constrained_variable.( model, - POI.Parameter.(ones(Int(N / 2))), + MOI.Parameter.(ones(Int(N / 2))), ) ) for _ in 1:M @@ -427,7 +427,7 @@ function poi_add_sqf_parameters_parameters_obj(N::Int, M::Int) first.( MOI.add_constrained_variable.( model, - POI.Parameter.(ones(Int(N / 2))), + MOI.Parameter.(ones(Int(N / 2))), ) ) for _ in 1:M @@ -451,7 +451,7 @@ function poi_add_sqf_parameters_parameters_obj_parameter_update(N::Int, M::Int) first.( MOI.add_constrained_variable.( model, - POI.Parameter.(ones(Int(N / 2))), + MOI.Parameter.(ones(Int(N / 2))), ) ) for _ in 1:M diff --git a/benchmark/run_benchmarks_jump.jl b/benchmark/run_benchmarks_jump.jl index 9ddc49e9..fe95b743 100644 --- a/benchmark/run_benchmarks_jump.jl +++ b/benchmark/run_benchmarks_jump.jl @@ -43,7 +43,7 @@ function poi_add_parameters(N::Int) ), ), ) - @variable(model, x[i = 1:N] in POI.Parameter(1)) + @variable(model, x[i = 1:N] in MOI.Parameter(1.0)) return nothing end @@ -56,7 +56,7 @@ function poi_add_parameters_and_variables(N::Int) ), ), ) - @variable(model, x[i = 1:N] in POI.Parameter(1)) + @variable(model, x[i = 1:N] in MOI.Parameter(1.0)) return nothing end @@ -71,7 +71,7 @@ function poi_add_parameters_and_variables_alternating(N::Int) ) for i in 1:Int(N / 2) @variable(model) - @variable(model, set = POI.Parameter(1)) + @variable(model, set = MOI.Parameter(1.0)) end return nothing end @@ -112,7 +112,7 @@ function poi_add_saf_variables_and_parameters_ctr(N::Int, M::Int) ), ) @variable(model, x[i = 1:Int(N / 2)]) - @variable(model, p[i = 1:Int(N / 2)] in POI.Parameter.(0)) + @variable(model, p[i = 1:Int(N / 2)] in MOI.Parameter.(0)) @constraint(model, con[i = 1:M], sum(x) + sum(p) >= 1) return nothing end @@ -130,7 +130,7 @@ function poi_add_saf_variables_and_parameters_ctr_parameter_update( ), ) @variable(model, x[i = 1:Int(N / 2)]) - @variable(model, p[i = 1:Int(N / 2)] in POI.Parameter.(0)) + @variable(model, p[i = 1:Int(N / 2)] in MOI.Parameter.(0)) @constraint(model, con[i = 1:M], sum(x) + sum(p) >= 1) MOI.set.(model, POI.ParameterValue(), p, 0.5) POI.update_parameters!(backend(model)) @@ -173,7 +173,7 @@ function poi_add_sqf_variables_parameters_ctr(N::Int, M::Int) ), ) @variable(model, x[i = 1:Int(N / 2)]) - @variable(model, p[i = 1:Int(N / 2)] in POI.Parameter.(1)) + @variable(model, p[i = 1:Int(N / 2)] in MOI.Parameter.(1)) @constraint(model, con[i = 1:M], dot(x, p) >= 1) return nothing end @@ -188,7 +188,7 @@ function poi_add_sqf_variables_parameters_ctr_parameter_update(N::Int, M::Int) ), ) @variable(model, x[i = 1:Int(N / 2)]) - @variable(model, p[i = 1:Int(N / 2)] in POI.Parameter.(1)) + @variable(model, p[i = 1:Int(N / 2)] in MOI.Parameter.(1)) @constraint(model, con[i = 1:M], dot(x, p) >= 1) MOI.set.(model, POI.ParameterValue(), p, 0.5) POI.update_parameters!(backend(model)) @@ -205,7 +205,7 @@ function poi_add_sqf_parameters_parameters_ctr(N::Int, M::Int) ), ) @variable(model, x[i = 1:Int(N / 2)]) - @variable(model, p[i = 1:Int(N / 2)] in POI.Parameter.(1)) + @variable(model, p[i = 1:Int(N / 2)] in MOI.Parameter.(1)) @constraint(model, con[i = 1:M], dot(p, p) >= 1) return nothing end @@ -220,7 +220,7 @@ function poi_add_sqf_parameters_parameters_ctr_parameter_update(N::Int, M::Int) ), ) @variable(model, x[i = 1:Int(N / 2)]) - @variable(model, p[i = 1:Int(N / 2)] in POI.Parameter.(1)) + @variable(model, p[i = 1:Int(N / 2)] in MOI.Parameter.(1)) @constraint(model, con[i = 1:M], dot(p, p) >= 1) MOI.set.(model, POI.ParameterValue(), p, 0.5) POI.update_parameters!(backend(model)) @@ -265,7 +265,7 @@ function poi_add_saf_variables_and_parameters_obj(N::Int, M::Int) ), ) @variable(model, x[i = 1:Int(N / 2)]) - @variable(model, p[i = 1:Int(N / 2)] in POI.Parameter.(1)) + @variable(model, p[i = 1:Int(N / 2)] in MOI.Parameter.(1)) for _ in 1:M @objective(model, Min, sum(x) + sum(p)) end @@ -285,7 +285,7 @@ function poi_add_saf_variables_and_parameters_obj_parameter_update( ), ) @variable(model, x[i = 1:Int(N / 2)]) - @variable(model, p[i = 1:Int(N / 2)] in POI.Parameter.(1)) + @variable(model, p[i = 1:Int(N / 2)] in MOI.Parameter.(1)) for _ in 1:M @objective(model, Min, sum(x) + sum(p)) end @@ -336,7 +336,7 @@ function poi_add_sqf_variables_parameters_obj(N::Int, M::Int) ), ) @variable(model, x[i = 1:Int(N / 2)]) - @variable(model, p[i = 1:Int(N / 2)] in POI.Parameter.(1)) + @variable(model, p[i = 1:Int(N / 2)] in MOI.Parameter.(1)) for _ in 1:M @objective(model, Min, dot(x, p)) end @@ -353,7 +353,7 @@ function poi_add_sqf_variables_parameters_obj_parameter_update(N::Int, M::Int) ), ) @variable(model, x[i = 1:Int(N / 2)]) - @variable(model, p[i = 1:Int(N / 2)] in POI.Parameter.(1)) + @variable(model, p[i = 1:Int(N / 2)] in MOI.Parameter.(1)) for _ in 1:M @objective(model, Min, dot(x, p)) end @@ -374,7 +374,7 @@ function poi_add_sqf_parameters_parameters_obj(N::Int, M::Int) ), ) @variable(model, x[i = 1:Int(N / 2)]) - @variable(model, p[i = 1:Int(N / 2)] in POI.Parameter.(1)) + @variable(model, p[i = 1:Int(N / 2)] in MOI.Parameter.(1)) for _ in 1:M @objective(model, Min, dot(p, p)) end @@ -391,7 +391,7 @@ function poi_add_sqf_parameters_parameters_obj_parameter_update(N::Int, M::Int) ), ) @variable(model, x[i = 1:Int(N / 2)]) - @variable(model, p[i = 1:Int(N / 2)] in POI.Parameter.(1)) + @variable(model, p[i = 1:Int(N / 2)] in MOI.Parameter.(1)) for _ in 1:M @objective(model, Min, dot(p, p)) end diff --git a/benchmark/run_benders_quantile_regression_benchmark.jl b/benchmark/run_benders_quantile_regression_benchmark.jl index fcebb0c5..7765efec 100644 --- a/benchmark/run_benders_quantile_regression_benchmark.jl +++ b/benchmark/run_benders_quantile_regression_benchmark.jl @@ -142,7 +142,7 @@ function slave_model(PARAM, K) @variable(slave, β[i = 1:N_Candidates] == 0, Param()) elseif PARAM == 1 # Create parameters - @variable(slave, β[i = 1:N_Candidates] in POI.Parameter.(0)) + @variable(slave, β[i = 1:N_Candidates] in MOI.Parameter.(0.0)) else # Create fixed variables @variables(slave, begin diff --git a/docs/src/Examples/benders.md b/docs/src/Examples/benders.md index 5b707214..2fb10ace 100644 --- a/docs/src/Examples/benders.md +++ b/docs/src/Examples/benders.md @@ -153,7 +153,7 @@ function inner_model(K) # create the regression coefficient representation # Create parameters - β = [@variable(inner, set = POI.Parameter(0)) for i in 1:N_Candidates] + β = [@variable(inner, set = MOI.Parameter(0.0)) for i in 1:N_Candidates] for (i, βi) in enumerate(β) set_name(βi, "β[$i]") end diff --git a/docs/src/Examples/example.md b/docs/src/Examples/example.md index 0d9fc4df..db7428be 100644 --- a/docs/src/Examples/example.md +++ b/docs/src/Examples/example.md @@ -26,12 +26,12 @@ for x_i in x end ``` -Now, let's consider 3 [`ParametricOptInterface.Parameter`](@ref). Two of them, `y`, `z`, will be placed in the constraints and one, `w`, in the objective function. We'll start all three of them with a value equal to `0`: +Now, let's consider 3 `MathOptInterface.Parameter`. Two of them, `y`, `z`, will be placed in the constraints and one, `w`, in the objective function. We'll start all three of them with a value equal to `0`: ```@example moi1 -w, cw = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) -y, cy = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) -z, cz = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) +w, cw = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) +y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) +z, cz = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) ``` Let's add the constraints. Notice that we treat parameters and variables in the same way when building the functions that will be placed in some set to create a constraint (`Function-in-Set`): @@ -146,12 +146,12 @@ We declare the variable `x` as in a typical `JuMP` model: @variable(model, x[i = 1:2] >= 0) ``` -Now, let's consider 3 [`ParametricOptInterface.Parameter`](@ref). Two of them, `y`, `z`, will be placed in the constraints and one, `w`, in the objective function. We'll start all three of them with a value equal to `0`: +Now, let's consider 3 `MathOptInterface.Parameter`. Two of them, `y`, `z`, will be placed in the constraints and one, `w`, in the objective function. We'll start all three of them with a value equal to `0`: ```@example jump1 -@variable(model, y in ParametricOptInterface.Parameter(0)) -@variable(model, z in ParametricOptInterface.Parameter(0)) -@variable(model, w in ParametricOptInterface.Parameter(0)) +@variable(model, y in MathOptInterface.Parameter(0.0)) +@variable(model, z in MathOptInterface.Parameter(0.0)) +@variable(model, w in MathOptInterface.Parameter(0.0)) ``` Let's add the constraints. Notice that we treat parameters the same way we treat variables when writing the model: @@ -246,9 +246,9 @@ const POI = ParametricOptInterface model = Model(() -> ParametricOptInterface.Optimizer(HiGHS.Optimizer())) @variable(model, x[i = 1:3] >= 0) -@variable(model, p1[i = 1:3] in ParametricOptInterface.Parameter(0)) -@variable(model, p2[i = 1:3] in ParametricOptInterface.Parameter.([1, 10, 45])) -@variable(model, p3[i = 1:3] in ParametricOptInterface.Parameter.(ones(3))) +@variable(model, p1[i = 1:3] in MathOptInterface.Parameter(0.0)) +@variable(model, p2[i = 1:3] in MathOptInterface.Parameter.([1, 10, 45])) +@variable(model, p3[i = 1:3] in MathOptInterface.Parameter.(ones(3))) ``` ## JuMP Example - Dealing with parametric expressions as variable bounds @@ -263,7 +263,7 @@ const POI = ParametricOptInterface model = direct_model(POI.Optimizer(HiGHS.Optimizer())) @variable(model, x) -@variable(model, p in POI.Parameter(0.0)) +@variable(model, p in MOI.Parameter(0.0)) @constraint(model, x >= p) ``` @@ -288,7 +288,7 @@ const POI = ParametricOptInterface model = direct_model(POI.Optimizer(HiGHS.Optimizer())) @variable(model, x) -@variable(model, p in POI.Parameter(0.0)) +@variable(model, p in MOI.Parameter(0.0)) # Indicate that all the new constraints will be valid variable bounds MOI.set(model, POI.ConstraintsInterpretation(), POI.ONLY_BOUNDS) @@ -357,7 +357,7 @@ To multiply a parameter in a quadratic term, the user will need to use the `POI.QuadraticObjectiveCoef` model attribute. ```@example moi2 -p = first(MOI.add_constrained_variable.(optimizer, POI.Parameter(1.0))) +p = first(MOI.add_constrained_variable.(optimizer, MOI.Parameter(1.0))) MOI.set(optimizer, POI.QuadraticObjectiveCoef(), (x,y), p) ``` @@ -403,7 +403,7 @@ model = direct_model(optimizer) @variable(model, x >= 0) @variable(model, y >= 0) -@variable(model, p in POI.Parameter(1.0)) +@variable(model, p in MOI.Parameter(1.0)) @constraint(model, 2x + y <= 4) @constraint(model, x + 2y <= 4) @objective(model, Max, (x^2 + y^2)/2) @@ -447,7 +447,7 @@ POI currently works with NLPs when users wish to add the parameters to the non-N ```julia @variable(model, x) @variable(model, y) -@variable(model, z in POI.Parameter(10)) +@variable(model, z in MOI.Parameter(10)) @constraint(model, x + y >= z) @NLobjective(model, Min, x^2 + y^2) ``` @@ -457,7 +457,7 @@ but does not work with models that have parameters on the NL expressions like th ```julia @variable(model, x) @variable(model, y) -@variable(model, z in POI.Parameter(10)) +@variable(model, z in MOI.Parameter(10)) @constraint(model, x + y >= z) @NLobjective(model, Min, x^2 + y^2 + z) # There is a parameter here ``` @@ -481,7 +481,7 @@ POI_cached_optimizer() = POI.Optimizer(cached()) model = Model(() -> POI_cached_optimizer()) @variable(model, x) @variable(model, y) -@variable(model, z in POI.Parameter(10)) +@variable(model, z in MOI.Parameter(10)) @constraint(model, x + y >= z) @NLobjective(model, Min, x^2 + y^2) ``` @@ -493,7 +493,7 @@ If users wish to make modifications on variable bounds the POI interface will he ```julia model = Model(() -> POI.Optimizer(Ipopt.Optimizer())) @variable(model, x) -@variable(model, z in POI.Parameter(10)) +@variable(model, z in MOI.Parameter(10)) MOI.set(model, POI.ConstraintsInterpretation(), POI.ONLY_BOUNDS) @constraint(model, x >= z) @NLobjective(model, Min, x^2) diff --git a/docs/src/Examples/markowitz.md b/docs/src/Examples/markowitz.md index 73d4fcd0..800fd595 100644 --- a/docs/src/Examples/markowitz.md +++ b/docs/src/Examples/markowitz.md @@ -47,7 +47,7 @@ function first_model(μ,Σ) N = length(μ) @variable(portfolio, x[1:N] >= 0) - @variable(portfolio, γ in POI.Parameter(0.0)) + @variable(portfolio, γ in MOI.Parameter(0.0)) @objective(portfolio, Max, γ*dot(μ,x) - x' * Σ * x) @constraint(portfolio, sum(x) == 1) diff --git a/docs/src/manual.md b/docs/src/manual.md index 696aff6d..7ac73354 100644 --- a/docs/src/manual.md +++ b/docs/src/manual.md @@ -56,22 +56,26 @@ optimizer = POI.Optimizer(HiGHS.Optimizer()) ### Parameters -A [`ParametricOptInterface.Parameter`](@ref) is a variable with a fixed value that can be changed by the user. +A `MathOptInterface.Parameter` is a set used to define a variable with a fixed value that +can be changed by the user. It is analogous to `MathOptInterface.EqualTo`, but can be used +by special methods like the ones in this package to remove the fixed variable from the +optimization problem. This permits the usage of multiplicative parameters in lienar models +and might speedup solves since the number of variables is reduced. ### Adding a new parameter to a model -To add a parameter to a model, we must use the `MOI.add_constrained_variable()` function, passing as its arguments the model and a [`ParametricOptInterface.Parameter`](@ref) with its given value: +To add a parameter to a model, we must use the `MOI.add_constrained_variable()` function, passing as its arguments the model and a `MathOptInterface.Parameter` with its given value: ```julia -y, cy = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) +y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) ``` ### Changing the parameter value -To change a given parameter's value, access its `VariableIndex` and set it to the new value using the [`ParametricOptInterface.Parameter`](@ref) structure. +To change a given parameter's value, access its `VariableIndex` and set it to the new value using the `MathOptInterface.Parameter` structure. ```julia -MOI.set(optimizer, POI.ParameterValue(), y, POI.Parameter(2.0)) +MOI.set(optimizer, POI.ParameterValue(), y, MOI.Parameter(2.0)) ``` ### Retrieving the dual of a parameter diff --git a/docs/src/reference.md b/docs/src/reference.md index a978374a..acb5eba3 100644 --- a/docs/src/reference.md +++ b/docs/src/reference.md @@ -3,7 +3,6 @@ ```@docs ParametricOptInterface.ConstraintsInterpretation ParametricOptInterface.Optimizer -ParametricOptInterface.Parameter ParametricOptInterface.ParameterDual ParametricOptInterface.ParameterValue ``` \ No newline at end of file diff --git a/src/ParametricOptInterface.jl b/src/ParametricOptInterface.jl index 6e43f98d..cca9137a 100644 --- a/src/ParametricOptInterface.jl +++ b/src/ParametricOptInterface.jl @@ -16,22 +16,22 @@ const PARAMETER_INDEX_THRESHOLD = Int64(4_611_686_018_427_387_904) # div(typemax const SIMPLE_SCALAR_SETS{T} = Union{MOI.LessThan{T},MOI.GreaterThan{T},MOI.EqualTo{T}} -""" - Parameter(val::Float64) +# """ +# Parameter(val::Float64) -The `Parameter` structure stores the numerical value associated to a given -parameter. +# The `Parameter` structure stores the numerical value associated to a given +# parameter. -## Example +# ## Example -```julia-repl -julia> ParametricOptInterface.Parameter(5) -ParametricOptInterface.Parameter(5) -``` -""" -struct Parameter <: MOI.AbstractScalarSet - val::Float64 -end +# ```julia-repl +# julia> MathOptInterface.Parameter(5.0) +# MathOptInterface.Parameter(5.0) +# ``` +# """ +# struct Parameter <: MOI.AbstractScalarSet +# val::Float64 +# end # Utilities for using a CleverDict in Parameters struct ParameterIndex @@ -642,6 +642,17 @@ function MOI.get( return MOI.get(model.optimizer, attr, ci) end end +function MOI.get( + model::Optimizer{T}, + ::MOI.ConstraintFunction, + cp::MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{T}}, +) where {T} + p = MOI.VariableIndex(cp.value) + if !is_parameter_in_model(model, p) + error("Parameter not in the model") + end + return p +end function MOI.get( model::Optimizer, @@ -751,7 +762,9 @@ function MOI.get( model::Optimizer, ::MOI.ListOfConstraintIndices{F,S}, ) where {S,F} - return collect(values(model.constraint_outer_to_inner[F, S])) + list = collect(values(model.constraint_outer_to_inner[F, S])) + sort!(list, lt = (x, y)->(x.value < y.value)) + return list end function MOI.get( @@ -761,7 +774,10 @@ function MOI.get( return length(model.constraint_outer_to_inner[F, S]) end -function MOI.supports_add_constrained_variable(::Optimizer, ::Type{Parameter}) +function MOI.supports_add_constrained_variable( + ::Optimizer{T}, + ::Type{MOI.Parameter{T}}, +) where {T} return true end @@ -780,11 +796,11 @@ function MOI.add_variable(model::Optimizer) ) end -function MOI.add_constrained_variable(model::Optimizer, set::Parameter) +function MOI.add_constrained_variable(model::Optimizer{T}, set::MOI.Parameter{T}) where {T} next_parameter_index!(model) p = MOI.VariableIndex(model.last_parameter_index_added) - MOI.Utilities.CleverDicts.add_item(model.parameters, set.val) - cp = MOI.ConstraintIndex{MOI.VariableIndex,Parameter}( + MOI.Utilities.CleverDicts.add_item(model.parameters, set.value) + cp = MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{T}}( model.last_parameter_index_added, ) _add_to_constraint_map!(model, cp) @@ -951,16 +967,32 @@ function MOI.get( end function MOI.set( - model::Optimizer, + model::Optimizer{T}, ::MOI.ConstraintSet, - cp::MOI.ConstraintIndex{MOI.VariableIndex,Parameter}, - set::Parameter, -) + cp::MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{T}}, + set::MOI.Parameter{T}, +) where {T} p = MOI.VariableIndex(cp.value) if !is_parameter_in_model(model, p) error("Parameter not in the model") end - return model.updated_parameters[p_idx(p)] = set.val + return model.updated_parameters[p_idx(p)] = set.value +end + +function MOI.get( + model::Optimizer{T}, + ::MOI.ConstraintSet, + cp::MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{T}}, +) where {T} + p = MOI.VariableIndex(cp.value) + if !is_parameter_in_model(model, p) + error("Parameter not in the model") + end + val = model.updated_parameters[p_idx(p)] + if isnan(val) + return MOI.Parameter{T}(model.parameters[p_idx(p)]) + end + return MOI.Parameter{T}(val) end """ @@ -987,8 +1019,8 @@ function MOI.set( var::MOI.VariableIndex, val::Float64, ) - ci = MOI.ConstraintIndex{MOI.VariableIndex,Parameter}(var.value) - set = MOI.set(opt, MOI.ConstraintSet(), ci, Parameter(val)) + ci = MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{Float64}}(var.value) + set = MOI.set(opt, MOI.ConstraintSet(), ci, MOI.Parameter(val)) return nothing end @@ -998,8 +1030,8 @@ function MOI.set( var::MOI.VariableIndex, val::Float64, ) - ci = MOI.ConstraintIndex{MOI.VariableIndex,Parameter}(var.value) - set = MOI.set(model, MOI.ConstraintSet(), ci, Parameter(val)) + ci = MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{Float64}}(var.value) + set = MOI.set(model, MOI.ConstraintSet(), ci, MOI.Parameter(val)) return nothing end @@ -1026,9 +1058,9 @@ function MOI.get( ::ParameterValue, var::MOI.VariableIndex, ) - ci = MOI.ConstraintIndex{MOI.VariableIndex,Parameter}(var.value) + ci = MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{Float64}}(var.value) set = MOI.get(opt, MOI.ConstraintSet(), ci) - return set.val + return set.value end function MOI.get(model::Optimizer, ::ParameterValue, var::MOI.VariableIndex) @@ -1309,6 +1341,23 @@ function MOI.delete(model::Optimizer, v::MOI.VariableIndex) MOI.delete(model.original_objective_cache, v) # TODO - what happens if the variable was in a SAF that was converted to bounds? # solution: do not allow if that is the case (requires going trhought the scalar affine cache) + # TODO - deleting a variable also deletes constraints + for (F, S) in MOI.Utilities.DoubleDicts.nonempty_outer_keys(model.constraint_outer_to_inner) + _delete_variable_index_constraint(model.constraint_outer_to_inner, F, S, v.value) + end + return +end + +function _delete_variable_index_constraint(d, F, S, v) + return +end +function _delete_variable_index_constraint(d, F::Type{MOI.VariableIndex}, S, value) + inner = d[F, S] + for k in keys(inner) + if k.value == value + delete!(inner, k) + end + end return end @@ -1335,14 +1384,14 @@ function MOI.delete( ) where {F<:MOI.ScalarAffineFunction,S<:MOI.AbstractSet} if haskey(model.affine_outer_to_inner, c) ci_inner = model.affine_outer_to_inner[c] - deleteat!(model.affine_outer_to_inner, c) - deleteat!(model.affine_constraint_cache, c) - deleteat!(model.affine_constraint_cache_set, c) + delete!(model.affine_outer_to_inner, c) + delete!(model.affine_constraint_cache, c) + delete!(model.affine_constraint_cache_set, c) MOI.delete(model.optimizer, ci_inner) else MOI.delete(model.optimizer, c) end - deleteat!(model.constraint_outer_to_inner, c) + delete!(model.constraint_outer_to_inner, c) return end @@ -1351,6 +1400,7 @@ function MOI.delete( c::MOI.ConstraintIndex{F,S}, ) where {F<:Union{MOI.VariableIndex,MOI.VectorOfVariables},S<:MOI.AbstractSet} MOI.delete(model.optimizer, c) + delete!(model.constraint_outer_to_inner, c) return end @@ -1359,6 +1409,7 @@ function MOI.delete( c::MOI.ConstraintIndex{F,S}, ) where {F<:MOI.VectorAffineFunction,S<:MOI.AbstractSet} MOI.delete(model.optimizer, c) + delete!(model.constraint_outer_to_inner, c) deleteat!(model.vector_affine_constraint_cache, c) return end @@ -1520,13 +1571,13 @@ function _poi_default_copy_to(dest::T, src::MOI.ModelLike) where {T} Any[ MOI.get(src, MOI.ListOfConstraintIndices{F,S}()) for (F, S) in MOI.get(src, MOI.ListOfConstraintTypesPresent()) if - MOI.Utilities._is_variable_function(F) && S != Parameter + MOI.Utilities._is_variable_function(F) && S != MOI.Parameter{Float64} ], Any[MOI.Utilities._try_constrain_variables_on_creation( dest, src, index_map, - Parameter, + MOI.Parameter{Float64}, )], ) else diff --git a/src/duals.jl b/src/duals.jl index 7c2140b1..5cf12495 100644 --- a/src/duals.jl +++ b/src/duals.jl @@ -107,10 +107,10 @@ struct ParameterDual <: MOI.AbstractVariableAttribute end MOI.is_set_by_optimize(::ParametricOptInterface.ParameterDual) = true -function MOI.get(model::Optimizer, ::ParameterDual, v::MOI.VariableIndex) +function MOI.get(model::Optimizer{T}, ::ParameterDual, v::MOI.VariableIndex) where {T} if !is_additive( model, - MOI.ConstraintIndex{MOI.VariableIndex,Parameter}(v.value), + MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{T}}(v.value), ) error("Cannot compute the dual of a multiplicative parameter") end @@ -118,10 +118,10 @@ function MOI.get(model::Optimizer, ::ParameterDual, v::MOI.VariableIndex) end function MOI.get( - model::Optimizer, + model::Optimizer{T}, ::MOI.ConstraintDual, - cp::MOI.ConstraintIndex{MOI.VariableIndex,Parameter}, -) + cp::MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{T}}, +) where {T} if !is_additive(model, cp) error("Cannot compute the dual of a multiplicative parameter") end diff --git a/test/jump_tests.jl b/test/jump_tests.jl index 16edf29f..c47a33d7 100644 --- a/test/jump_tests.jl +++ b/test/jump_tests.jl @@ -7,9 +7,9 @@ function test_jump_direct_affine_parameters() optimizer = POI.Optimizer(GLPK.Optimizer()) model = direct_model(optimizer) @variable(model, x[i = 1:2] >= 0) - @variable(model, y in POI.Parameter(0)) - @variable(model, w in POI.Parameter(0)) - @variable(model, z in POI.Parameter(0)) + @variable(model, y in MOI.Parameter(0.0)) + @variable(model, w in MOI.Parameter(0.0)) + @variable(model, z in MOI.Parameter(0.0)) @constraint(model, 2 * x[1] + x[2] + y <= 4) @constraint(model, 1 * x[1] + 2 * x[2] + z <= 4) @objective(model, Max, 4 * x[1] + 3 * x[2] + w) @@ -30,9 +30,9 @@ function test_jump_direct_parameter_times_variable() optimizer = POI.Optimizer(GLPK.Optimizer()) model = direct_model(optimizer) @variable(model, x[i = 1:2] >= 0) - @variable(model, y in POI.Parameter(0)) - @variable(model, w in POI.Parameter(0)) - @variable(model, z in POI.Parameter(0)) + @variable(model, y in MOI.Parameter(0.0)) + @variable(model, w in MOI.Parameter(0.0)) + @variable(model, z in MOI.Parameter(0.0)) @constraint(model, 2 * x[1] + x[2] + y <= 4) @constraint(model, (1 + y) * x[1] + 2 * x[2] + z <= 4) @objective(model, Max, 4 * x[1] + 3 * x[2] + w) @@ -52,9 +52,9 @@ end function test_jump_affine_parameters() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) @variable(model, x[i = 1:2] >= 0) - @variable(model, y in POI.Parameter(0)) - @variable(model, w in POI.Parameter(0)) - @variable(model, z in POI.Parameter(0)) + @variable(model, y in MOI.Parameter(0.0)) + @variable(model, w in MOI.Parameter(0.0)) + @variable(model, z in MOI.Parameter(0.0)) @constraint(model, 2 * x[1] + x[2] + y <= 4) @constraint(model, 1 * x[1] + 2 * x[2] + z <= 4) @objective(model, Max, 4 * x[1] + 3 * x[2] + w) @@ -74,9 +74,9 @@ end function test_jump_parameter_times_variable() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) @variable(model, x[i = 1:2] >= 0) - @variable(model, y in POI.Parameter(0)) - @variable(model, w in POI.Parameter(0)) - @variable(model, z in POI.Parameter(0)) + @variable(model, y in MOI.Parameter(0.0)) + @variable(model, w in MOI.Parameter(0.0)) + @variable(model, z in MOI.Parameter(0.0)) @test MOI.get(model, POI.ParameterValue(), y) == 0 @constraint(model, 2 * x[1] + x[2] + y <= 4) @constraint(model, (1 + y) * x[1] + 2 * x[2] + z <= 4) @@ -104,7 +104,7 @@ function test_jump_constraintfunction_getter() ), ) vx = @variable(model, x[i = 1:2]) - vp = @variable(model, p[i = 1:2] in POI.Parameter.(-1)) + vp = @variable(model, p[i = 1:2] in MOI.Parameter.(-1.0)) c1 = @constraint(model, con, sum(x) + sum(p) >= 1) c2 = @constraint(model, conq, sum(x .* p) >= 1) c3 = @constraint(model, conqa, sum(x .* p) + x[1]^2 + x[1] + p[1] >= 1) @@ -255,14 +255,14 @@ function test_jump_interpret_parameteric_bounds() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) MOI.set(model, POI.ConstraintsInterpretation(), POI.ONLY_BOUNDS) @variable(model, x[i = 1:2]) - @variable(model, p[i = 1:2] in POI.Parameter.(-1)) + @variable(model, p[i = 1:2] in MOI.Parameter.(-1.0)) @constraint(model, [i in 1:2], x[i] >= p[i]) @objective(model, Min, sum(x)) optimize!(model) @test MOI.get(model, MOI.ListOfConstraintTypesPresent()) == Tuple{Type,Type}[ (MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}), - (MOI.VariableIndex, POI.Parameter), + (MOI.VariableIndex, MOI.Parameter{Float64}), ] @test MOI.get( backend(model).optimizer.model.optimizer, @@ -279,14 +279,14 @@ function test_jump_interpret_parameteric_bounds_expression() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) MOI.set(model, POI.ConstraintsInterpretation(), POI.ONLY_BOUNDS) @variable(model, x[i = 1:2]) - @variable(model, p[i = 1:2] in POI.Parameter.(-1)) + @variable(model, p[i = 1:2] in MOI.Parameter.(-1.0)) @constraint(model, [i in 1:2], x[i] >= p[i] + p[1]) @objective(model, Min, sum(x)) optimize!(model) @test MOI.get(model, MOI.ListOfConstraintTypesPresent()) == Tuple{Type,Type}[ (MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}), - (MOI.VariableIndex, POI.Parameter), + (MOI.VariableIndex, MOI.Parameter{Float64}), ] @test MOI.get( backend(model).optimizer.model.optimizer, @@ -303,14 +303,14 @@ function test_jump_direct_interpret_parameteric_bounds() model = direct_model(POI.Optimizer(GLPK.Optimizer())) MOI.set(model, POI.ConstraintsInterpretation(), POI.ONLY_BOUNDS) @variable(model, x[i = 1:2]) - @variable(model, p[i = 1:2] in POI.Parameter.(-1)) + @variable(model, p[i = 1:2] in MOI.Parameter.(-1.0)) @constraint(model, [i in 1:2], x[i] >= p[i]) @objective(model, Min, sum(x)) optimize!(model) @test MOI.get(model, MOI.ListOfConstraintTypesPresent()) == - Tuple{Type,Type}[ - (MOI.VariableIndex, POI.Parameter), + Tuple{Type,Type}[ (MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}), + (MOI.VariableIndex, MOI.Parameter{Float64}), ] @test MOI.get( backend(model).optimizer, @@ -327,22 +327,21 @@ function test_jump_direct_interpret_parameteric_bounds_no_interpretation() model = direct_model(POI.Optimizer(GLPK.Optimizer())) MOI.set(model, POI.ConstraintsInterpretation(), POI.ONLY_CONSTRAINTS) @variable(model, x[i = 1:2]) - @variable(model, p[i = 1:2] in POI.Parameter.(-1)) + @variable(model, p[i = 1:2] in MOI.Parameter.(-1.0)) @constraint(model, [i in 1:2], x[i] >= p[i]) @objective(model, Min, sum(x)) optimize!(model) @test MOI.get(model, MOI.ListOfConstraintTypesPresent()) == - Tuple{Type,Type}[( - MOI.ScalarAffineFunction{Float64}, - MOI.GreaterThan{Float64}, - )] + Tuple{Type,Type}[ + (MOI.ScalarAffineFunction{Float64},MOI.GreaterThan{Float64}), + (MOI.VariableIndex,MOI.Parameter{Float64}), + ] @test MOI.get( backend(model).optimizer, MOI.ListOfConstraintTypesPresent(), - ) == Tuple{Type,Type}[( - MOI.ScalarAffineFunction{Float64}, - MOI.GreaterThan{Float64}, - )] + ) == Tuple{Type,Type}[ + (MOI.ScalarAffineFunction{Float64},MOI.GreaterThan{Float64}), + ] @test objective_value(model) == -2 MOI.set(model, POI.ParameterValue(), p[1], 4.0) optimize!(model) @@ -354,7 +353,7 @@ function test_jump_direct_interpret_parameteric_bounds_change() model = direct_model(POI.Optimizer(GLPK.Optimizer())) MOI.set(model, POI.ConstraintsInterpretation(), POI.ONLY_BOUNDS) @variable(model, x[i = 1:2]) - @variable(model, p[i = 1:2] in POI.Parameter.(-1)) + @variable(model, p[i = 1:2] in MOI.Parameter.(-1.0)) @constraint(model, [i in 1:2], x[i] >= p[i]) @test_throws ErrorException @constraint(model, [i in 1:2], 2x[i] >= p[i]) MOI.set(model, POI.ConstraintsInterpretation(), POI.ONLY_CONSTRAINTS) @@ -372,7 +371,7 @@ function test_jump_direct_interpret_parameteric_bounds_both() model = direct_model(POI.Optimizer(GLPK.Optimizer())) MOI.set(model, POI.ConstraintsInterpretation(), POI.BOUNDS_AND_CONSTRAINTS) @variable(model, x[i = 1:2]) - @variable(model, p[i = 1:2] in POI.Parameter.(-1)) + @variable(model, p[i = 1:2] in MOI.Parameter.(-1.0)) @constraint(model, [i in 1:2], x[i] >= p[i]) @constraint(model, [i in 1:2], 2x[i] >= p[i]) @objective(model, Min, sum(x)) @@ -388,7 +387,7 @@ function test_jump_direct_interpret_parameteric_bounds_invalid() model = direct_model(POI.Optimizer(GLPK.Optimizer())) MOI.set(model, POI.ConstraintsInterpretation(), POI.ONLY_BOUNDS) @variable(model, x[i = 1:2]) - @variable(model, p[i = 1:2] in POI.Parameter.(-1)) + @variable(model, p[i = 1:2] in MOI.Parameter.(-1.0)) @test_throws ErrorException @constraint( model, [i in 1:2], @@ -408,7 +407,7 @@ function test_jump_set_variable_start_value() optimizer = POI.Optimizer(cached) model = direct_model(optimizer) @variable(model, x >= 0) - @variable(model, p in POI.Parameter(0)) + @variable(model, p in MOI.Parameter(0.0)) set_start_value(x, 1.0) @test start_value(x) == 1 err = ErrorException( @@ -423,7 +422,7 @@ function test_jump_direct_get_parameter_value() model = direct_model(POI.Optimizer(GLPK.Optimizer())) @variable(model, x, lower_bound = 0.0, upper_bound = 10.0) @variable(model, y, binary = true) - @variable(model, z, set = POI.Parameter(10)) + @variable(model, z, set = MOI.Parameter(10.0)) c = @constraint(model, 19.0 * x - z + 22.0 * y <= 1.0) @objective(model, Min, x + y) @test MOI.get(model, POI.ParameterValue(), z) == 10 @@ -434,7 +433,7 @@ function test_jump_get_parameter_value() model = Model(() -> ParametricOptInterface.Optimizer(GLPK.Optimizer())) @variable(model, x, lower_bound = 0.0, upper_bound = 10.0) @variable(model, y, binary = true) - @variable(model, z, set = POI.Parameter(10)) + @variable(model, z, set = MOI.Parameter(10)) c = @constraint(model, 19.0 * x - z + 22.0 * y <= 1.0) @objective(model, Min, x + y) @test MOI.get(model, POI.ParameterValue(), z) == 10 @@ -452,7 +451,7 @@ function test_jump_sdp_scalar_parameter() optimizer = POI.Optimizer(cached) m = direct_model(optimizer) set_silent(m) - @variable(m, p in POI.Parameter(0)) + @variable(m, p in MOI.Parameter(0.0)) @variable(m, x[1:2, 1:2], Symmetric) @objective(m, Min, x[1, 1] + x[2, 2]) @constraint(m, LinearAlgebra.Symmetric(x .- [1+p 0; 0 1+p]) in PSDCone()) @@ -476,7 +475,7 @@ function test_jump_sdp_matrix_parameter() m = direct_model(optimizer) set_silent(m) P1 = [1 2; 2 3] - @variable(m, p[1:2, 1:2] in POI.Parameter.(P1)) + @variable(m, p[1:2, 1:2] in MOI.Parameter.(P1)) @variable(m, x[1:2, 1:2], Symmetric) @objective(m, Min, x[1, 1] + x[2, 2]) @constraint(m, LinearAlgebra.Symmetric(x - p) in PSDCone()) @@ -491,7 +490,7 @@ end function test_jump_dual_basic() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) - @variable(model, x[1:2] in POI.Parameter.(ones(2) .* 4.0)) + @variable(model, x[1:2] in MOI.Parameter.(ones(2) .* 4.0)) @variable(model, y[1:6]) @constraint(model, ctr1, 3 * y[1] >= 2 - 7 * x[1]) @objective(model, Min, 5 * y[1]) @@ -506,7 +505,7 @@ end function test_jump_dual_multiplicative_fail() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) @variable(model, x) - @variable(model, p in POI.Parameter(1.0)) + @variable(model, p in MOI.Parameter(1.0)) @constraint(model, cons, x * p >= 3) @objective(model, Min, 2x) optimize!(model) @@ -519,7 +518,7 @@ end function test_jump_dual_objective_min() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) @variable(model, x) - @variable(model, p in POI.Parameter(1.0)) + @variable(model, p in MOI.Parameter(1.0)) @constraint(model, cons, x >= 3 * p) @objective(model, Min, 2x + p) optimize!(model) @@ -530,7 +529,7 @@ end function test_jump_dual_objective_max() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) @variable(model, x) - @variable(model, p in POI.Parameter(1.0)) + @variable(model, p in MOI.Parameter(1.0)) @constraint(model, cons, x >= 3 * p) @objective(model, Max, -2x + p) optimize!(model) @@ -540,7 +539,7 @@ end function test_jump_dual_multiple_parameters_1() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) - @variable(model, x[1:6] in POI.Parameter.(ones(6) .* 4.0)) + @variable(model, x[1:6] in MOI.Parameter.(ones(6) .* 4.0)) @variable(model, y[1:6]) @constraint(model, ctr1, 3 * y[1] >= 2 - 7 * x[3]) @constraint(model, ctr2, 3 * y[1] >= 2 - 7 * x[3]) @@ -574,7 +573,7 @@ end function test_jump_duals_LessThan() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) - @variable(model, α in POI.Parameter(-1.0)) + @variable(model, α in MOI.Parameter(-1.0)) @variable(model, x) cref = @constraint(model, x ≤ α) @objective(model, Max, x) @@ -593,7 +592,7 @@ end function test_jump_duals_EqualTo() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) - @variable(model, α in POI.Parameter(-1.0)) + @variable(model, α in MOI.Parameter(-1.0)) @variable(model, x) cref = @constraint(model, x == α) @objective(model, Max, x) @@ -611,7 +610,7 @@ end function test_jump_duals_GreaterThan() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) - @variable(model, α in POI.Parameter(1.0)) + @variable(model, α in MOI.Parameter(1.0)) MOI.set(model, POI.ParameterValue(), α, -1.0) @variable(model, x) cref = @constraint(model, x >= α) @@ -630,7 +629,7 @@ end function test_jump_dual_multiple_parameters_2() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) - @variable(model, α[1:10] in POI.Parameter.(ones(10))) + @variable(model, α[1:10] in MOI.Parameter.(ones(10))) @variable(model, x) cref = @constraint(model, x == sum(2 * α[i] for i in 1:10)) @objective(model, Min, x) @@ -643,7 +642,7 @@ end function test_jump_dual_mixing_params_and_vars_1() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) - @variable(model, α[1:5] in POI.Parameter.(ones(5))) + @variable(model, α[1:5] in MOI.Parameter.(ones(5))) @variable(model, x) cref = @constraint(model, sum(x for i in 1:5) == sum(2 * α[i] for i in 1:5)) @objective(model, Min, x) @@ -656,7 +655,7 @@ end function test_jump_dual_mixing_params_and_vars_2() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) - @variable(model, α[1:5] in POI.Parameter.(ones(5))) + @variable(model, α[1:5] in MOI.Parameter.(ones(5))) @variable(model, x) cref = @constraint(model, 0.0 == sum(-x + 2 * α[i] for i in 1:5)) @objective(model, Min, x) @@ -669,7 +668,7 @@ end function test_jump_dual_mixing_params_and_vars_3() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) - @variable(model, α[1:5] in POI.Parameter.(ones(5))) + @variable(model, α[1:5] in MOI.Parameter.(ones(5))) @variable(model, x) cref = @constraint(model, 0.0 == sum(-x + 2.0 + 2 * α[i] for i in 1:5)) @objective(model, Min, x) @@ -682,7 +681,7 @@ end function test_jump_dual_add_after_solve() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) - @variable(model, α in POI.Parameter(1.0)) + @variable(model, α in MOI.Parameter(1.0)) MOI.set(model, POI.ParameterValue(), α, -1.0) @variable(model, x) cref = @constraint(model, x <= α) @@ -691,7 +690,7 @@ function test_jump_dual_add_after_solve() @test JuMP.value(x) == -1.0 @test JuMP.dual(cref) == -1.0 @test MOI.get(model, POI.ParameterDual(), α) == -1.0 - @variable(model, b in POI.Parameter(-2.0)) + @variable(model, b in MOI.Parameter(-2.0)) cref = @constraint(model, x <= b) JuMP.optimize!(model) @test JuMP.value(x) == -2.0 @@ -703,7 +702,7 @@ end function test_jump_dual_add_ctr_alaternative() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) - @variable(model, α in POI.Parameter(-1.0)) + @variable(model, α in MOI.Parameter(-1.0)) @variable(model, x) exp = x - α cref = @constraint(model, exp ≤ 0) @@ -717,7 +716,7 @@ end function test_jump_dual_delete_constraint() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) - @variable(model, α in POI.Parameter(-1.0)) + @variable(model, α in MOI.Parameter(-1.0)) @variable(model, x) cref1 = @constraint(model, x ≤ α / 2) cref2 = @constraint(model, x ≤ α) @@ -752,7 +751,7 @@ function test_jump_nlp() model = Model(() -> POI_cached_optimizer()) @variable(model, x) @variable(model, y) - @variable(model, z in ParametricOptInterface.Parameter(10)) + @variable(model, z in MOI.Parameter(10.0)) @constraint(model, x + y >= z) @NLobjective(model, Min, x^2 + y^2) optimize!(model) @@ -767,7 +766,7 @@ function test_jump_nlp() MOI.set(ipopt, MOI.RawOptimizerAttribute("print_level"), 0) model = Model(() -> ParametricOptInterface.Optimizer(ipopt)) @variable(model, x) - @variable(model, z in ParametricOptInterface.Parameter(10)) + @variable(model, z in MOI.Parameter(10.0)) MOI.set( model, ParametricOptInterface.ConstraintsInterpretation(), @@ -806,7 +805,7 @@ function test_jump_direct_vector_parameter_affine_nonnegatives() set_silent(model) @variable(model, x) @variable(model, y) - @variable(model, t in POI.Parameter(5)) + @variable(model, t in MOI.Parameter(5.0)) @constraint(model, [(x - t + 1), (y - t + 2)...] in MOI.Nonnegatives(2)) @objective(model, Min, x + y) optimize!(model) @@ -842,7 +841,7 @@ function test_jump_direct_vector_parameter_affine_nonpositives() set_silent(model) @variable(model, x) @variable(model, y) - @variable(model, t in POI.Parameter(5)) + @variable(model, t in MOI.Parameter(5.0)) @constraint(model, [(-x + t - 1), (-y + t - 2)...] in MOI.Nonpositives(2)) @objective(model, Min, x + y) optimize!(model) @@ -884,7 +883,7 @@ function test_jump_direct_soc_parameters() @variable(model, x) @variable(model, y) @variable(model, t) - @variable(model, p in POI.Parameter(0)) + @variable(model, p in MOI.Parameter(0.0)) @constraint(model, [y - 1 / √2] in MOI.Nonnegatives(1)) @constraint(model, [t - 1] in MOI.Zeros(1)) @constraint(model, [t, (x - p), y...] in SecondOrderCone()) @@ -907,7 +906,7 @@ function test_jump_direct_qp_objective() MOI.set(model, MOI.Silent(), true) @variable(model, x >= 0) @variable(model, y >= 0) - @variable(model, p in POI.Parameter(1.0)) + @variable(model, p in MOI.Parameter(1.0)) @constraint(model, 2x + y <= 4) @constraint(model, x + 2y <= 4) @objective(model, Max, (x^2 + y^2) / 2) @@ -1006,7 +1005,7 @@ function test_jump_direct_rsoc_constraints() @variable(model, x) @variable(model, y) @variable(model, t) - @variable(model, p in POI.Parameter(0)) + @variable(model, p in MOI.Parameter(0.0)) @constraint(model, [y - 1 / √2] in MOI.Nonnegatives(1)) @constraint(model, [t - 1] in MOI.Zeros(1)) @constraint(model, [t, x, y - p] in RotatedSecondOrderCone()) @@ -1031,8 +1030,8 @@ function test_jump_quadratic_interval() MOI.set(model, MOI.Silent(), true) @variable(model, x >= 0) @variable(model, y >= 0) - @variable(model, p in POI.Parameter(10.0)) - @variable(model, q in POI.Parameter(4.0)) + @variable(model, p in MOI.Parameter(10.0)) + @variable(model, q in MOI.Parameter(4.0)) @constraint(model, 0 <= x - p * y + q <= 0) @objective(model, Min, x + y) optimize!(model) @@ -1065,8 +1064,8 @@ function test_jump_quadratic_interval_cached() # MOI.set(model, MOI.Silent(), true) @variable(model, x >= 0) @variable(model, y >= 0) - @variable(model, p in POI.Parameter(10.0)) - @variable(model, q in POI.Parameter(4.0)) + @variable(model, p in MOI.Parameter(10.0)) + @variable(model, q in MOI.Parameter(4.0)) @constraint(model, 0 <= x - p * y + q <= 0) @objective(model, Min, x + y) optimize!(model) @@ -1085,7 +1084,7 @@ end function test_affine_parametric_objective() model = Model(() -> POI.Optimizer(GLPK.Optimizer())) - @variable(model, p in POI.Parameter(1.0)) + @variable(model, p in MOI.Parameter(1.0)) @variable(model, 0 <= x <= 1) @objective(model, Max, (p + 0.5) * x) optimize!(model) diff --git a/test/moi_tests.jl b/test/moi_tests.jl index 8c9057ef..54cb6f65 100644 --- a/test/moi_tests.jl +++ b/test/moi_tests.jl @@ -16,9 +16,9 @@ function test_basic_tests() optimizer = POI.Optimizer(GLPK.Optimizer()) MOI.set(optimizer, MOI.Silent(), true) x = MOI.add_variables(optimizer, 2) - y, cy = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) + y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) z = MOI.VariableIndex(4) - cz = MOI.ConstraintIndex{MOI.VariableIndex,POI.Parameter}(4) + cz = MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{Float64}}(4) for x_i in x MOI.add_constraint(optimizer, x_i, MOI.GreaterThan(0.0)) end @@ -59,12 +59,12 @@ function test_basic_tests() MOI.VariableIndex[MOI.VariableIndex(1), MOI.VariableIndex(2)] @test MOI.get(optimizer, POI.ListOfParameterIndices()) == POI.ParameterIndex[POI.ParameterIndex(1)] - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(1.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(1.0)) @test_throws ErrorException("Parameter not in the model") MOI.set( optimizer, MOI.ConstraintSet(), cz, - POI.Parameter(1.0), + MOI.Parameter(1.0), ) MOI.optimize!(optimizer) @test MOI.get(optimizer, MOI.ObjectiveValue()) == 2 @@ -112,7 +112,7 @@ function test_basic_special_cases_of_getters() for x_i in x MOI.add_constraint(optimizer, x_i, MOI.GreaterThan(0.0)) end - y, cy = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) + y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) quad_terms = MOI.ScalarQuadraticTerm{Float64}[] push!(quad_terms, MOI.ScalarQuadraticTerm(A[1, 1], x[1], y)) push!(quad_terms, MOI.ScalarQuadraticTerm(A[1, 2], x[1], y)) @@ -286,7 +286,7 @@ function test_moi_ListOfConstraintTypesPresent() first.( MOI.add_constrained_variable.( model, - POI.Parameter.(ones(Int(N / 2))), + MOI.Parameter.(ones(Int(N / 2))), ), ) @@ -301,7 +301,10 @@ function test_moi_ListOfConstraintTypesPresent() ) list_ctrs_types = MOI.get(model, MOI.ListOfConstraintTypesPresent()) @test list_ctrs_types == - [(MOI.ScalarQuadraticFunction{Float64}, MOI.GreaterThan{Float64})] + [ + (MOI.ScalarQuadraticFunction{Float64}, MOI.GreaterThan{Float64}), + (MOI.VariableIndex, MOI.Parameter{Float64}) + ] return end @@ -314,9 +317,9 @@ function test_production_problem_example() b2 = 4.0 x = MOI.add_variables(optimizer, length(c)) @test typeof(x[1]) == MOI.VariableIndex - w, cw = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) - y, cy = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) - z, cz = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) + w, cw = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) + y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) + z, cz = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) @test MOI.get(optimizer, MOI.VariablePrimal(), w) == 0 for x_i in x MOI.add_constraint(optimizer, x_i, MOI.GreaterThan(0.0)) @@ -355,9 +358,9 @@ function test_production_problem_example() MOI.get(optimizer, MOI.VariablePrimal(), w) MOI.get(optimizer, MOI.VariablePrimal(), y) MOI.get(optimizer, MOI.VariablePrimal(), z) - MOI.set(optimizer, MOI.ConstraintSet(), cw, POI.Parameter(2.0)) - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(1.0)) - MOI.set(optimizer, MOI.ConstraintSet(), cz, POI.Parameter(1.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cw, MOI.Parameter(2.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(1.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cz, MOI.Parameter(1.0)) MOI.optimize!(optimizer) @test MOI.get(optimizer, MOI.VariablePrimal(), w) == 2.0 @test MOI.get(optimizer, MOI.VariablePrimal(), y) == 1.0 @@ -367,14 +370,14 @@ function test_production_problem_example() @test ≈(MOI.get(optimizer, MOI.ConstraintDual(), cy), 5 / 3, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.ConstraintDual(), cz), 2 / 3, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.ConstraintDual(), cw), -3.0, atol = ATOL) - MOI.set(optimizer, MOI.ConstraintSet(), cw, POI.Parameter(0.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cw, MOI.Parameter(0.0)) MOI.optimize!(optimizer) @test MOI.get(optimizer, MOI.VariablePrimal(), w) == 0.0 @test MOI.get(optimizer, MOI.VariablePrimal(), y) == 1.0 @test MOI.get(optimizer, MOI.VariablePrimal(), z) == 1.0 @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 7, atol = ATOL) @test MOI.get.(optimizer, MOI.VariablePrimal(), x) == [1.0, 1.0] - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(-5.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(-5.0)) MOI.optimize!(optimizer) @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 12.0, atol = ATOL) @test MOI.get.(optimizer, MOI.VariablePrimal(), x) == [3.0, 0.0] @@ -392,9 +395,9 @@ function test_production_problem_example_duals() b2 = 4.0 x = MOI.add_variables(optimizer, length(c)) @test typeof(x[1]) == MOI.VariableIndex - w, cw = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) - y, cy = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) - z, cz = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) + w, cw = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) + y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) + z, cz = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) @test MOI.get(optimizer, MOI.VariablePrimal(), w) == 0 for x_i in x MOI.add_constraint(optimizer, x_i, MOI.GreaterThan(0.0)) @@ -440,23 +443,23 @@ function test_production_problem_example_duals() -0.5 * MOI.get(optimizer, MOI.ConstraintDual(), ci2), atol = 1e-4, ) - MOI.set(optimizer, MOI.ConstraintSet(), cw, POI.Parameter(2.0)) - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(1.0)) - MOI.set(optimizer, MOI.ConstraintSet(), cz, POI.Parameter(1.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cw, MOI.Parameter(2.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(1.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cz, MOI.Parameter(1.0)) MOI.optimize!(optimizer) @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 7.0, atol = ATOL) @test MOI.get.(optimizer, MOI.VariablePrimal(), x) == [0.0, 1.0] @test ≈(MOI.get(optimizer, MOI.ConstraintDual(), cy), 9.0, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.ConstraintDual(), cz), 0.0, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.ConstraintDual(), cw), -2.0, atol = ATOL) - MOI.set(optimizer, MOI.ConstraintSet(), cw, POI.Parameter(0.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cw, MOI.Parameter(0.0)) MOI.optimize!(optimizer) @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 3.0, atol = ATOL) @test MOI.get.(optimizer, MOI.VariablePrimal(), x) == [0.0, 1.0] @test ≈(MOI.get(optimizer, MOI.ConstraintDual(), cy), 9.0, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.ConstraintDual(), cz), 0.0, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.ConstraintDual(), cw), -2.0, atol = ATOL) - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(-5.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(-5.0)) MOI.optimize!(optimizer) @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 14.0, atol = ATOL) @test ≈( @@ -485,9 +488,9 @@ function test_production_problem_example_parameters_for_duals_and_intervals() b2 = 4.0 x = MOI.add_variables(optimizer, length(c)) @test typeof(x[1]) == MOI.VariableIndex - w, cw = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) - y, cy = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) - z, cz = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) + w, cw = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) + y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) + z, cz = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) @test MOI.get(optimizer, MOI.VariablePrimal(), w) == 0 for x_i in x MOI.add_constraint(optimizer, x_i, MOI.GreaterThan(0.0)) @@ -533,23 +536,23 @@ function test_production_problem_example_parameters_for_duals_and_intervals() -0.5 * MOI.get(optimizer, MOI.ConstraintDual(), ci2), atol = 1e-4, ) - MOI.set(optimizer, MOI.ConstraintSet(), cw, POI.Parameter(2.0)) - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(1.0)) - MOI.set(optimizer, MOI.ConstraintSet(), cz, POI.Parameter(1.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cw, MOI.Parameter(2.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(1.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cz, MOI.Parameter(1.0)) MOI.optimize!(optimizer) @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 7.0, atol = ATOL) @test MOI.get.(optimizer, MOI.VariablePrimal(), x) == [0.0, 1.0] @test ≈(MOI.get(optimizer, MOI.ConstraintDual(), cy), 9.0, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.ConstraintDual(), cz), 0.0, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.ConstraintDual(), cw), -2.0, atol = ATOL) - MOI.set(optimizer, MOI.ConstraintSet(), cw, POI.Parameter(0.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cw, MOI.Parameter(0.0)) MOI.optimize!(optimizer) @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 3.0, atol = ATOL) @test MOI.get.(optimizer, MOI.VariablePrimal(), x) == [0.0, 1.0] @test ≈(MOI.get(optimizer, MOI.ConstraintDual(), cy), 9.0, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.ConstraintDual(), cz), 0.0, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.ConstraintDual(), cw), -2.0, atol = ATOL) - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(-5.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(-5.0)) MOI.optimize!(optimizer) @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 14.0, atol = ATOL) @test ≈( @@ -581,7 +584,7 @@ function test_vector_parameter_affine_nonnegatives() MOI.set(model, MOI.Silent(), true) x = MOI.add_variable(model) y = MOI.add_variable(model) - t, ct = MOI.add_constrained_variable(model, POI.Parameter(5)) + t, ct = MOI.add_constrained_variable(model, MOI.Parameter(5.0)) A = [1.0 0 -1; 0 1 -1] b = [1.0; 2] terms = @@ -640,7 +643,7 @@ function test_vector_parameter_affine_nonpositives() MOI.set(model, MOI.Silent(), true) x = MOI.add_variable(model) y = MOI.add_variable(model) - t, ct = MOI.add_constrained_variable(model, POI.Parameter(5)) + t, ct = MOI.add_constrained_variable(model, MOI.Parameter(5.0)) A = [-1.0 0 1; 0 -1 1] b = [-1.0; -2] terms = @@ -703,7 +706,7 @@ function test_vector_soc_parameters() model = POI.Optimizer(cached) MOI.set(model, MOI.Silent(), true) x, y, t = MOI.add_variables(model, 3) - p, cp = MOI.add_constrained_variable(model, POI.Parameter(0)) + p, cp = MOI.add_constrained_variable(model, MOI.Parameter(0.0)) MOI.set( model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), @@ -911,7 +914,7 @@ function test_qp_parameter_in_affine_constraint() G = [2.0 3.0 1.0; 1.0 1.0 1.0] h = [4.0; 3.0] x = MOI.add_variables(optimizer, 2) - y, cy = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) + y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) quad_terms = MOI.ScalarQuadraticTerm{Float64}[] for i in 1:2 for j in i:2 # indexes (i,j), (j,i) will be mirrored. specify only one kind @@ -943,7 +946,7 @@ function test_qp_parameter_in_affine_constraint() @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 12.5, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.VariablePrimal(), x[1]), 5.0, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.VariablePrimal(), x[2]), -2.0, atol = ATOL) - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(1.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(1.0)) MOI.optimize!(optimizer) @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 5.0, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.VariablePrimal(), x[1]), 3.0, atol = ATOL) @@ -962,8 +965,8 @@ function test_qp_parameter_in_quadratic_constraint() G = [2.0 3.0 1.0 0.0; 1.0 1.0 0.0 1.0] h = [4.0; 3.0] x = MOI.add_variables(optimizer, 2) - y, cy = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) - w, cw = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) + y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) + w, cw = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) quad_terms = MOI.ScalarQuadraticTerm{Float64}[] for i in 1:2 for j in i:2 # indexes (i,j), (j,i) will be mirrored. specify only one kind @@ -1001,8 +1004,8 @@ function test_qp_parameter_in_quadratic_constraint() @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 12.5, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.VariablePrimal(), x[1]), 5.0, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.VariablePrimal(), x[2]), -2.0, atol = ATOL) - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(1.0)) - MOI.set(optimizer, MOI.ConstraintSet(), cw, POI.Parameter(2.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(1.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cw, MOI.Parameter(2.0)) MOI.optimize!(optimizer) @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 5.7142, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.VariablePrimal(), x[1]), 2.1428, atol = ATOL) @@ -1027,7 +1030,7 @@ function test_qp_variable_times_variable_plus_parameter() for x_i in x MOI.add_constraint(optimizer, x_i, MOI.GreaterThan(0.0)) end - y, cy = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) + y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) quad_terms = MOI.ScalarQuadraticTerm{Float64}[] push!(quad_terms, MOI.ScalarQuadraticTerm(A[1, 1], x[1], x[1])) push!(quad_terms, MOI.ScalarQuadraticTerm(A[1, 2], x[1], x[2])) @@ -1056,7 +1059,7 @@ function test_qp_variable_times_variable_plus_parameter() -MOI.get(optimizer, MOI.ConstraintDual(), cons_index), atol = ATOL, ) - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(2.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(2.0)) MOI.optimize!(optimizer) @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 8.6609, atol = ATOL) return @@ -1075,7 +1078,7 @@ function test_qp_variable_times_variable_plus_parameter_duals() for x_i in x MOI.add_constraint(optimizer, x_i, MOI.GreaterThan(0.0)) end - y, cy = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) + y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) quad_terms = MOI.ScalarQuadraticTerm{Float64}[] push!(quad_terms, MOI.ScalarQuadraticTerm(A[1, 1], x[1], x[1])) push!(quad_terms, MOI.ScalarQuadraticTerm(A[1, 2], x[1], x[2])) @@ -1106,7 +1109,7 @@ function test_qp_variable_times_variable_plus_parameter_duals() -2 * MOI.get(optimizer, MOI.ConstraintDual(), cons_index), atol = ATOL, ) - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(2.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(2.0)) MOI.optimize!(optimizer) @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 8.2376, atol = ATOL) return @@ -1126,7 +1129,7 @@ function test_qp_parameter_times_variable() MOI.add_constraint(optimizer, x_i, MOI.GreaterThan(0.0)) end MOI.add_constraint(optimizer, x[1], MOI.LessThan(20.0)) - y, cy = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) + y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) quad_terms = MOI.ScalarQuadraticTerm{Float64}[] push!(quad_terms, MOI.ScalarQuadraticTerm(A[1, 1], x[1], x[1])) push!(quad_terms, MOI.ScalarQuadraticTerm(A[1, 2], x[1], y)) @@ -1149,7 +1152,7 @@ function test_qp_parameter_times_variable() @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 30.25, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.VariablePrimal(), x[1]), 0.5, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.VariablePrimal(), x[2]), 29.25, atol = ATOL) - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(2.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(2.0)) MOI.optimize!(optimizer) @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 22.0, atol = ATOL) return @@ -1169,7 +1172,7 @@ function test_qp_variable_times_parameter() MOI.add_constraint(optimizer, x_i, MOI.GreaterThan(0.0)) end MOI.add_constraint(optimizer, x[1], MOI.LessThan(20.0)) - y, cy = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) + y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) quad_terms = MOI.ScalarQuadraticTerm{Float64}[] push!(quad_terms, MOI.ScalarQuadraticTerm(A[2, 2], y, y)) push!(quad_terms, MOI.ScalarQuadraticTerm(A[1, 2], y, x[1])) @@ -1192,7 +1195,7 @@ function test_qp_variable_times_parameter() @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 30.25, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.VariablePrimal(), x[1]), 0.5, atol = ATOL) @test ≈(MOI.get(optimizer, MOI.VariablePrimal(), x[2]), 29.25, atol = ATOL) - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(2.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(2.0)) MOI.optimize!(optimizer) @test ≈(MOI.get(optimizer, MOI.ObjectiveValue()), 22.0, atol = ATOL) return @@ -1212,8 +1215,8 @@ function test_qp_parameter_times_parameter() MOI.add_constraint(optimizer, x_i, MOI.GreaterThan(0.0)) end MOI.add_constraint(optimizer, x[1], MOI.LessThan(20.0)) - y, cy = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) - z, cz = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) + y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) + z, cz = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) quad_terms = MOI.ScalarQuadraticTerm{Float64}[] push!(quad_terms, MOI.ScalarQuadraticTerm(A[1, 1], y, y)) push!(quad_terms, MOI.ScalarQuadraticTerm(A[1, 2], y, z)) @@ -1244,14 +1247,14 @@ function test_qp_parameter_times_parameter() 10.0, atol = ATOL, ) - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(2.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(2.0)) MOI.optimize!(optimizer) @test isapprox(MOI.get(optimizer, MOI.ObjectiveValue()), 42.0, atol = ATOL) - MOI.set(optimizer, MOI.ConstraintSet(), cz, POI.Parameter(1.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cz, MOI.Parameter(1.0)) MOI.optimize!(optimizer) @test isapprox(MOI.get(optimizer, MOI.ObjectiveValue()), 36.0, atol = ATOL) - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(-1.0)) - MOI.set(optimizer, MOI.ConstraintSet(), cz, POI.Parameter(-1.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(-1.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cz, MOI.Parameter(-1.0)) MOI.optimize!(optimizer) @test isapprox(MOI.get(optimizer, MOI.ObjectiveValue()), 45.0, atol = ATOL) return @@ -1268,7 +1271,7 @@ function test_qp_quadratic_constant() G = [2.0 3.0; 1.0 1.0] h = [4.0; 3.0] x = MOI.add_variables(optimizer, 2) - y, cy = MOI.add_constrained_variable(optimizer, POI.Parameter(0)) + y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) quad_terms = MOI.ScalarQuadraticTerm{Float64}[] for i in 1:2 for j in i:2 # indexes (i,j), (j,i) will be mirrored. specify only one kind @@ -1311,7 +1314,7 @@ function test_qp_quadratic_constant() -2.0, atol = ATOL, ) - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(1.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(1.0)) MOI.optimize!(optimizer) # @test isapprox(MOI.get(optimizer, MOI.ObjectiveValue()), 5.7142, atol = ATOL) # @test isapprox.(MOI.get(optimizer, MOI.VariablePrimal(), x[1]), 2.1428, atol = ATOL) @@ -1330,8 +1333,8 @@ function test_qp_objective_parameter_times_parameter() for x_i in x MOI.add_constraint(optimizer, x_i, MOI.GreaterThan(0.0)) end - y, cy = MOI.add_constrained_variable(optimizer, POI.Parameter(1)) - z, cz = MOI.add_constrained_variable(optimizer, POI.Parameter(1)) + y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(1.0)) + z, cz = MOI.add_constrained_variable(optimizer, MOI.Parameter(1.0)) quad_terms = MOI.ScalarQuadraticTerm{Float64}[] push!(quad_terms, MOI.ScalarQuadraticTerm(1.0, y, z)) objective_function = MOI.ScalarQuadraticFunction( @@ -1356,10 +1359,10 @@ function test_qp_objective_parameter_times_parameter() ErrorException("Cannot compute the dual of a multiplicative parameter") @test_throws err MOI.get(optimizer, MOI.ConstraintDual(), cy) @test_throws err MOI.get(optimizer, MOI.ConstraintDual(), cz) - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(2.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(2.0)) MOI.optimize!(optimizer) @test isapprox(MOI.get(optimizer, MOI.ObjectiveValue()), 2.0, atol = ATOL) - MOI.set(optimizer, MOI.ConstraintSet(), cz, POI.Parameter(3.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cz, MOI.Parameter(3.0)) MOI.optimize!(optimizer) @test isapprox(MOI.get(optimizer, MOI.ObjectiveValue()), 6.0, atol = ATOL) MOI.set(optimizer, POI.ParameterValue(), y, 5) @@ -1386,8 +1389,8 @@ function test_qp_objective_affine_parameter() for x_i in x MOI.add_constraint(optimizer, x_i, MOI.GreaterThan(0.0)) end - y, cy = MOI.add_constrained_variable(optimizer, POI.Parameter(1)) - z, cz = MOI.add_constrained_variable(optimizer, POI.Parameter(1)) + y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(1.0)) + z, cz = MOI.add_constrained_variable(optimizer, MOI.Parameter(1.0)) quad_terms = MOI.ScalarQuadraticTerm{Float64}[] push!(quad_terms, MOI.ScalarQuadraticTerm(A[1, 1], x[1], x[1])) push!(quad_terms, MOI.ScalarQuadraticTerm(A[1, 2], x[1], x[2])) @@ -1410,14 +1413,14 @@ function test_qp_objective_affine_parameter() 0, atol = ATOL, ) - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(2.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(2.0)) MOI.optimize!(optimizer) @test isapprox(MOI.get(optimizer, MOI.ObjectiveValue()), 5.0, atol = ATOL) - MOI.set(optimizer, MOI.ConstraintSet(), cz, POI.Parameter(3.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cz, MOI.Parameter(3.0)) MOI.optimize!(optimizer) @test isapprox(MOI.get(optimizer, MOI.ObjectiveValue()), 7.0, atol = ATOL) - MOI.set(optimizer, MOI.ConstraintSet(), cy, POI.Parameter(5.0)) - MOI.set(optimizer, MOI.ConstraintSet(), cz, POI.Parameter(5.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cy, MOI.Parameter(5.0)) + MOI.set(optimizer, MOI.ConstraintSet(), cz, MOI.Parameter(5.0)) MOI.optimize!(optimizer) @test isapprox(MOI.get(optimizer, MOI.ObjectiveValue()), 15.0, atol = ATOL) return @@ -1429,7 +1432,7 @@ function test_qp_objective_parameter_in_quadratic_part() x = MOI.add_variable(model) y = MOI.add_variable(model) z = MOI.add_variable(model) - p = first(MOI.add_constrained_variable.(model, POI.Parameter(1.0))) + p = first(MOI.add_constrained_variable.(model, MOI.Parameter(1.0))) MOI.add_constraint(model, x, MOI.GreaterThan(0.0)) MOI.add_constraint(model, y, MOI.GreaterThan(0.0)) cons1 = @@ -1479,7 +1482,7 @@ function test_qp_objective_parameter_in_quadratic_part() MOI.set(model, MOI.Silent(), true) x = MOI.add_variable(model) y = MOI.add_variable(model) - p = first(MOI.add_constrained_variable.(model, POI.Parameter(1.0))) + p = first(MOI.add_constrained_variable.(model, MOI.Parameter(1.0))) MOI.add_constraint(model, x, MOI.GreaterThan(0.0)) MOI.add_constraint(model, y, MOI.GreaterThan(0.0)) cons1 = @@ -1517,7 +1520,7 @@ function test_qp_objective_parameter_in_quadratic_part() MOI.set(model, MOI.Silent(), true) x = MOI.add_variable(model) y = MOI.add_variable(model) - p = first(MOI.add_constrained_variable.(model, POI.Parameter(1.0))) + p = first(MOI.add_constrained_variable.(model, MOI.Parameter(1.0))) MOI.add_constraint(model, x, MOI.GreaterThan(0.0)) MOI.add_constraint(model, y, MOI.GreaterThan(0.0)) cons1 = @@ -1543,7 +1546,7 @@ function test_qp_objective_parameter_in_quadratic_part() MOI.set(model, MOI.Silent(), true) x = MOI.add_variable(model) y = MOI.add_variable(model) - p = first(MOI.add_constrained_variable.(model, POI.Parameter(1.0))) + p = first(MOI.add_constrained_variable.(model, MOI.Parameter(1.0))) MOI.add_constraint(model, x, MOI.GreaterThan(0.0)) MOI.add_constraint(model, y, MOI.GreaterThan(0.0)) cons1 =