diff --git a/src/julia/src/MIPLearn.jl b/src/julia/src/MIPLearn.jl index 2458438..15ba77b 100644 --- a/src/julia/src/MIPLearn.jl +++ b/src/julia/src/MIPLearn.jl @@ -32,6 +32,7 @@ end function set_warm_start(self, solution) for (basename, subsolution) in solution for (idx, value) in subsolution + value != nothing || continue var = self.basename_idx_to_var[basename, idx] JuMP.set_start_value(var, value) end @@ -45,6 +46,7 @@ end function fix(self, solution) for (basename, subsolution) in solution for (idx, value) in subsolution + value != nothing || continue var = self.basename_idx_to_var[basename, idx] JuMP.fix(var, value, force=true) end diff --git a/src/julia/test/learning_solver.jl b/src/julia/test/learning_solver.jl index de2ea80..df2f74e 100644 --- a/src/julia/test/learning_solver.jl +++ b/src/julia/test/learning_solver.jl @@ -13,38 +13,21 @@ using Gurobi [505., 352., 458., 220.], 67.0) model = instance.to_model() - - solver = LearningSolver(solver=JuMPSolver(optimizer=optimizer)) + solver = LearningSolver(solver=JuMPSolver(optimizer=optimizer), + mode="heuristic") stats = solver.solve(instance, model) - - @test stats["Lower bound"] == 1183.0 - @test stats["Upper bound"] == 1183.0 - @test stats["Sense"] == "max" - @test stats["Wallclock time"] > 0 - -# solution = solver.get_solution() -# @test solution["x[1]"] == 1.0 -# @test solution["x[2]"] == 0.0 -# @test solution["x[3]"] == 1.0 -# @test solution["x[4]"] == 1.0 -# -# stats = solver.solve_lp() -# @test round(stats["Optimal value"], digits=3) == 1287.923 -# -# solution = solver.get_solution() -# @test round(solution["x[1]"], digits=3) == 1.000 -# @test round(solution["x[2]"], digits=3) == 0.923 -# @test round(solution["x[3]"], digits=3) == 1.000 -# @test round(solution["x[4]"], digits=3) == 0.000 -# -# solver.fix(Dict( -# "x[1]" => 1.0, -# "x[2]" => 0.0, -# "x[3]" => 0.0, -# "x[4]" => 1.0, -# )) -# stats = solver.solve() -# @test stats["Lower bound"] == 725.0 -# @test stats["Upper bound"] == 725.0 + @test instance.solution["x"]["1"] == 1.0 + @test instance.solution["x"]["2"] == 0.0 + @test instance.solution["x"]["3"] == 1.0 + @test instance.solution["x"]["4"] == 1.0 + @test instance.lower_bound == 1183.0 + @test instance.upper_bound == 1183.0 + @test round(instance.lp_solution["x"]["1"], digits=3) == 1.000 + @test round(instance.lp_solution["x"]["2"], digits=3) == 0.923 + @test round(instance.lp_solution["x"]["3"], digits=3) == 1.000 + @test round(instance.lp_solution["x"]["4"], digits=3) == 0.000 + @test round(instance.lp_value, digits=3) == 1287.923 + solver.fit([instance]) + solver.solve(instance) end end \ No newline at end of file diff --git a/src/julia/test/runtests.jl b/src/julia/test/runtests.jl index f421296..940124f 100644 --- a/src/julia/test/runtests.jl +++ b/src/julia/test/runtests.jl @@ -3,8 +3,12 @@ # Released under the modified BSD license. See COPYING.md for more details. using Test +using PyCall + +logging = pyimport("logging") +logging.basicConfig(format="%(levelname)10s %(message)s", level=logging.DEBUG) @testset "MIPLearn" begin include("jump_solver.jl") - #include("learning_solver.jl") + include("learning_solver.jl") end \ No newline at end of file