Skip to content

Commit

Permalink
Update benders_decomposition.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Oct 5, 2023
1 parent 07a9278 commit 8d2d4eb
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions docs/src/tutorials/algorithms/benders_decomposition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ print(lazy_model)

# What differs is that we write a callback function instead of a loop:

k = 0

number_of_subproblem_solves = 0
function my_callback(cb_data)
status = callback_node_status(cb_data, lazy_model)
if status != MOI.CALLBACK_NODE_STATUS_INTEGER
Expand All @@ -254,6 +253,7 @@ function my_callback(cb_data)
end
x_k = callback_value.(cb_data, x)
θ_k = callback_value(cb_data, θ)
number_of_subproblem_solves += 1
ret = solve_subproblem(x_k)
if θ_k < (ret.obj - 1e-6)
## Only add the constraint if θ_k violates the constraint
Expand All @@ -269,6 +269,13 @@ set_attribute(lazy_model, MOI.LazyConstraintCallback(), my_callback)

optimize!(lazy_model)

# For this model, the callback algorithm required more solves of the subproblem:

number_of_subproblem_solves

# But for larger problem, you cann expect the callback algorithm to be more
# efficient than the iterative algorithm.

# Finally, we can obtain the optimal solution:

Test.@test value.(x) == [0.0, 1.0] #src
Expand Down

0 comments on commit 8d2d4eb

Please sign in to comment.