From b91ca9e6cb4966f3be604ea737d429a68bf7a17d Mon Sep 17 00:00:00 2001 From: Alinson S Xavier Date: Wed, 6 Jan 2021 09:14:58 -0600 Subject: [PATCH] Re-add RELOG.write function --- src/model.jl | 5 +---- src/reports.jl | 6 ++++++ test/model_test.jl | 16 +++++++++++----- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/model.jl b/src/model.jl index fe8ed96..2177d1e 100644 --- a/src/model.jl +++ b/src/model.jl @@ -280,10 +280,7 @@ function solve(instance::Instance; solution = get_solution(model, marginal_costs=marginal_costs) if output != nothing - @info "Writing solution: $output" - open(output, "w") do file - JSON.print(file, solution, 2) - end + write(solution, output) end return solution diff --git a/src/reports.jl b/src/reports.jl index ef89d48..a068ae8 100644 --- a/src/reports.jl +++ b/src/reports.jl @@ -255,6 +255,12 @@ function transportation_emissions_report(solution)::DataFrame return df end +function write(solution::AbstractDict, filename::AbstractString) + @info "Writing solution: $filename" + open(filename, "w") do file + JSON.print(file, solution, 2) + end +end write_plants_report(solution, filename) = CSV.write(filename, plants_report(solution)) diff --git a/test/model_test.jl b/test/model_test.jl index a012323..c66e6e7 100644 --- a/test/model_test.jl +++ b/test/model_test.jl @@ -36,15 +36,21 @@ using RELOG, Cbc, JuMP, Printf, JSON, MathOptInterface.FileFormats @test lower_bound(v) == 0.0 @test upper_bound(v) == 1.0 - #dest = FileFormats.Model(format = FileFormats.FORMAT_LP) - #MOI.copy_to(dest, model.mip) - #MOI.write_to_file(dest, "model.lp") + # dest = FileFormats.Model(format = FileFormats.FORMAT_LP) + # MOI.copy_to(dest, model.mip) + # MOI.write_to_file(dest, "model.lp") end @testset "solve (exact)" begin - solution_filename = tempname() + solution_filename_a = tempname() + solution_filename_b = tempname() solution = RELOG.solve("$(pwd())/../instances/s1.json", - output=solution_filename) + output=solution_filename_a) + + @test isfile(solution_filename_a) + + RELOG.write(solution, solution_filename_b) + @test isfile(solution_filename_b) @test "Costs" in keys(solution) @test "Fixed operating (\$)" in keys(solution["Costs"])