-
Notifications
You must be signed in to change notification settings - Fork 1
Handling schedules and Gantt charts
scheptk
includes the class Schedule
, which can be used to save, load and print schedules that can be generated by the supporting scheduling layouts, or can be also generated autonomously by adding tasks to an existing schedule.
A typical schedule file is a text file containing the following tags:
[JOBS=5]
[MACHINES=4]
[SCHEDULE_DATA=1,0,10,0,10,10;1,10,20,2,40,20;2,80,120;1,30,10;3,30,10]
[JOB_ORDER=0,1,2,3,4]
The tag JOBS
indicates the number of jobs in the schedule, MACHINES
the number of machines, and SCHEDULE_DATA
contains the tasks for each job (in the order given by JOB_ORDER
) in the form of a tuple machine, starting_time, duration
.
A schedule stored in a file sched.sch
can be open using the constructor of the class Schedule
. If no argument is specified, an empty instance of the Schedule
class is created. The following code opens and print the schedule contained in the file openshop.sch
from scheptk.scheptk import Schedule
sched = Schedule('openshop.sch')
sched.print()
If the schedule has been generated autonomously, or is contained in an instance of the class Schedule
, it can be saved using save(filename)
.
from scheptk.scheptk import Schedule, Task
gantt = Schedule()
gantt.add_task(Task(0,0,10,20))
gantt.add_task(Task(0,1,0,10))
gantt.add_task(Task(1,1,10,30))
gantt.add_task(Task(1,2,40,60))
gantt.save('resulting_schedule.sched')
A schedule obtained from a given instance
using a solution sol
, it can be saved using the method write_schedule(sol, filename)
.
from scheptk.scheptk import OpenShop
instance = OpenShop('test_openshop.txt')
sol = [7,5,4,0,1,6,3,2,8]
instance.write_schedule(sol, 'openshop.sch')
Alternatively, the method create_schedule(solution)
can be used to get the corresponding schedule and then saving it using the save()
method of the class Schedule
as seen before.
from scheptk.scheptk import OpenShop
instance = OpenShop('test_openshop.txt')
sol = [7,5,4,0,1,6,3,2,8]
gantt = instance.create_schedule(sol)
gantt.save('openshop.sch')
Use the method print()
in the class schedule. A filename to store the image can be specified optionally:
from scheptk.scheptk import Schedule, Task
gantt = Schedule()
gantt.add_task(Task(0,0,10,20))
gantt.add_task(Task(0,1,0,10))
gantt.add_task(Task(1,1,10,30))
gantt.add_task(Task(1,2,40,60))
gantt.print()
If the schedule is to be generated from a solution
in a given layout, you can use the method print_schedule(solution)
of the corresponding layout
from scheptk.scheptk import FlowShop
instance = FlowShop("test_flowshop.txt")
sequence = [0,1,4,3,2]
instance.print_schedule(sequence, 'flowshop_sample.png')
The following image is printed:
Alternatively, use create_schedule()
to first obtain the schedule and later print it with the print()
method, i.e.
from scheptk.scheptk import FlowShop
instance = FlowShop("test_flowshop.txt")
sequence = [0,1,4,3,2]
gantt = instance.create_schedule(sequence)
gantt.print('flowshop_sample.png')
A schedule can be created by adding tasks to an instance of the class Schedule
. The tasks are added using the method add_task()
, which takes as argument an instance of the class Task
. The constructor of the class Task
requires four arguments, i.e. Task(job, machine, st, ct)
where job
and machine
indicates the job and the machine whereas st
and ct
indicate the starting and completion times of the task, respectively. The following code creates an empty schedule, then it populates it with several tasks and finally prints the resulting schedule:
from scheptk.scheptk import Schedule, Task
gantt = Schedule()
gantt.add_task(Task(0,0,10,20))
gantt.add_task(Task(0,1,0,10))
gantt.add_task(Task(1,1,10,30))
gantt.add_task(Task(1,2,40,60))
gantt.add_task(Task(2,2,80,200))
gantt.add_task(Task(3,1,30,40))
gantt.add_task(Task(4,3,30,40))
gantt.print('figure.png')
The schedule generated is the following: