def test_force_schedule_optional_tasks_3(self) -> None: """Check an error is raised if ever one of the task is not optional.""" ps.SchedulingProblem("ForceScheduleOptionalTasks3", horizon=14) task_1 = ps.VariableDurationTask("task1") # this one is not optional task_2 = ps.FixedDurationTask("task2", duration=7, optional=True) with self.assertRaises(TypeError): ps.ForceScheduleNOptionalTasks([task_1, task_2], 2)
def test_get_scheduled_tasks(self) -> None: # task_1 cannot be scheduled, only tasks 2 and 3 can be pb = ps.SchedulingProblem("GetScheduledTasks", horizon=14) task_1 = ps.FixedDurationTask("task1", duration=15, optional=True) task_2 = ps.FixedDurationTask("task2", duration=7, optional=True) task_3 = ps.FixedDurationTask("task3", duration=2, optional=True) ps.ForceScheduleNOptionalTasks([task_1, task_2, task_3], 2) solver = ps.SchedulingSolver(pb) solution = solver.solve() self.assertTrue(solution) scheduled_tasks_dictionary = solution.get_scheduled_tasks() self.assertEqual(len(scheduled_tasks_dictionary), 2) self.assertTrue("task2" in scheduled_tasks_dictionary) self.assertTrue("task3" in scheduled_tasks_dictionary)
def test_force_schedule_optional_tasks_2(self) -> None: """Just change the number of tasks to be scheduled.""" pb = ps.SchedulingProblem("ForceScheduleOptionalTasks2", horizon=14) task_1 = ps.VariableDurationTask("task1", optional=True) task_2 = ps.FixedDurationTask("task2", duration=7, optional=True) task_3 = ps.FixedDurationTask("task3", duration=2, optional=True) ps.ForceScheduleNOptionalTasks([task_1, task_2, task_3], 2) solver = ps.SchedulingSolver(pb) solution = solver.solve() self.assertTrue(solution) results = [ solution.tasks[task_1.name].scheduled, solution.tasks[task_2.name].scheduled, solution.tasks[task_3.name].scheduled, ] self.assertEqual(results.count(True), 2)
def test_force_schedule_optional_tasks(self) -> None: """task_3 is not scheduled, because task_2 should not.""" pb = ps.SchedulingProblem("ForceScheduleOptionalTasks", horizon=9) task_1 = ps.VariableDurationTask("task1", optional=True) task_2 = ps.FixedDurationTask("task2", duration=4, optional=True) task_3 = ps.FixedDurationTask("task3", duration=1, optional=True) ps.ForceScheduleNOptionalTasks([task_1, task_2, task_3], 1) solver = ps.SchedulingSolver(pb) solution = solver.solve() self.assertTrue(solution) results = [ solution.tasks[task_1.name].scheduled, solution.tasks[task_2.name].scheduled, solution.tasks[task_3.name].scheduled, ] self.assertEqual(results.count(True), 1)