-
Notifications
You must be signed in to change notification settings - Fork 0
/
oort.py
31 lines (24 loc) · 877 Bytes
/
oort.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
import ortools
from ortools.linear_solver import pywraplp
solver = pywraplp.Solver.CreateSolver('SAT')
infinity = solver.infinity()
x = solver.IntVar(0.0, infinity, 'x')
y = solver.IntVar(0.0, infinity, 'y')
z = solver.IntVar(0.0, infinity, 'z')
w = solver.IntVar(0.0, infinity, 'w')
u = solver.IntVar(0.0, infinity, 'u')
solver.Add(3*x + 4*y + 2*z + 5*w <= 7)
solver.Add(-x + 5*y - z + 3*w -2*u <= 4)
solver.Add(2*y - w - u <= 1)
solver.Maximize(4*x + 8*y + 3*z + 10*w - u)
status = solver.Solve()
if status == pywraplp.Solver.OPTIMAL:
print('Solution:')
print('Objective value =', solver.Objective().Value())
print('x =', x.solution_value())
print('y =', y.solution_value())
print('z =', z.solution_value())
print('w =', w.solution_value())
print('u =', u.solution_value())
else:
print('The problem does not have an optimal solution.')