I have a problem which goes as follows. There are n
items. Each item i
takes m_i
time to manufacture and t_i
time to test. Obviously, an item must be manufactured before being tested. At any point of time, manufacturing queue and testing queue can have only one item in each of them. Now, the objective is to schedule the items to minimize the total production time.
I have written the code for this:
# data is a list of lists which will be in the form of [[id, m_i, t_i]]
data.sort(key=lambda x: x[1]) # Sort by manufacturing time
print(f"Items will be produced in the order: {', '.join(str(x[0]) for x in data)}")
idle = 0
# Idle time is the total time when the testing unit will have no work
schedule = 0
for drone in data:
if last and last <= drone[1]:
idle = drone[1] - last + 1
schedule += drone[2]
last = schedule + idle
print(f"The total production time is {schedule+idle}")
Now, for the following input,
1 / 5 / 7
2 / 1 / 2
3 / 8 / 2
4 / 5 / 4
5 / 3 / 7
6 / 4 / 4
I want to visualize it this way
As you can see above, an item is moved to testing queue as soon as it is manufactured and the next item is pulled into the manufacturing queue. If the manufacturing queue still has time left, the testing queue will be idle as there are no drones to be tested. Now, I want to visualize the above code this way.
How to achieve this?
source https://stackoverflow.com/questions/74145557/greedy-algorithm-visualization
Comments
Post a Comment