示例#1
0
 def test2DSurfaceFloatSP(self):
     alg = ga.GeneticAlgorithm(
         Fitness(), [ga.GAFloat(0.0, 10.0),
                     ga.GAFloat(0.0, 10.0)],
         n_processes=1)
     _ = alg.optimize(max_iter=5000, callback=callback)
示例#2
0
    cx, cy, sigma = 5.0, 9.0, 2.0
    dist2 = (x - cx)**2 + (y - cy)**2
    scale = 1.0 / (2 * np.pi * sigma**2)
    val += scale * np.exp(-dist2 / (2 * sigma**2))

    return -val


# use True and False to toggle between running GA and loading archived results
if True:
    # Check the fitness function
    print myFitness(8, 2)
    assert abs(myFitness(8, 2) + 0.63) < 0.01

    # Here are the three arguments
    args = [ga.GAFloat(0, 10), ga.GAFloat(0, 10)]

    # no keyword arguments this time
    kwargs = {}

    ilog = pv.ImageLog()
    ga_test = ga.GeneticAlgorithm(myFitness, args, kwargs, n_processes='AUTO')

    print 'running ga'

    result = ga_test.optimize(max_iter=2000, callback=callback, display=True)
    print "Best Score =", result[0]
    print "Best args =", result[1]
    print "Best kwargs =", result[2]

else:
示例#3
0
 def test2DSurfaceFloatMP(self):
     alg = ga.GeneticAlgorithm(
         Fitness(), [ga.GAFloat(0.0, 10.0),
                     ga.GAFloat(0.0, 10.0)],
         n_processes=4)
     _ = alg.optimize(max_iter=1000)