#NEWLINE# def main( prng = None , display = False ) : #NEWLINE# #INDENT# if ( prng is None ) : #NEWLINE# #INDENT# prng = Random ( ) #NEWLINE# prng . seed ( time ( ) ) #NEWLINE# #UNINDENT# problem = inspyred . benchmarks . Ackley ( 2 ) #NEWLINE# ea = inspyred . swarm . PSO ( prng ) #NEWLINE# ea . terminator = inspyred . ec . terminators . evaluation_termination #NEWLINE# ea . topology = inspyred . swarm . topologies . ring_topology #NEWLINE# final_pop = ea . evolve ( generator = problem . generator , evaluator = problem . evaluator , pop_size = 100 , bounder = problem . bounder , maximize = problem . maximize , max_evaluations = 30000 , neighborhood_size = 5 ) #NEWLINE# if display : #NEWLINE# #INDENT# best = max ( final_pop ) #NEWLINE# print ( 'Best Solution: \n{0}' . format ( str ( best ) ) ) #NEWLINE# #UNINDENT# return ea