forked from ds4dm/PySCIPOpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_vars.py
71 lines (55 loc) · 1.57 KB
/
test_vars.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from pyscipopt import Model
def test_variablebounds():
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))
def test_vtype():
m = Model()
x = m.addVar(vtype= 'C', lb=-5.5, ub=8)
y = m.addVar(vtype= 'I', lb=-5.2, ub=8)
z = m.addVar(vtype= 'B', lb=-5.2, ub=8)
w = m.addVar(vtype= 'M', lb=-5.2, ub=8)
assert x.vtype() == "CONTINUOUS"
assert y.vtype() == "INTEGER"
assert z.vtype() == "BINARY"
assert w.vtype() == "IMPLINT"
m.chgVarType(x, 'I')
assert x.vtype() == "INTEGER"
m.chgVarType(y, 'M')
assert y.vtype() == "IMPLINT"
if __name__ == "__main__":
test_variablebounds()
test_vtype()