def test_Genome_eval(self):
     coils = GAutils.get_coils_from_excel()
     subject = Genome.Genome()
     subject.evaluate(subject.sequence, Steel.calculate_max_penalty(), coils)
     self.assertTrue(subject.penalty < 1 and subject.penalty > 0)
     self.assertTrue(subject.fitness < 1 and subject.fitness > 0)
     self.assertTrue(subject.fitness + subject.penalty == 1)
Esempio n. 2
0
def main():
    """
    This is the main method that runs the algorithm and provides the excel
    :return: NONE
    """
    if os.path.isfile(CONST_EXCEL_FILE_NAME_TO_READ):
        coils = GAutils.get_coils_from_excel()
        improvements_values = []
        for i in range(20):
            improvements_values.append(GAutils.testing_the_algorithm(coils, i))
        temp = str(GAutils.CONST_EXCEL_FILE_NAME_TO_WRITE).split("\\")
        temp = str(temp[7]) + str(improvements_values.index(max(improvements_values))) + ".xlsx"
        print("The best improvement is in file: " + temp)
    else:
        print("Excel file not found, system shutdown")
        exit()
 def test_Genome_eval(self):
     coils = GAutils.get_coils_from_excel()
     subject = Genome.Genome()
     subject.evaluate(subject.sequence, Steel.calculate_max_penalty(),
                      coils)
     self.assertTrue(subject.penalty < 1 and subject.penalty > 0)
     self.assertTrue(subject.fitness < 1 and subject.fitness > 0)
     self.assertTrue(subject.fitness + subject.penalty == 1)
Esempio n. 4
0
def main():
    """
    This is the main method that runs the algorithm and provides the excel
    :return: NONE
    """
    if os.path.isfile(CONST_EXCEL_FILE_NAME_TO_READ):
        coils = GAutils.get_coils_from_excel()
        improvements_values = []
        for i in range(20):
            improvements_values.append(GAutils.testing_the_algorithm(coils, i))
        temp = str(GAutils.CONST_EXCEL_FILE_NAME_TO_WRITE).split("\\")
        temp = str(temp[7]) + str(
            improvements_values.index(max(improvements_values))) + ".xlsx"
        print("The best improvement is in file: " + temp)
    else:
        print("Excel file not found, system shutdown")
        exit()
Esempio n. 5
0
 def test_calculate_transition_penalty(self):
     # we calculated the transition penalty between the 2 first coils outside the program: 0.1885
     coils = GAutils.get_coils_from_excel()
     population = Population.Population(coils)
     population.createInitial(GAutils.CONST_POPULATION_SIZE)
     # coils[0] is pf type Steel and holds the attributes for the coils
     temp = coils[0].calculate_penalty(coils[1])
     temp = float("%.4f" % temp)
     self.assertAlmostEqual(temp, 0.1984)
Esempio n. 6
0
 def test_get_chromosome_by_index(self):
     coils = GAutils.get_coils_from_excel()
     population = Population.Population(coils)
     population.createInitial(GAutils.CONST_POPULATION_SIZE)
     pop = population.getPop()
     self.assertEqual(pop[1].getSequence(),
                      (population.get_chromosome_by_index(1)).getSequence())
     self.assertNotEqual(
         pop[1].getSequence(),
         (population.get_chromosome_by_index(2)).getSequence())
Esempio n. 7
0
 def test_get_best_sol(self):
     coils = GAutils.get_coils_from_excel()
     population = Population.Population(coils)
     population.createInitial(GAutils.CONST_POPULATION_SIZE)
     pop = population.getPop()
     max_fit = pop[0].getFit()
     index = 0
     for i in range(GAutils.CONST_POPULATION_SIZE):
         if pop[i].getFit() > max_fit:
             index = i
             max_fit = pop[i].getFit()
     self.assertEqual(index, (population.get_best_solution())[0])
Esempio n. 8
0
 def test_set_get_pop(self):
     coils = GAutils.get_coils_from_excel()
     population1 = Population.Population(coils)
     population1.createInitial(GAutils.CONST_POPULATION_SIZE)
     pop1 = population1.getPop()
     population2 = Population.Population(coils)
     population2.createInitial(GAutils.CONST_POPULATION_SIZE)
     pop2 = population2.getPop()
     self.assertNotEqual(pop1, pop2)
     population2.setPop(pop1)
     pop2 = population2.getPop()
     self.assertEqual(pop1, pop2)
Esempio n. 9
0
 def test_fitness_prob(self):
     coils = GAutils.get_coils_from_excel()
     population = Population.Population(coils)
     population.createInitial(GAutils.CONST_POPULATION_SIZE)
     population.updateGenesRange()
     self.assertAlmostEqual(population.getFitnessProb(), 1)
Esempio n. 10
0
 def test_is_improvement_exist(self):
     coils = GAutils.get_coils_from_excel()
     self.assertTrue(GAutils.testing_the_algorithm(coils) > 0)