Beispiel #1
0
    def avaliacao(self, populacao):

        n = len(populacao)

        def steps(k):
            individuo = populacao[k, :]
            obj = self.funcao_objetivo(individuo)
            return obj

        ncpu = cpu_count()
        pool = ProcessPool(nodes=ncpu)
        pesos = array(pool.map(steps, range(n)))
        pool.close()
        pool.join()
        pool.clear()
        shutdown()

        return pesos
Beispiel #2
0
    assert res == std


def test_processing():
    from pathos.pools import ProcessPool as MPP
    pool = MPP()
    res = timed_pool(pool, items, delay, verbose)
    assert res == std


def test_threading():
    from pathos.pools import ThreadPool as MTP
    pool = MTP()
    res = timed_pool(pool, items, delay, verbose)
    assert res == std


if __name__ == '__main__':
    if verbose:
        print("CONFIG: delay = %s" % delay)
        print("CONFIG: items = %s" % items)
        print("")

    from pathos.helpers import freeze_support, shutdown
    freeze_support()
    test_serial()
    test_pp()
    test_processing()
    test_threading()
    shutdown()
Beispiel #3
0
    from pathos.pools import ParallelPool as Pool

    solver = DifferentialEvolutionSolver2(ND, NP)
    solver.SetMapper(Pool().map)
    solver.SetRandomInitialPoints(min=[-100.0] * ND, max=[100.0] * ND)
    solver.SetEvaluationLimits(generations=MAX_GENERATIONS)
    solver.SetGenerationMonitor(VerboseMonitor(30))
    solver.enable_signal_handler()

    strategy = Best1Exp
    #strategy = Best1Bin

    solver.Solve(ChebyshevCost, termination=VTR(0.01), strategy=strategy, \
                 CrossProbability=1.0, ScalingFactor=0.9 , \
                 sigint_callback=plot_solution)

    solution = solver.Solution()

    return solution


if __name__ == '__main__':
    from pathos.helpers import freeze_support, shutdown
    freeze_support()  # help Windows use multiprocessing
    solution = main()
    shutdown()  # help multiprocessing shutdown all workers
    print_solution(solution)
    plot_solution(solution)

# end of file