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 @@ -2,6 +2,7 @@

## Unreleased
### Added
- 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
Expand Down
1 change: 1 addition & 0 deletions src/pyscipopt/scip.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ cdef extern from "scip/scip.h":
SCIP_Real SCIPgetSolTransObj(SCIP* scip, SCIP_SOL* sol)
SCIP_RETCODE SCIPcreateSol(SCIP* scip, SCIP_SOL** sol, SCIP_HEUR* heur)
SCIP_RETCODE SCIPcreatePartialSol(SCIP* scip, SCIP_SOL** sol,SCIP_HEUR* heur)
SCIP_RETCODE SCIPcreateOrigSol(SCIP* scip, SCIP_SOL** sol, SCIP_HEUR* heur)
SCIP_RETCODE SCIPsetSolVal(SCIP* scip, SCIP_SOL* sol, SCIP_VAR* var, SCIP_Real val)
SCIP_RETCODE SCIPtrySolFree(SCIP* scip, SCIP_SOL** sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool* stored)
SCIP_RETCODE SCIPtrySol(SCIP* scip, SCIP_SOL* sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool* stored)
Expand Down
21 changes: 20 additions & 1 deletion src/pyscipopt/scip.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -4507,7 +4507,7 @@ cdef class Model:
locale.setlocale(locale.LC_NUMERIC,user_locale)

def createSol(self, Heur heur = None):
"""Create a new primal solution.
"""Create a new primal solution in the transformed space.

:param Heur heur: heuristic that found the solution (Default value = None)

Expand Down Expand Up @@ -4541,6 +4541,25 @@ cdef class Model:
partialsolution = Solution.create(self._scip, _sol)
return partialsolution

def createOrigSol(self, Heur heur = None):
"""Create a new primal solution in the original space.

:param Heur heur: heuristic that found the solution (Default value = None)

"""
cdef SCIP_HEUR* _heur
cdef SCIP_SOL* _sol

if isinstance(heur, Heur):
n = str_conversion(heur.name)
_heur = SCIPfindHeur(self._scip, n)
else:
_heur = NULL

PY_SCIP_CALL(SCIPcreateOrigSol(self._scip, &_sol, _heur))
solution = Solution.create(self._scip, _sol)
return solution

def printBestSol(self, write_zeros=False):
"""Prints the best feasible primal solution."""
user_locale = locale.getlocale(category=locale.LC_NUMERIC)
Expand Down
28 changes: 28 additions & 0 deletions tests/test_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,34 @@ def test_solution_create():
assert m.getSolObjVal(s1) == -1
m.freeSol(s1)

def test_createOrigSol():
m = Model()

x = m.addVar("x", lb=0, ub=2, obj=-1)
y = m.addVar("y", lb=1, ub=4, obj=1)
z = m.addVar("z", lb=1, ub=5, obj=10)
m.addCons(x * x <= y*z)
m.presolve()

s = m.createOrigSol()
s[x] = 2.0
s[y] = 5.0
s[z] = 10.0
assert not m.checkSol(s)
assert m.addSol(s, free=True)

s1 = m.createOrigSol()
m.setSolVal(s1, x, 1.0)
m.setSolVal(s1, y, 1.0)
m.setSolVal(s1, z, 1.0)
assert m.checkSol(s1)
assert m.addSol(s1, free=False)

m.optimize()

assert m.getSolObjVal(s1) == 10.0
m.freeSol(s1)


def test_solution_evaluation():
m = Model()
Expand Down