ТОП просматриваемых книг сайта:
Mathematical Programming for Power Systems Operation. Alejandro Garcés Ruiz
Читать онлайн.Название Mathematical Programming for Power Systems Operation
Год выпуска 0
isbn 9781119747284
Автор произведения Alejandro Garcés Ruiz
Жанр Физика
Издательство John Wiley & Sons Limited
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.
Notes
1 1 We incorporate uncertainty in the models using robust optimization. Chapter 6 is dedicated to this aspect.
2 2 It is usual to consider the Frobenius norm as explained in Chapter 12.
3 3 See appendix C for a brief introduction to Python.
2 A brief introduction to mathematical optimization
Learning outcomes
By the end of this chapter, the student will be able to:
Establish first-order conditions for locally optimal solutions.
Solve unconstrained optimization problems, using the gradient method, implemented in Python.
Solve equality-constrained optimization problems, using Newton’s method implemented in Python.
2.1 About sets and functions
Sets and functions are familiar concepts in mathematics. A set is a well-defined collection of distinct objects, considered an object in its own right. A function is a map that takes objects from one set (i.e., input or domain) and returns an object in another set (i.e., output or image). An optimization problem consists of finding the best object in the output set and its corresponding input, as shown schematically in Figure 2.1. The input set Ω is called the set of feasible solutions, and the best object corresponds to a minimum or a maximum, according to an objective function f:Ω⊆Rn→R.
Figure 2.1 Representation of the sets related to a general optimization problem.
Solving an optimization problem implies not only to find the value of the objective function (e.g., fmin or fmax) but also the value x, at the input set Ω (e.g.,xmin, xmax). These values are represented as follows:
(2.1)
(2.2)
Notice that fmin and fmax are numbers whereas xmin and xmax are vectors. The following example shows the difference between min and argmin (the same applies for max and argmax).
Example 2.1
Let us consider four simple optimization problems and their respective solution, namely1:
(2.3)
(2.4)