Skip to content

Commit

Permalink
fixes and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquimg committed May 13, 2023
1 parent e86c942 commit 787299e
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 77 deletions.
2 changes: 2 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
MibS_jll = "118347d2-e127-56b9-9933-6abf9cc1adc1"
QuadraticToBinary = "014a38d5-7acb-4e20-b6c0-4fe5c2344fd1"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
SCIP = "82193955-e24f-5292-bf16-6f2c5261a85f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Expand All @@ -17,3 +18,4 @@ HiGHS = "=1.5.1"
Ipopt = "=1.0.2"
MibS_jll = "=1.1.3"
QuadraticToBinary = "=0.4.0"
SCIP = "=0.11.12"
6 changes: 3 additions & 3 deletions docs/src/tutorials/conic_lower.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ described in example 3.3 from
```math
\begin{align}
&\max_{x \in \mathbb{R}} \quad x + 3y_1 \\
&\st \quad 2 \leq x \leq 6\\
& \hspace{28pt} y(x) \in \argmin_{y\in {\mathbb{R}^3}} -y_1\\
& \hspace{58pt} \st \quad x + y_1 \leq 8 \\
&\textit{s.t.} \quad 2 \leq x \leq 6\\
& \hspace{28pt} y(x) \in \arg\min_{y\in {\mathbb{R}^3}} -y_1\\
& \hspace{58pt} \textit{s.t.} \quad x + y_1 \leq 8 \\
& \hspace{76pt} \quad x + 4y_1 \geq 8 \\
& \hspace{76pt} \quad x + 2y_1 \leq 12 \\
& \hspace{76pt} \quad y \in {SOC}_3 \label{eq-soc}
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/lower_duals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ set_lower_bound(lambda, 0.0)
set_upper_bound(lambda, 1000.0)

# Then, as before, we set a solver
# (now SCIP with the `QuadraticToBinary.jl` wrapper) and a solution method
# (now HiGHS with the `QuadraticToBinary.jl` wrapper) and a solution method
# (now Fortuny-Amat and McCarl):

set_optimizer(model,
Expand All @@ -107,4 +107,4 @@ for i in 1:3
var = @variable(Upper(model), variable_type = DualOf(reserves[i]))
push!(my_duals, var)
end
my_duals
my_duals # a vector of anonimous variables
4 changes: 2 additions & 2 deletions docs/src/tutorials/lower_duals.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ set_upper_bound(lambda, 1000.0)
```

Then, as before, we set a solver
(now SCIP with the `QuadraticToBinary.jl` wrapper) and a solution method
(now HiGHS with the `QuadraticToBinary.jl` wrapper) and a solution method
(now Fortuny-Amat and McCarl):

```@example lower_duals
Expand Down Expand Up @@ -126,7 +126,7 @@ for i in 1:3
var = @variable(Upper(model), variable_type = DualOf(reserves[i]))
push!(my_duals, var)
end
my_duals
my_duals # a vector of anonimous variables
```

!!! info
Expand Down
81 changes: 39 additions & 42 deletions docs/src/tutorials/modes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

# We start loading all libraries needed for this example.

using BilevelJuMP, QuadraticToBinary, HiGHS, Ipopt
using BilevelJuMP, HiGHS, Ipopt, SCIP

# Now we create a bilevel model with the `BilevelModel` constructor with no
# solver nor mode specified.
Expand Down Expand Up @@ -96,35 +96,33 @@ objective_value(model)

# ## `SOS1Mode` and `SCIP.Optimizer`

# ```julia
# set_optimizer(model, SCIP.Optimizer)
#
# BilevelJuMP.set_mode(model, BilevelJuMP.SOS1Mode())
#
# optimize!(model)
#
# objective_value(model)
# ```
set_optimizer(model, SCIP.Optimizer)

# !!! info
# This code was not executed because SCIP might have a non-standard
# intallation procedure in windows.
BilevelJuMP.set_mode(model, BilevelJuMP.SOS1Mode())

optimize!(model)

objective_value(model)

# !!! warning
# SCIP requires a non-standard installation procedure in windows.
# See [SCIP.jl](https://github.com/scipopt/SCIP.jl#custom-installations) for
# more details.

# ## `IndicatorMode` and `SCIP.Optimizer`

# ```julia
# set_optimizer(model, SCIP.Optimizer)
#
# BilevelJuMP.set_mode(model, BilevelJuMP.IndicatorMode())
#
# optimize!(model)
#
# objective_value(model)
# ```
set_optimizer(model, SCIP.Optimizer)

BilevelJuMP.set_mode(model, BilevelJuMP.IndicatorMode())

optimize!(model)

objective_value(model)

# !!! info
# This code was not executed because SCIP might have a non-standard
# intallation procedure in windows.
# !!! warning
# SCIP requires a non-standard installation procedure in windows.
# See [SCIP.jl](https://github.com/scipopt/SCIP.jl#custom-installations) for
# more details.

# ## `ProductMode` and `Ipopt.Optimizer`

Expand Down Expand Up @@ -152,20 +150,19 @@ objective_value(model)

# ## `MixedMode` and `SCIP.Optimizer`

# ```julia
# set_optimizer(model, SCIP.Optimizer)
#
# BilevelJuMP.set_mode(model, BilevelJuMP.MixedMode(default = SOS1Mode()))
#
# BilevelJuMP.set_mode(c1, BilevelJuMP.IndicatorMode())
#
# BilevelJuMP.set_mode(c3, BilevelJuMP.SOS1Mode())
#
# optimize!(model)
#
# objective_value(model)
# ```

# !!! info
# This code was not executed because SCIP might have a non-standard
# intallation procedure in windows.
set_optimizer(model, SCIP.Optimizer)

BilevelJuMP.set_mode(model, BilevelJuMP.MixedMode(default = BilevelJuMP.SOS1Mode()))

BilevelJuMP.set_mode(c1, BilevelJuMP.IndicatorMode())

BilevelJuMP.set_mode(c3, BilevelJuMP.SOS1Mode())

optimize!(model)

objective_value(model)

# !!! warning
# SCIP requires a non-standard installation procedure in windows.
# See [SCIP.jl](https://github.com/scipopt/SCIP.jl#custom-installations) for
# more details.
26 changes: 16 additions & 10 deletions docs/src/tutorials/quad_to_bin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,21 @@ objective_value(model)
# However, this might lead to some solver not supporting certain functionality like SCIP.
# In this case we need to:

# ```julia
# SOLVER = SCIP.Optimizer()
# CACHED_SOLVER = MOI.Utilities.CachingOptimizer(
# MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()), SOLVER)
# Q_SOLVER = QuadraticToBinary.Optimizer{Float64}(CACHED_SOLVER)
# BilevelModel(()->Q_SOLVER, mode = BilevelJuMP.ProductMode(1e-5))
# ```
using SCIP

# !!! warning
# SCIP requires a non-standard installation procedure in windows.
# See [SCIP.jl](https://github.com/scipopt/SCIP.jl#custom-installations) for
# more details.

SOLVER = SCIP.Optimizer()

CACHED_SOLVER = MOI.Utilities.CachingOptimizer(
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()), SOLVER)

Q_SOLVER = QuadraticToBinary.Optimizer{Float64}(CACHED_SOLVER)

BilevelModel(()->Q_SOLVER, mode = BilevelJuMP.ProductMode(1e-5))

# Note that we used `()->Q_SOLVER` instead of just `Q_SOLVER` because `BilevelModel`
# requires as constructor and not an instance of an object.

# !!! info
# This code was not executed to avoid excessive dependencies to build these docs.
18 changes: 0 additions & 18 deletions src/moi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,24 +168,6 @@ function accept_vector_set(
return nothing
end

function reset!(::AbstractBilevelSolverMode)
return nothing
end

ignore_dual_objective(::AbstractBilevelSolverMode{T}) where {T} = true

function accept_vector_set(
mode::AbstractBilevelSolverMode{T},
con::Complement,
) where {T}
if con.is_vec
error(
"Set $(typeof(con.set_w_zero)) is not accepted when solution method is $(typeof(mode))",
)
end
return nothing
end

#=
ComplementBoundCache used in Big-M
=#
Expand Down

0 comments on commit 787299e

Please sign in to comment.