Skip to content

Commit

Permalink
Integrate TreeSearch in the new interface (#683)
Browse files Browse the repository at this point in the history
* v1 of tree search implementation

* draft for stopping crit + comment broken tests
  • Loading branch information
guimarqu authored Aug 11, 2022
1 parent c9d3009 commit f99e5f9
Show file tree
Hide file tree
Showing 15 changed files with 750 additions and 513 deletions.
15 changes: 11 additions & 4 deletions src/Algorithm/branching/branchingalgo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function _apply_conquer_alg_to_child!(
if ip_gap_closed(child_state, rtol = opt_rtol, atol = opt_atol)
@info "IP Gap is closed: $(ip_gap(child_state)). Abort treatment."
else
run!(algo, env, reform, ConquerInput(Node(child, -1), units_to_restore))
run!(algo, env, reform, ConquerInput(Node(child, -1), units_to_restore, true))
store_records!(reform, child.recordids)
end
child.conquerwasrun = true
Expand Down Expand Up @@ -288,10 +288,17 @@ end
function run!(algo::StrongBranching, env::Env, reform::Reformulation, input::DivideInput)::DivideOutput
parent = getparent(input)
optstate = getoptstate(parent)
nodestatus = getterminationstatus(optstate)

# We don't run the branching algorithm if the node is already conquered
if nodestatus == OPTIMAL || nodestatus == INFEASIBLE || ip_gap_closed(optstate)
println("Node is already conquered. No children will be generated.")
return DivideOutput(SbNode[], optstate)
end

if isempty(algo.rules)
@logmsg LogLevel(0) "No branching rule is defined. No children will be generated."
return DivideOutput(Node[], optstate)
return DivideOutput(SbNode[], optstate)
end

# We retrieve the original and extended solutions.
Expand All @@ -306,7 +313,7 @@ function run!(algo::StrongBranching, env::Env, reform::Reformulation, input::Div
end
else
@warn "no LP solution is passed to the branching algorithm. No children will be generated."
return DivideOutput(Node[], optstate)
return DivideOutput(SbNode[], optstate)
end

parent_is_root = iszero(getdepth(parent))
Expand All @@ -316,7 +323,7 @@ function run!(algo::StrongBranching, env::Env, reform::Reformulation, input::Div

if isempty(kept_branch_candidates)
@logmsg LogLevel(0) "No branching candidates found. No children will be generated."
return DivideOutput(Node[], optstate)
return DivideOutput(SbNode[], optstate)
end

# in the case of simple branching, it remains to generate the children
Expand Down
6 changes: 5 additions & 1 deletion src/Algorithm/conquer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ in the input so that it is not obtained each time the conquer algorithm runs.
struct ConquerInput <: AbstractInput
node::Node
units_to_restore::UnitsUsage
run_conquer::Bool
end

getnode(input::ConquerInput) = input.node
Expand Down Expand Up @@ -58,7 +59,7 @@ function apply_conquer_alg_to_node!(
else
isverbose(algo) && @logmsg LogLevel(-1) string("IP Gap is positive. Need to treat node.")

run!(algo, env, reform, ConquerInput(node, units_to_restore))
run!(algo, env, reform, ConquerInput(node, units_to_restore, true))
store_records!(reform, node.recordids)
end
node.conquerwasrun = true
Expand Down Expand Up @@ -120,6 +121,7 @@ function get_child_algorithms(algo::BendersConquer, reform::Reformulation)
end

function run!(algo::BendersConquer, env::Env, reform::Reformulation, input::ConquerInput)
!input.run_conquer && return
restore_from_records!(input)
node = getnode(input)
nodestate = getoptstate(node)
Expand Down Expand Up @@ -193,6 +195,7 @@ function get_child_algorithms(algo::ColCutGenConquer, reform::Reformulation)
end

function run!(algo::ColCutGenConquer, env::Env, reform::Reformulation, input::ConquerInput)
!input.run_conquer && return
restore_from_records!(input)
node = getnode(input)
nodestate = getoptstate(node)
Expand Down Expand Up @@ -372,6 +375,7 @@ function get_child_algorithms(algo::RestrMasterLPConquer, reform::Reformulation)
end

function run!(algo::RestrMasterLPConquer, env::Env, reform::Reformulation, input::ConquerInput)
!input.run_conquer && return
restore_from_records!(input)
node = getnode(input)
nodestate = getoptstate(node)
Expand Down
2 changes: 1 addition & 1 deletion src/Algorithm/node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Node
####################################################################

mutable struct Node
mutable struct Node <: AbstractNode
tree_order::Int
depth::Int
parent::Union{Nothing, Node}
Expand Down
Loading

0 comments on commit f99e5f9

Please sign in to comment.