Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
- Added more type annotations and deprecation markers to the stubs.
- Added tests for `getObjVal()` and `getVal()`
- Added `addConsLinear()` to add linear constraints from variables and coefficients without building an expression
- Added `SCIP_BOUNDTYPE` and `SCIP_BOUNDCHGTYPE` enums
### Fixed
- Fixed `MatrixVariable.varMayRound()` rounding direction
- Fixed `lotsizing_lazy` example: lock the handler's variables in `conslock` so presolve cannot aggregate them away (#1252)
- Dual and Farkas getters for linear, knapsack, and logicor constraints now return zero when presolving has removed them.
- Fixed incorrect `getObjVal()` result when called before `getBestSol()` (e.g., in event handlers).
- Fixed `getDualsolKnapsack()` and `getDualfarkasKnapsack()` returning 0 for original constraints, and the handler check in `getVarsAnd()` that could never fail
### Changed
- Replaced SCIP constant classes with `IntEnum` and `IntFlag`, including enum return values and type annotations (#1286).
- Replaced `format()` with f-strings in examples
- Refactor general expression conversion into per-class `to_scip_expr` recursion
- Made expression fields read-only to prevent accidental runtime modification
Expand Down
2 changes: 2 additions & 0 deletions src/pyscipopt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
from pyscipopt.scip import PY_SCIP_LPSOLSTAT as SCIP_LPSOLSTAT
from pyscipopt.scip import PY_SCIP_BRANCHDIR as SCIP_BRANCHDIR
from pyscipopt.scip import PY_SCIP_BENDERSENFOTYPE as SCIP_BENDERSENFOTYPE
from pyscipopt.scip import PY_SCIP_BOUNDTYPE as SCIP_BOUNDTYPE
from pyscipopt.scip import PY_SCIP_BOUNDCHGTYPE as SCIP_BOUNDCHGTYPE
from pyscipopt.scip import PY_SCIP_ROWORIGINTYPE as SCIP_ROWORIGINTYPE
from pyscipopt.scip import PY_SCIP_SOLORIGIN as SCIP_SOLORIGIN
from pyscipopt.scip import PY_SCIP_NODETYPE as SCIP_NODETYPE
Expand Down
4 changes: 2 additions & 2 deletions src/pyscipopt/benders.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ cdef SCIP_RETCODE PyBendersPresubsolve (SCIP* scip, SCIP_BENDERS* benders, SCIP_
solution = None
else:
solution = Solution.create(scip, sol)
enfotype = type
enfotype = PY_SCIP_BENDERSENFOTYPE(type)
result_dict = PyBenders.benderspresubsolve(solution, enfotype, checkint)
infeasible[0] = result_dict.get("infeasible", False)
auxviol[0] = result_dict.get("auxviol", False)
Expand Down Expand Up @@ -179,7 +179,7 @@ cdef SCIP_RETCODE PyBendersPostsolve (SCIP* scip, SCIP_BENDERS* benders, SCIP_SO
solution = None
else:
solution = Solution.create(scip, sol)
enfotype = type
enfotype = PY_SCIP_BENDERSENFOTYPE(type)
mergecandidates = []
for i in range(nmergecands):
mergecandidates.append(mergecands[i])
Expand Down
2 changes: 1 addition & 1 deletion src/pyscipopt/benderscut.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ cdef SCIP_RETCODE PyBenderscutExec (SCIP* scip, SCIP_BENDERS* benders, SCIP_BEND
solution = None
else:
solution = Solution.create(scip, sol)
enfotype = type
enfotype = PY_SCIP_BENDERSENFOTYPE(type)
result_dict = PyBenderscut.benderscutexec(solution, probnumber, enfotype)
result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
return SCIP_OKAY
10 changes: 5 additions & 5 deletions src/pyscipopt/conshdlr.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ cdef SCIP_RETCODE PyConsProp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** c
constraints = []
for i in range(nconss):
constraints.append(getPyCons(conss[i]))
result_dict = PyConshdlr.consprop(constraints, nusefulconss, nmarkedconss, proptiming)
result_dict = PyConshdlr.consprop(constraints, nusefulconss, nmarkedconss, PY_SCIP_PROPTIMING(proptiming))
result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
return SCIP_OKAY

Expand All @@ -353,8 +353,8 @@ cdef SCIP_RETCODE PyConsPresol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS**
result_dict["nupgdconss"] = nupgdconss[0]
result_dict["nchgcoefs"] = nchgcoefs[0]
result_dict["nchgsides"] = nchgsides[0]
result_dict["result"] = result[0]
PyConshdlr.conspresol(constraints, nrounds, presoltiming,
result_dict["result"] = PY_SCIP_RESULT(result[0])
PyConshdlr.conspresol(constraints, nrounds, PY_SCIP_PRESOLTIMING(presoltiming),
nnewfixedvars, nnewaggrvars, nnewchgvartypes, nnewchgbds, nnewholes,
nnewdelconss, nnewaddconss, nnewupgdconss, nnewchgcoefs, nnewchgsides, result_dict)
result[0] = result_dict["result"]
Expand All @@ -379,10 +379,10 @@ cdef SCIP_RETCODE PyConsResprop (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS*
cdef SCIP_RETCODE PyConsLock (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS* cons, SCIP_LOCKTYPE locktype, int nlockspos, int nlocksneg) noexcept with gil:
PyConshdlr = getPyConshdlr(conshdlr)
if cons == NULL:
PyConshdlr.conslock(None, locktype, nlockspos, nlocksneg)
PyConshdlr.conslock(None, PY_SCIP_LOCKTYPE(locktype), nlockspos, nlocksneg)
else:
PyCons = getPyCons(cons)
PyConshdlr.conslock(PyCons, locktype, nlockspos, nlocksneg)
PyConshdlr.conslock(PyCons, PY_SCIP_LOCKTYPE(locktype), nlockspos, nlocksneg)
return SCIP_OKAY

cdef SCIP_RETCODE PyConsActive (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS* cons) noexcept with gil:
Expand Down
2 changes: 1 addition & 1 deletion src/pyscipopt/heuristic.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ cdef SCIP_RETCODE PyHeurExec (SCIP* scip, SCIP_HEUR* heur, SCIP_HEURTIMING heurt
cdef SCIP_HEURDATA* heurdata
heurdata = SCIPheurGetData(heur)
PyHeur = <Heur>heurdata
result_dict = PyHeur.heurexec(heurtiming, nodeinfeasible)
result_dict = PyHeur.heurexec(PY_SCIP_HEURTIMING(heurtiming), nodeinfeasible)
result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
return SCIP_OKAY
6 changes: 3 additions & 3 deletions src/pyscipopt/lp.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ cdef class LP:

Returns
-------
tuple of (list of int, list of int)
tuple of (list of SCIP_BASESTAT, list of SCIP_BASESTAT)
Column basis statuses and row basis statuses.

"""
Expand All @@ -550,8 +550,8 @@ cdef class LP:

PY_SCIP_CALL(SCIPlpiGetBase(self.lpi, c_cstat, c_rstat))

cstat = [c_cstat[i] for i in range(ncols)]
rstat = [c_rstat[i] for i in range(nrows)]
cstat = [PY_SCIP_BASESTAT(c_cstat[i]) for i in range(ncols)]
rstat = [PY_SCIP_BASESTAT(c_rstat[i]) for i in range(nrows)]

free(c_rstat)
free(c_cstat)
Expand Down
2 changes: 1 addition & 1 deletion src/pyscipopt/presol.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ cdef SCIP_RETCODE PyPresolExec (SCIP* scip, SCIP_PRESOL* presol, int nrounds, SC
cdef SCIP_PRESOLDATA* presoldata
presoldata = SCIPpresolGetData(presol)
PyPresol = <Presol>presoldata
result_dict = PyPresol.presolexec(nrounds, presoltiming)
result_dict = PyPresol.presolexec(nrounds, PY_SCIP_PRESOLTIMING(presoltiming))
result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
nfixedvars[0] += result_dict.get("nnewfixedvars", 0)
naggrvars[0] += result_dict.get("nnewaggrvars", 0)
Expand Down
8 changes: 4 additions & 4 deletions src/pyscipopt/propagator.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ cdef SCIP_RETCODE PyPropPresol (SCIP* scip, SCIP_PROP* prop, int nrounds, SCIP_P
result_dict["nupgdconss"] = nupgdconss[0]
result_dict["nchgcoefs"] = nchgcoefs[0]
result_dict["nchgsides"] = nchgsides[0]
result_dict["result"] = result[0]
PyProp.proppresol(nrounds, presoltiming,
result_dict["result"] = PY_SCIP_RESULT(result[0])
PyProp.proppresol(nrounds, PY_SCIP_PRESOLTIMING(presoltiming),
nnewfixedvars, nnewaggrvars, nnewchgvartypes, nnewchgbds, nnewholes,
nnewdelconss, nnewaddconss, nnewupgdconss, nnewchgcoefs, nnewchgsides, result_dict)
result[0] = result_dict["result"]
Expand All @@ -138,7 +138,7 @@ cdef SCIP_RETCODE PyPropExec (SCIP* scip, SCIP_PROP* prop, SCIP_PROPTIMING propt
cdef SCIP_PROPDATA* propdata
propdata = SCIPpropGetData(prop)
PyProp = <Prop>propdata
returnvalues = PyProp.propexec(proptiming)
returnvalues = PyProp.propexec(PY_SCIP_PROPTIMING(proptiming))
result_dict = returnvalues
result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
return SCIP_OKAY
Expand All @@ -154,7 +154,7 @@ cdef SCIP_RETCODE PyPropResProp (SCIP* scip, SCIP_PROP* prop, SCIP_VAR* infervar
#TODO: parse bdchgidx?

PyProp = <Prop>propdata
returnvalues = PyProp.propresprop(confvar, inferinfo, boundtype, relaxedbd)
returnvalues = PyProp.propresprop(confvar, inferinfo, PY_SCIP_BOUNDTYPE(boundtype), relaxedbd)
result_dict = returnvalues
result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
return SCIP_OKAY
Loading
Loading