def test_if_then_else(self) -> None: pb = ps.SchedulingProblem("IfThenElse1", horizon=29) t_1 = ps.FixedDurationTask("t1", 3) t_2 = ps.FixedDurationTask("t2", 3) ite_constraint = ps.if_then_else( t_1.start == 1, # condition [ps.TaskStartAt(t_2, 3)], # then [ps.TaskStartAt(t_2, 6)], # else ) self.assertIsInstance(ite_constraint, ps.BoolRef) # force task t_1 to start at 2 ps.TaskStartAt(t_1, 2) pb.add_constraint(ite_constraint) solution = ps.SchedulingSolver(pb).solve() self.assertTrue(solution) self.assertEqual(solution.tasks["t1"].start, 2) self.assertEqual(solution.tasks["t2"].start, 6)
def test_implies(self) -> None: pb = ps.SchedulingProblem("Implies1", horizon=37) t_1 = ps.FixedDurationTask("t1", 2) t_2 = ps.FixedDurationTask("t2", 4) t_3 = ps.FixedDurationTask("t3", 7) # force task t_1 to start at 1 ps.TaskStartAt(t_1, 1) implies_constraint = ps.implies( t_1.start == 1, [ps.TaskStartAt(t_2, 3), ps.TaskStartAt(t_3, 17)]) self.assertIsInstance(implies_constraint, ps.BoolRef) pb.add_constraint(implies_constraint) solution = ps.SchedulingSolver(pb).solve() self.assertTrue(solution) self.assertEqual(solution.tasks["t1"].start, 1) self.assertEqual(solution.tasks["t2"].start, 3) self.assertEqual(solution.tasks["t3"].start, 17)