forked from tmdt-buw/schlably
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.py
67 lines (56 loc) · 3.3 KB
/
task.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""This file provides the Task class."""
# Standard package import
from typing import List
class Task:
"""
This class can be used to model tasks of a scheduling problem.
Multiple tasks can be used to model jobs of a scheduling problem.
:param job_index: index of the job to which multiple tasks belong
:param task_index: index of the task within the job (unique within job and gives order of tasks)
:param machines: list of machine indices applicable for the specific task (alternatives - pick one)
:param tools: list of tool indices applicable for the specific task (necessary - pick all)
:param deadline: time of deadline for the task
:param instance_hash: Individual hash to represent the instance
:param done: bool to determine status as done
:param runtime: time left for the task
:param started: time the task started at in the schedule
:param finished: time the task finished at in the schedule
:param selected_machine: selected machine index from the machines list for the specific schedule
:param _n_machines: number of all available machines in the scheduling problem instance
:param _n_tools: number of all available tools in the scheduling problem instance
:param _feasible_machine_from_instance_init: index of machine in the given instance generated by initial environment
run to generate deadline time
:param _feasible_order_index_from_instance_init: index of task in the given instance
generated by initial environment run to generate deadline time
"""
def __init__(self, job_index: int, task_index: int, machines: List[int] = None,
tools: List[int] = None, deadline: int = None, instance_hash: int = None, done: bool = None,
runtime: int = None, started: int = None, finished: int = None, selected_machine: int = None,
_n_machines: int = None, _n_tools: int = None, _feasible_machine_from_instance_init: int = None,
_feasible_order_index_from_instance_init: int = None):
# test for correct data type of required and throw type error otherwise
if not isinstance(job_index, int) or not isinstance(task_index, int):
raise TypeError("Job index and task index must be of type int.")
# public - static - required - don't touch after init
self.job_index = job_index
self.task_index = task_index
# public - static - optional - don't touch after init
self.machines = machines
self.tools = tools
self.deadline = deadline
self.instance_hash = instance_hash
# public - non-static - optional
self.done = done
self.runtime = runtime
self.started = started
self.finished = finished
self.selected_machine = selected_machine
# protected - optional
self._n_machines = _n_machines
self._n_tools = _n_tools
self._feasible_machine_from_instance_init = _feasible_machine_from_instance_init
self._feasible_order_index_from_instance_init = _feasible_order_index_from_instance_init
def __str__(self) -> str:
return f"Task - job index {self.job_index} - task index {self.task_index}"
def str_info(self) -> str:
return f"Job index {self.job_index}\nTask index {self.task_index}\nMachines {str(self.machines)}"