forked from scipopt/PySCIPOpt
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathtest_relax.py
More file actions
35 lines (26 loc) · 767 Bytes
/
test_relax.py
File metadata and controls
35 lines (26 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from pyscipopt import Model
from pyscipopt.scip import Relax
calls = []
class SoncRelax(Relax):
def relaxexec(self):
calls.append('relaxexec')
def test_relax():
m = Model()
m.hideOutput()
#include relaxator
m.includeRelax(SoncRelax(),'testrelaxator','Test that relaxator gets included')
#add Variables
x0 = m.addVar(vtype = "C", name = "x0")
x1 = m.addVar(vtype = "C", name = "x1")
x2 = m.addVar(vtype = "C", name = "x2")
#addCons
m.addCons(x0 >= 2)
m.addCons(x0**2 <= x1)
m.addCons(x1 * x2 >= x0)
m.setObjective(x1 + x0)
m.optimize()
print(m.getVal(x0))
assert 'relaxexec' in calls
assert len(calls) == 1
if __name__ == "__main__":
test_relax()