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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Fixed the type of MatrixExpr.sum(axis=...) result from MatrixVariable to MatrixExpr.
- Updated IIS result in PyiisfinderExec()
- Fixed lotsizing_lazy example
- Fixed incorrect getVal() result when _bestSol.sol was outdated
### Changed
- changed default value of enablepricing flag to True
### Removed
Expand Down
19 changes: 14 additions & 5 deletions src/pyscipopt/scip.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@
if rc == SCIP_OKAY:
pass
elif rc == SCIP_ERROR:
raise Exception('SCIP: unspecified error!')

Check failure on line 319 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / test-coverage (3.11)

SCIP: unspecified error!
elif rc == SCIP_NOMEMORY:
raise MemoryError('SCIP: insufficient memory error!')
elif rc == SCIP_READERROR:
Expand All @@ -335,7 +335,7 @@
raise Exception('SCIP: method cannot be called at this time'
+ ' in solution process!')
elif rc == SCIP_INVALIDDATA:
raise Exception('SCIP: error in input data!')

Check failure on line 338 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / test-coverage (3.11)

SCIP: error in input data!
elif rc == SCIP_INVALIDRESULT:
raise Exception('SCIP: method returned an invalid result code!')
elif rc == SCIP_PLUGINNOTFOUND:
Expand Down Expand Up @@ -1068,8 +1068,8 @@
"""Base class holding a pointer to corresponding SCIP_SOL."""

# We are raising an error here to avoid creating a solution without an associated model. See Issue #625
def __init__(self, raise_error = False):
if not raise_error:
def __init__(self, raise_error = True):
if raise_error:
raise ValueError("To create a solution you should use the createSol method of the Model class.")

@staticmethod
Expand All @@ -1093,7 +1093,7 @@
"""
if scip == NULL:
raise Warning("cannot create Solution with SCIP* == NULL")
sol = Solution(True)
sol = Solution(raise_error=False)
sol.sol = scip_sol
sol.scip = scip
return sol
Expand Down Expand Up @@ -10795,11 +10795,20 @@
A variable is also an expression.

"""
stage_check = SCIPgetStage(self._scip) not in [SCIP_STAGE_INIT, SCIP_STAGE_FREE]
cdef SCIP_SOL* current_best_sol

if not stage_check or self._bestSol.sol == NULL and SCIPgetStage(self._scip) != SCIP_STAGE_SOLVING:
stage_check = SCIPgetStage(self._scip) not in [SCIP_STAGE_INIT, SCIP_STAGE_FREE]
if not stage_check:
raise Warning("Method cannot be called in stage ", self.getStage())

# Ensure _bestSol is up-to-date (cheap pointer comparison)
current_best_sol = SCIPgetBestSol(self._scip)
if self._bestSol is None or self._bestSol.sol != current_best_sol:
self._bestSol = Solution.create(self._scip, current_best_sol)

if self._bestSol.sol == NULL and SCIPgetStage(self._scip) != SCIP_STAGE_SOLVING:
raise Warning("No solution available")

if isinstance(expr, MatrixExpr):
result = np.empty(expr.shape, dtype=float)
for idx in np.ndindex(result.shape):
Expand Down
Loading