mirror of
https://github.com/ANL-CEEESA/MIPLearn.jl.git
synced 2025-12-06 08:28:52 -06:00
Allow module to be precompiled
This commit is contained in:
@@ -2,12 +2,21 @@
|
|||||||
# Copyright (C) 2020-2021, UChicago Argonne, LLC. All rights reserved.
|
# Copyright (C) 2020-2021, UChicago Argonne, LLC. All rights reserved.
|
||||||
# Released under the modified BSD license. See COPYING.md for more details.
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
__precompile__(false)
|
|
||||||
module MIPLearn
|
module MIPLearn
|
||||||
|
|
||||||
using PyCall
|
using PyCall
|
||||||
global miplearn = pyimport("miplearn")
|
|
||||||
global traceback = pyimport("traceback")
|
global DynamicLazyConstraintsComponent = PyNULL()
|
||||||
|
global JuMPSolver = PyNULL()
|
||||||
|
global MinPrecisionThreshold = PyNULL()
|
||||||
|
global miplearn = PyNULL()
|
||||||
|
global ObjectiveValueComponent = PyNULL()
|
||||||
|
global PrimalSolutionComponent = PyNULL()
|
||||||
|
global PyFileInstance = PyNULL()
|
||||||
|
global PyJuMPInstance = PyNULL()
|
||||||
|
global StaticLazyConstraintsComponent = PyNULL()
|
||||||
|
global traceback = PyNULL()
|
||||||
|
global UserCutsComponent = PyNULL()
|
||||||
|
|
||||||
include("utils/log.jl")
|
include("utils/log.jl")
|
||||||
include("utils/exceptions.jl")
|
include("utils/exceptions.jl")
|
||||||
@@ -19,12 +28,19 @@ include("solvers/learning.jl")
|
|||||||
include("solvers/macros.jl")
|
include("solvers/macros.jl")
|
||||||
include("utils/benchmark.jl")
|
include("utils/benchmark.jl")
|
||||||
|
|
||||||
DynamicLazyConstraintsComponent = miplearn.DynamicLazyConstraintsComponent
|
function __init__()
|
||||||
UserCutsComponent = miplearn.UserCutsComponent
|
copy!(miplearn, pyimport("miplearn"))
|
||||||
ObjectiveValueComponent = miplearn.ObjectiveValueComponent
|
copy!(traceback, pyimport("traceback"))
|
||||||
PrimalSolutionComponent = miplearn.PrimalSolutionComponent
|
copy!(DynamicLazyConstraintsComponent, miplearn.DynamicLazyConstraintsComponent)
|
||||||
StaticLazyConstraintsComponent = miplearn.StaticLazyConstraintsComponent
|
copy!(UserCutsComponent, miplearn.UserCutsComponent)
|
||||||
MinPrecisionThreshold = miplearn.MinPrecisionThreshold
|
copy!(ObjectiveValueComponent, miplearn.ObjectiveValueComponent)
|
||||||
|
copy!(PrimalSolutionComponent, miplearn.PrimalSolutionComponent)
|
||||||
|
copy!(StaticLazyConstraintsComponent, miplearn.StaticLazyConstraintsComponent)
|
||||||
|
copy!(MinPrecisionThreshold, miplearn.MinPrecisionThreshold)
|
||||||
|
__init_PyFileInstance__()
|
||||||
|
__init_PyJuMPInstance__()
|
||||||
|
__init_JuMPSolver__()
|
||||||
|
end
|
||||||
|
|
||||||
export DynamicLazyConstraintsComponent,
|
export DynamicLazyConstraintsComponent,
|
||||||
UserCutsComponent,
|
UserCutsComponent,
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
# Released under the modified BSD license. See COPYING.md for more details.
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
|
|
||||||
@pydef mutable struct PyFileInstance <: miplearn.Instance
|
function __init_PyFileInstance__()
|
||||||
|
@pydef mutable struct Class <: miplearn.Instance
|
||||||
function __init__(self, filename)
|
function __init__(self, filename)
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.loaded = nothing
|
self.loaded = nothing
|
||||||
@@ -50,9 +51,10 @@
|
|||||||
self.loaded.py.samples = self.samples
|
self.loaded.py.samples = self.samples
|
||||||
save(self.filename, self.loaded)
|
save(self.filename, self.loaded)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
copy!(PyFileInstance, Class)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
struct FileInstance <: Instance
|
struct FileInstance <: Instance
|
||||||
py::PyCall.PyObject
|
py::PyCall.PyObject
|
||||||
filename::AbstractString
|
filename::AbstractString
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
using JuMP
|
using JuMP
|
||||||
using JLD2
|
using JLD2
|
||||||
|
|
||||||
|
function __init_PyJuMPInstance__()
|
||||||
@pydef mutable struct PyJuMPInstance <: miplearn.Instance
|
@pydef mutable struct Class <: miplearn.Instance
|
||||||
function __init__(self, model)
|
function __init__(self, model)
|
||||||
init_miplearn_ext(model)
|
init_miplearn_ext(model)
|
||||||
self.model = model
|
self.model = model
|
||||||
@@ -44,6 +44,8 @@ using JLD2
|
|||||||
c = constraint_by_name(model, cname)
|
c = constraint_by_name(model, cname)
|
||||||
return get(model.ext[:miplearn][:constraint_categories], c, nothing)
|
return get(model.ext[:miplearn][:constraint_categories], c, nothing)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
copy!(PyJuMPInstance, Class)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -467,7 +467,8 @@ function get_constraints(
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@pydef mutable struct JuMPSolver <: miplearn.solvers.internal.InternalSolver
|
function __init_JuMPSolver__()
|
||||||
|
@pydef mutable struct Class <: miplearn.solvers.internal.InternalSolver
|
||||||
function __init__(self, optimizer_factory)
|
function __init__(self, optimizer_factory)
|
||||||
self.data = JuMPSolverData(
|
self.data = JuMPSolverData(
|
||||||
optimizer_factory,
|
optimizer_factory,
|
||||||
@@ -605,6 +606,8 @@ end
|
|||||||
|
|
||||||
solve_lp(self; tee=false) =
|
solve_lp(self; tee=false) =
|
||||||
solve_lp(self.data, tee=tee)
|
solve_lp(self.data, tee=tee)
|
||||||
|
end
|
||||||
|
copy!(JuMPSolver, Class)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user