Exemple #1
0
    def test_load_buffer_2(self) -> None:
        pb = ps.SchedulingProblem("LoadBuffer2")

        task_1 = ps.FixedDurationTask("task1", duration=3)
        task_2 = ps.FixedDurationTask("task2", duration=3)
        task_3 = ps.FixedDurationTask("task3", duration=3)
        buffer = ps.NonConcurrentBuffer("Buffer1", initial_state=10)

        pb.add_constraint(ps.TaskStartAt(task_1, 5))
        pb.add_constraint(ps.TaskStartAt(task_2, 10))
        pb.add_constraint(ps.TaskStartAt(task_3, 15))
        c1 = ps.TaskLoadBuffer(task_1, buffer, quantity=3)
        pb.add_constraint(c1)

        c2 = ps.TaskLoadBuffer(task_2, buffer, quantity=2)
        pb.add_constraint(c2)

        c3 = ps.TaskLoadBuffer(task_3, buffer, quantity=1)
        pb.add_constraint(c3)

        solver = ps.SchedulingSolver(pb)
        solution = solver.solve()
        self.assertTrue(solution)
        self.assertEqual(solution.buffers[buffer.name].state, [10, 13, 15, 16])
        self.assertEqual(solution.buffers[buffer.name].state_change_times,
                         [8, 13, 18])
Exemple #2
0
    def test_buffer_bounds_1(self) -> None:
        # n tasks take 1, n tasks feed one. Bounds 0 to 1
        pb = ps.SchedulingProblem("BufferBounds1")

        n = 3
        unloading_tasks = [
            ps.FixedDurationTask("LoadTask_%i" % i, duration=3)
            for i in range(n)
        ]
        loading_tasks = [
            ps.FixedDurationTask("UnloadTask_%i" % i, duration=3)
            for i in range(n)
        ]
        # create buffer
        buffer = ps.NonConcurrentBuffer("Buffer1",
                                        lower_bound=0,
                                        upper_bound=1)

        for t in unloading_tasks:
            ps.TaskUnloadBuffer(t, buffer, quantity=1)

        for t in loading_tasks:
            ps.TaskLoadBuffer(t, buffer, quantity=1)

        pb.add_objective_makespan()

        solver = ps.SchedulingSolver(
            pb, max_time=300,
            parallel=True)  # , debug=True)#, logics="QF_UFIDL")
        solution = solver.solve()
        self.assertTrue(solution)
        self.assertEqual(solution.horizon, 9)
Exemple #3
0
    def test_load_unload_feed_buffers_1(self) -> None:
        # one task that consumes and feed two different buffers
        pb = ps.SchedulingProblem("LoadUnloadBuffer1")

        task_1 = ps.FixedDurationTask("task1", duration=3)
        buffer_1 = ps.NonConcurrentBuffer("Buffer1", initial_state=10)
        buffer_2 = ps.NonConcurrentBuffer("Buffer2", initial_state=0)

        pb.add_constraint(ps.TaskStartAt(task_1, 5))
        c1 = ps.TaskUnloadBuffer(task_1, buffer_1, quantity=3)
        pb.add_constraint(c1)

        c2 = ps.TaskLoadBuffer(task_1, buffer_2, quantity=2)
        pb.add_constraint(c2)

        solver = ps.SchedulingSolver(pb)
        solution = solver.solve()
        self.assertTrue(solution)
        self.assertEqual(solution.buffers[buffer_1.name].state, [10, 7])
        self.assertEqual(solution.buffers[buffer_1.name].state_change_times,
                         [5])
        self.assertEqual(solution.buffers[buffer_2.name].state, [0, 2])
        self.assertEqual(solution.buffers[buffer_2.name].state_change_times,
                         [8])

        # plot buffers
        solution.render_gantt_matplotlib(show_plot=False)
Exemple #4
0
    def test_load_buffer_1(self) -> None:
        # only one buffer and one task
        pb = ps.SchedulingProblem("LoadBuffer1")

        task_1 = ps.FixedDurationTask("task1", duration=3)
        buffer = ps.NonConcurrentBuffer("Buffer1", initial_state=10)

        ps.TaskStartAt(task_1, 5)
        ps.TaskLoadBuffer(task_1, buffer, quantity=3)

        solver = ps.SchedulingSolver(pb)
        solution = solver.solve()
        self.assertTrue(solution)
        self.assertEqual(solution.buffers[buffer.name].state, [10, 13])
        self.assertEqual(solution.buffers[buffer.name].state_change_times, [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")