Changed Program based on suggestions. New Code: Job Scheduling Algorithm 2
I have created an algorithm for job scheduling.
The algorithm goes through sub-lists in order with two nested for loops. Inside the nested for loops, the algorithm counts how many tasks for each job are completed. If this is equal to the number of tasks, then the profit for that job is added to the total profit.
Item start to Item end is an item using that machine from start to end. Machine start to Machine end is when the machines can process the items. A single task is a single machine doing items. The number required for a job is tasks to be completed while done tasks are tasks that will finish in the schedule. If those two counts are equal then the job is done, and profit is added to the profit var.
Here is the code
def output_profit(profit:int)->None: print("profit: " + str(profit), end = "\n") def output_subset(subset:[str])->None: for item in subset: print(str(item), end = " ") def main(): items = ["a", "b"] items_starts = [0, 3] items_ends = [2, 4] #total number of tasks that are needed for job i tasks_to_complete = [1,1] #tasks that are done for job i done_tasks = [0, 0] machine_starts = [0, 0] machine_ends = [1, 7] profits_for_job = [10, 12] profit = 0 for row in range(0, len(items)): for col in range(0, len(items) + 1): subset = items[row:col] for job_index in range(0, len(subset)): if items_starts[job_index] >= machine_starts[job_index]: if items_ends[job_index] <= machine_ends[job_index]: done_tasks[job_index] = done_tasks[job_index] + 1 profit = 0 for job_index in range(0, len(subset)): if tasks_to_complete[job_index] == done_tasks[job_index]: profit = profit + profits_for_job[job_index] output_profit(profit) output_subset(subset) if __name__ == "__main__": main()
I am looking for ways to improve the code readability and improve the algorithm's efficiency.