Created
April 15, 2021 12:55
-
-
Save samirsaci/36118af42e4a0cfb0ce334076d24acee to your computer and use it in GitHub Desktop.
Add constraints
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
| # Add Constraints: No Overlapping of tasks for the same machine | |
| # Create and add disjunctive constraints. | |
| for machine in all_machines: | |
| model.AddNoOverlap(machine_to_intervals[machine]) | |
| # Precedences inside a job: End Time of Step n is before starting time of Step n+1 | |
| for job_id, job in enumerate(jobs_data): | |
| for task_id in range(len(job) - 1): | |
| model.Add(all_tasks[job_id, task_id + | |
| 1].start >= all_tasks[job_id, task_id].end) | |
| # Objective: Minimize Makespan | |
| obj_var = model.NewIntVar(0, horizon, 'makespan') | |
| model.AddMaxEquality(obj_var, [ | |
| all_tasks[job_id, len(job) - 1].end | |
| for job_id, job in enumerate(jobs_data) | |
| ]) | |
| model.Minimize(obj_var) | |
| # Declare Solver Model | |
| solver = cp_model.CpSolver() | |
| status = solver.Solve(model) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment