# Job Scheduling Algorithm 2

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

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:
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):

profit = 0
for job_row in range(len(jobs)):
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()
$$$$


• 'algorithm' is not correct at all and will fail at runtime. please make sure your code works before posting it. start and end are never read. time is never defined. 'row' is never defined--it is typo-d as 'job_row' the second time. use 'for job in robs', not 'for job_row in range(len(jobs)) together with 'jobs[job_row]'. I would generally recommend a linter, which should catch all these errors.
• I personally think it's fine to put the contents of 'main' directly in the if __name__ == "__main__" block, but I've seen it both ways.
• For the output_ methods, consider returning a string, and printing the string, as two steps. " ".join()` may help.