forked from scipopt/PySCIPOpt
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathtest_solution.py
More file actions
37 lines (28 loc) · 846 Bytes
/
test_solution.py
File metadata and controls
37 lines (28 loc) · 846 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
from pyscipopt import Model
def test_solution_getbest():
m = Model()
x = m.addVar("x", lb=0, ub=2, obj=-1)
y = m.addVar("y", lb=0, ub=4, obj=0)
m.addCons(x*x <= y)
m.optimize()
sol = m.getBestSol()
assert round(sol[x]) == 2.0
assert round(sol[y]) == 4.0
print(sol) # prints the solution in the transformed space
m.freeTransform()
sol = m.getBestSol()
assert round(sol[x]) == 2.0
assert round(sol[y]) == 4.0
print(sol) # prints the solution in the original space
def test_solution_create():
m = Model()
x = m.addVar("x", lb=0, ub=2, obj=-1)
y = m.addVar("y", lb=0, ub=4, obj=0)
m.addCons(x*x <= y)
s = m.createSol()
s[x] = 2.0
s[y] = 4.0
assert m.addSol(s, free=True)
if __name__ == "__main__":
test_solution_getbest()
test_solution_create()