forked from ds4dm/PySCIPOpt
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_variablebounds.py
More file actions
48 lines (37 loc) · 899 Bytes
/
test_variablebounds.py
File metadata and controls
48 lines (37 loc) · 899 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
36
37
38
39
40
41
42
43
44
45
46
47
from pyscipopt import Model
m = Model()
x0 = m.addVar(lb=-5, ub=8)
r1 = m.addVar()
r2 = m.addVar()
y0 = m.addVar(lb=3)
t = m.addVar(lb=None)
z = m.addVar()
m.chgVarLbGlobal(x0, -2)
m.chgVarUbGlobal(x0, 4)
infeas, tightened = m.tightenVarLb(x0, -5)
assert not infeas
assert not tightened
infeas, tightened = m.tightenVarLbGlobal(x0, -1)
assert not infeas
assert tightened
infeas, tightened = m.tightenVarUb(x0, 3)
assert not infeas
assert tightened
infeas, tightened = m.tightenVarUbGlobal(x0, 9)
assert not infeas
assert not tightened
infeas, fixed = m.fixVar(z, 7)
assert not infeas
assert fixed
assert m.delVar(z)
m.addCons(r1 >= x0)
m.addCons(r2 >= -x0)
m.addCons(y0 == r1 +r2)
m.setObjective(t)
m.addCons(t >= r1 * (r1 - x0) + r2 * (r2 + x0))
m.optimize()
print("x0", m.getVal(x0))
print("r1", m.getVal(r1))
print("r2", m.getVal(r2))
print("y0", m.getVal(y0))
print("t", m.getVal(t))