예제 #1
0
def client(dispatcher):
	client_id = dispatcher.checkin()
	dispatcher.add_log("hello from %d-client"%client_id)
	logging.info("hello from %d-client"%client_id)
	while True:
		while dispatcher.workQueueSize() == 0:
			
			time.sleep(1)

		try:
			(id, job) = dispatcher.getWork()
		except Queue.Empty:
			dispatcher.add_log("%d-client has problem getting item from queue"%(client_id))
			logging.info("%d-client has problem getting item from queue"%(client_id))

		if job == "Poison":
			dispatcher.add_log("%d-client taking poison"%client_id)
			dispatcher.checkout()
			break

		#print "got job:",
		dispatcher.add_log("%d-client has job: %s"%(client_id,str(job)))
		#result = function(job)
		result = siesta.siesta_function("_".join([str(y) for y in job]),job)
		dispatcher.add_log("%d-client with job: %s has result: %s"%(client_id,str(job),str(result)))
		#print result
		try:
			dispatcher.putResult((id,result))
		except Queue.Full:
			dispatcher.add_log("%d-client has problem adding items to the queue"%(client_id))
예제 #2
0

	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()