Skip to content

Commit 7ce5f2a

Browse files
authored
Merge pull request #537 from scipopt/fix-tests
fix concurrent solve test
2 parents d35d651 + 62445e6 commit 7ce5f2a

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

src/pyscipopt/scip.pxd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,9 @@ cdef extern from "scip/scip_tree.h":
16811681
cdef extern from "scip/scip_var.h":
16821682
SCIP_RETCODE SCIPchgVarBranchPriority(SCIP* scip, SCIP_VAR* var, int branchpriority)
16831683

1684+
cdef extern from "tpi/tpi.h":
1685+
int SCIPtpiGetNumThreads()
1686+
16841687
cdef class Expr:
16851688
cdef public terms
16861689

src/pyscipopt/scip.pyx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3096,8 +3096,12 @@ cdef class Model:
30963096
def solveConcurrent(self):
30973097
"""Transforms, presolves, and solves problem using additional solvers which emphasize on
30983098
finding solutions."""
3099-
PY_SCIP_CALL(SCIPsolveConcurrent(self._scip))
3100-
self._bestSol = Solution.create(self._scip, SCIPgetBestSol(self._scip))
3099+
if SCIPtpiGetNumThreads() == 1:
3100+
warnings.warn("SCIP was compiled without task processing interface. Parallel solve not possible - using optimize() instead of solveConcurrent()")
3101+
self.optimize()
3102+
else:
3103+
PY_SCIP_CALL(SCIPsolveConcurrent(self._scip))
3104+
self._bestSol = Solution.create(self._scip, SCIPgetBestSol(self._scip))
31013105

31023106
def presolve(self):
31033107
"""Presolve the problem."""

tests/test_lp_concurrent.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/test_model.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ def test_model():
7878

7979
assert s.getStatus() == 'unbounded'
8080

81+
def test_solve_concurrent():
82+
s = Model()
83+
x = s.addVar("x", vtype = 'C', obj = 1.0)
84+
y = s.addVar("y", vtype = 'C', obj = 2.0)
85+
c = s.addCons(x + y <= 10.0)
86+
s.setMaximize()
87+
s.solveConcurrent()
88+
assert s.getStatus() == 'optimal'
89+
assert s.getObjVal() == 20.0
8190

8291
def test_multiple_cons_simple():
8392
def assert_conss_eq(a, b):
@@ -177,4 +186,8 @@ def test_model_ptr():
177186

178187
if __name__ == "__main__":
179188
test_model()
189+
test_solve_concurrent()
190+
test_multiple_cons_simple()
191+
test_multiple_cons_names()
192+
test_multiple_cons_params()
180193
test_model_ptr()

0 commit comments

Comments
 (0)