print "Invalid option" if option == 1: problem = Schwefel() elif option == 2: problem = TravelingSalesman() elif option == 3: problem = Rastrigin() elif option == 4: problem = RadioNetwork() if option >= 1 and option <= 4: print '[MASTER] Starting' # Generate the population to create the probabilist models # pop = util.new_population(problem) print '[MASTER] Population size: ', len(pop) # Get the best to use as a model to the others # best_boy = get_bestest(pop, problem) ## 25% ## comm.send({'problem': problem, 'models': generate_models(pop, best_boy, 0.25)}, dest=1, tag=0) ## 50% ## comm.send({'problem': problem, 'models': generate_models(pop, best_boy, 0.50)}, dest=2, tag=0) ## 75% ## comm.send({'problem': problem, 'models': generate_models(pop, best_boy, 0.75)}, dest=3, tag=0) ## 100% ##
def generate_populations(problem, size): populations = [] for model_id in xrange(size): pop = util.new_population(problem) populations.append(pop) return populations