-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSimpleLP.py
64 lines (50 loc) · 1.76 KB
/
SimpleLP.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
59
60
61
62
63
64
"""
## GAMSSOURCE: https://www.gams.com/latest/psoptlib_ml/libhtml/psoptlib_SimpleLP.html
## LICENSETYPE: Demo
## MODELTYPE: LP
Simple linear programming model
For more details please refer to Chapter 2 (Gcode2.1), of the following book:
Soroudi, Alireza. Power System Optimization Modeling in GAMS. Springer, 2017.
--------------------------------------------------------------------------------
Model type: LP
--------------------------------------------------------------------------------
Contributed by
Dr. Alireza Soroudi
IEEE Senior Member
email: alireza.soroudi@gmail.com
We do request that publications derived from the use of the developed GAMS code
explicitly acknowledge that fact by citing
Soroudi, Alireza. Power System Optimization Modeling in GAMS. Springer, 2017.
DOI: doi.org/10.1007/978-3-319-62350-4
"""
from __future__ import annotations
from gamspy import Container, Equation, Model, Variable
def main():
m = Container()
# VARIABLES #
x1 = Variable(m, name="x1")
x2 = Variable(m, name="x2")
x3 = Variable(m, name="x3")
# EQUATIONS #
eq1 = Equation(m, name="eq1", type="regular")
eq2 = Equation(m, name="eq2", type="regular")
eq3 = Equation(m, name="eq3", type="regular")
eq1[...] = x1 + 2 * x2 >= 3
eq2[...] = x3 + x2 >= 5
eq3[...] = x1 + x3 == 4
eq4 = x1 + 3 * x2 + 3 * x3 # Objective Function
LP1 = Model(
m,
name="LP1",
equations=m.getEquations(),
problem="lp",
sense="min",
objective=eq4,
)
LP1.solve()
print("Objective Function Value: ", round(LP1.objective_value, 4), "\n")
print("x1: ", round(x1.toValue(), 4))
print("x2: ", round(x2.toValue(), 4))
print("x3: ", round(x3.toValue(), 4))
if __name__ == "__main__":
main()