def test_case4(self):
        """Testing the calculate rank weights function when c=0 and n=0"""

        rankWeights = Solution.calcRankWeights(c=0,n=0)
        expected = {}

        self.assertEqual(rankWeights,expected)
Example #2
0
    def setUp(self):

        self.students, self.supervisors = createRandomData(4, 8, 18)

        # Generating rank weights for c = 0.5
        self.rankWeights = Solution.calcRankWeights()

        #Creating fitness cache

        self.dummySolution = Solution()
        self.fitnessCache = {}
        for sup in self.supervisors:
            supervisorKeywords = self.supervisors[sup].getKeywords()
            for stu in self.students:
                studentKeywords = self.students[stu].getKeywords()
                f_stu, f_sup = self.dummySolution.kw_similarity(
                    studentKeywords, supervisorKeywords, self.rankWeights)
                self.fitnessCache[str((stu, sup))] = (f_stu, f_sup)

        #Setting up the GA Object

        self.mutationOp = mutate
        self.selectionOp = tournamentSelection
        self.crossoverOp = crossover

        self.geneticAlgorithm = GeneticAlgorithm(
            self.students, self.supervisors, self.fitnessCache,
            self.rankWeights, self.mutationOp, self.crossoverOp,
            self.selectionOp)

        #Parameters for GA

        self.numberOfGenerations = 20
        self.populationSize = 10
        self.mutationProbability = 0.1
        self.swapProbability = 0.3
        self.transferProbability = 0.5

        #Initializing population
        self.population = self.geneticAlgorithm.initializePopulation(
            self.populationSize)
        self.maxFst = max(self.population, key=lambda x: x.getFst()).getFst()
        self.minFst = min(self.population, key=lambda x: x.getFst()).getFst()

        self.maxFsup = max(self.population,
                           key=lambda x: x.getFsup()).getFsup()
        self.minFsup = min(self.population,
                           key=lambda x: x.getFsup()).getFsup()
    def test_case2(self):
        """Testing the calculate Rank Weights function when c = 1"""

        rankWeights = Solution.calcRankWeights(c=1)

        result = True
        
        expected = 0.2
        
        for i in rankWeights:

            if rankWeights[i] != expected:

                result = False
                break

        self.assertTrue(result)
    def test_case3(self):
        """Testing the calculate rank weights function when c = 0.3"""

        rankWeights = Solution.calcRankWeights(c=0.3)

        result = round(sum(rankWeights.values()),15)

        expected = {1: 0.701705143, 2: 0.210511543, 3: 0.063153463, 4: 0.0189460389, 5: 0.005683812}

        result2 = True

        for i in rankWeights:

            if round(rankWeights[i],8) != round(expected[i],8):
                result2 = False
                break
        

        self.assertEqual((result,result2),(1,True))
    def setUp(self):

        #Creating a list of students and supervisors

        topicNames, topicPaths, topicIDs, levels = parseFile(
            "pystsup/test/acm.txt")

        self.supervisors = {}
        self.students = {}

        stuID = "student"
        supID = "supervisor"

        stuList1 = [
            "MapReduce-based systems", "Multidimensional range search",
            "Open source software", "Data mining", "Online shopping"
        ]
        stuList2 = [
            "Heuristic function construction", "Multi-agent systems",
            "Open source software", "Data mining", "Speech recognition"
        ]
        stuList3 = [
            "Multi-agent systems", "Speech recognition",
            "Heuristic function construction", "Data mining",
            "Object identification"
        ]
        stuList4 = [
            "Multi-agent systems", "Intelligent agents", "Speech recognition",
            "Object identification", "Heuristic function construction"
        ]

        supList1 = [
            "Multi-agent systems", "Intelligent agents",
            "MapReduce-based systems", "Object identification",
            "Heuristic function construction"
        ]
        supList2 = [
            "Open source software", "Data mining", "Speech recognition",
            "Object identification", "Heuristic function construction"
        ]
        supList3 = [
            "Multi-agent systems", "Intelligent agents", "Speech recognition",
            "Object identification", "Heuristic function construction"
        ]

        supList = [supList1, supList2, supList3]
        supQuota = [2, 2, 1]
        stuList = [stuList1, stuList2, stuList3, stuList4]

        for i in range(3):
            toAdd = []
            sup_list = {}
            rank = 0
            for kw in supList[i]:
                rank += 1
                sup_list[rank] = [
                    kw, getPath(kw, topicNames, topicPaths, topicIDs)
                ]

            sup = supID + str(i + 1)
            quota = supQuota[i]

            supervisorObject = Supervisor(sup, sup_list, quota)

            self.supervisors[sup] = supervisorObject

        for i in range(4):
            toAdd = []
            stu_list = {}
            rank = 0
            for kw in stuList[i]:
                rank += 1
                stu_list[rank] = [
                    kw, getPath(kw, topicNames, topicPaths, topicIDs)
                ]

            stu = stuID + str(i + 1)
            studentObject = Student(stu, stu_list)
            self.students[stu] = studentObject

        # Generating rank weights for c = 0.5

        self.rankWeights = Solution.calcRankWeights()

        #Creating fitness cache

        self.dummySolution = Solution()

        self.fitnessCache = {}

        for sup in self.supervisors:
            supervisorKeywords = self.supervisors[sup].getKeywords()
            for stu in self.students:
                studentKeywords = self.students[stu].getKeywords()
                f_stu, f_sup = self.dummySolution.kw_similarity(
                    studentKeywords, supervisorKeywords, self.rankWeights)
                self.fitnessCache[str((stu, sup))] = (f_stu, f_sup)

        # Creating two graphs and solutions

        self.graph1 = BipartiteGraph()
        self.graph2 = BipartiteGraph()

        self.graph1.addEdge("supervisor1", "student2")
        self.graph1.addEdge("supervisor2", "student4")
        self.graph1.addEdge("supervisor3", "student1")
        self.graph1.addEdge("supervisor1", "student3")

        self.solution1 = Solution(self.graph1)

        self.graph2.addEdge("supervisor1", "student2")
        self.graph2.addEdge("supervisor2", "student1")
        self.graph2.addEdge("supervisor3", "student4")
        self.graph2.addEdge("supervisor1", "student3")

        self.solution2 = Solution(self.graph2)