程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Multi objective genetic algorithm nsgaii for solving environmental economic scheduling (Python code implementation)

編輯:Python

Catalog

1 Mathematical model of environmental economic dispatching of power system

2 Numerical example ——IEEE10 node

2.1 data ​

 2.2 Python Code learning

3 Expand knowledge a little  


1 Mathematical model of environmental economic dispatching of power system

 


2 Numerical example ——IEEE10 node

2.1 data

I made a form , Convenient for programming, reading and writing :

 2.2 Python Code learning

This article only shows part of the code , All code points here : We are shipping your work details

Multi objective genetic algorithm NSGAII It is widely used in multi-objective problems of power system , As long as the objective function and constraints in this paper are changed , That's it .

#======== Import third-party library =============
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['font.sans-serif'] = ['SimHei'] # Specify default font
mpl.rcParams['axes.unicode_minus'] = False # Resolve save image is negative '-' Questions displayed as squares
import matplotlib;
matplotlib.use('TkAgg')
from tqdm import tqdm # Progress bar settings
# ======== Import data =============
# ~~~~~~~~~~~~~~~~~~~~~ Read the file ~~~~~~~~~~~~~~~~~~~~~~
file=pd.read_csv('IEEE10.csv')# Unit parameters
#B=pd.read_csv('B10.csv')
#B=np.reshape()
B=np.array([[0.000049, 0.000014 ,0.000015, 0.000015, 0.000016, 0.000017 ,0.000017, 0.000018 ,0.000019, 0.00002],
[0.000014, 0.000045, 0.000016, 0.000016, 0.000017 ,0.000015, 0.000015 ,0.000016 ,0.000018, 0.000018],
[0.000015, 0.000016, 0.000039, 0.00001 ,0.000012, 0.000012 ,0.000014, 0.000014, 0.000016, 0.000016],
[0.000015, 0.000016, 0.00001, 0.00004, 0.000014 ,0.00001 ,0.000011, 0.000012, 0.000014, 0.000015],
[0.000016, 0.000017, 0.000012, 0.000014, 0.000035, 0.000011, 0.000013, 0.000013, 0.000015, 0.000016],
[0.000017, 0.000015, 0.000012, 0.00001, 0.000011 ,0.000036, 0.000012, 0.000012, 0.000014, 0.000015],
[0.000017 ,0.000015 ,0.000014, 0.000011, 0.000013, 0.000012, 0.000038, 0.000016, 0.000016, 0.000018],
[0.000018 ,0.000016, 0.000014, 0.000012, 0.000013, 0.000012, 0.000016 ,0.00004, 0.000015, 0.000016],
[0.000019 ,0.000018 ,0.000016, 0.000014, 0.000015 ,0.000014 ,0.000016, 0.000015, 0.000042 ,0.000019],
[0.00002, 0.000018 ,0.000016 ,0.000015, 0.000016, 0.000015, 0.000018 ,0.000016, 0.000019 ,0.000044]])
P_max = file['b'] # Unit upper limit
P_min = file['c'] # # Unit lower limit
# ~~~~~~~~~~~~~~~~~ Unit characteristic coefficient ~~~~~~~~~~~~~~~~~~~~~~~~·
ai = file['d']
bi=file['e']
ci=file['f']
di=file['g']
ei=file['h']
# ~~~~~~~ Emission characteristic coefficient ~~~~~~~~~~~~~~~~·
ali=file['g']
beti=file['h']
gari=file['i']
eti=file['l']
dali=file['m']
# ====== Multi objective optimization algorithm once The solution can only be solved at a single moment ===============
class GaMultiobjective(object):
def __init__(self, Pload1, P_max, P_min, ai, bi, ci, di, ei, ali, beti, gari, eti, dali):
self.Pload1 = Pload1 # load
self.P_max = P_max # Unit upper limit
self.P_min = P_min # Unit lower limit
self.ai = ai
self.bi = bi
self.ci = ci
self.di = di
self.ei = ei
self.ali = ali
self.beti = beti
self.gari = gari
self.eti = eti
self.dali = dali
# === Initial population ====
def Initialize(self):
X = np.zeros((self.NP, 10)) # Initialization group ,10 representative Output of one unit
for n in range(self.NP): # Traverse every particle
X[n, 0] = np.random.uniform(10, 55, 1)[0] # G1
X[n, 1] = np.random.uniform(20, 80, 1)[0] # G2
X[n, 2] = np.random.uniform(47, 120, 1)[0] # G3
X[n, 3] = np.random.uniform(20, 130, 1)[0] # G4
X[n, 4] = np.random.uniform(50, 160, 1)[0] # G5
X[n, 5] = np.random.uniform(70, 240, 1)[0] # G6
X[n, 6] = np.random.uniform(60, 300, 1)[0] # G7
X[n, 7] = np.random.uniform(70, 340, 1)[0] # G8
X[n, 8] = np.random.uniform(130, 470, 1)[0] # G9
X[n, 9] = np.random.uniform(150, 470, 1)[0] # G10
return X
# ========== Define the objective function 、 And the corresponding penalty items =============
# === Defined function 1 Objective function 1: System operation cost ===
def function1(self, X1):
"""
Individual objective function
:param X1: ( individual [G1,G2,G3,G4,G5,G6,G7,G8,G9,G10]
:return: function 1 The value of the objective function
"""
SUMCOST = [] # Total cost of storage
for i in range (9): # Traverse each unit ,Python It's from 0 Start index ,0-9:10 Units
cost = self.ci[i] * X1[i] * X1[i] + self.bi[i]* X1[i] +self.ai[i]+\
np.abs(self.di[i]*np.sin(ei[i]*(self.P_min[i]-X1[i]))) # Consider the valve point effect
SUMCOST.append(cost)
return np.sum(SUMCOST)
# ==== Defined function 2 Total pollution emissions ====
def function2(self, X1):
"""
Individual objective function
:param X1: ( individual [G1,G2,G3,G4,G5,G6,G7,G8,G9,G10]
:return: function 2 The value of the objective function
"""
emission=[] # Store total pollution emissions
for i in range(9):
e=self.ali[i]+self.beti[i]*X1[i]+self.gari[i]*X1[i]*X1[i]+self.eti[i]*np.exp(self.dali[i]*X1[i])
emission.append(e)
return np.sum(emission)
# === Corresponding constraints Load balance constraint ( This example calc_e() It doesn't work , The load balance constraint has been resolved by other means )===
def calc_e(self, X1):
"""
function 1 Corresponding individual penalty item
:param X1: ( individual [G1,G2,G3,G4,G5,G6,G7,G8,G9,G10]
:return:
"""
Ploss=0
for i in range(9):
for j in range(9):
Ploss+=X1[i]*B[i][j]*X1[j]
# cost=np.abs(X1[0]+X1[1]+X1[2]+X1[3]+X1[4]+X1[5]+X1[6]+X1[7]+X1[8]+X1[9]-np.sum(Ploss)-self.Pload1)
# return cost
return max(0,abs(sum(X1)-Ploss-Pload1-0.1))

3 Expand knowledge a little  


This modern “ Explore 、 conquer ” State of mind , The evolution of the world map can be seen at a glance . Long before history entered modern times , Many cultures already have their own maps of the world . Of course , At that time, no one really knew what the world was like , People in Asia and Africa know nothing about America , American culture does not know the situation in Asia and Africa . But in unfamiliar areas , It's not an unspoken sum on the map , The monsters and wonders are painted . There is no blank space on these maps , It makes people feel that the whole world is under their own control .

stay 15、16 century , The European map of the world began to appear large gaps . From this point, we can see the development of scientific mentality , And the motives of European imperialism . The blank space on the map can be said to be a major breakthrough in psychology and thought , It is clear that Europeans are willing to admit that they know nothing about a large part of the world .

chart 1 1459 European world map in . You can see that the map seems to be full of details , Even Europeans at that time
                                  South Africa, which I knew nothing about , There are dense messages .
1492 year , Columbus sailed westward from Spain , I hope to find a new route to East Asia . Columbus still believed in the old map of the world , Think the whole world can be seen on the map . Columbus extrapolated from the old map , Japan should be located about... West of Spain 7000 Kilometers away . But in fact , The distance from Spain to East Asia is more than 20000 kilometers , And there is an American continent in the middle that he doesn't know .1492 year 10 month 12 About the early morning of the th 2 spot , Columbus and his party had their first contact with this unknown continent . Pita (Pinta) The watchman Juan · rodriguez · Belmeho (Juan Rodriguez Berme jo) From the mast, you can see the present Bahamas , Shout :“ There is land ! There is land !”

Columbus believed that the island was located outside East Asia , Belong to “Indies”( Indian places , Including India today 、 Indochina Peninsula and East Indies ), So he called the locals “Indians”( This is what native Americans are also known as “ Indian ” Why ). Until he died , Columbus didn't think he had made a big mistake . Whether for him or many contemporary people , Said he found a completely unknown continent , It's hard to imagine . After all, for thousands of years , Great thinkers and scholars can't even make mistakes 《 Bible 》, All we know is that there is Europe 、 Africa and Asia . How could it be that they were all wrong ? Don't 《 Bible 》 I missed more than half the world , didn't say a word ? This situation , It's like saying in 1969 Apollo 11 On its way to the moon , Hit another moon that no one has ever seen . And because Columbus was unwilling to accept his ignorance , We can say that he is still a medieval man , Convinced that they already know the world , So even with such a major discovery , Can't convince him .
 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved