diff --git a/CHANGELOG.md b/CHANGELOG.md index 203eeb45..1c6cdf10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Added primal_dual_evolution recipe and a plot recipe ### Fixed ### Changed +- Allowed writeProblem to print to standard output ### Removed ## 5.2.1 - 2024.10.29 diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index d2063f5f..2bbcb810 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -2911,22 +2911,27 @@ cdef class Model: user_locale = locale.getlocale(category=locale.LC_NUMERIC) locale.setlocale(locale.LC_NUMERIC, "C") - str_absfile = abspath(filename) - absfile = str_conversion(str_absfile) - fn, ext = splitext(absfile) - - if len(ext) == 0: - ext = str_conversion('.cip') - fn = fn + ext - ext = ext[1:] - - if trans: - PY_SCIP_CALL(SCIPwriteTransProblem(self._scip, fn, ext, genericnames)) + if filename: + str_absfile = abspath(filename) + absfile = str_conversion(str_absfile) + fn, ext = splitext(absfile) + if len(ext) == 0: + ext = str_conversion('.cip') + fn = fn + ext + ext = ext[1:] + + if trans: + PY_SCIP_CALL(SCIPwriteTransProblem(self._scip, fn, ext, genericnames)) + else: + PY_SCIP_CALL(SCIPwriteOrigProblem(self._scip, fn, ext, genericnames)) + + if verbose: + print('wrote problem to file ' + str_absfile) else: - PY_SCIP_CALL(SCIPwriteOrigProblem(self._scip, fn, ext, genericnames)) - - if verbose: - print('wrote problem to file ' + str_absfile) + if trans: + PY_SCIP_CALL(SCIPwriteTransProblem(self._scip, NULL, str_conversion('.cip')[1:], genericnames)) + else: + PY_SCIP_CALL(SCIPwriteOrigProblem(self._scip, NULL, str_conversion('.cip')[1:], genericnames)) locale.setlocale(locale.LC_NUMERIC,user_locale) diff --git a/tests/test_model.py b/tests/test_model.py index f5dcd062..41c01756 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -67,6 +67,7 @@ def test_model(): s.writeProblem('model') s.writeProblem('model.lp') + s.writeProblem(filename=False) s.freeProb() s = Model()