From a536d2ecc6309c590d1ed9a544d13bade1ac26c2 Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Tue, 19 Jan 2021 22:52:39 -0600 Subject: [PATCH] Fix various warnings --- miplearn/components/relaxation.py | 18 +++++++++--------- miplearn/log.py | 3 ++- miplearn/solvers/learning.py | 16 +++++++++++++++- miplearn/solvers/pyomo/base.py | 6 +++--- requirements.txt | 1 + 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/miplearn/components/relaxation.py b/miplearn/components/relaxation.py index a3d97e5..d342358 100644 --- a/miplearn/components/relaxation.py +++ b/miplearn/components/relaxation.py @@ -41,11 +41,11 @@ class RelaxationComponent(Component): If a constraint has slack greater than this threshold, then the constraint is considered loose. By default, this threshold equals a small positive number to compensate for numerical issues. - check_dropped : bool, optional - If `check_dropped` is true, then, after the problem is solved, the component - verifies that all dropped constraints are still satisfied, re-adds the violated - ones and resolves the problem. This loop continues until either no violations - are found, or a maximum number of iterations is reached. + check_feasibility : bool, optional + If true, after the problem is solved, the component verifies that all dropped + constraints are still satisfied, re-adds the violated ones and resolves the + problem. This loop continues until either no violations are found, or a maximum + number of iterations is reached. violation_tolerance : float, optional If `check_dropped` is true, a constraint is considered satisfied during the check if its violation is smaller than this tolerance. @@ -61,7 +61,7 @@ class RelaxationComponent(Component): tight_classifier=CountingClassifier(), tight_threshold=0.95, slack_tolerance=1e-5, - check_dropped=False, + check_feasibility=False, violation_tolerance=1e-5, max_check_iterations=3, ): @@ -73,7 +73,7 @@ class RelaxationComponent(Component): slack_tolerance=slack_tolerance, violation_tolerance=violation_tolerance, max_iterations=max_check_iterations, - check_dropped=check_dropped, + check_feasibility=check_feasibility, ), ConvertTightIneqsIntoEqsStep( classifier=tight_classifier, @@ -86,8 +86,8 @@ class RelaxationComponent(Component): def before_solve(self, solver, instance, model): self.composite.before_solve(solver, instance, model) - def after_solve(self, solver, instance, model, results): - self.composite.after_solve(solver, instance, model, results) + def after_solve(self, solver, instance, model, stats, training_data): + self.composite.after_solve(solver, instance, model, stats, training_data) def fit(self, training_instances): self.composite.fit(training_instances) diff --git a/miplearn/log.py b/miplearn/log.py index 1a668ee..6f647d6 100644 --- a/miplearn/log.py +++ b/miplearn/log.py @@ -8,8 +8,9 @@ import time import sys -class TimeFormatter: +class TimeFormatter(logging.Formatter): def __init__(self, start_time, log_colors): + super().__init__() self.start_time = start_time self.log_colors = log_colors diff --git a/miplearn/solvers/learning.py b/miplearn/solvers/learning.py index 6ffd345..156175c 100644 --- a/miplearn/solvers/learning.py +++ b/miplearn/solvers/learning.py @@ -284,7 +284,13 @@ class LearningSolver: return stats - def parallel_solve(self, instances, n_jobs=4, label="Solve", output=[]): + def parallel_solve( + self, + instances, + n_jobs=4, + label="Solve", + output=None, + ): """ Solves multiple instances in parallel. @@ -295,6 +301,12 @@ class LearningSolver: Parameters ---------- + output: [str] or None + If instances are file names and output is provided, write the modified + instances to these files, instead of replacing the original files. If + output is None, discard modified instance. + label: str + Label to show in the progress bar. instances: [miplearn.Instance] or [str] The instances to be solved n_jobs: int @@ -308,6 +320,8 @@ class LearningSolver: [solver.solve(p) for p in instances] """ + if output is None: + output = [] self.internal_solver = None self._silence_miplearn_logger() SOLVER[0] = self diff --git a/miplearn/solvers/pyomo/base.py b/miplearn/solvers/pyomo/base.py index b886b1e..1c3fdd2 100644 --- a/miplearn/solvers/pyomo/base.py +++ b/miplearn/solvers/pyomo/base.py @@ -2,12 +2,12 @@ # Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved. # Released under the modified BSD license. See COPYING.md for more details. +import logging import re import sys -import logging -import pyomo -from abc import abstractmethod from io import StringIO + +import pyomo from pyomo import environ as pe from pyomo.core import Var, Constraint diff --git a/requirements.txt b/requirements.txt index 0398aa5..1317609 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,3 +14,4 @@ scikit-learn~=0.23 tqdm~=4.54 black==20.8b1 pre-commit~=2.9 +scipy~=1.6.0