First, I got the path of the input file of network.
- import epanet.toolkit as en
- epanet_proj = en.createproject()
- en.open(ph=epanet_proj, inpFile=“D:/L-Town/Battledim-project/L-Town_50.inp”, rptFile=“D:/L-Town/Battledim-project/L-Town_50.rpt”,outFile="")
There are two patterns (resdential and commercial)
The indices of resdential and commercial patterns are 1 and 2 respectively.
Then I create a population with 20 indivdiuals. Each indivdiual is like a vector of residential and commercial multipliers.
I used the code ‘ENgetpatternlen’ to retrieve the number of time periods in those two pattern.
The number of time period is 50.
I started to put each individual in the model
- for timestep in range(0,50):
num_of_individual = 20
for i in range(num_of_individual ):
for l in range(len(2)):
if l == 0:
multiplier_r = en.setpatternvalue(epanet_proj,l+1,timestep+1,population[i][l])
if l == 1:
multiplier_c = en.setpatternvalue(epanet_proj,l+1,timestep+1,population[i][l])
There are 50 timesteps totally. At first 30 timesteps, each indivdiual could lead to different corresponding pressures, but starting from 31st timestep, it always retrieved the same model-simulated pressure no matter which individual was put in the model.
Please have a look.
Thank you very much.