From dc37d78b8579401f0c9bacfb70704a9c83138ebd Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Wed, 27 Nov 2024 14:32:46 +0100 Subject: [PATCH 1/6] Allow writeProblem to write to stdout --- CHANGELOG.md | 58 ++++++++++++++++++++++++++++++++++++++++++ src/pyscipopt/scip.pxi | 35 +++++++++++++++---------- tests/test_model.py | 1 + 3 files changed, 81 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e56372c1..2ce79d04c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,68 @@ ## Unreleased ### Added +- Added stage checks to presolve, freereoptsolve, freetransform +- Added primal_dual_evolution recipe and a plot recipe +### Fixed +### Changed +- Allowed writeModel to print to standard output +### Removed + +## 5.2.1 - 2024.10.29 +### Added +- Expanded Statistics class to more problems. +- Created Statistics class +- Added parser to read .stats file +- Release checklist in `RELEASE.md` +- Added Python definitions and wrappers for SCIPstartStrongbranch, SCIPendStrongbranch SCIPgetBranchScoreMultiple, + SCIPgetVarStrongbranchInt, SCIPupdateVarPseudocost, SCIPgetVarStrongbranchFrac, SCIPcolGetAge, + SCIPgetVarStrongbranchLast, SCIPgetVarStrongbranchNode, SCIPallColsInLP, SCIPcolGetAge +- Added getBipartiteGraphRepresentation +- Added helper functions that facilitate testing +- Added Python definitions and wrappers for SCIPgetNImplVars, SCIPgetNContVars, SCIPvarMayRoundUp, + SCIPvarMayRoundDown, SCIPcreateLPSol, SCIPfeasFloor, SCIPfeasCeil, SCIPfeasRound, SCIPgetPrioChild, + SCIPgetPrioSibling +- Added additional tests to test_nodesel, test_heur, and test_strong_branching +- Migrated documentation to Readthedocs +- `attachEventHandlerCallback` method to Model for a more ergonomic way to attach event handlers +- Added Model method: optimizeNogil +- Added Solution method: getOrigin, retransform, translate +- Added SCIP.pxd: SCIP_SOLORIGIN, SCIPcopyOrigVars, SCIPcopyOrigConss, SCIPsolve nogil, SCIPretransformSol, SCIPtranslateSubSol, SCIPsolGetOrigin, SCIPhashmapCreate, SCIPhashmapFree +- Added additional tests to test_multi_threads, test_solution, and test_copy +### Fixed +- Fixed too strict getObjVal, getVal check +### Changed +- Changed createSol to now have an option of initialising at the current LP solution +- Unified documentation style of scip.pxi to numpydocs +### Removed + +## 5.1.1 - 2024-06-22 +### Added +- Added SCIP_STATUS_DUALLIMIT and SCIP_STATUS_PRIMALLIMIT +- Added SCIPprintExternalCodes (retrieves version of linked symmetry, lp solver, nl solver etc) +- Added recipe with reformulation for detecting infeasible constraints +- Wrapped SCIPcreateOrigSol and added tests +- Added verbose option for writeProblem and writeParams +- Expanded locale test +- Added methods for creating expression constraints without adding to problem +- Added methods for creating/adding/appending disjunction constraints +- Added check for pt_PT locale in test_model.py +- Added SCIPgetOrigConss and SCIPgetNOrigConss Cython bindings. +- Added transformed=False option to getConss, getNConss, and getNVars +### Fixed +- Fixed locale errors in reading +### Changed +- Made readStatistics a standalone function +### Removed + +## 5.0.1 - 2024-04-05 +### Added +- Added recipe for nonlinear objective functions - Added method for adding piecewise linear constraints - Add SCIP function SCIPgetTreesizeEstimation and wrapper getTreesizeEstimation - New test for model setLogFile ### Fixed +- Fixed locale fix - Fixed model.setLogFile(None) error - Add recipes sub-package - Fixed "weakly-referenced object no longer exists" when calling dropEvent in test_customizedbenders diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index b3e16e3b1..711f64fdc 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -1453,29 +1453,38 @@ cdef class Model: if not onlyroot: self.setIntParam("propagating/maxrounds", 0) - def writeProblem(self, filename='model.cip', trans=False, genericnames=False): + def writeProblem(self, filename='model.cip', trans=False, genericnames=False, verbose=True): """Write current model/problem to a file. :param filename: the name of the file to be used (Default value = 'model.cip'). Should have an extension corresponding to one of the readable file formats, described in https://www.scipopt.org/doc/html/group__FILEREADERS.php. :param trans: indicates whether the transformed problem is written to file (Default value = False) :param genericnames: indicates whether the problem should be written with generic variable and constraint names (Default value = False) - + :param verbose: whether to print a success message """ user_locale = locale.getlocale() locale.setlocale(locale.LC_ALL, "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)) - 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_ALL, user_locale) diff --git a/tests/test_model.py b/tests/test_model.py index df5e32cc2..ff06a6068 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -66,6 +66,7 @@ def test_model(): s.writeProblem('model') s.writeProblem('model.lp') + s.writeProblem(filename=False) s.freeProb() s = Model() From ef2f7f8b4a3486b8b06df9f6d4c1acd24c9fa2db Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Wed, 27 Nov 2024 14:35:40 +0100 Subject: [PATCH 2/6] correct method name --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ce79d04c..1c6cdf100 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - Added primal_dual_evolution recipe and a plot recipe ### Fixed ### Changed -- Allowed writeModel to print to standard output +- Allowed writeProblem to print to standard output ### Removed ## 5.2.1 - 2024.10.29 From b8a9cd6eeef753592fbb70e73439effab7646595 Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Wed, 27 Nov 2024 14:43:23 +0100 Subject: [PATCH 3/6] corrected docstring --- src/pyscipopt/scip.pxi | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index 4f15cd480..2bbcb8105 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -2890,12 +2890,23 @@ cdef class Model: self.setIntParam("propagating/maxrounds", 0) def writeProblem(self, filename='model.cip', trans=False, genericnames=False, verbose=True): - """Write current model/problem to a file. + """ + Write current model/problem to a file. + + Parameters + ---------- + filename : str, optional + the name of the file to be used (Default value = 'model.cip'). + Should have an extension corresponding to one of the readable file formats, + described in https://www.scipopt.org/doc/html/group__FILEREADERS.php. + trans : bool, optional + indicates whether the transformed problem is written to file (Default value = False) + genericnames : bool, optional + indicates whether the problem should be written with generic variable + and constraint names (Default value = False) + verbose : bool, optional + indicates whether a success message should be printed - :param filename: the name of the file to be used (Default value = 'model.cip'). Should have an extension corresponding to one of the readable file formats, described in https://www.scipopt.org/doc/html/group__FILEREADERS.php. - :param trans: indicates whether the transformed problem is written to file (Default value = False) - :param genericnames: indicates whether the problem should be written with generic variable and constraint names (Default value = False) - :param verbose: whether to print a success message """ user_locale = locale.getlocale(category=locale.LC_NUMERIC) locale.setlocale(locale.LC_NUMERIC, "C") From c40df4b3a40921f6c79f43a6db386b62aa2debc7 Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Sat, 30 Nov 2024 08:57:13 +0100 Subject: [PATCH 4/6] Replaced with displayProblem --- CHANGELOG.md | 2 +- src/pyscipopt/scip.pxi | 29 +++++++++++++++++++++++++++++ tests/test_model.py | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c6cdf100..21c638d26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,11 @@ ## Unreleased ### Added +- Added displayProblem to print problem to stdout - Added stage checks to presolve, freereoptsolve, freetransform - 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 2bbcb8105..e5bea801f 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -2889,6 +2889,35 @@ cdef class Model: if not onlyroot: self.setIntParam("propagating/maxrounds", 0) + def displayProblem(self, ext='.cip', trans=False, genericnames=False): + """ + Write current model/problem to a file. + + Parameters + ---------- + ext : str, optional + the extension to be used (Default value = '.cip'). + Should have an extension corresponding to one of the readable file formats, + described in https://www.scipopt.org/doc/html/group__FILEREADERS.php. + trans : bool, optional + indicates whether the transformed problem is written to file (Default value = False) + genericnames : bool, optional + indicates whether the problem should be written with generic variable + and constraint names (Default value = False) + verbose : bool, optional + indicates whether a success message should be printed + + """ + user_locale = locale.getlocale(category=locale.LC_NUMERIC) + locale.setlocale(locale.LC_NUMERIC, "C") + + if trans: + PY_SCIP_CALL(SCIPwriteTransProblem(self._scip, NULL, str_conversion(ext)[1:], genericnames)) + else: + PY_SCIP_CALL(SCIPwriteOrigProblem(self._scip, NULL, str_conversion(ext)[1:], genericnames)) + + locale.setlocale(locale.LC_NUMERIC,user_locale) + def writeProblem(self, filename='model.cip', trans=False, genericnames=False, verbose=True): """ Write current model/problem to a file. diff --git a/tests/test_model.py b/tests/test_model.py index 41c017563..fa779f6a8 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -67,7 +67,7 @@ def test_model(): s.writeProblem('model') s.writeProblem('model.lp') - s.writeProblem(filename=False) + s.displayProblem() s.freeProb() s = Model() From aed4cd5e0b04ec3d61ceaad59b6ad6ceff99de1b Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Mon, 2 Dec 2024 10:36:49 +0100 Subject: [PATCH 5/6] Rename to printProblem, fix docstring --- CHANGELOG.md | 2 +- src/pyscipopt/scip.pxi | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21c638d26..93e9363e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased ### Added -- Added displayProblem to print problem to stdout +- Added printProblem to print problem to stdout - Added stage checks to presolve, freereoptsolve, freetransform - Added primal_dual_evolution recipe and a plot recipe ### Fixed diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index e5bea801f..04dba32f2 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -2889,9 +2889,9 @@ cdef class Model: if not onlyroot: self.setIntParam("propagating/maxrounds", 0) - def displayProblem(self, ext='.cip', trans=False, genericnames=False): + def printProblem(self, ext='.cip', trans=False, genericnames=False): """ - Write current model/problem to a file. + Write current model/problem to standard output. Parameters ---------- @@ -2904,9 +2904,6 @@ cdef class Model: genericnames : bool, optional indicates whether the problem should be written with generic variable and constraint names (Default value = False) - verbose : bool, optional - indicates whether a success message should be printed - """ user_locale = locale.getlocale(category=locale.LC_NUMERIC) locale.setlocale(locale.LC_NUMERIC, "C") From 3b4eb05d40a88a46c178430d37d79ddca1c86d5e Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Mon, 2 Dec 2024 10:39:08 +0100 Subject: [PATCH 6/6] Fix test name --- tests/test_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_model.py b/tests/test_model.py index fa779f6a8..2d07331e5 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -67,7 +67,7 @@ def test_model(): s.writeProblem('model') s.writeProblem('model.lp') - s.displayProblem() + s.printProblem() s.freeProb() s = Model()