def test_optional_task_dependency_3(self) -> None:
        """Type checking."""
        pb = ps.SchedulingProblem("OptionalDependency3", horizon=9)
        task_1 = ps.FixedDurationTask("task1", duration=5)  # mandatory
        task_2 = ps.FixedDurationTask("task2", duration=4)  # mandatory
        task_3 = ps.FixedDurationTask("task3", duration=1)  # mandatory

        with self.assertRaises(TypeError):
            ps.OptionalTaskConditionSchedule(task_1, pb.horizon > 10)

        with self.assertRaises(TypeError):
            ps.OptionalTasksDependency(task_2, task_3)
    def test_optional_condition_2(self) -> None:
        """A task scheduled only if the horizon is > 10."""
        pb = ps.SchedulingProblem("OptionalCondition2", horizon=9)
        task_1 = ps.FixedDurationTask("task1", duration=9)  # mandatory
        task_2 = ps.FixedDurationTask("task2", duration=4,
                                      optional=True)  # optional

        ps.OptionalTaskConditionSchedule(task_2, pb.horizon > 10)

        solver = ps.SchedulingSolver(pb, random_values=True)
        solution = solver.solve()
        self.assertTrue(solution)
        self.assertTrue(solution.tasks[task_1.name].scheduled)
        self.assertFalse(solution.tasks[task_2.name].scheduled)
    def test_optional_condition_1(self) -> None:
        """A task scheduled only if the horizon is > 10."""
        pb = ps.SchedulingProblem("OptionalCondition1")
        task_1 = ps.FixedDurationTask("task1", duration=13)  # mandatory
        task_2 = ps.FixedDurationTask("task2", duration=4,
                                      optional=True)  # optional

        cond = ps.OptionalTaskConditionSchedule(task_2, pb.horizon > 10)
        pb.add_constraint(cond)

        solver = ps.SchedulingSolver(pb)
        solution = solver.solve()
        self.assertTrue(solution)
        self.assertTrue(solution.tasks[task_1.name].scheduled)
        self.assertTrue(solution.tasks[task_2.name].scheduled)
    def test_optional_task_dependency_2(self) -> None:
        """task_3 is not scheduled, because task_2 should not."""
        pb = ps.SchedulingProblem("OptionalDependency2", horizon=9)
        task_1 = ps.FixedDurationTask("task1", duration=5)  # mandatory
        task_2 = ps.FixedDurationTask("task2", duration=4,
                                      optional=True)  # optional
        task_3 = ps.FixedDurationTask("task3", duration=1,
                                      optional=True)  # optional

        ps.OptionalTaskConditionSchedule(task_2, pb.horizon > 10)
        ps.OptionalTasksDependency(task_2, task_3)

        solver = ps.SchedulingSolver(pb)
        solution = solver.solve()
        self.assertTrue(solution)
        self.assertTrue(solution.tasks[task_1.name].scheduled)
        self.assertFalse(solution.tasks[task_2.name].scheduled)
        self.assertFalse(solution.tasks[task_3.name].scheduled)