Skip to content

Instantly share code, notes, and snippets.

@samirsaci
Created April 15, 2021 12:55
Show Gist options
  • Select an option

  • Save samirsaci/36118af42e4a0cfb0ce334076d24acee to your computer and use it in GitHub Desktop.

Select an option

Save samirsaci/36118af42e4a0cfb0ce334076d24acee to your computer and use it in GitHub Desktop.
Add constraints
# 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