我想运行一个python文件file.py 20次,1000次迭代,单次运行点击,这样我就不需要手动点击运行20次。
Init()
globalBest=pop[0].chromosome
# Saving Result
fp=open(resultFileName,"w");
fp.write("Iteration,Fitness,Chromosomes\n")
for i in range(0,iterations):
Crossover()
Mutation()
MemoriseGlobalBest()
if funEval >=maxFunEval:
break
if i%20==0:
print "I:",i,"\t Fitness:", bestFitness
fp.write(str(i) + "," + str(bestFitness) + "," + str(bestChromosome) + "\n")
print "I:",i+1,"\t Fitness:", bestFitness
fp.write(str(i+1) + "," + str(bestFitness) + "," + str(bestChromosome))
fp.close()
答案 0 :(得分:0)
您可以编写另一个脚本,将脚本调用20次。制作一个循环并在其中调用file.py 20次。
答案 1 :(得分:0)
尝试:
for iteration in range(20):
Init()
globalBest = pop[0].chromosome
# Saving Result
fp = open(resultFileName, "a")
fp.write("Iteration,Fitness,Chromosomes\n")
for i in range(0, iterations):
Crossover()
Mutation()
MemoriseGlobalBest()
if funEval >= maxFunEval:
break
if i % 20 == 0:
print
"I:", i, "\t Fitness:", bestFitness
fp.write(str(i) + "," + str(bestFitness) + "," + str(bestChromosome) + "\n")
print
"I:", i + 1, "\t Fitness:", bestFitness
fp.write(str(i + 1) + "," + str(bestFitness) + "," + str(bestChromosome))
fp.close()