def test_tasks_start_sync(self) -> None: pb = ps.SchedulingProblem("TasksStartSync") t_1 = ps.FixedDurationTask("t1", duration=2) t_2 = ps.FixedDurationTask("t2", duration=3) ps.TaskStartAt(t_1, 7) ps.TasksStartSynced(t_1, t_2) solver = ps.SchedulingSolver(pb) solution = solver.solve() self.assertTrue(solution) self.assertEqual(solution.tasks[t_1.name].start, solution.tasks[t_2.name].start)
def test_optional_tasks_start_sync_2(self) -> None: """Task 2 cannot be scheduled.""" pb = ps.SchedulingProblem("OptionalTasksStartSynced2", horizon=5) task_1 = ps.FixedDurationTask("task1", duration=3) # mandatory task_2 = ps.FixedDurationTask("task2", duration=4, optional=True) # optional pb.add_constraint(ps.TaskStartAt(task_1, 2)) pb.add_constraint(ps.TasksStartSynced(task_1, task_2)) 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.assertEqual(solution.tasks[task_1.name].start, 2) self.assertEqual(solution.tasks[task_1.name].end, 5)
def test_optional_tasks_start_sync_1(self) -> None: """Tasks can be scheduled.""" pb = ps.SchedulingProblem("OptionalTasksStartSynced1", horizon=6) task_1 = ps.FixedDurationTask("task1", duration=3) # mandatory task_2 = ps.FixedDurationTask("task2", duration=4, optional=True) # optional pb.add_constraint(ps.TaskStartAt(task_1, 2)) pb.add_constraint(ps.TasksStartSynced(task_1, task_2)) # Force schedule, otherwise by default it is not scheduled pb.add_constraint(task_2.scheduled == True) 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) self.assertEqual(solution.tasks[task_1.name].start, 2) self.assertEqual(solution.tasks[task_1.name].end, 5) self.assertEqual(solution.tasks[task_2.name].start, 2) self.assertEqual(solution.tasks[task_2.name].end, 6)