I believe the problem is caused by EPANET's use of the C library function tmpnam()
to create a new temporary hydraulics file name for each iteration of your genetic algorithm. The tmpnam()
function generates a different string each time it is called, up to TMP_MAX
times. If it is called more than TMP_MAX
times, the behavior is implementation defined.TMP_MAX
is defined in the C library header stdio.h which is 32767 for Microsoft C.
I can suggest two possible work-arounds you could try:
1. Request that EPANET save the hydraulic results from each run to a file whose name you supply, even though you won't be making use of the file. This can be done either in the input file you use for your analysis, by adding a line: HYDRAULICS SAVE filename
to the [OPTIONS] section where filename is the full path name of the file you want to use. Or you could call ENsavehydfile(filename)
prior to starting your genetic algorithm.
2. Instead of calling ENsolveH()
to evaluate your hydraulics at each iteration, use the call sequence:
ENinitH(0);
do {
ENrunH(&t);
// retrieve hydraulic results here
ENnextH(&tstep);
} while (tstep > 0);
and prior to starting your genetic algorithm call ENopenH()
. This option will be the more efficient alternative.
Lew Rossman