Skip to content

Commit

Permalink
Merge pull request #199 from joaquimg/jg/fixdoc
Browse files Browse the repository at this point in the history
Cleanup docs
  • Loading branch information
joaquimg authored May 23, 2023
2 parents fb67801 + ff3e3af commit 1572c9f
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 55 deletions.
2 changes: 1 addition & 1 deletion docs/src/examples/DTMP_example1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ set_silent(model)

optimize!(model)

# Auto testing
# Results

value(x)

Expand Down
40 changes: 28 additions & 12 deletions docs/src/examples/FOBP_example2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

using BilevelJuMP
using Ipopt
using Test
using Test #src

model = BilevelModel(Ipopt.Optimizer; mode = BilevelJuMP.ProductMode(1e-9))

Expand Down Expand Up @@ -82,15 +82,31 @@ BilevelJuMP.set_primal_upper_bound_hint(y, 9)

optimize!(model)

# Test expected results

@test objective_value(model) 3 * (3.5 * 8 / 15) + (8 / 15) atol = 1e-4
@test BilevelJuMP.lower_objective_value(model) -3.5 * 8 / 15 atol = 1e-4
@test objective_value(Lower(model)) -3.5 * 8 / 15 atol = 1e-4
@test value(x) 3.5 * 8 / 15 atol = 1e-4
@test value(y) 8 / 15 atol = 1e-4
@test value(u1) 3.5 * 8 / 15 atol = 1e-4
@test value(l1) 4.5 * 8 / 15 atol = 1e-4
@test dual(l1) [0] atol = 1e-4
@test dual(l3) [0] atol = 1e-4
objective_value(model)

objective_value(Lower(model))

value(x)

value(y)

value(u1)

value(l1)

dual(l1)

dual(l3)

# Test expected results #src

@test objective_value(model) 3 * (3.5 * 8 / 15) + (8 / 15) atol = 1e-4 #src
@test BilevelJuMP.lower_objective_value(model) -3.5 * 8 / 15 atol = 1e-4 #src
@test objective_value(Lower(model)) -3.5 * 8 / 15 atol = 1e-4 #src
@test value(x) 3.5 * 8 / 15 atol = 1e-4 #src
@test value(y) 8 / 15 atol = 1e-4 #src
@test value(u1) 3.5 * 8 / 15 atol = 1e-4 #src
@test value(l1) 4.5 * 8 / 15 atol = 1e-4 #src
@test dual(l1) [0] atol = 1e-4 #src
@test dual(l3) [0] atol = 1e-4 #src

47 changes: 36 additions & 11 deletions docs/src/examples/FOBP_example3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@

using BilevelJuMP
using Ipopt
using Test
using Test #src

model = BilevelModel(Ipopt.Optimizer; mode = BilevelJuMP.ProductMode(1e-9))

# Global variables

I = 7 # maximum literals
clauses = [[1, 2, 3], [-1, -4, 3], [7, -6, 4], [5, 6, 7]]
atol = 1e-6

# First we need to create all of the variables in the upper and lower problems:

# Upper level variables
Expand Down Expand Up @@ -99,15 +99,40 @@ end
# Dempe.

optimize!(model)

#
primal_status(model)

#

termination_status(model)

# Auto testing
@test objective_value(model) -1 atol = atol
@test value.(x) zeros(I) atol = atol
@test value.(ya) ones(I) atol = atol
@test value.(yb) zeros(I) atol = atol
@test value(z) 1 atol = atol
# @show dual.(b1) #≈ 6 atol=atol
# @show dual.(b2) #≈ 2 atol=atol
# @show dual.(b3) #≈ 2 atol=atol
# Results

objective_value(model)

#

value.(x)

#

value.(ya)

#

value.(yb)

#

value(z)


# Auto testing #src
atol = 1e-4 #src
@test objective_value(model) -1 atol = atol #src
@test value.(x) zeros(I) atol = atol #src
@test value.(ya) ones(I) atol = atol #src
@test value.(yb) zeros(I) atol = atol #src
@test value(z) 1 atol = atol #src

24 changes: 16 additions & 8 deletions docs/src/examples/FOBP_example4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@

using BilevelJuMP
using Ipopt
using Test
using Test #src

model = BilevelModel(Ipopt.Optimizer; mode = BilevelJuMP.ProductMode(1e-9))

# Global variables
atol = 1e-3

# First we need to create all of the variables in the upper and lower problems:

# Upper level variables
Expand Down Expand Up @@ -57,10 +54,21 @@ atol = 1e-3
# Dempe.

optimize!(model)

primal_status(model)

termination_status(model)

# Auto testing
@test objective_value(model) 0 atol = atol
@test value(x) 0 atol = atol
@test value(y) 0 atol = atol
# Results

objective_value(model)

value(x)

value(y)

# Auto testing #src
atol = 1e-3 # src
@test objective_value(model) 0 atol = atol #src
@test value(x) 0 atol = atol #src
@test value(y) 0 atol = atol #src
13 changes: 7 additions & 6 deletions docs/src/examples/FOBP_example5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@

using BilevelJuMP
using Ipopt
using Test
using Test #src

model = BilevelModel(Ipopt.Optimizer; mode = BilevelJuMP.ProductMode(1e-9))

# Global variables
atol = 1e-3

# First we need to create all of the variables in the upper and lower problems:

# Upper level variables
Expand All @@ -53,11 +50,15 @@ atol = 1e-3
@constraint(Lower(model), -4x + 5y <= 10)
@constraint(Lower(model), -4x - 5y <= 10)

# Initial Starting conditions #src

# Now we can solve the problem and verify the solution again that reported by
# Dempe.

optimize!(model)

primal_status(model)

termination_status(model)

value(x)

value(y)
16 changes: 10 additions & 6 deletions docs/src/examples/PHTP_example1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@

using BilevelJuMP
using Ipopt
using Test
using Test #src

model = BilevelModel(Ipopt.Optimizer; mode = BilevelJuMP.ProductMode(1e-9))

# Global variables
atol = 1e-3

# First we need to create all of the variables in the upper and lower problems:

# Upper level variables
Expand Down Expand Up @@ -62,8 +59,15 @@ atol = 1e-3
# the book.

optimize!(model)

primal_status(model)

termination_status(model)

@test value(x) 1 atol = atol
@test value(y) 0 atol = atol
value(x)

value(y)

atol = 1e-3 #src
@test value(x) 1 atol = atol #src
@test value(y) 0 atol = atol #src
23 changes: 17 additions & 6 deletions docs/src/examples/PHTP_example2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

using BilevelJuMP
using Ipopt
using Test
using Test #src

model = BilevelModel(Ipopt.Optimizer; mode = BilevelJuMP.ProductMode(1e-9))

Expand Down Expand Up @@ -61,12 +61,23 @@ model = BilevelModel(Ipopt.Optimizer; mode = BilevelJuMP.ProductMode(1e-9))
# Now we can solve the problem and verify the solution again that reported by the book

optimize!(model)

primal_status(model)

termination_status(model)

# Auto testing
@test objective_value(model) 0 atol = 1e-3
sol = vcat(value.(x), value.(y))
@test sol [0; 0; -10; -10] || sol [0; 30; -10; 10] #atol=1e-3
objective_value(model)

value.(x)

value.(y)

# Auto testing #src
@test objective_value(model) 0 atol = 1e-3 #src
sol = vcat(value.(x), value.(y)) #src
@test sol [0; 0; -10; -10] || sol [0; 30; -10; 10] #atol=1e-3 #src

# # Like any other optimization problem, there is a chance in bilevel optimization to find multiple solutions with the same optimal value; based on the inherent stochasticity of the algorithm and random seed, we are expecting two optimal solutions for this problem.
# # Like any other optimization problem, there is a chance in bilevel
# optimization to find multiple solutions with the same optimal value;
# based on the inherent stochasticity of the algorithm and random seed,
# we are expecting two optimal solutions for this problem.
14 changes: 9 additions & 5 deletions docs/src/examples/SOCBLP_example1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

using BilevelJuMP
using Ipopt
using Test
using Test #src

model = BilevelModel(
() -> MOI.Bridges.Constraint.SOCtoNonConvexQuad{Float64}(Ipopt.Optimizer());
Expand Down Expand Up @@ -90,12 +90,16 @@ end
# Now we can solve the problem and verify the solution again that reported by

optimize!(model)

primal_status(model)

termination_status(model)

objective_value(model)

value.(y)

@test objective_value(model) 12 atol = 1e-1
@test value(x) 6 atol = 1e-3
@test value(y[2]) >= 0 - 1e-3
@test value(y[1]) - value(y[2]) 2 atol = 1e-3
@test objective_value(model) 12 atol = 1e-1 #src
@test value(x) 6 atol = 1e-3 #src
@test value(y[2]) >= 0 - 1e-3 #src
@test value(y[1]) - value(y[2]) 2 atol = 1e-3 #src

2 comments on commit 1572c9f

@joaquimg
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/84057

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.1 -m "<description of version>" 1572c9fc60773ca0cdfadba07f7cd265a1217a37
git push origin v0.6.1

Please sign in to comment.