Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the branching tree file #434

Merged
merged 4 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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