diff --git a/examples/python/BUILD.bazel b/examples/python/BUILD.bazel index 7fbcfea4c2f..2aeac3e9c26 100644 --- a/examples/python/BUILD.bazel +++ b/examples/python/BUILD.bazel @@ -13,9 +13,9 @@ # BUILD file to run python examples. -load(":code_samples.bzl", "code_sample_compile_py", "code_sample_py") +load(":code_samples.bzl", "code_sample_compile_py", "code_sample_py", "code_sample_test_arg_py") -code_sample_py("arc_flow_cutting_stock_sat") +code_sample_compile_py("arc_flow_cutting_stock_sat") # Crash on mac, investigate. code_sample_py("assignment_with_constraints_sat") @@ -46,6 +46,12 @@ code_sample_py("jobshop_with_maintenance_sat") code_sample_py("knapsack_2d_sat") code_sample_compile_py("line_balancing_sat") # no input +code_sample_test_arg_py( + name="line_balancing_sat", + suffix="salbp_20_1", + data=["//examples/python/testdata:salbp_20_1.alb"], + args=["--input $(rootpath //examples/python/testdata:salbp_20_1.alb)"], +) code_sample_py("maze_escape_sat") diff --git a/examples/python/CMakeLists.txt b/examples/python/CMakeLists.txt index a6150632b42..1f4f37614f0 100644 --- a/examples/python/CMakeLists.txt +++ b/examples/python/CMakeLists.txt @@ -18,11 +18,8 @@ endif() file(GLOB PYTHON_SRCS "*.py") # Remove too long examples list(FILTER PYTHON_SRCS EXCLUDE REGEX ".*/line_balancing_sat.py") # need input file -list(FILTER PYTHON_SRCS EXCLUDE REGEX ".*/arc_flow_cutting_stock_sat.py") # too long list(FILTER PYTHON_SRCS EXCLUDE REGEX ".*/bus_driver_scheduling_sat.py") # too long -list(FILTER PYTHON_SRCS EXCLUDE REGEX ".*/cover_rectangle_sat.py") # too long list(FILTER PYTHON_SRCS EXCLUDE REGEX ".*/cvrptw_plot.py") # depend on numpy -list(FILTER PYTHON_SRCS EXCLUDE REGEX ".*/qubo_sat.py") # too long foreach(FILE_NAME IN LISTS PYTHON_SRCS) add_python_example(${FILE_NAME}) diff --git a/examples/python/code_samples.bzl b/examples/python/code_samples.bzl index 589dd58d6d1..df146a7b3f5 100644 --- a/examples/python/code_samples.bzl +++ b/examples/python/code_samples.bzl @@ -52,6 +52,19 @@ def code_sample_test_py(name): srcs_version = "PY3", ) +def code_sample_test_arg_py(name, suffix, args, data): + native.py_test( + name = name + "_" + suffix + "_py_test", + size = "medium", + srcs = [name + ".py"], + main = name + ".py", + data = data, + args = args, + deps = PYTHON_DEPS, + python_version = "PY3", + srcs_version = "PY3", + ) + def code_sample_py(name): code_sample_compile_py(name) code_sample_test_py(name) diff --git a/examples/python/cover_rectangle_sat.py b/examples/python/cover_rectangle_sat.py index add26955b8b..a566f09309b 100644 --- a/examples/python/cover_rectangle_sat.py +++ b/examples/python/cover_rectangle_sat.py @@ -82,12 +82,14 @@ def cover_rectangle(num_squares): # Creates a solver and solves. solver = cp_model.CpSolver() - solver.parameters.num_workers = 8 + solver.parameters.num_workers = 16 + # solver.parameters.log_search_progress = True + solver.parameters.max_time_in_seconds = 10.0 status = solver.Solve(model) print("%s found in %0.2fs" % (solver.StatusName(status), solver.WallTime())) # Prints solution. - if status == cp_model.OPTIMAL: + if status == cp_model.OPTIMAL or status == cp_model.FEASIBLE: display = [[" " for _ in range(size_x)] for _ in range(size_y)] for i in range(num_squares): sol_x = solver.Value(x_starts[i]) diff --git a/examples/python/testdata/BUILD.bazel b/examples/python/testdata/BUILD.bazel new file mode 100644 index 00000000000..c36fc13a7de --- /dev/null +++ b/examples/python/testdata/BUILD.bazel @@ -0,0 +1,21 @@ +# Copyright 2010-2022 Google LLC +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +package(default_visibility = ["//visibility:public"]) + +exports_files( + [ + "salbp_20_1.alb", + ], +) + diff --git a/examples/python/testdata/salbp_20_1.alb b/examples/python/testdata/salbp_20_1.alb new file mode 100644 index 00000000000..6b780dae89b --- /dev/null +++ b/examples/python/testdata/salbp_20_1.alb @@ -0,0 +1,51 @@ + +20 + + +1000 + + +0,268 + + + +1 142 +2 34 +3 140 +4 214 +5 121 +6 279 +7 50 +8 282 +9 129 +10 175 +11 97 +12 132 +13 107 +14 132 +15 69 +16 169 +17 73 +18 231 +19 120 +20 186 + + +1,6 +2,7 +4,8 +5,9 +6,10 +7,11 +8,12 +10,13 +11,13 +12,14 +12,15 +13,16 +13,17 +13,18 +14,20 +15,19 + +