Skip to content

Commit

Permalink
Merge pull request #140 from jump-dev/jg/moip
Browse files Browse the repository at this point in the history
Switch to MOI.Parameter and fixes tests
  • Loading branch information
joaquimg authored Dec 1, 2023
2 parents c0e8af9 + 2df7aad commit 7c862f4
Show file tree
Hide file tree
Showing 15 changed files with 402 additions and 334 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion benchmark/MOI_benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 15 additions & 15 deletions benchmark/run_benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ 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

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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
30 changes: 15 additions & 15 deletions benchmark/run_benchmarks_jump.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion benchmark/run_benders_quantile_regression_benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/src/Examples/benders.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 7c862f4

Please sign in to comment.