Skip to content

Commit

Permalink
Fixing the branching tree file (#434)
Browse files Browse the repository at this point in the history
* Fixed the branching tree file when used before the algorithm finishes

* Letting the pruned nodes appear in the branching tree file and marking pruned nodes as pruned

* Making it more clear that the last character (a closing brace) of the branching tree file is removed before updating it

* Overwritting the closing brace in the branching tree file without rewritting everything
  • Loading branch information
artalvpes authored Jan 20, 2021
1 parent 3ff9f41 commit 9772423
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
15 changes: 2 additions & 13 deletions src/Algorithm/branching/branchingalgo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ function perform_strong_branching_with_phases!(
sort!(group.children, by = x -> get_lp_primal_bound(getoptstate(x)))
end

pruned_nodes_indices = Vector{Int64}()
# Here, we avoid the removal of pruned nodes at this point to let them
# appear in the branching tree file
for (node_index, node) in enumerate(group.children)
if isverbose(current_phase.conquer_algo)
print(
Expand All @@ -162,21 +163,9 @@ function perform_strong_branching_with_phases!(
if isverbose(current_phase.conquer_algo)
println("Branch is conquered!")
end
push!(pruned_nodes_indices, node_index)
remove_states!(node.stateids)
end
end

deleteat!(group.children, pruned_nodes_indices)

if isempty(group.children)
setconquered!(group)
if isverbose(current_phase.conquer_algo)
println("SB phase ", phase_index, " candidate ", group_index, " is conquered !")
end
break
end

if phase_index < length(algo.phases)
# not the last phase, thus we compute the product score
compute_product_score!(group, getoptstate(parent))
Expand Down
30 changes: 24 additions & 6 deletions src/Algorithm/treesearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function init_branching_tree_file(algo::TreeSearchAlgorithm)
open(algo.branchingtreefile, "w") do file
println(file, "## dot -Tpdf thisfile > thisfile.pdf \n")
println(file, "digraph Branching_Tree {")
println(file, "\tedge[fontname = \"Courier\", fontsize = 10];")
print(file, "\tedge[fontname = \"Courier\", fontsize = 10];}")
end
end
return
Expand All @@ -206,13 +206,25 @@ function print_node_in_branching_tree_file(algo::TreeSearchAlgorithm, data::Tree
if algo.branchingtreefile !== nothing
pb = getvalue(get_ip_primal_bound(getoptstate(data)))
db = getvalue(get_ip_dual_bound(getoptstate(node)))
open(algo.branchingtreefile, "a") do file
open(algo.branchingtreefile, "r+") do file
# rewind the closing brace character
seekend(file)
pos = position(file)
seek(file, pos - 1)

# start writing over this character
ncur = get_tree_order(node)
time = Coluna._elapsed_solve_time()
@printf file "\tn%i [label= \"N_%i (%.0f s) \\n[%.4f , %.4f]\"];\n" ncur ncur time db pb
if ip_gap_closed(getoptstate(node))
@printf file "\n\tn%i [label= \"N_%i (%.0f s) \\nPRUNED\"];" ncur ncur time
else
@printf file "\n\tn%i [label= \"N_%i (%.0f s) \\n[%.4f , %.4f]\"];" ncur ncur time db pb
end
if !isrootnode(node)
npar = get_tree_order(getparent(node))
@printf file "\tn%i -> n%i [label= \"%s\"];\n" npar ncur node.branchdescription
@printf file "\n\tn%i -> n%i [label= \"%s\"];}" npar ncur node.branchdescription
else
print(file, "}")
end
end
end
Expand All @@ -221,8 +233,14 @@ end

function finish_branching_tree_file(algo::TreeSearchAlgorithm)
if algo.branchingtreefile !== nothing
open(algo.branchingtreefile, "a") do file
println(file, "}")
open(algo.branchingtreefile, "r+") do file
# rewind the closing brace character
seekend(file)
pos = position(file)
seek(file, pos - 1)

# just move the closing brace to the next line
println(file, "\n}")
end
end
return
Expand Down

0 comments on commit 9772423

Please sign in to comment.