I am looking for feedback to improve code readability and improve the algorithm's efficiency. I have already posted a question on code review about this. The feedback was helpful, and I did rethink the data structures.
Link to the previous question: Job Scheduling Algorithm
Info about classes:
Item is the item the machines work on. Machine is a single machine that can be used from start time to end time. A single task is a single item on a machine. Job is a complete job, and can have more than one task.
The algorithm schedules the tasks, re-orders them for the specific machine, and adds to total profit is a job is finished within the schedule.
class ItemModel:
def __init__(self, name:str, starts:int, ends:int)->None:
self.name = name
self.start = start
self.ends = ends
class JobModel:
def __init__(self, tasks_needed:int, tasks_done:int, profit:int)->None:
self.tasks_needed = tasks_needed
self.tasks_done = tasks_done
self.profit = profit
class MachineModel:
def __init__(self, starts:int, ends:int)->None:
self.starts = starts
self.ends = ends
class View:
def output_profit(profit:int)->None:
print("profit: " + str(profit), end = "\n")
def output_sublist(sublist:[int])->None:
for item in sublist:
print(str(item), end = " ")
print('\n')
def algorithm(items:[ItemModel], jobs:[JobModel], machines:[MachineModel])->(int, [ItemModel]):
total_profit = 0
for start in range(len(items)):
for end in range(len(items)):
for job_row in range(len(jobs)):
if (time >= jobs[job_row].start_time) and (time <= jobs[job_row].end_time):
jobs[job_row].task_done += 1
profit = 0
for job_row in range(len(jobs)):
if jobs[row].tasks_needed == jobs[row].tasks_done:
profit += jobs[row].profit
yield (profit, sublist)
def main():
items = [ItemModel("a", 0, 2), ItemModel("b", 3, 4)]
jobs = [JobModel(0, 0, 12), JobModel(0, 0, 10)]
machines = [MachineModel(0, 1), MachineModel(0, 7)]
View view = View()
for pair in algorithm(items, jobs, machines):
view.output_profit(pair[0])
view.output_sublist(pair[1])
if __name__ == "__main__":
main()
```