Пример #1
0
    def test_local_single(self):
        self.args.tumor_files = ['test/test_local.txt']
        patient = Patient(self.args, 0)
        patient.solve_local()

        self.assertEqual(get_obj_val(patient.model), 3)
        answer = ['A', 'B', 'C']
        if use_gurobi:
            self.assertEqual(len(patient.get_solutions(self.args.num_sol)), 5)
            self.assertIn(answer, patient.get_solutions(self.args.num_sol))
        else:
            self.assertSetEqual(set(answer), set(patient.get_solution()))
Пример #2
0
    def test_testcase_2(self):

        self.args.tumor_files = [
            'test/testcase_2/cancer_1.txt', 'test/testcase_2/cancer_2.txt',
            'test/testcase_2/cancer_3.txt'
        ]
        self.args.non_tumor_files = [
            'test/testcase_2/normal_1.txt', 'test/testcase_2/normal_2.txt',
            'test/testcase_2/normal_3.txt'
        ]

        self.args.r = 1
        patient_0 = Patient(self.args, 0)
        patient_1 = Patient(self.args, 1)
        patient_2 = Patient(self.args, 2)

        patient_0.solve_local()
        patient_1.solve_local()
        patient_2.solve_local()

        # without any restriction on normal_cell ub, then answer should be 1.
        self.assertEqual(1, len(patient_0.get_solution()))
        self.assertEqual(1, len(patient_1.get_solution()))
        self.assertEqual(1, len(patient_2.get_solution()))

        # if we set ub = 0, then there should not by any answer.
        self.args.non_tumor_ub = 0
        patient_0 = Patient(self.args, 0)
        patient_1 = Patient(self.args, 1)
        patient_2 = Patient(self.args, 2)

        # sys.exit() should be called here
        with self.assertRaises(SystemExit):
            patient_0.solve_local()
        with self.assertRaises(SystemExit):
            patient_1.solve_local()
        with self.assertRaises(SystemExit):
            patient_2.solve_local()

        # if lb = 0.5, then ub can be 0.2
        self.args.non_tumor_ub = 0.2
        self.args.tumor_lb = 0.5

        patient_0 = Patient(self.args, 0)
        patient_1 = Patient(self.args, 1)
        patient_2 = Patient(self.args, 2)

        patient_0.solve_local()
        patient_1.solve_local()
        patient_2.solve_local()

        self.assertEqual(1, len(patient_0.get_solution()))
        self.assertEqual(1, len(patient_1.get_solution()))
        self.assertEqual(1, len(patient_2.get_solution()))

        # if lb = 1 and ub = 0.4, then answer should be 3
        self.args.non_tumor_ub = 0.4
        self.args.tumor_lb = 1

        patient_0 = Patient(self.args, 0)
        patient_1 = Patient(self.args, 1)
        patient_2 = Patient(self.args, 2)

        patient_0.solve_local()
        patient_1.solve_local()
        patient_2.solve_local()

        self.assertEqual(3, len(patient_0.get_solution()))
        self.assertEqual(3, len(patient_1.get_solution()))
        self.assertEqual(3, len(patient_2.get_solution()))

        # Now solve ILP
        model, global_vars, patients = hitting_set.solve_ILP(self.args)

        # Answer should be 6 here
        self.assertEqual(get_obj_val(model), 6)

        # Raise ub to 0.5, and answer should be 3
        self.args.non_tumor_ub = 0.5
        model, global_vars, patients = hitting_set.solve_ILP(self.args)
        self.assertEqual(get_obj_val(model), 3)