Пример #1
0
def evolve_callback(ga_engine):
    global n
    best = ga_engine.bestIndividual()
    i, nearest_supers = eval_func(best, graph=True)
    title = 'Best Chromosome (Gen. %03d)' % n
    GAgraph.generate_graph(list(best.getBinary()), nearest_supers, FIELD_WIDTH, FIELD_HEIGHT, title,n)
    n += 1
Пример #2
0
def evolve_callback(ga_engine):
    global n
    best = ga_engine.bestIndividual()
    i, nearest_supers = eval_func(best, graph=True)
    title = 'Best Chromosome (Gen. %03d)' % n
    GAgraph.generate_graph(list(best.getBinary()), nearest_supers, FIELD_WIDTH,
                           FIELD_HEIGHT, title, n)
    n += 1
Пример #3
0
# The evaluator function (objective function)
genome.evaluator.set(eval_func)
genome.mutator.set(Mutators.G1DBinaryStringMutatorFlip)
#genome.initializator.set(chromosomes_init)

# Genetic Algorithm Instance
ga = GSimpleGA.GSimpleGA(genome)

ga.selector.set(Selectors.GRankSelector)
ga.setCrossoverRate(0.75)
ga.setMutationRate(0.02)
ga.setElitism(True)

ga.setGenerations(100)
ga.terminationCriteria.set(GSimpleGA.ConvergenceCriteria)

sqlite_adapter = DBAdapters.DBSQLite(identify="ex10", resetDB=True)
ga.setDBAdapter(sqlite_adapter)

# Do the evolution, with stats dump
# frequency of 10 generations
ga.evolve(freq_stats=10)

# Best individual
best = ga.bestIndividual()
#print best
i, nearest_supers = eval_func(best, graph=True)
title = r'$Rank \ Selection$'
GAgraph.generate_graph(list(best.getBinary()), nearest_supers, FIELD_WIDTH,
                       FIELD_HEIGHT, coords, title)
Пример #4
0
    # Set Probabilities for Genetic Algorithm
    ga.setCrossoverRate(Pc)
    ga.setMutationRate(Pm)

    ga.setElitism(True)
    ga.setElitismReplacement(NUM_NODES/4)

    ga.setGenerations(NUM_GENERATIONS)

    # Set up database for data storage and graphing with pyevolve_graph.py
    #sqlite_adapter = DBAdapters.DBSQLite(identify="ex10", resetDB=True)
    #adapter = DBAdapters.DBVPythonGraph(identify="run_01", frequency = 1)
    #ga.setDBAdapter(adapter)

    # Run genetic Algorithm
    ga.evolve(freq_stats=NUM_GENERATIONS/4)

    # Show best chromosome
    best = ga.bestIndividual()
    print 
    print "Best Chromosome:", '\n', best.getBinary()
    print "Fitness Raw Score:", best.getRawScore()
    print

    # Graph best chromosome
    i, nearest_supers = eval_func(best, graph=True)
    title = 'Node Placement'# % NUM_NODES
    GAgraph.generate_graph(list(best.getBinary()), nearest_supers, FIELD_WIDTH, FIELD_HEIGHT, title)