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_task_dependency_1(self) -> None: """task_2 is scheduled, because task_1 is.""" pb = ps.SchedulingProblem("OptionalDependency1") task_1 = ps.FixedDurationTask("task1", duration=9) # mandatory task_2 = ps.FixedDurationTask("task2", duration=4, optional=True) # optional ps.OptionalTasksDependency(task_1, task_2) 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)