From 8a4c4db7bdcbce51bab52e4c6405cf7df49a8182 Mon Sep 17 00:00:00 2001 From: Joaquim Garcia Date: Mon, 23 Oct 2023 02:26:41 -0300 Subject: [PATCH 1/9] properly organize constraint getters --- src/ParametricOptInterface.jl | 147 ++++++++++++++++------------------ 1 file changed, 67 insertions(+), 80 deletions(-) diff --git a/src/ParametricOptInterface.jl b/src/ParametricOptInterface.jl index e0ab8fc1..d9ed4fac 100644 --- a/src/ParametricOptInterface.jl +++ b/src/ParametricOptInterface.jl @@ -161,6 +161,9 @@ mutable struct Optimizer{T,OT<:MOI.ModelLike} <: MOI.AbstractOptimizer last_variable_index_added::Int64 last_parameter_index_added::Int64 + # mapping of all constraints: necessary for getters + constraint_outer_to_inner::DoubleDict{MOI.ConstraintIndex} + # affine constraint data last_affine_added::Int64 # Store the map for SAFs (some might be transformed into VI) @@ -234,6 +237,7 @@ mutable struct Optimizer{T,OT<:MOI.ModelLike} <: MOI.AbstractOptimizer ), 0, PARAMETER_INDEX_THRESHOLD, + DoubleDict{MOI.ConstraintIndex}(), # affine constraint 0, DoubleDict{MOI.ConstraintIndex}(), @@ -280,6 +284,7 @@ function MOI.is_empty(model::Optimizer) isempty(model.variables) && model.last_variable_index_added == 0 && model.last_parameter_index_added == PARAMETER_INDEX_THRESHOLD && + isempty(model.constraint_outer_to_inner) && # affine ctr model.last_affine_added == 0 && isempty(model.affine_outer_to_inner) && @@ -311,6 +316,7 @@ function MOI.empty!(model::Optimizer{T}) where {T} empty!(model.variables) model.last_variable_index_added = 0 model.last_parameter_index_added = PARAMETER_INDEX_THRESHOLD + empty!(model.constraint_outer_to_inner) # affine ctr model.last_affine_added = 0 empty!(model.affine_outer_to_inner) @@ -702,10 +708,6 @@ function MOI.set(model::Optimizer, attr::MOI.AbstractOptimizerAttribute, value) return end -function MOI.get(model::Optimizer, ::MOI.NumberOfConstraints{F,S}) where {F,S} - return length(MOI.get(model, MOI.ListOfConstraintIndices{F,S}())) -end - function MOI.get( model::Optimizer, attr::MOI.ConstraintSet, @@ -739,80 +741,24 @@ function MOI.get(model::Optimizer, attr::MOI.ResultCount) return MOI.get(model.optimizer, attr) end -# TODO: cleanup -# In the AbstractBridgeOptimizer, we collect all the possible constraint types and them filter with NumberOfConstraints. -# If NumberOfConstraints is zero then we remove it from the list. -# Here, you can look over keys(quadratic_outer_to_inner) and add the F-S types of all the keys in constraints. -# To implement NumberOfConstraints, you call NumberOfConstraints to the inner optimizer. -# Then you remove the number of constraints of that that in values(quadratic_outer_to_inner) function MOI.get(model::Optimizer, ::MOI.ListOfConstraintTypesPresent) - inner_ctrs = MOI.get(model.optimizer, MOI.ListOfConstraintTypesPresent()) - if !has_quadratic_constraint_caches(model) - return inner_ctrs - end - - cache_keys = collect(keys(model.quadratic_outer_to_inner)) - constraints = Set{Tuple{DataType,DataType}}() - - for (F, S) in inner_ctrs - inner_index = - MOI.get(model.optimizer, MOI.ListOfConstraintIndices{F,S}()) - cache_map_check = - quadratic_constraint_cache_map_check.(model, inner_index) - for type in typeof.(cache_keys[cache_map_check]) - push!(constraints, (type.parameters[1], type.parameters[2])) - end - # If not all the constraints are cached then also push the original type - # since there was a function with no parameters of that type - if !all(cache_map_check) - push!(constraints, (F, S)) - end - end - - return collect(constraints) -end - -function MOI.get( - model::Optimizer, - attr::MOI.ListOfConstraintIndices{F,S}, -) where {S,F<:Union{MOI.VectorOfVariables,MOI.VariableIndex}} - return MOI.get(model.optimizer, attr) + constraint_types = + MOI.Utilities.DoubleDicts.nonempty_outer_keys(model.constraint_outer_to_inner) + return collect(constraint_types) end function MOI.get( model::Optimizer, ::MOI.ListOfConstraintIndices{F,S}, -) where { - S<:MOI.AbstractSet, - F<:Union{MOI.ScalarAffineFunction{T},MOI.VectorAffineFunction{T}}, -} where {T} - inner_index = MOI.get(model.optimizer, MOI.ListOfConstraintIndices{F,S}()) - if !has_quadratic_constraint_caches(model) - return inner_index - end - - cache_map_check = quadratic_constraint_cache_map_check(mode, inner_index) - return inner_index[cache_map_check] +) where {S,F} + return collect(values(model.constraint_outer_to_inner[F, S])) end function MOI.get( model::Optimizer, - ::MOI.ListOfConstraintIndices{F,S}, -) where {S<:MOI.AbstractSet,F<:MOI.ScalarQuadraticFunction{T}} where {T} - inner_index = MOI.ConstraintIndex{F,S}[] - if MOI.supports_constraint(model.optimizer, F, S) - inner_index = - MOI.get(model.optimizer, MOI.ListOfConstraintIndices{F,S}()) - end - if !has_quadratic_constraint_caches(model) - return inner_index - end - - for key in keys(model.quadratic_outer_to_inner) - push!(inner_index, key) - end - - return inner_index + ::MOI.NumberOfConstraints{F,S}, +) where {S,F} + return length(model.constraint_outer_to_inner[F, S]) end function MOI.supports_add_constrained_variable(::Optimizer, ::Type{Parameter}) @@ -841,11 +787,26 @@ function MOI.add_constrained_variable(model::Optimizer, set::Parameter) cp = MOI.ConstraintIndex{MOI.VariableIndex,Parameter}( model.last_parameter_index_added, ) + _add_to_constraint_map!(model, ci) MOI.Utilities.CleverDicts.add_item(model.updated_parameters, NaN) update_number_of_parameters!(model) return p, cp end +function _add_to_constraint_map!(model::Optimizer, ci) + model.constraint_outer_to_inner[ci] = ci + return +end +function _add_to_constraint_map!(model::Optimizer, ci_in, ci_out) + model.constraint_outer_to_inner[ci_out] = ci_in + return +end +function _add_constraint_direct_and_cache_map!(model::Optimizer, f, set) + ci = MOI.add_constraint(model.optimizer, f, set) + _add_to_constraint_map!(model, ci) + return ci +end + function MOI.add_constraint( model::Optimizer, f::MOI.VariableIndex, @@ -856,7 +817,7 @@ function MOI.add_constraint( elseif !is_variable_in_model(model, f) error("Variable not in the model") end - return MOI.add_constraint(model.optimizer, f, set) + return _add_constraint_direct_and_cache_map!(model, f, set) end function add_constraint_with_parameters_on_function( @@ -902,7 +863,7 @@ function add_saf_constraint( model.last_affine_added, ) model.affine_outer_to_inner[outer_ci] = inner_ci - # model.outer_to_inner_map[outer_ci] = inner_ci + model.constraint_outer_to_inner[outer_ci] = inner_ci model.affine_constraint_cache[inner_ci] = pf model.affine_constraint_cache_set[inner_ci] = set return outer_ci @@ -924,7 +885,7 @@ function add_vi_constraint( model.last_affine_added, ) model.affine_outer_to_inner[outer_ci] = inner_ci - # model.outer_to_inner_map[outer_ci] = inner_ci + model.constraint_outer_to_inner[outer_ci] = inner_ci model.affine_constraint_cache[inner_ci] = pf model.affine_constraint_cache_set[inner_ci] = set return outer_ci @@ -936,7 +897,7 @@ function MOI.add_constraint( set::MOI.AbstractScalarSet, ) where {T} if !function_has_parameters(f) - return MOI.add_constraint(model.optimizer, f, set) + return _add_constraint_direct_and_cache_map!(model, f, set) else return add_constraint_with_parameters_on_function(model, f, set) end @@ -1256,7 +1217,7 @@ function MOI.add_constraint( if function_has_parameters(f) error("VectorOfVariables does not allow parameters") end - return MOI.add_constraint(model.optimizer, f, set) + return _add_constraint_direct_and_cache_map!(model, f, set) end function MOI.add_constraint( @@ -1265,7 +1226,7 @@ function MOI.add_constraint( set::MOI.AbstractVectorSet, ) where {T} if !function_has_parameters(f) - return MOI.add_constraint(model.optimizer, f, set) + return _add_constraint_direct_and_cache_map!(model, f, set) else return add_constraint_with_parameters_on_function(model, f, set) end @@ -1281,6 +1242,7 @@ function add_constraint_with_parameters_on_function( update_cache!(pf, model) inner_ci = MOI.add_constraint(model.optimizer, current_function(pf), set) model.vector_affine_constraint_cache[inner_ci] = pf + _add_to_constraint_map!(model, inner_ci) return inner_ci end @@ -1307,7 +1269,7 @@ function add_constraint_with_parameters_on_function( model.last_quad_add_added, ) model.quadratic_outer_to_inner[outer_ci] = inner_ci - # model.outer_to_inner_map[outer_ci] = inner_ci + model.constraint_outer_to_inner[outer_ci] = inner_ci else fa = MOI.ScalarAffineFunction(func.affine_terms, func.constant) inner_ci = MOI.Utilities.normalize_and_add_constraint( @@ -1322,7 +1284,7 @@ function add_constraint_with_parameters_on_function( # This part is used to remember that ci came from a quadratic function # It is particularly useful because sometimes the constraint mutates model.quadratic_outer_to_inner[outer_ci] = inner_ci - # model.outer_to_inner_map[outer_ci] = inner_ci + model.constraint_outer_to_inner[outer_ci] = inner_ci end model.quadratic_constraint_cache[inner_ci] = pf model.quadratic_constraint_cache_set[inner_ci] = s @@ -1335,7 +1297,7 @@ function MOI.add_constraint( set::MOI.AbstractScalarSet, ) where {T} if !function_has_parameters(f) - return MOI.add_constraint(model.optimizer, f, set) + return _add_constraint_direct_and_cache_map!(model, f, set) else return add_constraint_with_parameters_on_function(model, f, set) end @@ -1345,6 +1307,25 @@ function MOI.delete(model::Optimizer, v::MOI.VariableIndex) delete!(model.variables, v) MOI.delete(model.optimizer, v) 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) + return +end + +function MOI.delete( + model::Optimizer, + c::MOI.ConstraintIndex{F,S}, +) where {F<:MOI.ScalarQuadraticFunction,S<:MOI.AbstractSet} + if haskey(model.quadratic_outer_to_inner, c) + ci_inner = model.quadratic_outer_to_inner[c] + deleteat!(model.quadratic_outer_to_inner, c) + deleteat!(model.quadratic_constraint_cache, c) + deleteat!(model.quadratic_constraint_cache_set, c) + MOI.delete(model.optimizer, ci_inner) + else + MOI.delete(model.optimizer, c) + end + deleteat!(model.constraint_outer_to_inner, c) return end @@ -1352,10 +1333,16 @@ function MOI.delete( model::Optimizer, c::MOI.ConstraintIndex{F,S}, ) where {F<:MOI.ScalarAffineFunction,S<:MOI.AbstractSet} - if haskey(model.affine_constraint_cache, c) - delete!(model.affine_constraint_cache, c) + 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) + MOI.delete(model.optimizer, ci_inner) + else + MOI.delete(model.optimizer, c) end - MOI.delete(model.optimizer, c) + deleteat!(model.constraint_outer_to_inner, c) return end From 0d555424f608c3d51b3b6cae9545fb52aec17257 Mon Sep 17 00:00:00 2001 From: Joaquim Garcia Date: Mon, 23 Oct 2023 03:03:02 -0300 Subject: [PATCH 2/9] fix constraint vi interpretation --- src/ParametricOptInterface.jl | 2 +- test/jump_tests.jl | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ParametricOptInterface.jl b/src/ParametricOptInterface.jl index d9ed4fac..6e43f98d 100644 --- a/src/ParametricOptInterface.jl +++ b/src/ParametricOptInterface.jl @@ -787,7 +787,7 @@ function MOI.add_constrained_variable(model::Optimizer, set::Parameter) cp = MOI.ConstraintIndex{MOI.VariableIndex,Parameter}( model.last_parameter_index_added, ) - _add_to_constraint_map!(model, ci) + _add_to_constraint_map!(model, cp) MOI.Utilities.CleverDicts.add_item(model.updated_parameters, NaN) update_number_of_parameters!(model) return p, cp diff --git a/test/jump_tests.jl b/test/jump_tests.jl index 4edd316c..091ad365 100644 --- a/test/jump_tests.jl +++ b/test/jump_tests.jl @@ -308,7 +308,10 @@ function test_jump_direct_interpret_parameteric_bounds() @objective(model, Min, sum(x)) optimize!(model) @test MOI.get(model, MOI.ListOfConstraintTypesPresent()) == - Tuple{Type,Type}[(MOI.VariableIndex, MOI.GreaterThan{Float64})] + Tuple{Type,Type}[ + (MOI.VariableIndex, POI.Parameter), + (MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}), + ] @test MOI.get( backend(model).optimizer, MOI.ListOfConstraintTypesPresent(), From 2767883049f832344c9c8ec7e6fbf0daf482ab2c Mon Sep 17 00:00:00 2001 From: Joaquim Garcia Date: Thu, 30 Nov 2023 14:52:48 -0300 Subject: [PATCH 3/9] Switch to MOI.Parameter and fixes tests --- README.md | 2 +- benchmark/MOI_benchmarks.jl | 2 +- benchmark/run_benchmarks.jl | 30 ++-- benchmark/run_benchmarks_jump.jl | 30 ++-- ...n_benders_quantile_regression_benchmark.jl | 2 +- docs/src/Examples/benders.md | 2 +- docs/src/Examples/example.md | 38 ++--- docs/src/Examples/markowitz.md | 2 +- docs/src/manual.md | 14 +- docs/src/reference.md | 1 - src/ParametricOptInterface.jl | 121 ++++++++++----- src/duals.jl | 10 +- test/jump_tests.jl | 129 ++++++++-------- test/moi_tests.jl | 143 +++++++++--------- 14 files changed, 291 insertions(+), 235 deletions(-) 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 = From b206c99d18e0caf1f8bf56a4bbd23c3ee91428ec Mon Sep 17 00:00:00 2001 From: Joaquim Garcia Date: Thu, 30 Nov 2023 14:56:50 -0300 Subject: [PATCH 4/9] fox format --- src/ParametricOptInterface.jl | 51 +++++++++++++++++++++++------------ src/duals.jl | 6 ++++- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/ParametricOptInterface.jl b/src/ParametricOptInterface.jl index cca9137a..78c5165d 100644 --- a/src/ParametricOptInterface.jl +++ b/src/ParametricOptInterface.jl @@ -753,8 +753,9 @@ function MOI.get(model::Optimizer, attr::MOI.ResultCount) end function MOI.get(model::Optimizer, ::MOI.ListOfConstraintTypesPresent) - constraint_types = - MOI.Utilities.DoubleDicts.nonempty_outer_keys(model.constraint_outer_to_inner) + constraint_types = MOI.Utilities.DoubleDicts.nonempty_outer_keys( + model.constraint_outer_to_inner, + ) return collect(constraint_types) end @@ -763,14 +764,11 @@ function MOI.get( ::MOI.ListOfConstraintIndices{F,S}, ) where {S,F} list = collect(values(model.constraint_outer_to_inner[F, S])) - sort!(list, lt = (x, y)->(x.value < y.value)) + sort!(list, lt = (x, y) -> (x.value < y.value)) return list end -function MOI.get( - model::Optimizer, - ::MOI.NumberOfConstraints{F,S}, -) where {S,F} +function MOI.get(model::Optimizer, ::MOI.NumberOfConstraints{F,S}) where {S,F} return length(model.constraint_outer_to_inner[F, S]) end @@ -796,7 +794,10 @@ function MOI.add_variable(model::Optimizer) ) end -function MOI.add_constrained_variable(model::Optimizer{T}, set::MOI.Parameter{T}) where {T} +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.value) @@ -1019,7 +1020,8 @@ function MOI.set( var::MOI.VariableIndex, val::Float64, ) - ci = MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{Float64}}(var.value) + ci = + MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{Float64}}(var.value) set = MOI.set(opt, MOI.ConstraintSet(), ci, MOI.Parameter(val)) return nothing end @@ -1030,7 +1032,8 @@ function MOI.set( var::MOI.VariableIndex, val::Float64, ) - ci = MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{Float64}}(var.value) + ci = + MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{Float64}}(var.value) set = MOI.set(model, MOI.ConstraintSet(), ci, MOI.Parameter(val)) return nothing end @@ -1058,7 +1061,8 @@ function MOI.get( ::ParameterValue, var::MOI.VariableIndex, ) - ci = MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{Float64}}(var.value) + ci = + MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{Float64}}(var.value) set = MOI.get(opt, MOI.ConstraintSet(), ci) return set.value end @@ -1342,8 +1346,15 @@ function MOI.delete(model::Optimizer, v::MOI.VariableIndex) # 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) + 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 @@ -1351,7 +1362,12 @@ end function _delete_variable_index_constraint(d, F, S, v) return end -function _delete_variable_index_constraint(d, F::Type{MOI.VariableIndex}, S, value) +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 @@ -1366,7 +1382,7 @@ function MOI.delete( c::MOI.ConstraintIndex{F,S}, ) where {F<:MOI.ScalarQuadraticFunction,S<:MOI.AbstractSet} if haskey(model.quadratic_outer_to_inner, c) - ci_inner = model.quadratic_outer_to_inner[c] + ci_inner = model.quadratic_outer_to_inner[c] deleteat!(model.quadratic_outer_to_inner, c) deleteat!(model.quadratic_constraint_cache, c) deleteat!(model.quadratic_constraint_cache_set, c) @@ -1383,7 +1399,7 @@ function MOI.delete( c::MOI.ConstraintIndex{F,S}, ) where {F<:MOI.ScalarAffineFunction,S<:MOI.AbstractSet} if haskey(model.affine_outer_to_inner, c) - ci_inner = model.affine_outer_to_inner[c] + ci_inner = model.affine_outer_to_inner[c] delete!(model.affine_outer_to_inner, c) delete!(model.affine_constraint_cache, c) delete!(model.affine_constraint_cache_set, c) @@ -1571,7 +1587,8 @@ 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 != MOI.Parameter{Float64} + MOI.Utilities._is_variable_function(F) && + S != MOI.Parameter{Float64} ], Any[MOI.Utilities._try_constrain_variables_on_creation( dest, diff --git a/src/duals.jl b/src/duals.jl index 5cf12495..0a74646f 100644 --- a/src/duals.jl +++ b/src/duals.jl @@ -107,7 +107,11 @@ struct ParameterDual <: MOI.AbstractVariableAttribute end MOI.is_set_by_optimize(::ParametricOptInterface.ParameterDual) = true -function MOI.get(model::Optimizer{T}, ::ParameterDual, v::MOI.VariableIndex) where {T} +function MOI.get( + model::Optimizer{T}, + ::ParameterDual, + v::MOI.VariableIndex, +) where {T} if !is_additive( model, MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{T}}(v.value), From e48622e30d25fc4196b38927e70cf1fcdc08699d Mon Sep 17 00:00:00 2001 From: Joaquim Garcia Date: Thu, 30 Nov 2023 14:57:43 -0300 Subject: [PATCH 5/9] format tests --- test/jump_tests.jl | 21 +++++++++++---------- test/moi_tests.jl | 9 ++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/test/jump_tests.jl b/test/jump_tests.jl index c47a33d7..31f74d0d 100644 --- a/test/jump_tests.jl +++ b/test/jump_tests.jl @@ -308,10 +308,10 @@ function test_jump_direct_interpret_parameteric_bounds() @objective(model, Min, sum(x)) optimize!(model) @test MOI.get(model, MOI.ListOfConstraintTypesPresent()) == - Tuple{Type,Type}[ - (MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}), - (MOI.VariableIndex, MOI.Parameter{Float64}), - ] + Tuple{Type,Type}[ + (MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}), + (MOI.VariableIndex, MOI.Parameter{Float64}), + ] @test MOI.get( backend(model).optimizer, MOI.ListOfConstraintTypesPresent(), @@ -332,16 +332,17 @@ function test_jump_direct_interpret_parameteric_bounds_no_interpretation() @objective(model, Min, sum(x)) optimize!(model) @test MOI.get(model, MOI.ListOfConstraintTypesPresent()) == - Tuple{Type,Type}[ - (MOI.ScalarAffineFunction{Float64},MOI.GreaterThan{Float64}), - (MOI.VariableIndex,MOI.Parameter{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) diff --git a/test/moi_tests.jl b/test/moi_tests.jl index 54cb6f65..9c64906e 100644 --- a/test/moi_tests.jl +++ b/test/moi_tests.jl @@ -300,11 +300,10 @@ function test_moi_ListOfConstraintTypesPresent() MOI.GreaterThan(1.0), ) list_ctrs_types = MOI.get(model, MOI.ListOfConstraintTypesPresent()) - @test list_ctrs_types == - [ - (MOI.ScalarQuadraticFunction{Float64}, MOI.GreaterThan{Float64}), - (MOI.VariableIndex, MOI.Parameter{Float64}) - ] + @test list_ctrs_types == [ + (MOI.ScalarQuadraticFunction{Float64}, MOI.GreaterThan{Float64}), + (MOI.VariableIndex, MOI.Parameter{Float64}), + ] return end From 95a24cead67ee1f6f7991b799c1ff9a72be95609 Mon Sep 17 00:00:00 2001 From: Joaquim Garcia Date: Thu, 30 Nov 2023 15:16:25 -0300 Subject: [PATCH 6/9] fix test that depend of set order --- test/jump_tests.jl | 56 +++++++++++++++++++++++++++++----------------- test/moi_tests.jl | 6 +++-- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/test/jump_tests.jl b/test/jump_tests.jl index 31f74d0d..2dd27999 100644 --- a/test/jump_tests.jl +++ b/test/jump_tests.jl @@ -259,15 +259,20 @@ function test_jump_interpret_parameteric_bounds() @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}[ + expected = Tuple{Type,Type}[ (MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}), (MOI.VariableIndex, MOI.Parameter{Float64}), ] - @test MOI.get( + result = MOI.get(model, MOI.ListOfConstraintTypesPresent()) + @test Set(result) == Set(expected) + @test length(result) == length(expected) + expected = Tuple{Type,Type}[(MOI.VariableIndex, MOI.GreaterThan{Float64})] + result = MOI.get( backend(model).optimizer.model.optimizer, MOI.ListOfConstraintTypesPresent(), - ) == Tuple{Type,Type}[(MOI.VariableIndex, MOI.GreaterThan{Float64})] + ) + @test Set(result) == Set(expected) + @test length(result) == length(expected) @test objective_value(model) == -2 MOI.set(model, POI.ParameterValue(), p[1], 4.0) optimize!(model) @@ -283,15 +288,20 @@ function test_jump_interpret_parameteric_bounds_expression() @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}[ + expected = Tuple{Type,Type}[ (MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}), (MOI.VariableIndex, MOI.Parameter{Float64}), ] - @test MOI.get( + result = MOI.get(model, MOI.ListOfConstraintTypesPresent()) + @test Set(result) == Set(expected) + @test length(result) == length(expected) + expected = Tuple{Type,Type}[(MOI.VariableIndex, MOI.GreaterThan{Float64})] + result = MOI.get( backend(model).optimizer.model.optimizer, MOI.ListOfConstraintTypesPresent(), - ) == Tuple{Type,Type}[(MOI.VariableIndex, MOI.GreaterThan{Float64})] + ) + @test Set(result) == Set(expected) + @test length(result) == length(expected) @test objective_value(model) == -4 MOI.set(model, POI.ParameterValue(), p[1], 4.0) optimize!(model) @@ -307,15 +317,18 @@ function test_jump_direct_interpret_parameteric_bounds() @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}[ + expected = 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.VariableIndex, MOI.GreaterThan{Float64})] + result = MOI.get(model, MOI.ListOfConstraintTypesPresent()) + @test Set(result) == Set(expected) + @test length(result) == length(expected) + expected = Tuple{Type,Type}[(MOI.VariableIndex, MOI.GreaterThan{Float64})] + result = + MOI.get(backend(model).optimizer, MOI.ListOfConstraintTypesPresent()) + @test Set(result) == Set(expected) + @test length(result) == length(expected) @test objective_value(model) == -2 MOI.set(model, POI.ParameterValue(), p[1], 4.0) optimize!(model) @@ -331,18 +344,21 @@ function test_jump_direct_interpret_parameteric_bounds_no_interpretation() @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}[ + expected = 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}[( + result = MOI.get(model, MOI.ListOfConstraintTypesPresent()) + @test Set(result) == Set(expected) + @test length(result) == length(expected) + expected = Tuple{Type,Type}[( MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}, ),] + result = + MOI.get(backend(model).optimizer, MOI.ListOfConstraintTypesPresent()) + @test Set(result) == Set(expected) + @test length(result) == length(expected) @test objective_value(model) == -2 MOI.set(model, POI.ParameterValue(), p[1], 4.0) optimize!(model) diff --git a/test/moi_tests.jl b/test/moi_tests.jl index 9c64906e..ef2cba31 100644 --- a/test/moi_tests.jl +++ b/test/moi_tests.jl @@ -299,11 +299,13 @@ function test_moi_ListOfConstraintTypesPresent() ), MOI.GreaterThan(1.0), ) - list_ctrs_types = MOI.get(model, MOI.ListOfConstraintTypesPresent()) - @test list_ctrs_types == [ + result = MOI.get(model, MOI.ListOfConstraintTypesPresent()) + expected = [ (MOI.ScalarQuadraticFunction{Float64}, MOI.GreaterThan{Float64}), (MOI.VariableIndex, MOI.Parameter{Float64}), ] + @test Set(result) == Set(expected) + @test length(result) == length(expected) return end From 1ab21af6deaa52e05a7c2d10771258b399e232e0 Mon Sep 17 00:00:00 2001 From: Joaquim Garcia Date: Thu, 30 Nov 2023 15:55:26 -0300 Subject: [PATCH 7/9] MathOptInterface -> MOI --- docs/src/Examples/example.md | 20 ++++++++++---------- docs/src/manual.md | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/src/Examples/example.md b/docs/src/Examples/example.md index db7428be..cdad6370 100644 --- a/docs/src/Examples/example.md +++ b/docs/src/Examples/example.md @@ -26,7 +26,7 @@ for x_i in x end ``` -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`: +Now, let's consider 3 `MOI.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, MOI.Parameter(0.0)) @@ -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 `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`: +Now, let's consider 3 `MOI.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 MathOptInterface.Parameter(0.0)) -@variable(model, z in MathOptInterface.Parameter(0.0)) -@variable(model, w in MathOptInterface.Parameter(0.0)) +@variable(model, y in MOI.Parameter(0.0)) +@variable(model, z in MOI.Parameter(0.0)) +@variable(model, w in MOI.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 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))) +@variable(model, p1[i = 1:3] in MOI.Parameter(0.0)) +@variable(model, p2[i = 1:3] in MOI.Parameter.([1, 10, 45])) +@variable(model, p3[i = 1:3] in MOI.Parameter.(ones(3))) ``` ## JuMP Example - Dealing with parametric expressions as variable bounds @@ -267,7 +267,7 @@ model = direct_model(POI.Optimizer(HiGHS.Optimizer())) @constraint(model, x >= p) ``` -Since parameters are treated like variables JuMP lowers this to MathOptInterface as `x - p >= 0` which is not a variable bound but a linear constraint.This means that the current representation of this problem at the solver level is: +Since parameters are treated like variables JuMP lowers this to MOI as `x - p >= 0` which is not a variable bound but a linear constraint.This means that the current representation of this problem at the solver level is: ```math \begin{align} @@ -343,7 +343,7 @@ MOI.set(optimizer, MOI.ObjectiveSense(), MOI.MAX_SENSE) obj_func = MOI.ScalarQuadraticFunction( [MOI.ScalarQuadraticTerm(1.0, x, x) MOI.ScalarQuadraticTerm(1.0, y, y)], - MathOptInterface.ScalarAffineTerm{Float64}[], + MOI.ScalarAffineTerm{Float64}[], 0.0, ) MOI.set( diff --git a/docs/src/manual.md b/docs/src/manual.md index 7ac73354..d8ff2e1e 100644 --- a/docs/src/manual.md +++ b/docs/src/manual.md @@ -56,15 +56,15 @@ optimizer = POI.Optimizer(HiGHS.Optimizer()) ### Parameters -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 +A `MOI.Parameter` is a set used to define a variable with a fixed value that +can be changed by the user. It is analogous to `MOI.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 `MathOptInterface.Parameter` 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 `MOI.Parameter` with its given value: ```julia y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0)) @@ -72,7 +72,7 @@ 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 `MathOptInterface.Parameter` structure. +To change a given parameter's value, access its `VariableIndex` and set it to the new value using the `MOI.Parameter` structure. ```julia MOI.set(optimizer, POI.ParameterValue(), y, MOI.Parameter(2.0)) From 3221e85494071ddcf91fc1deba0d6129c0925a13 Mon Sep 17 00:00:00 2001 From: Joaquim Garcia Date: Thu, 30 Nov 2023 15:56:02 -0300 Subject: [PATCH 8/9] [no ci] remove comment --- src/ParametricOptInterface.jl | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/ParametricOptInterface.jl b/src/ParametricOptInterface.jl index 78c5165d..cf0aacf5 100644 --- a/src/ParametricOptInterface.jl +++ b/src/ParametricOptInterface.jl @@ -16,23 +16,6 @@ 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) - -# The `Parameter` structure stores the numerical value associated to a given -# parameter. - -# ## Example - -# ```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 index::Int64 From 2df7aad59c7631650d877bbaaa0608ddbbc49157 Mon Sep 17 00:00:00 2001 From: Joaquim Garcia Date: Thu, 30 Nov 2023 20:47:25 -0300 Subject: [PATCH 9/9] up project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 43e23dc1..4388fa0c 100644 --- a/Project.toml +++ b/Project.toml @@ -10,7 +10,7 @@ MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" GLPK = "1" Ipopt = "1" JuMP = "1" -MathOptInterface = "1.3" +MathOptInterface = "1.13.2" SCS = "1" julia = "1.6"