电力系统—转移因子法求潮流(Python实现)

64 阅读8分钟

 

第四步:得到线路功率:

3、案例简单分析 


4、案例实现 


(1)案例

    不考虑网络约束:

考虑网络约束:

 (2)代码实现(方法1)

import numpy as np

from scipy.optimize import minimize

目标函数(FG1+FG2+FG3)

def fun(args1):

A0,a0, a1, a2,B0, b0, b1, b2,C0, c0, c1, c2 = args1

v = lambda x: (A0+a0*x[0] + a1 * x[1] + a2 * x[2]

  • B0+b0*x[3] + b1 * x[4] + b2 * x[5]

  • C0+c0*x[6] + c1 * x[7] + c2 * x[8])

return v

def con(args2):

D, x0min, x0max, x1min, x1max, x2min, x2max,x3min, x3max,x4min, x4max,x5min, x5max,x6min, x6max,x7min, x7max,x8min, x8max= args2

cons = ({'type': 'eq', 'fun': lambda x: (100+x[0] + x[1] + x[2]+100+x[3]+x[4]+x[5]+50+x[6]+x[7]+x[8])-D}, #等式约束

#不等式约束

{'type': 'ineq', 'fun': lambda x: 300-np.abs((-2/3)(100+x[3]+x[4]+x[5]-(1/3)(50+x[6]+x[7]+x[8]+(1/3)*D)))},

{'type': 'ineq', 'fun': lambda x: 300 - np.abs((-1 / 3) * (100 + x[3] + x[4] + x[5] - (2/ 3)*(50 + x[6] + x[7] + x[8] + (2/ 3) * D)))},

{'type': 'ineq', 'fun': lambda x: 330 - np.abs((1 / 3) * (100 + x[3] + x[4] + x[5] - (1 / 3)*(50 + x[6] + x[7] + x[8] + (1 / 3) * D)))},

#考虑网络约束

{'type': 'ineq', 'fun': lambda x: 190-(100+x[3]+x[4]+x[5]-(50+x[6]+x[7]+x[8]))},

#上下界

{'type': 'ineq', 'fun': lambda x: x[0] - x0min},

{'type': 'ineq', 'fun': lambda x: -x[0] + x0max},

{'type': 'ineq', 'fun': lambda x: x[1] - x1min},

{'type': 'ineq', 'fun': lambda x: -x[1] + x1max},

{'type': 'ineq', 'fun': lambda x: x[2] - x2min},

{'type': 'ineq', 'fun': lambda x: -x[2] + x2max},

{'type': 'ineq', 'fun': lambda x: x[3] - x3min},

{'type': 'ineq', 'fun': lambda x: -x[3] + x3max},

{'type': 'ineq', 'fun': lambda x: x[4] - x4min},

{'type': 'ineq', 'fun': lambda x: -x[4] + x4max},

{'type': 'ineq', 'fun': lambda x: x[5] - x5min},

{'type': 'ineq', 'fun': lambda x: -x[5] + x5max},

{'type': 'ineq', 'fun': lambda x: x[6] - x6min},

{'type': 'ineq', 'fun': lambda x: -x[6] + x6max},

{'type': 'ineq', 'fun': lambda x: x[7] - x7min},

{'type': 'ineq', 'fun': lambda x: -x[7] + x7max},

{'type': 'ineq', 'fun': lambda x: x[8] - x8min},

{'type': 'ineq', 'fun': lambda x: -x[8] + x8max})

return cons

def main():

args1 = (3300,40,50,57.5,4225,43.75,46.25,48.75,2910,55.8,57,58.2)

args2 = (800, 0,200,0,200,0,100,0,100,0,100,0,100,0,50,0,50,0,50)

cons = con(args2)

x0 = np.random.uniform(10, 400, 9) # 初值

res = minimize(fun(args1), x0, method='SLSQP', constraints=cons)

print('FGi-代价:', res.fun)

print(res.success)

x=res.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

PD=800

线路潮流

PL12 = 0 * PG1 - (2 / 3) * PG2 - (1 / 3) * (PG3 - PD)

PL13 = 0 * PG1 - 0.5 * (1 / 3) * PG2 - (1 / 3) * (PG3 - PD)

PL23 = 0 * PG1 + (1 / 3) * PG2 - (1 / 3) * (PG3 - PD)

原理注解

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))

if name == "main":

main()

结果

FGi-代价: 35170.250000008295

True

机组PG1= 499.99999999971374

机组PG2= 245.00000000012272

机组PG3= 55.0000000001636

线路PL13= 207.49999999992502

线路PL12= 84.99999999986366

线路PL23= 329.99999999998636

Process finished with exit code 0

 (3)代码实现(方法2)

import numpy as np

from scipy import optimize as opt

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 (40p11+50p12+57.5p13+43.75p21+46.25p22+48.75p23+55.8p31+57p32+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个约束条件

def main():

初始值

x0 = np.random.uniform(10, 400, 9)

计算

如果你也是看准了Python,想自学Python,在这里为大家准备了丰厚的免费学习大礼包,带大家一起学习,给大家剖析Python兼职、就业行情前景的这些事儿。

一、Python所有方向的学习路线

Python所有方向路线就是把Python常用的技术点做整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。

二、学习软件

工欲善其必先利其器。学习Python常用的开发软件都在这里了,给大家节省了很多时间。

三、全套PDF电子书

书籍的好处就在于权威和体系健全,刚开始学习的时候你可以只看视频或者听某个人讲课,但等你学完之后,你觉得你掌握了,这时候建议还是得去看一下书籍,看权威技术书籍也是每个程序员必经之路。

四、入门学习视频

我们在看视频学习的时候,不能光动眼动脑不动手,比较科学的学习方法是在理解之后运用它们,这时候练手项目就很适合了。

四、实战案例

光学理论是没用的,要学会跟着一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。

五、面试资料

我们学习Python必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有阿里大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。

成为一个Python程序员专家或许需要花费数年时间,但是打下坚实的基础只要几周就可以,如果你按照我提供的学习路线以及资料有意识地去实践,你就有很大可能成功! 最后祝你好运!!!

了解详情:docs.qq.com/doc/DSnl3ZG…