-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample2.py
58 lines (56 loc) · 1.15 KB
/
example2.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
# http://web.mit.edu/lpsolve/doc/Python.htm
# P = (110)(1.30)x + (30)(2.00)y + (125)(1.56) = 143x + 60y + 195z
# 120x + 210y + 150.75z <= 15000
# 110x + 30y + 125z <= 4000
# x + y + z <= 75
# x >= 0, y >= 0, z >= 0
import lpsolve_wrapper as lw
model = lw.Model(
notations={
'x': lw.notation(
lower_bound=0,
),
'y': lw.notation(
lower_bound=0,
),
'z': lw.notation(
lower_bound=0,
)
})
model.add_constr(
coefs=[
lw.coef('x', 120),
lw.coef('y', 210),
lw.coef('z', 150.75),
],
right_value=15000,
constr_type=lw.LEQ
)
model.add_constr(
coefs=[
lw.coef('x', 110),
lw.coef('y', 30),
lw.coef('z', 125),
],
right_value=4000,
constr_type=lw.LEQ
)
model.add_constr(
coefs=[
lw.coef('x', 1),
lw.coef('y', 1),
lw.coef('z', 1),
],
right_value=75,
constr_type=lw.LEQ
)
objective, notation_list = model.lp_solve(
obj_func={
'x': 143,
'y': 60,
'z': 195,
},
minimize=False
)
print('objective:', objective)
print('notations:', notation_list)