Mathematical Programming for Power Systems Operation. Alejandro Garcés Ruiz

Чтение книги онлайн.

Читать онлайн книгу Mathematical Programming for Power Systems Operation - Alejandro Garcés Ruiz страница 17

Mathematical Programming for Power Systems Operation - Alejandro Garcés Ruiz

Скачать книгу

The converters and the user’s location are fixed, but the common point E can be moved at will. The coordinates of the solar panels and the final user areA = (0, 40), B = (20, 70), C = (30, 0), and D = (100, 50) respectively.

begin inline style D equals left parenthesis 100 comma 50 right parenthesis end style

      Figure 2.6 A small photovoltaic system with three solar panels.

       min space blank f space equals cost subscript stack A E with bar on top end subscript open double vertical bar top enclose A E end enclose close double vertical bar space plus space cost subscript stack B E with bar on top end subscript open double vertical bar stack C E with bar on top close double vertical bar space cost subscript stack D E with bar on top end subscript open double vertical bar top enclose D E end enclose close double vertical bar (2.35)

      where costij¯ is the unitary cost of the cable that connects the point i and j, and ij¯ is the corresponding length.

      The costs of the cables are costAE¯ = 12, costBE¯ = 13, costCE¯=11 and costDE¯=18 The distance between any two points U = (u0, u1) and V = (v0, v1) is given by the following expression:

       dist equals square root of left parenthesis straight u subscript 0 minus straight v subscript 0 right parenthesis squared plus left parenthesis straight u subscript 1 minus straight v subscript 1 right parenthesis squared end root (2.36)

      This equation is required several times; thus, it is useful to define a function, as presented below:

      import numpy as np A = (0,40) B = (20,70) C = (30,0) D = (100,50) def dist(U,V): return np.sqrt((U[0]-V[0])**2 + (U[1]-V[1])**2) P = [31,45] f = 12*dist(P,A) + 13*dist(P,B) + 11*dist(P,C) + 18*dist(P,D) print(f)

       nabla dist left parenthesis straight U comma straight V right parenthesis equals fraction numerator 1 over denominator dist invisible function application left parenthesis straight U comma straight V right parenthesis end fraction left parenthesis table attributes columnspacing 1em end attributes row cell straight u subscript 0 minus straight v subscript 0 end cell row cell straight u subscript 1 minus straight v subscript 1 end cell end table right parenthesis (2.37)

      then,

       table attributes columnalign right left right left right left right left right left right left columnspacing 0em 2em 0em 2em 0em 2em 0em 2em 0em 2em 0em end attributes row cell nabla straight f left parenthesis straight x right parenthesis equals end cell cell 12 nabla dist left parenthesis straight x comma straight A right parenthesis plus 13 nabla dist left parenthesis straight x comma straight B right parenthesis plus 11 nabla dist left parenthesis straight x comma straight C right parenthesis plus end cell row blank cell 18 nabla dist left parenthesis straight x comma straight D right parenthesis end cell end table (2.38)

      These functions are easily defined in Python as follows:

      def g_d(U,V): "gradient of the distance" return [U[0]-V[0],U[1]-V[1]]/dist(U,V) def grad_f(E): "gradient of the objective function" return 12*g_d(E,A)+13*g_d(E,B)+11*g_d(E,C)+18*g_d(E,D)

      Now the gradient method consists in applying the iteration given by (Equation 2.30), as presented below:

      t = 0.5

      E = np.array([10,10])

      for iter in range(50): E = E -t*grad_f(E) f = 12*dist(E,A) + 13*dist(E,B) + 11*dist(E,C) + 18*dist(E,D) print("Position:",E) print("Gradient",grad_f(E)) print("Cost",f)

      In this case, t = 0.5 and a initial point E = (10, 10) with 50 iterations were enough to find the solution. The reader is invited to try with other values and analyze the effect on the algorithm’s convergence.

      Example 2.7

      The convergence of the algorithm can be visualized by using the module MatplotLib as follows:

      import matplotlib.pyplot as plt t = 0.5 conv = [] E = [10,10] for iter in range(50): E += - t*grad_f(E) conv += [np.linalg.norm(grad_f(E))] plt.semilogy(conv) plt.grid() plt.xlabel("Iteration") plt.ylabel("|Gradient|") plt.show()

begin inline style ‖ nabla f ‖ less or equal than 10 to the power of negative 4 end exponent end style

      Figure 2.7 Convergence of the gradient method.

      Notice that addition was simplified by the statement +=. In general, an statement such as x=x+1 is equivalent to x+=1. More details about this aspect are presented in Appendix C.

      Reality imposes physical constraints into the problems and these constraints must be considered into the model. For example, an optimization

Скачать книгу