def test_population_size_after_crossover_net12_2(self):
     list_of_demands = get_demands_from_file(net12_2_string_demands)
     first_population = generate_first_population(list_of_demands)
     first_population_length = len(first_population)
     new_population = crossover_chromosomes(first_population, 1)
     if len(first_population) % 2 == 0:
         self.assertEqual(first_population_length * 2, len(new_population))
     else:
         self.assertEqual(first_population_length * 2 - 1,
                          len(new_population))
Exemple #2
0
    # List for holdings Link objects, get Link objects from txt string
    list_of_links = Parser.get_links_list_from_file(net_string_links)

    # print(Parser.get_number_of_links(net_string_links))
    # print(Parser.get_number_of_demands(net_string_demands))

    list_of_demands = Parser.get_demands_from_file(net_string_demands)

    # for x in range(0, len(list_of_links)):
    #     list_of_links[x].print_link_properties()

    # for y in range(0, len(list_of_demands)):
    #     list_of_demands[y].print_demand_properties()

    first_population = generate_first_population(list_of_demands,
                                                 initial_population_size)

    current_population = first_population
    calculate_fitness(list_of_links, list_of_demands, current_population)

    for item in first_population:
        print('Genes of current chromosome')
        for gene in item.list_of_genes:
            print(gene.list_of_alleles)
        print("DAP:" + str(item.fitness_dap))
        print("DDAP:" + str(item.fitness_ddap))

    while check_if_stop():
        start = time.time()
        old_ddap = current_population[0].fitness_ddap
        old_dap = current_population[0].fitness_dap
 def test_demand_volumes_on_chromosome_list_of_genes_net12_2(self):
     list_of_demands = get_demands_from_file(net12_2_string_demands)
     first_population = generate_first_population(list_of_demands)
     for chromosome in first_population:
         for gene in chromosome.list_of_genes:
             self.assertEqual(gene.demand_volume, sum(gene.list_of_alleles))