forked from scipopt/PySCIPOpt
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathtest_reopt.py
More file actions
36 lines (26 loc) · 838 Bytes
/
test_reopt.py
File metadata and controls
36 lines (26 loc) · 838 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
import unittest
from pyscipopt import Model
class ReoptimizationTest(unittest.TestCase):
def test_reopt(self):
m = Model()
m.enableReoptimization()
x = m.addVar(name="x", ub=5)
y = m.addVar(name="y", lb=-2, ub=10)
m.addCons(2 * x + y >= 8)
m.setObjective(x + y)
m.optimize()
print("x", m.getVal(x))
print("y", m.getVal(y))
self.assertEqual(m.getVal(x), 5.0)
self.assertEqual(m.getVal(y), -2.0)
m.freeReoptSolve()
m.addCons(y <= 3)
m.addCons(y + x <= 6)
m.chgReoptObjective(- x - 2 * y)
m.optimize()
print("x", m.getVal(x))
print("y", m.getVal(y))
self.assertEqual(m.getVal(x), 3.0)
self.assertEqual(m.getVal(y), 3.0)
if __name__ == '__main__':
unittest.main()