minor reindent

This commit is contained in:
Laurent Perron
2019-07-10 09:38:45 -07:00
parent c57643a26a
commit 2ab87773a9
11 changed files with 23 additions and 30 deletions

View File

@@ -15,7 +15,6 @@
# [START import]
from __future__ import print_function
from ortools.algorithms import pywrapknapsack_solver
# [END import]

View File

@@ -15,7 +15,6 @@
# [START import]
from __future__ import print_function
from ortools.algorithms import pywrapknapsack_solver
# [END import]

View File

@@ -15,7 +15,6 @@
from __future__ import print_function
# [START import]
from ortools.linear_solver import pywraplp
# [END import]

View File

@@ -15,7 +15,6 @@
# [START import]
from __future__ import print_function
from ortools.linear_solver import pywraplp
# [END import]

View File

@@ -15,7 +15,6 @@
# [START import]
from __future__ import print_function
from ortools.linear_solver import pywraplp
# [END import]

View File

@@ -76,8 +76,8 @@ def CPIsFunSat():
model.AddAllDifferent(letters)
# CP + IS + FUN = TRUE
model.Add(c * base + p + i * base + s + f * base * base + u * base + n ==
t * base * base * base + r * base * base + u * base + e)
model.Add(c * base + p + i * base + s + f * base * base + u * base +
n == t * base * base * base + r * base * base + u * base + e)
# [END constraints]
# [START solve]

View File

@@ -34,7 +34,6 @@ class NursesPartialSolutionPrinter(cp_model.CpSolverSolutionCallback):
self._solution_count = 0
def on_solution_callback(self):
self._solution_count += 1
if self._solution_count in self._solutions:
print('Solution %i' % self._solution_count)
for d in range(self._num_days):
@@ -48,6 +47,7 @@ class NursesPartialSolutionPrinter(cp_model.CpSolverSolutionCallback):
if not is_working:
print(' Nurse {} does not work'.format(n))
print()
self._solution_count += 1
def solution_count(self):
return self._solution_count

View File

@@ -36,8 +36,8 @@ def RabbitsAndPheasantsSat():
status = solver.Solve(model)
if status == cp_model.FEASIBLE:
print('%i rabbits and %i pheasants' % (solver.Value(r),
solver.Value(p)))
print('%i rabbits and %i pheasants' %
(solver.Value(r), solver.Value(p)))
RabbitsAndPheasantsSat()

View File

@@ -52,17 +52,17 @@ def RankTasks(model, starts, presences, ranks):
if presences[i] != 1:
tmp_array.append(presences[i].Not())
# Makes sure that if i is not performed, all precedences are false.
model.AddImplication(presences[i].Not(), precedences[(i,
j)].Not())
model.AddImplication(presences[i].Not(), precedences[(j,
i)].Not())
model.AddImplication(presences[i].Not(),
precedences[(i, j)].Not())
model.AddImplication(presences[i].Not(),
precedences[(j, i)].Not())
if presences[j] != 1:
tmp_array.append(presences[j].Not())
# Makes sure that if j is not performed, all precedences are false.
model.AddImplication(presences[j].Not(), precedences[(i,
j)].Not())
model.AddImplication(presences[j].Not(), precedences[(j,
i)].Not())
model.AddImplication(presences[j].Not(),
precedences[(i, j)].Not())
model.AddImplication(presences[j].Not(),
precedences[(j, i)].Not())
# The following bool_or will enforce that for any two intervals:
# i precedes j or j precedes i or at least one interval is not
# performed.
@@ -102,8 +102,9 @@ def RankingSampleSat():
presence = True
else:
presence = model.NewBoolVar('presence_%i' % t)
interval = model.NewOptionalIntervalVar(
start, duration, end, presence, 'o_interval_%i' % t)
interval = model.NewOptionalIntervalVar(start, duration, end,
presence,
'o_interval_%i' % t)
starts.append(start)
ends.append(end)
intervals.append(interval)

View File

@@ -16,7 +16,6 @@
# [START import]
from __future__ import print_function
from ortools.sat.python import cp_model
# [END import]
@@ -55,8 +54,8 @@ def main():
for n in all_nurses:
for d in all_days:
for s in all_shifts:
shifts[(n, d, s)] = model.NewBoolVar('shift_n%id%is%i' % (n, d,
s))
shifts[(n, d,
s)] = model.NewBoolVar('shift_n%id%is%i' % (n, d, s))
# [END variables]
# Each shift is assigned to exactly one nurse in .

View File

@@ -59,17 +59,15 @@ def step_function_sample_sat():
# expr == 0 on [5, 6] U [8, 10]
b0 = model.NewBoolVar('b0')
model.AddLinearExpressionInDomain(x,
cp_model.Domain.FromIntervals(
[(5, 6), (8, 10)])).OnlyEnforceIf(b0)
model.AddLinearExpressionInDomain(
x, cp_model.Domain.FromIntervals([(5, 6), (8, 10)])).OnlyEnforceIf(b0)
model.Add(expr == 0).OnlyEnforceIf(b0)
# expr == 2 on [0, 1] U [3, 4] U [11, 20]
b2 = model.NewBoolVar('b2')
model.AddLinearExpressionInDomain(x,
cp_model.Domain.FromIntervals(
[(0, 1), (3, 4),
(11, 20)])).OnlyEnforceIf(b2)
model.AddLinearExpressionInDomain(
x, cp_model.Domain.FromIntervals([(0, 1), (3, 4),
(11, 20)])).OnlyEnforceIf(b2)
model.Add(expr == 2).OnlyEnforceIf(b2)
# expr == 3 when x == 7