#(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.3x[0]+0.0007x[0]*x[0])
#(3.23)ineq:所有机组两小时内排放SO2量不超过8t
def con41(x):
return 8-(0.02*(4+0.3x[0]+0.0007x[0]x[0]+4+0.3x[3]+0.0007*x[3]*x[3])+
0.015*(3+0.32x[1]+0.0004x[1]x[1]+3+0.32x[4]+0.0004*x[4]*x[4])+ #机组2
0.01*(3.5+0.3x[2]+0.00045x[2]x[2])+3.5+0.3x[5]+0.00045*x[5]*x[5]) #机组3
#(3.23)ineq:所有机组两小时内排放SO2量大于0t
def con42(x):
return 0.02*(4+0.3x[0]+0.0007x[0]x[0]+4+0.3x[3]+0.0007*x[3]*x[3])+\
0.015*(3+0.32x[1]+0.0004x[1]x[1]+3+0.32x[4]+0.0004*x[4]*x[4])+\
0.01*(3.5+0.3x[2]+0.00045x[2]x[2])+3.5+0.3x[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)