mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 09:28:51 -06:00
Make LearningSolver working with JuMP
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user