Reputation: 27
I am currently studying this Job Shop Problem from Google OR-Tools and I need your help to understand this one,
jobs_data = [ # task = (machine_id, processing_time).
[(0, 3), (1, 2), (2, 2)], # Job0
[(0, 2), (2, 1), (1, 4)], # Job1
[(1, 4), (2, 3)] # Job2
]
machines_count = 1 + max(task[0] for job in jobs_data for task in job)
all_machines = range(machines_count)
I want to understand this line:
machines_count = 1 + max(task[0] for job in jobs_data for task in job)
Thanks.
Upvotes: 0
Views: 675
Reputation: 10789
The line you are referring to can be translated into the following (hopefully more understandable) code:
count = []
for job in jobs_data: #job is a list of tuples
for task in job: #task is one tuple
count.append(task[0]) #task[0] is the first item of the tuple
machines_count = 1 + max(count)
Upvotes: 0
Reputation: 1344
task[0] for job in jobs_data for task in job
can be transferred into the following
new_list = []
for job in jobs_data: # for each Job
for task in job: # for each task
print(task[0])
new_list.append(task[0]) # get the id
max()
just select the maximum.
Upvotes: 3