Пример #1
0
def do_training():
    print(genom_struct_path, MEMS_info, cuncurrency)

    ga = GeneticAlgorithm(genom_struct_path)
    start_time = time.time()
    population = ga.run(init_population_size,
                        population_size,
                        mutation_rate,
                        num_iteratitions,
                        crossover_type,
                        calc_fitness,
                        fitness_goal,
                        cuncurrency=cuncurrency,
                        reverse_fitness_order=True,
                        population_np_path=population_np_path,
                        reload_np_population_rate=reload_np_population_rate)

    save_models(population)
    end_time = time.time()
    print(population[:3].astype(float))
    print(population[:, -1].astype(float))
    print('Runtime :', end_time - start_time)
Пример #2
0
def main():
    setup_data_manager()
    dm = DataManager.shared()
    from genetic_algorithm.genetic_algorithm import GeneticAlgorithm

    population = setup_population()
    generation_number = 1

    while generation_number != NUMBER_OF_GENERATIONS and population.get_chromosomes(
    )[0].get_fitness() < TARGET_FITNESS:
        population = GeneticAlgorithm.evolve(population)
        population.calculate_fitness(dm.get_X_train(), dm.get_y_train())
        population.get_chromosomes().sort(key=lambda ann: ann.get_fitness(),
                                          reverse=True)
        print_population(population, generation_number)
        generation_number += 1
from utilities.objective_functions import TSPObjectiveFunction
from genetic_algorithm.genetic_algorithm import GeneticAlgorithm

obj = TSPObjectiveFunction(num_points=20)
solution = obj.min_v
number_of_generations = 50
population_size = 1000
percent_crossover = 0.6
percent_mutation = 0.1

GA = GeneticAlgorithm(objective_function=obj,
                      experiment_type='iter_lim',
                      population_size=population_size,
                      pct_crossover=percent_crossover,
                      pct_mutation=percent_mutation,
                      num_iters=number_of_generations)

GA_response = GA.minimize_objective()

print("")
print("GA answer: {}".format(GA_response[0]))
print("Percent Error: {}".format(GA_response[1]))
print("Timing of code: {}".format(GA_response[2]))
print("Correct answer: {}".format(solution))





Пример #4
0
    # Load logger
    global logger
    logging.config.dictConfig(yaml.load(open('logging.yaml')))
    logger = logging.getLogger(GeneticAlgorithm.LOGGER_HANDLER_NAME)

    path = 'genom_struct.csv'
    init_population_size = 6000
    population_size = 100
    mutation_rate = 0.20
    num_iteratitions = 100
    crossover_type = GeneticAlgorithm.TWO_POINT_CROSSOVER
    fitness_goal = 0.00001

    load_dataset()

    ga = GeneticAlgorithm(path)
    start_time = time.time()
    population = ga.run(init_population_size,
                        population_size,
                        mutation_rate,
                        num_iteratitions,
                        crossover_type,
                        calc_fitness,
                        fitness_goal,
                        cuncurrency=20,
                        reverse_fitness_order=False)
    save_models(population)
    end_time = time.time()
    print(population[:3].astype(float))
    print(population[:, -1].astype(float))
    print('Runtime :', end_time - start_time)
Пример #5
0
  
  # Build priority Matrix
  priority_matrix = build_priority_matrix(args.priority, clients_index, salesman_index)
  
  if args.debug == 1 and not args.priority is None:
    priority_matrix = build_priority_matrix_test(clients, salesman, initial_territory)

  print(priority_matrix)
  
  # Genetic Algorithm with Configuration
  ga = GeneticAlgorithm(
        SalesTerritories(salesman, clients, 
          dist_matrix, priority_matrix, initial_territory, 
          limit=args.generations, 
          size=args.init_population,
          prob_crossover=args.prob_crossover,
          prob_mutation=args.prob_mutation,
          local_search=args.local_search,
          elitism=args.elitism,
          params=params)
        )

  log("Init Otimization...\n\n")

  population = ga.run(args.processes)

  # Best Solution
  best_territory = ga.best_solution
  log("Best Solution: "+str(ga.genetics.fitness(best_territory)))
  
  # History
Пример #6
0
def run_gen_alg(gen_alg: GeneticAlgorithm, generations: int):
    for gen in tqdm(range(generations)):
        gen_alg.iterate_population()
Пример #7
0
if __name__ == "__main__":

    log_file = "./logs/gen_alg.log"
    logger.create_rotating_log(log_file)
    log = logger.logger
    log.info("----- Starting Genetic Algorithm -----")

    champ_info = get_champion_information(
        "genetic_algorithm/full_champion_data.json")
    enemy_team = create_enemy_team_comp(ENEMY_TEAM, champ_info)
    filtered_champ_info = filter_champion_information(ENEMY_TEAM, champ_info)
    genetic_algorithm = GeneticAlgorithm(
        population=POPULATION,
        crossover_rate=CROSSOVER_RATE,
        mutation_rate=MUTATION_RATE,
        base_team_composition=enemy_team,
        champion_information=filtered_champ_info,
        meta=META)
    run_gen_alg(genetic_algorithm, NUM_GENERATIONS)

    print("enemy team")
    for champion in enemy_team.champions:
        print(f"{champion.id}: {champion.name}")
        print("----------------------------------------")

    print("\nyour team")
    for champion in genetic_algorithm.best_individuals[0].champions:
        print(champion.name)
        print(champion.matchups)
        print("----------------------------------------")