Skip to content

Commit

Permalink
Merge pull request #729 from Joao-Dionisio/delete-double-declaration
Browse files Browse the repository at this point in the history
Fixes printing a solution to refer to original variables
  • Loading branch information
mmghannam authored Oct 6, 2023
2 parents 9648807 + 057b165 commit 32f4640
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Add SCIP function SCIPgetSolTime and wrapper getSolTime
### Fixed
- Fixed segmentation fault when accessing the Solution class directly
- Changed getSols so that it prints solutions in terms of the original variables
### Changed
- Improved error message when using < or > instead of <= or >=
### Removed
Expand Down
4 changes: 2 additions & 2 deletions src/pyscipopt/scip.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ cdef class Solution:

vals = {}
self._checkStage("SCIPgetSolVal")
for i in range(SCIPgetNVars(self.scip)):
scip_var = SCIPgetVars(self.scip)[i]
for i in range(SCIPgetNOrigVars(self.scip)):
scip_var = SCIPgetOrigVars(self.scip)[i]

# extract name
cname = bytes(SCIPvarGetName(scip_var))
Expand Down
8 changes: 8 additions & 0 deletions tests/test_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ def test_create_solution():
with pytest.raises(ValueError):
scip.Solution()

def test_print_soltion():
m = Model()

m.addVar()
m.optimize()

assert str(m.getSols()[0]) == "{'x1': -0.0}"

if __name__ == "__main__":
test_solution_getbest()
test_solution_create()

0 comments on commit 32f4640

Please sign in to comment.