enable more python tests in cmake; add rule to run python examples with args in bazel
This commit is contained in:
@@ -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")
|
||||
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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])
|
||||
|
||||
21
examples/python/testdata/BUILD.bazel
vendored
Normal file
21
examples/python/testdata/BUILD.bazel
vendored
Normal file
@@ -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",
|
||||
],
|
||||
)
|
||||
|
||||
51
examples/python/testdata/salbp_20_1.alb
vendored
Normal file
51
examples/python/testdata/salbp_20_1.alb
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
<number of tasks>
|
||||
20
|
||||
|
||||
<cycle time>
|
||||
1000
|
||||
|
||||
<order strength>
|
||||
0,268
|
||||
|
||||
|
||||
<task times>
|
||||
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
|
||||
|
||||
<precedence relations>
|
||||
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
|
||||
|
||||
<end>
|
||||
Reference in New Issue
Block a user