From dc37d78b8579401f0c9bacfb70704a9c83138ebd Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Wed, 27 Nov 2024 14:32:46 +0100 Subject: [PATCH 1/3] 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/3] 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/3] 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")