def compute(self):
        # init toolbox
        toolbox = base.Toolbox()
        configuration_executor.execute(self.configuration, toolbox, self.comp_prop)
        self.set_globals()
        # toolbox.register("evaluate", self.f_problem)
        # before tests, only rastrigin
        toolbox.register("evaluate", self.problem_arg)

        # init population
        pop = toolbox.population(n=self.POP)
        hof = tools.HallOfFame(maxsize=self.HOF_SIZE)
        stats = tools.Statistics(lambda ind: ind.fitness.values)
        stats.register("avg", tools.mean)
        stats.register("std", tools.std)
        stats.register("min", min)
        stats.register("max", max)

        population, partial_res = alg_helper.eaSimple(pop, toolbox, cxpb=0.8, mutpb=1, ngen=self.GEN,monitoring=self.monitoring,
            stats=stats, halloffame=hof, verbose=True)

        print "Best individual:  " + str(self.convertArrToFloat(hof[0]))
        print "Rastrigin value: " + str(hof[0].fitness.values) + "\n\n\n"
        sorted_individuals = [self.convertArrToFloat(ind) for ind in hof]
        fitness_values = [ind.fitness.values[0] for ind in hof]
        stats_results = [stats.data[name][0][self.GEN][-1] for name in stats.functions]
        stats_part_results = [[stats.data[name][0][i][-1] for name in stats.functions] for i in xrange(self.GEN)]

        return sorted_individuals,fitness_values, partial_res, stats_results, stats_part_results
Exemple #2
0
def computePipes(computation, algorithm, args):
    NBR_DEMES = 3  # hardcoded for the moment because VM has only 3 threads
    pipes = [Pipe(True) for _ in range(NBR_DEMES)]
    pipes_in = deque(p[0] for p in pipes)
    pipes_out = deque(p[1] for p in pipes)
    pipes_in.rotate(1)
    pipes_out.rotate(-1)
    results = list()
    queue = Queue()
    for iter in xrange(computation['repeat']):
        algs = list()
        processes = list()
        # in order to create all names in module, so deserialization runs painlessly
        configuration_executor.execute(args['configuration'], base.Toolbox(), dict())
        for deme in xrange(NBR_DEMES):
            args['rank'] = (pipes_in[deme], pipes_out[deme], queue)
            algs.append(eval(algorithm)(**args))
            processes.append(Process(target=algs[-1].compute))
        for proc in processes:
            proc.start()
        for deme in xrange(NBR_DEMES):
            results.append(queue.get())
        for proc in processes:
            proc.join()
    return results
 def parse_and_execute_configuration(self):
     configuration_executor.execute(self.configuration, self.toolbox, self.comp_prop)