def sed_file(name,X): var_file = siesta.list_variables() var_names=[x[0] for x in var_file] output_string ="" for x in zip(var_names,X): output_string += "s/$%s/%f/g\n"%(x[0],x[1]) out=open(name,"w") out.write(output_string) out.close
p=sorted(swarm,key=lambda x: x.cost)[0].position sed_file("final.sed",p) print "Results:", return [math.sqrt(sum([i**2 for i in p])),p] if __name__ == "__main__": #setup logging logging.basicConfig(filename="swarm.log",level=logging.DEBUG) min_p=Vector([0,0]) max_p=Vector([2,2]) #constants=[23,500,1,0,2.8446,0,-0.3328] #constants=[60,2000,1,0,2.9708,0,-0.27] constants=[3,20,1,0,2.9708,0,-0.27] print "Running Siesta PSO with parameters %s" %str(constants) logging.info("Running Siesta PSO with parameters %s" %str(constants)) #print run(my_function,min_p,max_p,constants,2) var_file=siesta.list_variables() min_p_list=[float(x[1]) for x in var_file] max_p_list=[float(x[2]) for x in var_file] min_p=Vector(min_p_list) max_p=Vector(max_p_list) print run(lambda x :siesta.siesta_function("_".join([str(y) for y in x]),x),min_p,max_p,constants,False) multi.poison() # ans=run(N,iterations,1,min_p,max_p,lambda x :siesta.siesta_function("_".join([str(y) for y in x]),x))[1] # print ans # out=open("final","w") # out.write(str(ans)) # out.close()