Beispiel #1
0
 def testRestart(self):
     fitness = FitnessNapsack()
     ilog = pv.ImageLog()
     restart_dir = ilog.dir
     #fitness.solve()
     alg = ga.GeneticAlgorithm(fitness,[ga.GARanking(100)],n_processes=1)
     result = alg.optimize(max_iter=500,ilog=ilog)
     
     time.sleep(2)
     #print "Restarting..."
     ilog = pv.ImageLog()
     alg = ga.GeneticAlgorithm(fitness,[ga.GARanking(100)],n_processes=1)
     result = alg.optimize(max_iter=1000,ilog=ilog,restart_dir=restart_dir)
Beispiel #2
0
 def testGAUnitRect(self):
     #print "Running unitrect test"
     alg = ga.GeneticAlgorithm(fitnessUnitRect, [
         ga.GAUnitRect2(
             min_width=0.05, min_height=0.05, max_height=1.0, max_width=1.0)
     ],
                               population_size=20,
                               n_processes=4)
     _ = alg.optimize(max_iter=1000, callback=unitRectCallback)
Beispiel #3
0

# 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:
    # load the archived result

    # look in the "/tmp" directory for a log of the run in a *_pyvis directory
    # pkl files document the result
    # this directory can also be used to restart a GA run if there was a problem
Beispiel #4
0
 def testGAUnitVector(self):
     #print "Running unitrect test"
     alg = ga.GeneticAlgorithm(fitnessUnitVector, [ga.GAUnitVector(9)],
                               population_size=20,
                               n_processes=1)
     _ = alg.optimize(max_iter=10000)
Beispiel #5
0
 def testNapsack(self):
     fitness = FitnessNapsack()
     #fitness.solve()
     alg = ga.GeneticAlgorithm(fitness, [ga.GARanking(100)], n_processes=1)
     result = alg.optimize(max_iter=1000)
Beispiel #6
0
 def test2DSurfaceIntSP(self):
     alg = ga.GeneticAlgorithm(
         FitnessInt(), [ga.GAInteger(0, 1000),
                        ga.GAInteger(0, 1000)],
         n_processes=1)
     _ = alg.optimize(max_iter=1000)
Beispiel #7
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)
Beispiel #8
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)
Beispiel #9
0
 def dtestNapsack(self):
     fitness = FitnessNapsack()
     #fitness.solve()
     alg = ga.GeneticAlgorithm(FitnessNapsack(), [ga.GARanking(100)],
                               n_processes=1)
     score, args, kwargs = alg.optimize(max_iter=1000)