[CP-SAT] deprecate SearchAllSolutions and SolveWithSolutionCallback

This commit is contained in:
Laurent Perron
2021-05-03 12:11:39 +02:00
parent bd43a1c004
commit efd16c78da
72 changed files with 241 additions and 99 deletions

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -73,7 +74,10 @@ def EnumerateAllKnapsacksWithRepetition(item_sizes, total_size_min,
solver = cp_model.CpSolver()
solution_collector = AllSolutionCollector(variables)
solver.SearchForAllSolutions(model, solution_collector)
# Enumerate all solutions.
solver.parameters.enumerate_all_solutions = True
# Solve
solver.Solve(model, solution_collector)
return solution_collector.combinations()

View File

@@ -163,7 +163,7 @@ def main():
solver = cp_model.CpSolver()
solution_printer = SolutionPrinter(values, colors, all_groups, all_items,
item_in_group)
status = solver.SolveWithSolutionCallback(model, solution_printer)
status = solver.Solve(model, solution_printer)
if status == cp_model.OPTIMAL:
print('Optimal epsilon: %i' % solver.ObjectiveValue())

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -172,7 +173,7 @@ def flexible_jobshop():
# Solve model.
solver = cp_model.CpSolver()
solution_printer = SolutionPrinter()
status = solver.SolveWithSolutionCallback(model, solution_printer)
status = solver.Solve(model, solution_printer)
# Print final solution.
for job_id in all_jobs:

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View File

@@ -95,8 +95,7 @@ def jobshop_with_maintenance():
# Solve model.
solver = cp_model.CpSolver()
solution_printer = SolutionPrinter()
status = solver.SolveWithSolutionCallback(model, solution_printer)
#status = solver.Solve(model)
status = solver.Solve(model, solution_printer)
# Output solution.
if status == cp_model.OPTIMAL:

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View File

@@ -78,7 +78,8 @@ def main(board_size):
### Solve model.
solver = cp_model.CpSolver()
solution_printer = NQueenSolutionPrinter(queens)
status = solver.SearchForAllSolutions(model, solution_printer)
solver.parameters.enumerate_all_solutions = True
status = solver.Solve(model, solution_printer)
print()
print('Statistics')

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -378,7 +379,7 @@ def solve_shift_scheduling(params, output_proto):
if params:
text_format.Parse(params, solver.parameters)
solution_printer = cp_model.ObjectiveSolutionPrinter()
status = solver.SolveWithSolutionCallback(model, solution_printer)
status = solver.Solve(model, solution_printer)
# Print solution.
if status == cp_model.OPTIMAL or status == cp_model.FEASIBLE:

View File

@@ -263,7 +263,7 @@ def main(args):
if parameters:
text_format.Merge(parameters, solver.parameters)
solution_printer = SolutionPrinter()
solver.SolveWithSolutionCallback(model, solution_printer)
solver.Solve(model, solution_printer)
print(solver.ResponseStats())
for job_id in all_jobs:
print('job %i starts at %i end ends at %i' %

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -423,7 +424,7 @@ def steel_mill_slab(problem, break_symmetries):
solver = cp_model.CpSolver()
solver.parameters.num_search_workers = 8
objective_printer = cp_model.ObjectiveSolutionPrinter()
status = solver.SolveWithSolutionCallback(model, objective_printer)
status = solver.Solve(model, objective_printer)
### Output the solution.
if status in (cp_model.OPTIMAL, cp_model.FEASIBLE):
@@ -593,7 +594,7 @@ def steel_mill_slab_with_valid_slabs(problem, break_symmetries):
solver.num_search_workers = 8
solution_printer = SteelMillSlabSolutionPrinter(orders, assign, loads,
losses)
status = solver.SolveWithSolutionCallback(model, solution_printer)
status = solver.Solve(model, solution_printer)
### Output the solution.
if status == cp_model.OPTIMAL:
@@ -661,7 +662,7 @@ def steel_mill_slab_with_column_generation(problem):
solver.parameters.num_search_workers = 8
solver.parameters.log_search_progress = True
solution_printer = cp_model.ObjectiveSolutionPrinter()
status = solver.SolveWithSolutionCallback(model, solution_printer)
status = solver.Solve(model, solution_printer)
### Output the solution.
if status in (cp_model.OPTIMAL, cp_model.FEASIBLE):

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View File

@@ -98,7 +98,7 @@ def tasks_and_workers_assignment_sat():
solver = cp_model.CpSolver()
solver.parameters.max_time_in_seconds = 60 * 60 * 2
objective_printer = ObjectivePrinter()
status = solver.SolveWithSolutionCallback(model, objective_printer)
status = solver.Solve(model, objective_printer)
print(solver.ResponseStats())
if status == cp_model.OPTIMAL:

View File

@@ -123,10 +123,11 @@ def main():
# Solve model.
solver = cp_model.CpSolver()
solver.parameters.enumerate_all_solutions = True
solution_printer = SolutionPrinter(num_vendors, num_hours,
possible_schedules, selected_schedules,
hours_stat, min_vendors)
status = solver.SearchForAllSolutions(model, solution_printer)
status = solver.Solve(model, solution_printer)
print('Status = %s' % solver.StatusName(status))
print('Statistics')

View File

@@ -202,7 +202,7 @@ def solve_with_discrete_model():
### Solve model.
solver = cp_model.CpSolver()
solution_printer = WeddingChartPrinter(seats, names, num_tables, num_guests)
solver.SolveWithSolutionCallback(model, solution_printer)
solver.Solve(model, solution_printer)
print("Statistics")
print(" - conflicts : %i" % solver.NumConflicts())

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright 2010-2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.