Skip to content

Commit

Permalink
polish sat doc
Browse files Browse the repository at this point in the history
  • Loading branch information
lperron committed Jul 24, 2018
1 parent 3689de9 commit f6d2b1d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
28 changes: 15 additions & 13 deletions ortools/sat/doc/scheduling.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,17 @@ public class CodeSamplesSat

## NoOverlap constraint

A no overlap constraint simply states that all intervals are disjoint.
It is build with a list of interval variables. Fixed intervals are useful to
exclude part of the timeline.
A NoOverlap constraint simply states that all intervals are disjoint. It is
built with a list of interval variables. Fixed intervals are useful for
excluding part of the timeline.

In the following examples. We want to schedule 3 tasks on 3 weeks excluding
weekends, mimizing the last day of work.
weekends, making the final day as early as possible.

### Python code

```python
"""Code sample to demonstrates how to build a no overlap constraint."""
"""Code sample to demonstrate how to build a NoOverlap constraint."""

from __future__ import absolute_import
from __future__ import division
Expand All @@ -278,22 +278,22 @@ def NoOverlapSample():

# Task 0, duration 2.
start_0 = model.NewIntVar(0, horizon, 'start_0')
duration_0 = 2 # Python cp/sat code accept integer variables or constants.
duration_0 = 2 # Python cp/sat code accepts integer variables or constants.
end_0 = model.NewIntVar(0, horizon, 'end_0')
task_0 = model.NewIntervalVar(start_0, duration_0, end_0, 'task_0')
# Task 1, duration 4.
start_1 = model.NewIntVar(0, horizon, 'start_1')
duration_1 = 4 # Python cp/sat code accept integer variables or constants.
duration_1 = 4 # Python cp/sat code accepts integer variables or constants.
end_1 = model.NewIntVar(0, horizon, 'end_1')
task_1 = model.NewIntervalVar(start_1, duration_1, end_1, 'task_1')

# Task 2, duration 3.
start_2 = model.NewIntVar(0, horizon, 'start_2')
duration_2 = 3 # Python cp/sat code accept integer variables or constants.
duration_2 = 3 # Python cp/sat code accepts integer variables or constants.
end_2 = model.NewIntVar(0, horizon, 'end_2')
task_2 = model.NewIntervalVar(start_2, duration_2, end_2, 'task_2')

# Week ends.
# Weekends.
weekend_0 = model.NewIntervalVar(5, 2, 7, 'weekend_0')
weekend_1 = model.NewIntervalVar(12, 2, 14, 'weekend_1')
weekend_2 = model.NewIntervalVar(19, 2, 21, 'weekend_2')
Expand All @@ -311,11 +311,13 @@ def NoOverlapSample():
status = solver.Solve(model)

if status == cp_model.OPTIMAL:
# Print out makespan and the starts of all tasks.
# Print out makespan and the start times for all tasks.
print('Optimal Schedule Length: %i' % solver.ObjectiveValue())
print('Task 0 starts at %i' % solver.Value(start_0))
print('Task 1 starts at %i' % solver.Value(start_1))
print('Task 2 starts at %i' % solver.Value(start_2))
else:
print('Solver exited with nonoptimal status: %i' % status)


NoOverlapSample()
Expand Down Expand Up @@ -436,7 +438,6 @@ void NoOverlapSample() {
}
}


} // namespace sat
} // namespace operations_research

Expand All @@ -458,6 +459,7 @@ public class CodeSamplesSat
static void NoOverlapSample()
{
CpModel model = new CpModel();
// Three weeks.
int horizon = 21;
// Task 0, duration 2.
Expand All @@ -481,7 +483,7 @@ public class CodeSamplesSat
IntervalVar task_2 =
model.NewIntervalVar(start_2, duration_2, end_2, "task_2");
// Week ends.
// Weekends.
IntervalVar weekend_0 = model.NewIntervalVar(5, 2, 7, "weekend_0");
IntervalVar weekend_1 = model.NewIntervalVar(12, 2, 14, "weekend_1");
IntervalVar weekend_2 = model.NewIntervalVar(19, 2, 21, "weekend_2");
Expand Down Expand Up @@ -523,7 +525,7 @@ at that time point is less than a given capacity.

## Alternative resources for one interval

## Ranking or tasks in a disjunctive resource
## Ranking tasks in a disjunctive resource

## Transitions in a disjunctive resource

Expand Down
1 change: 0 additions & 1 deletion ortools/sat/samples/no_overlap_sample.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ void NoOverlapSample() {
}
}


} // namespace sat
} // namespace operations_research

Expand Down
3 changes: 2 additions & 1 deletion ortools/sat/samples/no_overlap_sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class CodeSamplesSat
static void NoOverlapSample()
{
CpModel model = new CpModel();
// Three weeks.
int horizon = 21;

// Task 0, duration 2.
Expand All @@ -42,7 +43,7 @@ static void NoOverlapSample()
IntervalVar task_2 =
model.NewIntervalVar(start_2, duration_2, end_2, "task_2");

// Week ends.
// Weekends.
IntervalVar weekend_0 = model.NewIntervalVar(5, 2, 7, "weekend_0");
IntervalVar weekend_1 = model.NewIntervalVar(12, 2, 14, "weekend_1");
IntervalVar weekend_2 = model.NewIntervalVar(19, 2, 21, "weekend_2");
Expand Down
14 changes: 8 additions & 6 deletions ortools/sat/samples/no_overlap_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Code sample to demonstrates how to build a no overlap constraint."""
"""Code sample to demonstrate how to build a NoOverlap constraint."""

from __future__ import absolute_import
from __future__ import division
Expand All @@ -26,22 +26,22 @@ def NoOverlapSample():

# Task 0, duration 2.
start_0 = model.NewIntVar(0, horizon, 'start_0')
duration_0 = 2 # Python cp/sat code accept integer variables or constants.
duration_0 = 2 # Python cp/sat code accepts integer variables or constants.
end_0 = model.NewIntVar(0, horizon, 'end_0')
task_0 = model.NewIntervalVar(start_0, duration_0, end_0, 'task_0')
# Task 1, duration 4.
start_1 = model.NewIntVar(0, horizon, 'start_1')
duration_1 = 4 # Python cp/sat code accept integer variables or constants.
duration_1 = 4 # Python cp/sat code accepts integer variables or constants.
end_1 = model.NewIntVar(0, horizon, 'end_1')
task_1 = model.NewIntervalVar(start_1, duration_1, end_1, 'task_1')

# Task 2, duration 3.
start_2 = model.NewIntVar(0, horizon, 'start_2')
duration_2 = 3 # Python cp/sat code accept integer variables or constants.
duration_2 = 3 # Python cp/sat code accepts integer variables or constants.
end_2 = model.NewIntVar(0, horizon, 'end_2')
task_2 = model.NewIntervalVar(start_2, duration_2, end_2, 'task_2')

# Week ends.
# Weekends.
weekend_0 = model.NewIntervalVar(5, 2, 7, 'weekend_0')
weekend_1 = model.NewIntervalVar(12, 2, 14, 'weekend_1')
weekend_2 = model.NewIntervalVar(19, 2, 21, 'weekend_2')
Expand All @@ -59,11 +59,13 @@ def NoOverlapSample():
status = solver.Solve(model)

if status == cp_model.OPTIMAL:
# Print out makespan and the starts of all tasks.
# Print out makespan and the start times for all tasks.
print('Optimal Schedule Length: %i' % solver.ObjectiveValue())
print('Task 0 starts at %i' % solver.Value(start_0))
print('Task 1 starts at %i' % solver.Value(start_1))
print('Task 2 starts at %i' % solver.Value(start_2))
else:
print('Solver exited with nonoptimal status: %i' % status)


NoOverlapSample()

0 comments on commit f6d2b1d

Please sign in to comment.