mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-07 09:58:51 -06:00
33 lines
882 B
Python
33 lines
882 B
Python
# 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
|
|
import sys
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class RedirectOutput:
|
|
def __init__(self, streams):
|
|
self.streams = streams
|
|
|
|
def write(self, data):
|
|
for stream in self.streams:
|
|
stream.write(data)
|
|
|
|
def flush(self):
|
|
for stream in self.streams:
|
|
stream.flush()
|
|
|
|
def __enter__(self):
|
|
self._original_stdout = sys.stdout
|
|
self._original_stderr = sys.stderr
|
|
sys.stdout = self
|
|
sys.stderr = self
|
|
return self
|
|
|
|
def __exit__(self, _type, _value, _traceback):
|
|
sys.stdout = self._original_stdout
|
|
sys.stderr = self._original_stderr
|