parent
117ed8d4cd
commit
dabcfef00f
@ -0,0 +1,7 @@
|
|||||||
|
global BasicCollector = PyNULL()
|
||||||
|
|
||||||
|
function __init_collectors__()
|
||||||
|
copy!(BasicCollector, pyimport("miplearn.collectors.basic").BasicCollector)
|
||||||
|
end
|
||||||
|
|
||||||
|
export BasicCollector
|
@ -0,0 +1,65 @@
|
|||||||
|
|
||||||
|
global MinProbabilityClassifier = PyNULL()
|
||||||
|
global SingleClassFix = PyNULL()
|
||||||
|
global PrimalComponentAction = PyNULL()
|
||||||
|
global SetWarmStart = PyNULL()
|
||||||
|
global FixVariables = PyNULL()
|
||||||
|
global EnforceProximity = PyNULL()
|
||||||
|
global ExpertPrimalComponent = PyNULL()
|
||||||
|
global IndependentVarsPrimalComponent = PyNULL()
|
||||||
|
global JointVarsPrimalComponent = PyNULL()
|
||||||
|
global SolutionConstructor = PyNULL()
|
||||||
|
global MemorizingPrimalComponent = PyNULL()
|
||||||
|
global SelectTopSolutions = PyNULL()
|
||||||
|
global MergeTopSolutions = PyNULL()
|
||||||
|
|
||||||
|
function __init_components__()
|
||||||
|
copy!(
|
||||||
|
MinProbabilityClassifier,
|
||||||
|
pyimport("miplearn.classifiers.minprob").MinProbabilityClassifier,
|
||||||
|
)
|
||||||
|
copy!(SingleClassFix, pyimport("miplearn.classifiers.singleclass").SingleClassFix)
|
||||||
|
copy!(
|
||||||
|
PrimalComponentAction,
|
||||||
|
pyimport("miplearn.components.primal.actions").PrimalComponentAction,
|
||||||
|
)
|
||||||
|
copy!(SetWarmStart, pyimport("miplearn.components.primal.actions").SetWarmStart)
|
||||||
|
copy!(FixVariables, pyimport("miplearn.components.primal.actions").FixVariables)
|
||||||
|
copy!(EnforceProximity, pyimport("miplearn.components.primal.actions").EnforceProximity)
|
||||||
|
copy!(
|
||||||
|
ExpertPrimalComponent,
|
||||||
|
pyimport("miplearn.components.primal.expert").ExpertPrimalComponent,
|
||||||
|
)
|
||||||
|
copy!(
|
||||||
|
IndependentVarsPrimalComponent,
|
||||||
|
pyimport("miplearn.components.primal.indep").IndependentVarsPrimalComponent,
|
||||||
|
)
|
||||||
|
copy!(
|
||||||
|
JointVarsPrimalComponent,
|
||||||
|
pyimport("miplearn.components.primal.joint").JointVarsPrimalComponent,
|
||||||
|
)
|
||||||
|
copy!(
|
||||||
|
SolutionConstructor,
|
||||||
|
pyimport("miplearn.components.primal.mem").SolutionConstructor,
|
||||||
|
)
|
||||||
|
copy!(
|
||||||
|
MemorizingPrimalComponent,
|
||||||
|
pyimport("miplearn.components.primal.mem").MemorizingPrimalComponent,
|
||||||
|
)
|
||||||
|
copy!(SelectTopSolutions, pyimport("miplearn.components.primal.mem").SelectTopSolutions)
|
||||||
|
copy!(MergeTopSolutions, pyimport("miplearn.components.primal.mem").MergeTopSolutions)
|
||||||
|
end
|
||||||
|
|
||||||
|
export MinProbabilityClassifier,
|
||||||
|
SingleClassFix,
|
||||||
|
PrimalComponentAction,
|
||||||
|
SetWarmStart,
|
||||||
|
FixVariables,
|
||||||
|
EnforceProximity,
|
||||||
|
ExpertPrimalComponent,
|
||||||
|
IndependentVarsPrimalComponent,
|
||||||
|
JointVarsPrimalComponent,
|
||||||
|
SolutionConstructor,
|
||||||
|
MemorizingPrimalComponent,
|
||||||
|
SelectTopSolutions,
|
||||||
|
MergeTopSolutions
|
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
global FeaturesExtractor = PyNULL()
|
||||||
|
global AlvLouWeh2017Extractor = PyNULL()
|
||||||
|
global DummyExtractor = PyNULL()
|
||||||
|
global H5FieldsExtractor = PyNULL()
|
||||||
|
|
||||||
|
function __init_extractors__()
|
||||||
|
copy!(FeaturesExtractor, pyimport("miplearn.extractors.abstract").FeaturesExtractor)
|
||||||
|
copy!(
|
||||||
|
AlvLouWeh2017Extractor,
|
||||||
|
pyimport("miplearn.extractors.AlvLouWeh2017").AlvLouWeh2017Extractor,
|
||||||
|
)
|
||||||
|
copy!(DummyExtractor, pyimport("miplearn.extractors.dummy").DummyExtractor)
|
||||||
|
copy!(H5FieldsExtractor, pyimport("miplearn.extractors.fields").H5FieldsExtractor)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
export FeaturesExtractor, AlvLouWeh2017Extractor, DummyExtractor, H5FieldsExtractor
|
@ -0,0 +1,7 @@
|
|||||||
|
global LearningSolver = PyNULL()
|
||||||
|
|
||||||
|
function __init_solvers_learning__()
|
||||||
|
copy!(LearningSolver, pyimport("miplearn.solvers.learning").LearningSolver)
|
||||||
|
end
|
||||||
|
|
||||||
|
export LearningSolver
|
Binary file not shown.
@ -0,0 +1,14 @@
|
|||||||
|
function fixture_setcover_data()
|
||||||
|
return SetCoverData(
|
||||||
|
costs = [5, 10, 12, 6, 8],
|
||||||
|
incidence_matrix = [
|
||||||
|
1 0 0 1 0
|
||||||
|
1 1 0 0 0
|
||||||
|
0 0 1 1 1
|
||||||
|
],
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
function fixture_setcover_model()
|
||||||
|
return build_setcover_model(fixture_setcover_data())
|
||||||
|
end
|
@ -1,5 +1,18 @@
|
|||||||
using MIPLearn
|
using MIPLearn
|
||||||
|
|
||||||
|
function test_io()
|
||||||
|
test_pkl_gz()
|
||||||
|
test_h5()
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_pkl_gz()
|
||||||
|
original = Dict("K1" => 1, "K2" => [0, 1, 2], "K3" => "Hello")
|
||||||
|
dirname = tempdir()
|
||||||
|
MIPLearn.write_pkl_gz([original], dirname)
|
||||||
|
recovered = MIPLearn.read_pkl_gz("$dirname/00000.pkl.gz")
|
||||||
|
@test recovered == original
|
||||||
|
end
|
||||||
|
|
||||||
function test_h5()
|
function test_h5()
|
||||||
h5 = H5File(tempname(), "w")
|
h5 = H5File(tempname(), "w")
|
||||||
_test_roundtrip_scalar(h5, "A")
|
_test_roundtrip_scalar(h5, "A")
|
@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
function test_usage()
|
||||||
|
LogisticRegression = pyimport("sklearn.linear_model").LogisticRegression
|
||||||
|
|
||||||
|
@debug "Generating data files..."
|
||||||
|
dirname = tempdir()
|
||||||
|
data = [fixture_setcover_data()]
|
||||||
|
data_filenames = write_pkl_gz(data, dirname)
|
||||||
|
h5_filenames = ["$(f).h5" for f in data_filenames]
|
||||||
|
|
||||||
|
@debug "Setting up LearningSolver..."
|
||||||
|
solver = LearningSolver(
|
||||||
|
components = [
|
||||||
|
IndependentVarsPrimalComponent(
|
||||||
|
base_clf = SingleClassFix(
|
||||||
|
MinProbabilityClassifier(
|
||||||
|
base_clf = LogisticRegression(),
|
||||||
|
thresholds = [0.95, 0.95],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
extractor = AlvLouWeh2017Extractor(),
|
||||||
|
action = SetWarmStart(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
@debug "Collecting training data..."
|
||||||
|
bc = BasicCollector()
|
||||||
|
bc.collect(data_filenames, build_setcover_model)
|
||||||
|
|
||||||
|
@debug "Training models..."
|
||||||
|
solver.fit(data_filenames)
|
||||||
|
|
||||||
|
@debug "Solving model..."
|
||||||
|
solver.optimize(data_filenames[1], build_setcover_model)
|
||||||
|
|
||||||
|
@debug "Checking solution..."
|
||||||
|
h5 = H5File(h5_filenames[1])
|
||||||
|
@test h5.get_scalar("mip_obj_value") == 11.0
|
||||||
|
end
|
Loading…
Reference in new issue