mirror of
https://github.com/ANL-CEEESA/MIPLearn.jl.git
synced 2025-12-06 08:28:52 -06:00
Partial implementation of parallel_solve
This commit is contained in:
@@ -6,20 +6,16 @@ __precompile__(false)
|
||||
module MIPLearn
|
||||
|
||||
using PyCall
|
||||
|
||||
export JuMPInstance
|
||||
export LearningSolver
|
||||
export @feature
|
||||
export @category
|
||||
|
||||
miplearn = pyimport("miplearn")
|
||||
global miplearn = pyimport("miplearn")
|
||||
global traceback = pyimport("traceback")
|
||||
|
||||
include("utils/log.jl")
|
||||
include("utils/exceptions.jl")
|
||||
include("instance/abstract.jl")
|
||||
include("instance/jump.jl")
|
||||
include("instance/file.jl")
|
||||
include("solvers/jump.jl")
|
||||
include("solvers/learning.jl")
|
||||
include("solvers/macros.jl")
|
||||
include("instance/jump.jl")
|
||||
include("instance/file.jl")
|
||||
|
||||
end # module
|
||||
|
||||
8
src/instance/abstract.jl
Normal file
8
src/instance/abstract.jl
Normal file
@@ -0,0 +1,8 @@
|
||||
# MIPLearn: Extensible Framework for Learning-Enhanced Mixed-Integer Optimization
|
||||
# Copyright (C) 2020-2021, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
abstract type Instance
|
||||
end
|
||||
|
||||
|
||||
@@ -55,12 +55,16 @@ end
|
||||
|
||||
struct FileInstance <: Instance
|
||||
py::PyCall.PyObject
|
||||
filename::AbstractString
|
||||
end
|
||||
|
||||
|
||||
function FileInstance(filename)::FileInstance
|
||||
filename isa AbstractString || error("filename should be a string. Found $(typeof(filename)) instead.")
|
||||
return FileInstance(PyFileInstance(filename))
|
||||
return FileInstance(
|
||||
PyFileInstance(filename),
|
||||
filename,
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -2,18 +2,21 @@
|
||||
# Copyright (C) 2020-2021, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
using Distributed
|
||||
|
||||
|
||||
struct LearningSolver
|
||||
py::PyCall.PyObject
|
||||
end
|
||||
|
||||
|
||||
abstract type Instance
|
||||
optimizer_factory
|
||||
end
|
||||
|
||||
|
||||
function LearningSolver(optimizer_factory)::LearningSolver
|
||||
py = miplearn.LearningSolver(solver=JuMPSolver(optimizer_factory))
|
||||
return LearningSolver(py)
|
||||
return LearningSolver(
|
||||
py,
|
||||
optimizer_factory,
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@@ -31,7 +34,19 @@ function fit!(solver::LearningSolver, instances::Vector{<:Instance})
|
||||
end
|
||||
|
||||
|
||||
function parallel_solve!(solver::LearningSolver, instances::Vector{FileInstance})
|
||||
filenames = [instance.filename for instance in instances]
|
||||
optimizer_factory = solver.optimizer_factory
|
||||
@sync @distributed for filename in filenames
|
||||
s = LearningSolver(optimizer_factory)
|
||||
solve!(s, FileInstance(filename))
|
||||
nothing
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
export Instance,
|
||||
LearningSolver,
|
||||
solve!,
|
||||
fit!
|
||||
fit!,
|
||||
parallel_solve!
|
||||
|
||||
@@ -62,3 +62,7 @@ macro category(obj, category)
|
||||
set_category!($(esc(obj)), $(esc(category)))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
export @feature,
|
||||
@category
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
using PyCall
|
||||
traceback = pyimport("traceback")
|
||||
|
||||
|
||||
macro python_call(expr)
|
||||
|
||||
Reference in New Issue
Block a user