Читать книгу Mathematical Programming for Power Systems Operation - Alejandro Garcés Ruiz - Страница 27
1.5 Using Python
ОглавлениеPython is a general programming language that is gaining attention in power systems optimization. Although it is neither a mathematical software nor an algebraic modeling language, it has many free tools for solving optimization problems. Moreover, there are many other tools for data manipulation, plotting, and integration with other software. Hence, it is a convenient platform for solving practical problems and integrate different resources3.
We use a module named CvxPy (cvxpy) [10] that allows to solve convex and mixed-integer convex optimization problems; this module, together with NumPy, MatplotLib, and Pandas, forms a robust platform for solving all types of optimization problems in power systems applications. Let us consider, for instance, the following optimization problem:
(1.11)
where x ∈ 6 and c = (5, 3, 2, 4, 8, 7)⊤. A model in CvxPy for this problem looks as follows:
import numpy as np import cvxpy as cvx c = np.array([5,3,2,4,8,7]) x = cvx.Variable(6) objective = cvx.Minimize(c.T * x) constraints = [ sum(x) == 1, x >= 0] Model = cvx.Problem(objective,constraints) Model.solve()
Without much effort, we can identify variables, the objective function, and constraints. This neat code feature is an essential aspect of Python and CvxPy. After the problem is solved, we can make additional analyses using the same platform. This combination of tools is, of course, a great advantage; however, we must avoid any fanaticism for software. There are many programming languages and many modules for mathematical optimization. What is learned in this book may be translated to any other language. The problem is the same, although its implementation may change from one platform to another.
We made a great effort in making the examples as simple as possible (we call them toy-models). This approach allows us to understand each problem individually and do numerical experiments. Real operation models may include different aspects of these toy-models; for instance, they may combine economic dispatch, optimal power flow, and state estimation. These models are highly involved with thousands of variables and constraints. Nevertheless, they can be solved using the same paradigm presented in this book.