def test_multiple_workers_work_load_2(self) -> None:
        ### the same as above but changing 'min' to 'exact', there's no solution
        pb = ps.SchedulingProblem("MultipleWorkersWorkLoad2", horizon=12)

        worker_1 = ps.Worker("Worker1")
        worker_2 = ps.Worker("Worker2")

        task1 = ps.FixedDurationTask("Task1", duration=10)
        task1.add_required_resources([worker_1, worker_2])

        ps.WorkLoad(worker_1, {(0, 4): 2})
        ps.WorkLoad(worker_2, {(2, 6): 2}, kind="exact")

        solver = ps.SchedulingSolver(pb)
        solution = solver.solve()
        self.assertFalse(solution)
    def test_resource_work_load_exception(self) -> None:
        ps.SchedulingProblem("ResourceWorkLoadException", horizon=12)

        worker_1 = ps.Worker("Worker1")

        with self.assertRaises(ValueError):
            ps.WorkLoad(worker_1, {(0, 6): 2}, kind="foo")
    def test_multiple_workers_work_load_1(self) -> None:
        pb = ps.SchedulingProblem("MultipleWorkersWorkLoad1", horizon=12)

        worker_1 = ps.Worker("Worker1")
        worker_2 = ps.Worker("Worker2")

        task1 = ps.FixedDurationTask("Task1", duration=10)
        task1.add_required_resources([worker_1, worker_2])

        ps.WorkLoad(worker_1, {(0, 4): 2})
        ps.WorkLoad(worker_2, {(2, 6): 2}, kind="min")

        solver = ps.SchedulingSolver(pb)
        solution = solver.solve()
        self.assertTrue(solution)
        self.assertTrue(solution.tasks[task1.name].start == 2)
    def test_resource_work_load_eq(self) -> None:
        pb = ps.SchedulingProblem("ResourceWorkLoadEq", horizon=12)
        task_1 = ps.FixedDurationTask("task1", duration=7)

        worker_1 = ps.Worker("Worker1")
        task_1.add_required_resource(worker_1)

        ps.WorkLoad(worker_1, {(0, 6): 3}, kind="exact")
        solver = ps.SchedulingSolver(pb)
        solution = solver.solve()
        self.assertTrue(solution)
        # the only possible solution is that the task is scheduled form 3 to 9
        self.assertEqual(solution.tasks[task_1.name].start, 3)
        self.assertEqual(solution.tasks[task_1.name].end, 10)
    def test_resource_work_load_basic(self) -> None:
        pb = ps.SchedulingProblem("ResourceWorkLoadBasic", horizon=12)
        task_1 = ps.FixedDurationTask("task1", duration=8)

        worker_1 = ps.Worker("Worker1")
        task_1.add_required_resource(worker_1)

        ps.WorkLoad(worker_1, {(0, 6): 2})

        solver = ps.SchedulingSolver(pb)
        solution = solver.solve()
        self.assertTrue(solution)
        # the only possible solution is that the task is scheduled form 4 to 12
        self.assertEqual(solution.tasks[task_1.name].start, 4)
        self.assertEqual(solution.tasks[task_1.name].end, 12)
    def test_resource_work_load_min(self) -> None:
        pb = ps.SchedulingProblem("ResourceWorkLoadMin", horizon=20)
        task_1 = ps.FixedDurationTask("task1", duration=7)

        worker_1 = ps.Worker("Worker1")
        task_1.add_required_resource(worker_1)

        ps.WorkLoad(worker_1, {(6, 8): 2}, kind="min")

        solver = ps.SchedulingSolver(pb)
        solution = solver.solve()

        self.assertTrue(solution)
        # the only possible solution is that the task is scheduled form 3 to 9
        self.assertTrue(solution.tasks[task_1.name].start <= 6)
        self.assertTrue(solution.tasks[task_1.name].end >= 8)
    def test_json_export_1(self):
        pb = ps.SchedulingProblem("JSONExport1", horizon=10)
        # tasks
        task_1 = ps.FixedDurationTask("task1", duration=3)
        task_2 = ps.VariableDurationTask("task2")
        task_3 = ps.ZeroDurationTask("task3")

        # buffers
        buffer_1 = ps.NonConcurrentBuffer("Buffer1", initial_state=10)
        buffer_2 = ps.NonConcurrentBuffer("Buffer2", initial_state=0)

        # resources
        worker_1 = ps.Worker("Worker1")
        worker_2 = ps.Worker("Worker2")
        worker_3 = ps.Worker("Worker3")

        sw_1 = ps.SelectWorkers([worker_1, worker_2, worker_3])
        sw_2 = ps.SelectWorkers([worker_1, worker_2, worker_3])
        sw_3 = ps.SelectWorkers([worker_1, worker_2, worker_3])

        ps.CumulativeWorker("CumulMachine1", size=3)
        ps.CumulativeWorker("CumulMachine2", size=7)

        # assign resources to tasks
        task_1.add_required_resources([worker_1, worker_2])
        task_2.add_required_resource(sw_1)
        task_3.add_required_resource(sw_2)

        # task constraints
        ps.TaskPrecedence(task_1, task_2)
        ps.TaskStartAt(task_1, 5)
        ps.TaskUnloadBuffer(task_1, buffer_1, quantity=3)
        ps.TaskLoadBuffer(task_1, buffer_2, quantity=2)

        # resource constraints
        ps.SameWorkers(sw_1, sw_2)
        ps.DistinctWorkers(sw_2, sw_3)
        ps.WorkLoad(worker_1, {(0, 6): 3, (19, 24): 4}, kind="exact")
        ps.ResourceUnavailable(worker_1, [(1, 3), (6, 8)])
        ps.ResourceTasksDistance(worker_1,
                                 distance=4,
                                 mode="exact",
                                 list_of_time_intervals=[[10, 18]])

        # export to json
        solver = ps.SchedulingSolver(pb)
        ps.export_json_to_file(pb, solver, "test_export_1.json")
    def test_selectworker_work_load_1(self) -> None:
        pb = ps.SchedulingProblem("SelectWorkerWorkLoad1", horizon=12)

        worker_1 = ps.Worker("Worker1")
        worker_2 = ps.Worker("Worker2")

        task1 = ps.FixedDurationTask("Task1", duration=10)

        task1.add_required_resource(ps.SelectWorkers([worker_1, worker_2], 1, "min"))
        # the workload on worker_1 forces 0 between 4 and 8
        # then the worker_1 can not be assigned
        ps.WorkLoad(worker_1, {(4, 8): 0})

        solver = ps.SchedulingSolver(pb)
        solution = solver.solve()
        print(solution)
        self.assertTrue(solution)
        self.assertTrue(
            solution.tasks[task1.name].assigned_resources == [worker_2.name]
        )
Exemple #9
0
    def test_resource_work_load_3(self) -> None:
        # same problem, but we force two tasks to be scheduled at start and end
        # of the planning
        pb = ps.SchedulingProblem("ResourceWorkLoadUnavailability", horizon=12)
        task_1 = ps.FixedDurationTask("task1", duration=4)
        task_2 = ps.FixedDurationTask("task2", duration=4)
        worker_1 = ps.Worker("Worker1")
        task_1.add_required_resource(worker_1)
        task_2.add_required_resource(worker_1)

        c1 = ps.WorkLoad(worker_1, {(4, 8): 0})
        pb.add_constraint(c1)

        solver = ps.SchedulingSolver(pb)
        solution = solver.solve()
        self.assertTrue(solution)
        # there should be one task from 0 to 4 and one task from 8 to 12.
        self.assertTrue(solution.tasks[task_1.name].start == 0
                        or solution.tasks[task_2.name].start == 0)
        self.assertTrue(solution.tasks[task_1.name].start == 8
                        or solution.tasks[task_2.name].start == 8)
        # Create tasks and assign resources
        tasks = []
        for j in range(NB_TASKS_PER_WORKER):
            tasks.append(
                ps.FixedDurationTask(f"{name}__{j:02d}",
                                     duration=1,
                                     optional=True))
            tasks[-1].add_required_resources([general_worker, worker])

        workers.append({"name": name, "worker": worker, "tasks": tasks})

    workload = {period: MAX_TASKS_PER_PERIOD for period in PERIODS}
    workload[(0, horizon)] = MAX_TASKS_IN_PROBLEM

    for worker in workers:
        ps.WorkLoad(worker["worker"], workload, kind="max")

    # Add constraints, define objective and solve problem
    pb.add_objective_resource_utilization(general_worker)
    solver = ps.SchedulingSolver(pb)
    solution = solver.solve()
    if not solution:
        break

    computation_times.append(time.perf_counter() - init_time)
    plot_abs.append(i)

    solver.print_statistics()

plt.title("Benchmark_mixed_constraints %s:%s" % (bench_date, bench_id))
plt.plot(plot_abs, computation_times, "D-", label="Computing time")