Ejemplo n.º 1
0
    def test_solution_inequality(self):
        solution_obj1 = csv_data_solution_factory.get_solution()
        solution_obj2 = csv_data_solution_factory.get_solution()

        self.assertNotEqual(
            solution_obj1, solution_obj2,
            "These two solution.Solutions should not be equal")
 def test_create_gantt_chart_w_start_and_end_times(self):
     solution_obj = csv_data_solution_factory.get_solution()
     solution_obj.create_gantt_chart_html_file(
         self.output_file,
         start_date=datetime.date.today(),
         start_time=datetime.time(10, 0),
         end_time=datetime.time(21, 0))
     self.assertTrue(self.output_file.with_suffix('.html').exists())
    def test_solution_set_add(self):
        solution_set = _SolutionSet()

        # add a Solution
        solution_obj1 = csv_data_solution_factory.get_solution()
        solution_set.add(solution_obj1)

        # make sure Solution was added
        self.assertTrue(solution_obj1 in solution_set)
        self.assertEqual(solution_set.size, 1)

        # add another Solution
        solution_obj2 = csv_data_solution_factory.get_solution()
        solution_set.add(solution_obj2)

        # make sure last Solution was added
        self.assertTrue(solution_obj2 in solution_set)
        self.assertEqual(solution_set.size, 2)
Ejemplo n.º 4
0
    def test_incomplete_solution(self):
        try:
            solution_obj = csv_data_solution_factory.get_solution()
            Solution(csv_data,
                     np.delete(solution_obj.operation_2d_array, 0, axis=0))

            self.fail("Failed to raise solution.IncompleteSolutionException")

        except IncompleteSolutionException:
            pass
    def test_tabu_list_enqueue(self):
        # add solutions to tabu list
        tabu_list = _TabuList()
        size = 100
        while tabu_list.solutions.size < size:
            sol = csv_data_solution_factory.get_solution()
            tabu_list.put(sol)
            self.assertTrue(sol in tabu_list)

        self.assertEqual(len(tabu_list), size)
    def test_tabu_list_dequeue(self):
        initial_solution = csv_data_solution_factory.get_solution()

        # build tabu_list and solutions list
        tabu_list = _TabuList()
        tabu_list.put(initial_solution)
        lst = [initial_solution]
        size = 100
        while tabu_list.solutions.size < size:
            solution_obj = csv_data_solution_factory.get_solution()
            tabu_list.put(solution_obj)
            lst.append(solution_obj)

        # check that solutions are dequeued in correct order
        i = 0
        while 0 < tabu_list.solutions.size:
            self.assertTrue(lst[i] in tabu_list)
            self.assertEqual(lst[i], tabu_list.get())
            self.assertFalse(lst[i] in tabu_list)
            i += 1
Ejemplo n.º 7
0
    def test_infeasible_solution(self):
        try:
            solution_obj = csv_data_solution_factory.get_solution()
            solution_obj.operation_2d_array[[
                0, 200
            ]] = solution_obj.operation_2d_array[[200, 0]]
            Solution(csv_data, solution_obj.operation_2d_array)

            self.fail("Failed to raise solution.InfeasibleSolutionException")

        except InfeasibleSolutionException:
            pass
Ejemplo n.º 8
0
    def test_solution_less_than(self):
        solution_obj1 = csv_data_solution_factory.get_solution()
        solution_obj2 = Solution(csv_data, solution_obj1.operation_2d_array)
        solution_obj2.makespan -= 1

        self.assertLess(solution_obj2, solution_obj1,
                        "solution_obj2 should be less than solution_obj1")

        solution_obj2.makespan += 1
        solution_obj2.machine_makespans[0] -= 1

        self.assertLess(solution_obj2, solution_obj1,
                        "solution_obj2 should be less than solution_obj1")
Ejemplo n.º 9
0
    def test_pickle_to_file(self):
        solution_obj = csv_data_solution_factory.get_solution()
        with open(tmp_dir / 'test_solution.pkl', 'wb') as fout:
            pickle.dump(solution_obj, fout)

        self.assertTrue((tmp_dir / 'test_solution.pkl').exists(),
                        "The pickled solution does not exist")

        with open(tmp_dir / 'test_solution.pkl', 'rb') as fin:
            solution_obj_pickled = pickle.load(fin)

        self.assertEqual(
            solution_obj, solution_obj_pickled,
            "The pickled solution should be equal to solution_obj")
Ejemplo n.º 10
0
    def test_solution_greater_than(self):
        solution_obj1 = csv_data_solution_factory.get_solution()
        solution_obj2 = Solution(csv_data, solution_obj1.operation_2d_array)
        solution_obj2.makespan -= 1

        self.assertGreater(
            solution_obj1, solution_obj2,
            "solution_obj2 should be greater than solution_obj1")

        solution_obj2.makespan += 1
        solution_obj2.machine_makespans[0] -= 1

        self.assertGreater(
            solution_obj1, solution_obj2,
            "solution_obj2 should be greater than solution_obj1")
    def test_max_heap(self):

        heap_size = 50
        heap = Heap(max_heap=True)
        for _ in range(heap_size):
            heap.push(csv_data_solution_factory.get_solution())

        self.assertEqual(heap_size, len(heap),
                         f"The max heap size should be equal to {heap_size}")

        while len(heap) > 1:
            sol = heap.pop()
            self.assertGreaterEqual(
                sol, heap[0],
                "The max heap solutions should be organized with the worst solutions (greatest) at the top"
            )
    def test_solution_set_remove(self):
        solution_set = _SolutionSet()

        # add a Solution
        solution_obj1 = csv_data_solution_factory.get_solution()
        solution_set.add(solution_obj1)

        # make sure Solution was added
        self.assertTrue(solution_obj1 in solution_set)

        # remove the Solution
        solution_set.remove(solution_obj1)

        # make sure solution was removed
        self.assertFalse(solution_obj1 in solution_set)
        self.assertEqual(solution_set.size, 0)
    def test_create_continuous_gantt_chart(self):
        solution_obj = csv_data_solution_factory.get_solution()

        # test without suffix
        solution_obj.create_gantt_chart_html_file(self.output_file,
                                                  continuous=True)
        self.assertTrue(self.output_file.with_suffix('.html').exists())

        output_file = self.output_file.with_suffix('.html')

        # test with suffix
        output_file.unlink()
        solution_obj.create_gantt_chart_html_file(output_file, continuous=True)
        self.assertTrue(output_file.exists())

        # test as string
        output_file.unlink()
        solution_obj.create_gantt_chart_html_file(str(output_file),
                                                  continuous=True)
        self.assertTrue(output_file.exists())
Ejemplo n.º 14
0
 def test_tournament_selection(self):
     selection_size = 5
     population = [csv_data_solution_factory.get_solution() for _ in range(self.population_size)]
     while len(population) > selection_size:
         parent = _tournament_selection(population, selection_size)
         self.assertNotIn(parent, population)
Ejemplo n.º 15
0
    def test_solution_equality(self):
        solution_obj1 = csv_data_solution_factory.get_solution()
        solution_obj2 = Solution(csv_data, solution_obj1.operation_2d_array)

        self.assertEqual(solution_obj1, solution_obj2,
                         "These two solution.Solutions should be equal")
Ejemplo n.º 16
0
 def test_random_selection(self):
     population = [csv_data_solution_factory.get_solution() for _ in range(self.population_size)]
     while len(population) > 0:
         parent = _random_selection(population)
         self.assertNotIn(parent, population)
Ejemplo n.º 17
0
 def test_solution_in_list(self):
     sol1 = csv_data_solution_factory.get_solution()
     sol2 = Solution(csv_data, sol1.operation_2d_array)
     lst = [sol1]
     self.assertIn(sol2, lst)