Пример #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
    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)
Пример #3
0
  # 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
  create_history_df(ga.avg_fitness).to_csv("{}/avg_fitness.csv".format(args.output))
  create_history_df(ga.best_fitness).to_csv("{}/best_fitness.csv".format(args.output))

  #for k in ga.genetics.fn.keys():
  #  create_history_df(ga.genetics.fn[k]).to_csv("{}/{}_fitness.csv".format(args.output, k))

  # Summary 
  chromo_summary  = ChromoSummary(salesman, clients, dist_matrix, priority_matrix)