目录
1、概述
(1)思维导图
(2)知识点
2、案例分析
(1)案例
(2)非线性规划简单实现
3、节能减排需求下的动态经济调度---非线性规划
(1)分析
(2)代码实现
(3)结果
4、参考文献
1、概述 (1)思维导图
上一节我们讲了基于拉格朗日及运筹规划方法的经济调度算法,这一节我们进入第二部分,节能减排需求下的动态经济调度及其安全校验方法。
(2)知识点
2、案例分析 (1)案例 (2)非线性规划简单实现
import numpy as np from scipy.optimize import minimize #目标函数 def fun(x): return 500*(4+0.3*x[0]+0.0007*x[0]*x[0])+550*(3+0.32*x[1]+0.0004*x[1]*x[1])+600*(3.5+0.3*x[2]+0.00045*x[2]*x[2])+ 500*(4+0.3*x[3]+0.0007*x[3]*x[3])+550*(3+0.32*x[4]+0.0004*x[4]*x[4])+600*(3.5+0.3*x[5]+0.00045*x[5]*x[5]) #(3.18) eq def con11(x): return 700-(x[0]+x[1]+x[2]) def con12(x): return 500-(x[3]+x[4]+x[5]) #(3.19) bound b1=(100,200) b2=(120,250) b3=(150,300) bunds=(b1,b2,b3,b1,b2,b3) #(3.20) ineq def con21(x): return x[3]-x[0]-(-50) def con22(x): return x[4]-x[1]-(-60) def con23(x): return x[5]-x[2]-(-150) #(3.21)ineq #(3.22)ineq:第一台机组第一个小时不超过70t def con31(x): return 70-(4+0.3*x[0]+0.0007*x[0]*x[0]) #(3.23)ineq:所有机组两小时内排放SO2量不超过8t def con41(x): return 8-(0.02*(4+0.3*x[0]+0.0007*x[0]*x[0]+4+0.3*x[3]+0.0007*x[3]*x[3])+ 0.015*(3+0.32*x[1]+0.0004*x[1]*x[1]+3+0.32*x[4]+0.0004*x[4]*x[4])+ #机组2 0.01*(3.5+0.3*x[2]+0.00045*x[2]*x[2])+3.5+0.3*x[5]+0.00045*x[5]*x[5]) #机组3 #(3.23)ineq:所有机组两小时内排放SO2量大于0t def con42(x): return 0.02*(4+0.3*x[0]+0.0007*x[0]*x[0]+4+0.3*x[3]+0.0007*x[3]*x[3])+ 0.015*(3+0.32*x[1]+0.0004*x[1]*x[1]+3+0.32*x[4]+0.0004*x[4]*x[4])+ 0.01*(3.5+0.3*x[2]+0.00045*x[2]*x[2])+3.5+0.3*x[5]+0.00045*x[5]*x[5] #(3.24) def main(): con1={'type':'eq','fun':con11} con2= {'type': 'eq', 'fun': con12} con3= {'type': 'ineq', 'fun': con21} con4= {'type': 'ineq', 'fun': con22} con5= {'type': 'ineq', 'fun': con23} con6= {'type': 'ineq', 'fun': con31} con7= {'type': 'ineq', 'fun': con41} con8= {'type': 'ineq', 'fun': con42} cons=([con1,con2,con3,con4,con5,con6,con7,con8]) x0=np.random.uniform(120,250,6) #初值 res=minimize(fun,x0,method='SLSQP',bounds=bunds,constraints=cons) print('*--------*') print('第一种表述:') print('minf(x):',res.fun) print(res.success) print('x:',[np.around(i) for i in res.x]) print('x1:',res.x[0]) print('x2:',res.x[1]) print('x3:',res.x[2]) print('*--------*') print('第二种表述:') print("optimization problem(res):{}".format(res.x)) print("Xopt={}".format(res.x)) print("minf(x)={:.4f}".format(res.fun)) print('第三种表述:') print('minFGi:' + str(fun(res.x))) print('解得:') print('*--------*') print('第一小时PG1:',res.x[0]) print('第一小时PG2:', res.x[1]) print('第一小时PG3:', res.x[2]) print('*--------*') print('第二小时PG1:', res.x[3]) print('第二小时PG2:', res.x[4]) print('第二小时PG3:', res.x[5]) if __name__ == "__main__": main()
#结果 *--------* 第一种表述: minf(x): 218634.73692885612 False x: [146.0, 174.0, 150.0, 158.0, 192.0, 150.0] x1: 146.31545289519153 x2: 173.68454744729326 x3: 150.00000000000017 *--------* 第二种表述: optimization problem(res):[146.3154529 173.68454745 150. 157.89411855 192.10588145 150. ] Xopt=[146.3154529 173.68454745 150. 157.89411855 192.10588145 150. ] minf(x)=218634.7369 第三种表述: minFGi:218634.73692885612 解得: *--------* 第一小时PG1: 146.31545289519153 第一小时PG2: 173.68454744729326 第一小时PG3: 150.00000000000017 *--------* 第二小时PG1: 157.8941185494627 第二小时PG2: 192.10588145060618 第二小时PG3: 150.0 Process finished with exit code 0
这个结果和书本给出的答案差距较大,下面我们采用书本方法。
3、节能减排需求下的动态经济调度---非线性规划 (1)分析 (2)代码实现import numpy as np from scipy import optimize as opt from scipy.optimize import minimize # 目标函数 def fun(x): #=原文中的mincost #式子3-17 #500*(41+x[0]*0.456+x[1]*0.496+x[2]*0.524+x[3]*0.564)为第一台机组第一小时购煤成本 #550*(47.2+x[4]*0.456+x[5]*0.508) 为第二台机组第一小时购煤成本 #600*(58.6+x[6]*0.458+x[7]*0.502+x[8]*0.548)为第三台机组第一小时购煤成本 #500*(41+x[9]*0.456+x[10]*0.496+x[11]*0.524+x[12]*0.564)为第一台机组第二小时购煤成本 #550*(47.2+x[13]*0.456+x[14]*0.508) 为第二台机组第二小时购煤成本 #600 * (58.6 + x[15] * 0.458 + x[16] * 0.502 + x[17] * 0.548)为第三台机组第二小时购煤成本 return 500*(41+x[0]*0.456+x[1]*0.496+x[2]*0.524+x[3]*0.564)+550*(47.2+x[4]*0.456+x[5]*0.508)+600*(58.6+x[6]*0.458+x[7]*0.502+x[8]*0.548)+ 500*(41+x[9]*0.456+x[10]*0.496+x[11]*0.524+x[12]*0.564)+550*(47.2+x[13]*0.456+x[14]*0.508)+600*(58.6+x[15]*0.458+x[16]*0.502+x[17]*0.548) #约束条件 def constraint1(x):#式子3-18 return 100+x[0]+x[1]+x[2]+x[3]+120+x[4]+x[5]+150+x[6]+x[7]+x[8]-700 #等式约束,第一小时,三台机组 输出和为700MW def constraint2(x):#式子3-18 return 100+x[9]+x[10]+x[11]+x[12]+120+x[13]+x[14]+150+x[15]+x[16]+x[17]-500 #等式约束,第二小时,三台机组 输出和为500MW #边界约束 式子3-19 b1=(0.0,25)#0<=x[0,1,2,3]<=25 ,0<=x[9,10,11,12]<=25,PG1 b2=(0.0,100)#0<=x[4]<=100 x21min=0,x21max=100, 0<=x[13]<=100 PG2的约束 b3=(0.0,30)#0<=x[5]<=30 x22min=0,x22max=30 0<=x[14]<=30 PG2的约束 b4=(0.0,50)##0<=x[6,7,8]<=50 x3min=0,x3max=50 0<=x[15,16,17]<=50 PG3的约束 bnds = (b1,b1,b1,b1,b2,b3,b4,b4,b4,b1,b1,b1,b1,b2,b3,b4,b4,b4)#边界约束 式子3-19 #机组1爬坡约束 式子3-20 def constraint3(x): return x[9]+x[10]+x[11]+x[12]-x[0]-x[1]-x[2]-x[3]+50 #不等式约束,机组1的爬坡功率约束为50MW #机组2爬坡约束 式子3-20 def constraint4(x): return x[13]+x[14]-x[4]-x[5]+60 #不等式约束,机组2的爬坡功率约束为60MW #机组3爬坡约束式子3-20 def constraint5(x): return x[15]+x[16]+x[17]-x[6]-x[7]-x[8]+150#不等式约束,机组3的爬坡功率约束为150MW #第一台机组在第一小时消耗煤炭不超过70t 式子3-22 def constraint6(x): return 70-(41+x[0]*0.456+x[1]*0.496+x[2]*0.524+x[3]*0.564) #不等式约束 #所有机组在二小时内总的SO2的排放量不超过8t,式子3-23,3-24 def constraint7(x): return 8-0.02*(41+x[0]*0.456+x[1]*0.496+x[2]*0.524+x[3]*0.564)-0.02*(41+x[9]*0.456+x[10]*0.496+x[11]*0.524+x[12]*0.564)- 0.015*(47.2+x[4]*0.456+x[5]*0.508)-0.015*(47.2+x[13]*0.456+x[14]*0.508)- 0.01*(58.6+x[6]*0.458+x[7]*0.502+x[8]*0.548)-0.01*(58.6+x[15]*0.458+x[16]*0.502+x[17]*0.548) #不等式约束 #所有机组在二小时内总的SO2的排放量大于0t,式子3-23,3-24 def constraint8(x): return 0.02*(41+x[0]*0.456+x[1]*0.496+x[2]*0.524+x[3]*0.564)+0.02*(41+x[9]*0.456+x[10]*0.496+x[11]*0.524+x[12]*0.564)+ 0.015*(47.2+x[4]*0.456+x[5]*0.508)+0.015*(47.2+x[13]*0.456+x[14]*0.508)+ 0.01*(58.6+x[6]*0.458+x[7]*0.502+x[8]*0.548)+0.01*(58.6+x[15]*0.458+x[16]*0.502+x[17]*0.548) #不等式约束 def main(): con1 = {'type': 'eq', 'fun': constraint1} con2 = {'type': 'eq', 'fun': constraint2} con3 = {'type': 'ineq', 'fun': constraint3} con4 = {'type': 'ineq', 'fun': constraint4} con5 = {'type': 'ineq', 'fun': constraint5} con6 = {'type': 'ineq', 'fun': constraint6} con7 = {'type': 'ineq', 'fun': constraint7} con8 = {'type': 'ineq', 'fun': constraint8} cons = ([con1, con2, con3, con4, con5, con6, con7, con8]) # 8个约束条件 # 初始值 x0 = np.random.uniform(10, 40, 18) # 计算 solution = minimize(fun, x0, method='SLSQP', bounds=bnds, constraints=cons) x = solution.x print('目标值: ' + str(fun(x))) print('答案为') print('第一小时PG1', x[0] + x[1] + x[2] + x[3] + 100) print('第一小时PG2', x[4] + x[5] + 120) print('第一小时PG3', x[6] + x[7] + x[8] + 150) print('--------------') print('第二小时PG1', x[9] + x[10] + x[11] + x[12] + 100) print('第二小时PG2', x[13] + x[14] + 120) print('第二小时PG3', x[15] + x[16] + x[17] + 150) if __name__ =='__main__': main()(3)结果
目标值: 285143.09923674347 答案为 第一小时PG1 159.92366412213232 第一小时PG2 249.9999999999863 第一小时PG3 290.0763358776917 -------------- 第二小时PG1 150.0 第二小时PG2 200.0000000006473 第二小时PG3 150.0 Process finished with exit code 0
这次和答案很稳合。
4、参考文献https://blog.csdn.net/kobeyu652453/article/details/113928406
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)