def test_case13(self): """Testing the kPoint crossover function - for random 60sup:400stu solution""" solution1 = Solution.generateRandomSolution(self.students2, self.supervisors2) solution2 = Solution.generateRandomSolution(self.students2, self.supervisors2) solution3 = kPoint(solution1, solution2, self.supervisors2, self.students2, k=15) result = solution3.isValid(self.students2, self.supervisors2) self.assertTrue(result)
def test_case6(self): """Testing the K Point Crossover function - for random 3sup:4stu solution""" solution1 = Solution.generateRandomSolution(self.students, self.supervisors) solution2 = Solution.generateRandomSolution(self.students, self.supervisors) solution3 = kPoint(solution1, solution2, self.supervisors, self.students, k=3) result = solution3.isValid(self.students, self.supervisors) self.assertTrue(result)
def test_case1(self): """Testing the create random solution function""" solution1 = Solution.generateRandomSolution(self.students,self.supervisors) result = solution1.isValid(self.students,self.supervisors) self.assertEqual(result,True)
def test_case11(self): """Testing the ERX Modified crossover function - for random 60sup:400stu solution""" solution1 = Solution.generateRandomSolution(self.students2, self.supervisors2) solution2 = Solution.generateRandomSolution(self.students2, self.supervisors2) solution3 = crossover(solution1, solution2, self.supervisors, self.supervisors2, self.students2) structureResult = (solution3.getGraph().getStructure() == solution1.getGraph().getStructure()) or ( solution3.getGraph().getStructure() == solution2.getGraph().getStructure()) result = (solution3.isValid(self.students2, self.supervisors2)) and (structureResult) self.assertTrue(result)
def test_case6(self): """Testing mutation function for a randomly created solution 2""" mutationProbability = 0.3 swapProbability = 0.7 transferProbability = 0 solution1 = Solution.generateRandomSolution(self.students, self.supervisors) solution2 = mutate(solution1, self.supervisors, mutationProbability, swapProbability, transferProbability) result = solution2.isValid(self.students, self.supervisors) self.assertTrue(result)
def initializePopulation(self,size): """ Function to create a pool of random solutions of a given size. Used in the begining of the GA run to create intial population. Parameters: size (int) - the size of the population. Returns: population (list) - list containing 'n' randomly created Solution Objects, where n is the specified size. """ population = [] count = 0 while count < size: #Generate random solution, calculate and set Fst and Fsup values, then append to population list until its of the size we want. new = Solution.generateRandomSolution(self.students,self.supervisors) new.calcFitness(self.students,self.supervisors,self.rankWeights,self.fitnessCache) population.append(new) count+=1 return population