Created
April 15, 2021 12:30
-
-
Save samirsaci/3da459fdc3ddd0b61fd98476cc7d9c2a to your computer and use it in GitHub Desktop.
Init Variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Count Machines | |
| machines_count = 1 + max(task[0] for job in jobs_data for task in job) | |
| print("{:,} machines".format(machines_count)) | |
| all_machines = range(machines_count) | |
| # Computes horizon dynamically as the sum of all durations. | |
| horizon = sum(task[1] for job in jobs_data for task in job) | |
| print("Total Time using Naive Solution: {} min".format(horizon)) | |
| # Named tuple to store information about created variables | |
| task_type = collections.namedtuple('task_type', 'start end interval') | |
| # Named tuple to manipulate solution information. | |
| assigned_task_type = collections.namedtuple('assigned_task_type', | |
| 'start job index duration') | |
| # Creates job intervals and add to the corresponding machine lists. | |
| all_tasks = {} | |
| machine_to_intervals = collections.defaultdict(list) | |
| # Create Machine Sequences | |
| for job_id, job in enumerate(jobs_data): | |
| for task_id, task in enumerate(job): | |
| machine = task[0] | |
| duration = task[1] | |
| suffix = '_%i_%i' % (job_id, task_id) | |
| start_var = model.NewIntVar(0, horizon, 'start' + suffix) | |
| end_var = model.NewIntVar(0, horizon, 'end' + suffix) | |
| interval_var = model.NewIntervalVar(start_var, duration, end_var, | |
| 'interval' + suffix) | |
| all_tasks[job_id, task_id] = task_type(start=start_var, | |
| end=end_var, | |
| interval=interval_var) | |
| machine_to_intervals[machine].append(interval_var) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment