Skip to content

Commit

Permalink
Merge branch 'main' of github.com:google/or-tools
Browse files Browse the repository at this point in the history
  • Loading branch information
lperron committed Jul 5, 2023
2 parents 7f96bd4 + bba5838 commit 14460b3
Show file tree
Hide file tree
Showing 12 changed files with 2,880 additions and 17 deletions.
34 changes: 30 additions & 4 deletions cmake/python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -408,17 +408,43 @@ endif()
## Doc rules ##
###############
if(BUILD_PYTHON_DOC)
find_program(PDOC_PRG NAMES pdoc)
if (PDOC_PRG)
# add a target to generate API documentation with pdoc
# add a target to generate API documentation with Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${PROJECT_SOURCE_DIR}/ortools/python/Doxyfile.in ${PROJECT_BINARY_DIR}/python/Doxyfile @ONLY)
file(DOWNLOAD
https://raw.githubusercontent.com/jothepro/doxygen-awesome-css/v2.1.0/doxygen-awesome.css
${PROJECT_BINARY_DIR}/python/doxygen-awesome.css
SHOW_PROGRESS
)
add_custom_target(${PROJECT_NAME}_python_doc ALL
#COMMAND ${CMAKE_COMMAND} -E rm -rf ${PROJECT_BINARY_DIR}/docs/python
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/docs/python
COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/python/Doxyfile
DEPENDS
python_package
${PROJECT_BINARY_DIR}/python/Doxyfile
${PROJECT_BINARY_DIR}/python/doxygen-awesome.css
${PROJECT_SOURCE_DIR}/ortools/python/stylesheet.css
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Generating Python API documentation with Doxygen"
VERBATIM)
else()
message(WARNING "cmd `doxygen` not found, Python doc generation is disable!")
endif()

# pdoc doc
find_program(PDOC_PRG NAMES pdoc)
if (PDOC_PRG)
# add a target to generate API documentation with pdoc
add_custom_target(${PROJECT_NAME}_pdoc_doc ALL
#COMMAND ${CMAKE_COMMAND} -E rm -rf ${PROJECT_BINARY_DIR}/docs/pdoc
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/docs/pdoc
COMMAND ${PDOC_PRG}
--logo https://developers.google.com/optimization/images/orLogo.png
--no-search -d google
--footer-text "OR-Tools v${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
-o ${PROJECT_BINARY_DIR}/docs/python
-o ${PROJECT_BINARY_DIR}/docs/pdoc
${PROJECT_BINARY_DIR}/python/ortools
DEPENDS python_package
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
Expand Down
10 changes: 8 additions & 2 deletions examples/python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down
3 changes: 0 additions & 3 deletions examples/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
13 changes: 13 additions & 0 deletions examples/python/code_samples.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 4 additions & 2 deletions examples/python/cover_rectangle_sat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
21 changes: 21 additions & 0 deletions examples/python/testdata/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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 changes: 51 additions & 0 deletions examples/python/testdata/salbp_20_1.alb
Original file line number Diff line number Diff line change
@@ -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>
6 changes: 3 additions & 3 deletions ortools/pdlp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ if(NOT USE_PDLP)
endif()

file(GLOB _SRCS "*.h" "*.cc")
list(FILTER _SRCS EXCLUDE REGEX ".*/.*_test.cc")
list(FILTER _SRCS EXCLUDE REGEX ".*/gtest.*")
list(FILTER _SRCS EXCLUDE REGEX ".*/test.*")
list(FILTER _SRCS EXCLUDE REGEX "/[^/]*_test\\.cc$")
list(FILTER _SRCS EXCLUDE REGEX "/gtest[^/]*$")
list(FILTER _SRCS EXCLUDE REGEX "/test[^/]*$")

set(NAME ${PROJECT_NAME}_pdlp)

Expand Down
Loading

0 comments on commit 14460b3

Please sign in to comment.