diff --git a/src/Algorithm/branchcutprice.jl b/src/Algorithm/branchcutprice.jl index 2679210d8..3eac1e7f2 100644 --- a/src/Algorithm/branchcutprice.jl +++ b/src/Algorithm/branchcutprice.jl @@ -55,6 +55,7 @@ Parameters : function BranchCutAndPriceAlgorithm(; maxnumnodes::Int = 100000, branchingtreefile::String = "", + jsonfile::String = "", opt_atol::Float64 = Coluna.DEF_OPTIMALITY_ATOL, opt_rtol::Float64 = Coluna.DEF_OPTIMALITY_RTOL, restmastipheur_timelimit::Int = 600, @@ -151,6 +152,7 @@ function BranchCutAndPriceAlgorithm(; dividealg = branching, maxnumnodes = maxnumnodes, branchingtreefile = branchingtreefile, + jsonfile = jsonfile, opt_atol = opt_atol; opt_rtol = opt_rtol ) diff --git a/src/Algorithm/treesearch/printer.jl b/src/Algorithm/treesearch/printer.jl index 72cc1693c..4381e9900 100644 --- a/src/Algorithm/treesearch/printer.jl +++ b/src/Algorithm/treesearch/printer.jl @@ -126,12 +126,23 @@ filename(f::JSONFilePrinter) = f.filename function init_tree_search_file!(f::JSONFilePrinter) open(filename(f), "w") do file - println(file, "{") - println(file, "\t\"nodes\": [") + println(file, "[") end return end +# To get rid of "Inf". +function _printed_num(num) + if isinf(num) + if num < 0 + return -99999999999 + else + return +99999999999 + end + end + return num +end + function print_node_in_tree_search_file!(f::JSONFilePrinter, node::PrintedNode, sp::PrinterSearchSpace, env) is_root_node = iszero(getdepth(node.inner)) current_node_id = node.tree_order_id @@ -146,22 +157,18 @@ function print_node_in_tree_search_file!(f::JSONFilePrinter, node::PrintedNode, infeasible = getterminationstatus(node.inner.conquer_output) == INFEASIBLE open(filename(f), "r+") do file - # rewind the closing brace character seekend(file) - pos = position(file) - seek(file, pos - 1) - # start writing over this character - @printf file "\n\t\t{\"node_id\": %i, " current_node_id + @printf file "\n\t\t{ \"node_id\": %i, " current_node_id @printf file "\"depth\": %i, " current_node_depth @printf file "\"parent_id\": %s, " is_root_node ? "null" : string(current_parent_id) - @printf file "\"time\": %.0f, " time - @printf file "\"primal_bound\": %.4f, " global_pb - @printf file "\"local_dual_bound\": %.4f, " local_db - @printf file "\"global_dual_bound\": %.4f, " global_db + @printf file "\"time\": %.2f, " time + @printf file "\"primal_bound\": %.4f, " _printed_num(global_pb) + @printf file "\"local_dual_bound\": %.4f, " _printed_num(local_db) + @printf file "\"global_dual_bound\": %.4f, " _printed_num(global_db) @printf file "\"pruned\": %s, " gap_closed ? "true" : "false" @printf file "\"infeasible\": %s, " infeasible ? "true" : "false" - @printf file "\"branch\": \"%s\"}," is_root_node ? "null" : br_constr_description + @printf file "\"branch\": %s },\n" is_root_node ? "null" : string("\"", br_constr_description, "\"") end return end @@ -171,10 +178,9 @@ function close_tree_search_file!(f::JSONFilePrinter) # rewind the closing brace character seekend(file) pos = position(file) - seek(file, pos - 1) + seek(file, pos - 2) # just move the closing brace to the next line println(file, "\n\t]") - println(file, "}") end return end diff --git a/test/e2e/gap/generalized_assignment.jl b/test/e2e/gap/generalized_assignment.jl index 0caa49c97..e4b218418 100644 --- a/test/e2e/gap/generalized_assignment.jl +++ b/test/e2e/gap/generalized_assignment.jl @@ -52,7 +52,7 @@ function gap_toy_instance_2() @test MOI.get(model, MOI.NumberOfVariables()) == length(x) @test MOI.get(model, MOI.SolverName()) == "Coluna" end -register!(e2e_tests, "gap", gap_toy_instance) +register!(e2e_tests, "gap", gap_toy_instance_2) function gap_strong_branching() data = ClD.GeneralizedAssignment.data("mediumgapcuts3.txt")