Ejemplo n.º 1
0
def GenerateOffspring(parents):
    offspring = []
    while (len(offspring) != len(parents)):
        parentA, parentB = Selection.Selection(parents)
        childA, childB = Crossover.Crossover(parentA, parentB)
        childA = Mutation.Mutation(childA)
        childB = Mutation.Mutation(childB)
        offspring.append(childA)
        offspring.append(childB)
    return offspring
Ejemplo n.º 2
0
 def __init__(self, params):
     self.epochs = params['epochs']
     self.Crossover = Crossover(params['crossover_type'],
                                params['crossover_prob'])
     self.Population = Population(booth_function, params['population_size'],
                                  2, -10, 10,
                                  params['population_precision'])
     self.Mutation = Mutation(params['mutation_type'],
                              params['mutation_prob'])
     self.Inversion = Inversion(params['inversion_type'],
                                params['inversion_prob'])
     self.Selection = Selection(params['selection_type'],
                                params['selection_prob'])
     self.EliteStrategy = EliteStrategy(params['elite_prob'])
Ejemplo n.º 3
0
def compileMutations(data, type):
    mutationList = MutationList()
    for drug in data['viewer']['mutationsAnalysis']['drugResistance'][0][
            'drugScores']:
        for mutations in drug['partialScores']:
            try:
                x = mutations['mutations'][1]['text']
                muts = []
                for mutation in mutations['mutations']:
                    muts.append(mutation['text'])
                temp = mutations['mutations'][0]['text']
                mutationList.add_multimutant(
                    MultipleMutant(muts, mutations['score']))

            except:
                temp = mutations['mutations'][0]['text']
                if temp not in mutationList.get_names():
                    newMutation = Mutation(temp, type, mutations['score'])
                    mutationList.add_mutation(newMutation)
                else:
                    mutationList.add_score(temp, mutations['score'])
    mutationList.fill_blanks()
    mutationList.get_averages()
    return mutationList
Ejemplo n.º 4
0
                                                      mutation=mutation,
                                                      sizeOfPopulation=10,
                                                      genPopulation=populationGen,
                                                      numberChromosome=NN, epoche=100,
                                                      data=data)
    ans = bga.fit()
    print(ans)"""

    data = GenMtrx_NN()  # инициализация условий задачи (считывание матрицы расстояний)
    NN = len(data)  # считываем количество городов
    fitness = Fitness.Fitness('fitness_population_NN')
    crossover = Crossover.Crossover('crossover_NN')
    # Можно выбрать: inbreeding_NN,
    #                 outbreeding_NN
    #                 panmixia_NN
    #                 tournament_selection_NN
    #                 roulette_selection_NN
    selection = Selection.Selection('inbreeding_NN')
    mutation = Mutation.Mutation('insertion_deleting_mutation_NN')
    populationGen = Population.Population('elite_selection')
    bga = BasicGeneticAlgorithm.BasicGeneticAlgorithm(generator=genPopulation_NN,
                                                      fitness=fitness,
                                                      crossover=crossover,
                                                      selection=selection,
                                                      mutation=mutation,
                                                      sizeOfPopulation=100,
                                                      genPopulation=populationGen,
                                                      numberChromosome=100, epoche=100,
                                                      data=data)
    ans = bga.fit()
    print(ans)
Ejemplo n.º 5
0
    #         # print("COMBINED IS")
    #         # print(combined)
    #         if (combined == target):
    #             print("Its Done!")
    #             sys.exit()

    f = Fitness.Fitness(population)
    fitness = f.getFitness()

    s = Selection.Selection(fitness)
    firstChoice, secondChoice, maximum = s.selectFromPop()

    c = Crossover.Crossover(population, firstChoice, secondChoice)
    population = c.crossover()

    m = Mutation.Mutation(population, 10)
    population = m.mutate()

    if (catch == 1):

        print(
            "--------------------------------------------------------------------"
        )
        print("Program is finished!")
        print(
            "--------------------------------------------------------------------"
        )
        print("Final fitness: ")
        print(fitness)
        print(
            "--------------------------------------------------------------------"