Skip to content

Commit

Permalink
constraint_solver: format python files using Black
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Jul 10, 2023
1 parent 555b86a commit 89bc4b5
Show file tree
Hide file tree
Showing 27 changed files with 1,159 additions and 1,604 deletions.
49 changes: 30 additions & 19 deletions ortools/constraint_solver/samples/cp_is_fun_cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
def main():
# Constraint programming engine
# [START solver]
solver = pywrapcp.Solver('CP is fun!')
solver = pywrapcp.Solver("CP is fun!")
# [END solver]

# [START variables]
Expand All @@ -37,16 +37,16 @@ def main():
# Decision variables.
digits = list(range(0, base))
digits_without_zero = list(range(1, base))
c = solver.IntVar(digits_without_zero, 'C')
p = solver.IntVar(digits, 'P')
i = solver.IntVar(digits_without_zero, 'I')
s = solver.IntVar(digits, 'S')
f = solver.IntVar(digits_without_zero, 'F')
u = solver.IntVar(digits, 'U')
n = solver.IntVar(digits, 'N')
t = solver.IntVar(digits_without_zero, 'T')
r = solver.IntVar(digits, 'R')
e = solver.IntVar(digits, 'E')
c = solver.IntVar(digits_without_zero, "C")
p = solver.IntVar(digits, "P")
i = solver.IntVar(digits_without_zero, "I")
s = solver.IntVar(digits, "S")
f = solver.IntVar(digits_without_zero, "F")
u = solver.IntVar(digits, "U")
n = solver.IntVar(digits, "N")
t = solver.IntVar(digits_without_zero, "T")
r = solver.IntVar(digits, "R")
e = solver.IntVar(digits, "E")

# We need to group variables in a list to use the constraint AllDifferent.
letters = [c, p, i, s, f, u, n, t, r, e]
Expand All @@ -60,8 +60,10 @@ def main():
solver.Add(solver.AllDifferent(letters))

# CP + IS + FUN = TRUE
solver.Add(p + s + n + base * (c + i + u) + base * base * f == e +
base * u + base * base * r + base * base * base * t)
solver.Add(
p + s + n + base * (c + i + u) + base * base * f
== e + base * u + base * base * r + base * base * base * t
)
# [END constraints]

# [START solve]
Expand All @@ -71,16 +73,25 @@ def main():
while solver.NextSolution():
print(letters)
# Is CP + IS + FUN = TRUE?
assert (base * c.Value() + p.Value() + base * i.Value() + s.Value() +
base * base * f.Value() + base * u.Value() +
n.Value() == base * base * base * t.Value() +
base * base * r.Value() + base * u.Value() + e.Value())
assert (
base * c.Value()
+ p.Value()
+ base * i.Value()
+ s.Value()
+ base * base * f.Value()
+ base * u.Value()
+ n.Value()
== base * base * base * t.Value()
+ base * base * r.Value()
+ base * u.Value()
+ e.Value()
)
solution_count += 1
solver.EndSearch()
print(f'Number of solutions found: {solution_count}')
print(f"Number of solutions found: {solution_count}")
# [END solve]


if __name__ == '__main__':
if __name__ == "__main__":
main()
# [END program]
Loading

0 comments on commit 89bc4b5

Please sign in to comment.