Assigning codes to the book-Power Economic Dispatch (3): Economic Dispatch Model Considering Network Security Constraints

theory


Preliminary knowledge of examples in the book

Explanation:
import numpy as np
#A节点与发电机组关联矩阵
"""
    发电机组1,发电机组2,发电机组3
节点1
节点2
节点3
"""
A=np.array([[1,1,0],[0,0,1],[0,0,0]])

#B节点与负荷关联矩阵
"""
     节点2负荷,节点3负荷
节点1
节点2
节点3
"""

B=np.array([[0,0],[1,0],[0,1]])
#S为节点与支路关联矩阵。其支路始节点对应元素为1,终节点对应-1
""" 
    支路12 ,支路13,支路23 
节点1 
节点2  
节点3   

"""
S=np.array([[1,1,0],
   [-1,0,1],
   [0,-1,-1]])
#X为支路电抗矩阵,它是一个对角阵,对角元素为各支路电抗值,其余元素为0
X=np.array([[0.25,0,0],
   [0,0.25,0],
   [0,0,0.25]])

Text-Examples on the book

Regardless of network constraints

Consider network constraints

Text-Solving the calculation examples on the book

The objective function is shown in the figure

Without looking at this picture, I use my brain to think about
network security constraints. As the name suggests, they are in general scheduling. At the same time, they are trend satisfaction constraints, KCL, KVL, etc.

So we can understand that the optimization goal is the traditional economic dispatch optimization goal, and the
constraints are respectively

  • The equation constrains input power = load.
  • Inequality constraints, the upper and lower limits of the generator set.
  • The equation constraint power flow satisfies KCL, KVL. (When we find the power flow through the transfer factor algorithm, the power flow itself satisfies KCL, KVL), this is the upper and lower limit of the equation constraint that we transform into the power flow.

Transfer factor algorithm for power flow


#Node power net input vector Pinj=[PG1,PG2,PG3-PD3]

The format of the #SF matrix is ​​as follows. When injecting power into a node, the power must flow from the reference node.
Take the reference node as 1.

- When node 1 injects 1 power, When node 2 injects 1 power When node 3 injects 1 power
Branch 1-2 0 (inflow from node 1 and outflow from reference node 1, that is, do not take branch 1-2) -2/3 At this time, the current direction is 2 points to 1, which is opposite to 1-2, so it is -. According to the figure, the value 2/3 can be obtained -1/3
2 times branch 1-3 0 -1/3, the current direction is 3 to 1 -2/3
Branch 2-3 0 1/3 -1/3

Get the tidal current equation

Expand to get the trend of Figure 3-5 as follows

 PD3 = 800
 PL12 = -(2 / 3) * PG2 - (1 / 3) * PG3 + (1 / 3) * PD3
 PL13 = (-(1 / 3) * PG2 - (2 / 3) * PG3 + (2 / 3) * PD3) * 0.05
 PL23 = (1 / 3) * PG2 - (1 / 3) * PG3 + (1 / 3) * PD3

Programming language: python

import numpy as np
from scipy import  optimize as opt
import numpy as np
from scipy.optimize import minimize
# 目标函数
def objective(x): #=原文中的mincost 
    p11=x[0]
    p12=x[1]
    p13=x[2]
    p21=x[3]
    p22=x[4]
    p23=x[5]
    p31=x[6]
    p32=x[7]
    p33=x[8]

    return (40*p11+50*p12+57.5*p13+43.75*p21+46.25*p22+48.75*p23+55.8*p31+57*p32+58.2*p33)

# 约束条件
def constraint1(x):  #等式约束
   pI11 = x[0]
   pI12 = x[1]
   pI13 = x[2]
   pI21 = x[3]
   pI22 = x[4]
   pI23 = x[5]
   pI31 = x[6]
   pI32 = x[7]
   pI33 = x[8]
   PG1 = 100 + pI11 + pI12 + pI13
   PG2 = 100 + pI21 + pI22 + pI23
   PG3 = 50 + pI31 + pI32 + pI33

   return pI11+pI12+pI13+pI21+pI22+pI23+pI31+pI32+pI33-550
   #return PG1+PG2+PG3-800


#上下限
pI11=(0,200)
pI12 = (0,200)
pI13 = (0,100)
pI21 = (0,100)
pI22 = (0,100)
pI23 = (0,100)
pI31 =(0,50)
pI32 = (0,50)
pI33 = (0,50)

bnds=(pI11,pI12,pI13,pI21,pI22,pI23,pI31,pI32,pI33)

# 约束条件
def constraint2(x):  #不等式约束 线路PL12 《=300
    pI11 = x[0]
    pI12 = x[1]
    pI13 = x[2]
    pI21 = x[3]
    pI22 = x[4]
    pI23 = x[5]
    pI31 = x[6]
    pI32 = x[7]
    pI33 = x[8]
    PD3=800
    PG1 = 100 + pI11 + pI12 + pI13
    PG2 = 100 + pI21 + pI22 + pI23
    PG3 = 50 + pI31 + pI32 + pI33
    PL12 = -(2 / 3) * PG2 - (1 / 3) * PG3 + (1 / 3) * PD3
    return 300-np.abs(PL12)


# 约束条件
def constraint3(x):  #不等式约束 不等式约束 线路PL13 《=300
    pI11 = x[0]
    pI12 = x[1]
    pI13 = x[2]
    pI21 = x[3]
    pI22 = x[4]
    pI23 = x[5]
    pI31 = x[6]
    pI32 = x[7]
    pI33 = x[8]
    PD3=800
    PG1 = 100 + pI11 + pI12 + pI13
    PG2 = 100 + pI21 + pI22 + pI23
    PG3 = 50 + pI31 + pI32 + pI33
    PL13 = (-(1 / 3) * PG2 - (2 / 3) * PG3 + (2 / 3) * PD3) * 0.05
    return 300-np.abs(PL13)

# 约束条件
def constraint4(x):  #不等式约束 不等式约束 线路PL23 《=330
    pI11 = x[0]
    pI12 = x[1]
    pI13 = x[2]
    pI21 = x[3]
    pI22 = x[4]
    pI23 = x[5]
    pI31 = x[6]
    pI32 = x[7]
    pI33 = x[8]
    PD3=800
    PG1 = 100 + pI11 + pI12 + pI13
    PG2 = 100 + pI21 + pI22 + pI23
    PG3 = 50 + pI31 + pI32 + pI33
    PL23 = (1 / 3) * PG2 - (1 / 3) * PG3 + (1 / 3) * PD3
    return 330-np.abs(PL23)


con1 = {
    
    'type': 'eq', 'fun': constraint1}
con2 = {
    
    'type': 'ineq', 'fun': constraint2}
con3 = {
    
    'type': 'ineq', 'fun': constraint3}
con4 = {
    
    'type': 'ineq', 'fun': constraint4}
cons = ([con1,con2,con3,con4])  # 4个约束条件

if __name__ =='__main__':
   # 初始值
   x0 = np.random.uniform(10, 400, 9)
   # 计算
   solution = minimize(objective, x0, method='SLSQP',
                       bounds=bnds, constraints=cons)
   x = solution.x

   pI11 = x[0]
   pI12 = x[1]
   pI13 = x[2]
   pI21 = x[3]
   pI22 = x[4]
   pI23 = x[5]
   pI31 = x[6]
   pI32 = x[7]
   pI33 = x[8]
   #
   PG1 = 100 + pI11 + pI12 + pI13
   PG2 = 100 + pI21 + pI22 + pI23
   PG3 = 50 + pI31 + pI32 + pI33

   PL13 = 0.5 * ((0.01 + 0.01) * (PG3 - 800) + 0.01 * PG2) / (0.01 + 0.01 + 0.01)
   PL12 = ((0.01 + 0.01) * PG2 + 0.01 * (PG3 - 800)) / (0.01 + 0.01 + 0.01)
   PL23 = ((0.01 + 0.01) * (PG3 - 800) + 0.01 * PG1) / (0.01 + 0.01 + 0.01)

   print('PG1',PG1)
   print('PG2', PG2)
   print('PG3', PG3)
   print('PL13',np.abs(PL13))
   print('PL12',np.abs(PL12))
   print("PL23",np.abs(PL23))


The result is shown in the figure, this code is much simpler than the method given in the book.

See more optimization algorithms

Python solves constrained objective optimization problems (non-linear programming, particle swarm, genetic, differential evolution)

Insert picture description here
Difficulty: Understanding the transfer factor method to seek trends

Insert picture description here
Author: Electrical - Yudeng Wu. Writing is not easy. If you think this article is good, please give me a like and support.

Guess you like

Origin blog.csdn.net/kobeyu652453/article/details/114225950