From b0bf42e69dbe82196b6bf3a317ff74e73361bfa6 Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Tue, 6 Apr 2021 16:18:26 -0500 Subject: [PATCH] Remove obsolete extractor classes --- miplearn/__init__.py | 1 - miplearn/extractors.py | 45 ---------------------------------------- tests/test_extractors.py | 34 ------------------------------ 3 files changed, 80 deletions(-) delete mode 100644 miplearn/extractors.py delete mode 100644 tests/test_extractors.py diff --git a/miplearn/__init__.py b/miplearn/__init__.py index 632597b..0f76e73 100644 --- a/miplearn/__init__.py +++ b/miplearn/__init__.py @@ -22,7 +22,6 @@ from .components.primal import PrimalSolutionComponent from .components.steps.convert_tight import ConvertTightIneqsIntoEqsStep from .components.steps.drop_redundant import DropRedundantInequalitiesStep from .components.steps.relax_integrality import RelaxIntegralityStep -from .extractors import InstanceFeaturesExtractor from .instance import ( Instance, PickleGzInstance, diff --git a/miplearn/extractors.py b/miplearn/extractors.py deleted file mode 100644 index ad1f202..0000000 --- a/miplearn/extractors.py +++ /dev/null @@ -1,45 +0,0 @@ -# MIPLearn: Extensible Framework for Learning-Enhanced Mixed-Integer Optimization -# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved. -# Released under the modified BSD license. See COPYING.md for more details. - -import logging -from abc import ABC, abstractmethod - -import numpy as np - -logger = logging.getLogger(__name__) - - -class Extractor(ABC): - @abstractmethod - def extract(self, instances): - pass - - @staticmethod - def split_variables(instance): - result = {} - lp_solution = instance.training_data[0].lp_solution - for var_name in lp_solution: - for index in lp_solution[var_name]: - category = instance.get_variable_category(var_name, index) - if category is None: - continue - if category not in result: - result[category] = [] - result[category] += [(var_name, index)] - return result - - -class InstanceFeaturesExtractor(Extractor): - def extract(self, instances): - return np.vstack( - [ - np.hstack( - [ - instance.get_instance_features(), - instance.training_data[0].lp_value, - ] - ) - for instance in instances - ] - ) diff --git a/tests/test_extractors.py b/tests/test_extractors.py deleted file mode 100644 index e36dcd8..0000000 --- a/tests/test_extractors.py +++ /dev/null @@ -1,34 +0,0 @@ -# MIPLearn: Extensible Framework for Learning-Enhanced Mixed-Integer Optimization -# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved. -# Released under the modified BSD license. See COPYING.md for more details. -import numpy as np - -from miplearn.extractors import InstanceFeaturesExtractor -from miplearn.problems.knapsack import KnapsackInstance -from miplearn.solvers.learning import LearningSolver - - -def _get_instances(): - instances = [ - KnapsackInstance( - weights=[1.0, 2.0, 3.0], - prices=[10.0, 20.0, 30.0], - capacity=2.5, - ), - KnapsackInstance( - weights=[3.0, 4.0, 5.0], - prices=[20.0, 30.0, 40.0], - capacity=4.5, - ), - ] - models = [instance.to_model() for instance in instances] - solver = LearningSolver() - for (i, instance) in enumerate(instances): - solver.solve(instances[i], models[i]) - return instances, models - - -def test_instance_features_extractor(): - instances, models = _get_instances() - features = InstanceFeaturesExtractor().extract(instances) - assert features.shape == (2, 3)