-
Notifications
You must be signed in to change notification settings - Fork 1
/
example3.py
53 lines (51 loc) · 949 Bytes
/
example3.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
# http://web.mit.edu/lpsolve/doc/Python.htm
# max 4x1 + 2x2 + x3
# s.t. 2x1 + x2 <= 1
# x1 + 2x3 <= 2
# x1 + x2 + x3 = 1
# x1 >= 0
# x1 <= 1
# x2 >= 0
# x2 <= 1
# x3 >= 0
# x3 <= 2
import lpsolve_wrapper as lw
model = lw.Model(
notations={
'x': lw.notation(
shape=3,
upper_bound=[1, 1, 2],
lower_bound=0,
)
})
model.add_constr(
coefs=[
lw.coef('x', 2, idx=0),
lw.coef('x', 1, idx=1),
],
right_value=1,
constr_type=lw.LEQ
)
model.add_constr(
coefs=[
lw.coef('x', 1, idx=0),
lw.coef('x', 2, idx=2),
],
right_value=2,
constr_type=lw.LEQ
)
model.add_constr_mat(
coef_mats={
'x': [1, 1, 1]
},
right_value=1,
constr_type=lw.EQ
)
objective, notation_list = model.lp_solve(
obj_func={
'x': [4, 2, 1],
},
minimize=False
)
print('objective:', objective)
print('notations:', notation_list)