示例#1
0
def evolve(genome, initial_graph=None, **kwargs):
    '''
     takes a genome and options that define the genetic algorithm
                apply it to the genome
                returns infos about the best individual
    '''
    #depending on the evaluation_method, we will have different goals
    goal = emo.get_goal(genome.getParam("evaluation_method"))
    multiprocessing = kwargs.get("multiprocessing", False)
    #genetic_algorithm = kwargs.get("genetic_algorithm","default_algorithm")

    algo = gsga.GSimpleGA(genome)
    algo.setMultiProcessing(multiprocessing)

    #the selector is used to choose which ones will be parents of the next generation
    algo.selector.set(py.Selectors.GRouletteWheel)

    #elitism will keep the top individuals with their score in the next generation :
    #it can help us to keep track of some of the best graph generations
    #algo.setElitism(True)
    #algo.setElitismReplacement(10)

    algo.setMinimax(py.Consts.minimaxType[goal])

    #now we do evolve with algorithm and every freq stats, we compute statistics
    freq_stats = int(kwargs.get("freq_stats", "1"))
    filename_stats = kwargs.get("stats_path")
    stats_adapter = st.StatisticsInTxt(filename=filename_stats,
                                       frequency=freq_stats)
    algo.setDBAdapter(stats_adapter)

    number_of_generations = int(kwargs.get("nb_generations", "100"))
    algo.setGenerations(number_of_generations)
    algo.evolve()
def evolve(genome,rule_name,**kwargs):  
    '''
     takes a genome and options that define the genetic algorithm
                apply it to the genome
                returns infos about the best individual
    '''
   
    filename_stats = '../../results/temp/stats_quality_{}.txt'.format(rule_name)
    goal = emo.get_goal(genome.getParam("evaluation_method"))         
    multiprocessing = kwargs.get("multiprocessing",False)   
    algo = py.GSimpleGA.GSimpleGA(genome)
    algo.setMultiProcessing(multiprocessing)
    algo.selector.set(py.Selectors.GRouletteWheel)
    algo.setMinimax(py.Consts.minimaxType[goal]) 
    stats_adapter = st.StatisticsInTxt(rule_name,frequency = freq_stats)
    #stats_adapter = st.StatisticsQualityInTxt(rule_name,filename=filename_stats,frequency = freq_stats)
    algo.setDBAdapter(stats_adapter)
    number_of_generations = int(kwargs.get("nb_generations","100"))
    algo.setGenerations(number_of_generations)
    algo.evolve()
    return algo.bestIndividual()
def evolve(genome,initial_graph = None,**kwargs):  
    '''
     takes a genome and options that define the genetic algorithm
                apply it to the genome
                returns infos about the best individual
    '''
    #depending on the evaluation_method, we will have different goals
    goal = emo.get_goal(genome.getParam("evaluation_method"))         
    multiprocessing = kwargs.get("multiprocessing",False)   
    #genetic_algorithm = kwargs.get("genetic_algorithm","default_algorithm")
    
    algo = gsga.GSimpleGA(genome)
    algo.setMultiProcessing(multiprocessing)

    
    
    #the selector is used to choose which ones will be parents of the next generation
    algo.selector.set(py.Selectors.GRouletteWheel)
    
    #elitism will keep the top individuals with their score in the next generation : 
    #it can help us to keep track of some of the best graph generations
    #algo.setElitism(True)
    #algo.setElitismReplacement(10)
    
    
    algo.setMinimax(py.Consts.minimaxType[goal])
    
    
    
    
    #now we do evolve with algorithm and every freq stats, we compute statistics
    freq_stats = int(kwargs.get("freq_stats","1"))
    filename_stats = kwargs.get("stats_path")
    stats_adapter = st.StatisticsInTxt(filename=filename_stats,frequency = freq_stats)
    algo.setDBAdapter(stats_adapter)
    
    
    number_of_generations = int(kwargs.get("nb_generations","100"))
    algo.setGenerations(number_of_generations)
    algo.evolve()
示例#4
0
def evolve(genome, rule_name, **kwargs):
    '''
     takes a genome and options that define the genetic algorithm
                apply it to the genome
                returns infos about the best individual
    '''

    filename_stats = '../../results/temp/stats_quality_{}.txt'.format(
        rule_name)
    goal = emo.get_goal(genome.getParam("evaluation_method"))
    multiprocessing = kwargs.get("multiprocessing", False)
    algo = py.GSimpleGA.GSimpleGA(genome)
    algo.setMultiProcessing(multiprocessing)
    algo.selector.set(py.Selectors.GRouletteWheel)
    algo.setMinimax(py.Consts.minimaxType[goal])
    stats_adapter = st.StatisticsInTxt(rule_name, frequency=freq_stats)
    #stats_adapter = st.StatisticsQualityInTxt(rule_name,filename=filename_stats,frequency = freq_stats)
    algo.setDBAdapter(stats_adapter)
    number_of_generations = int(kwargs.get("nb_generations", "100"))
    algo.setGenerations(number_of_generations)
    algo.evolve()
    return algo.bestIndividual()