From b587d27a4a9c95767b6fd0e841c3e78703974359 Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Mon, 9 Mar 2020 11:48:13 +0100 Subject: [PATCH] Sync g3 -> gh --- cmake/doc/cmake.dot | 4 +- cmake/doc/generate_image.sh | 4 +- cmake/docker/alpine/Dockerfile | 2 +- cmake/docker/manylinux/build_manylinux.sh | 6 +- .../constraint_solver/tsp_circuit_board.ipynb | 14 +- .../constraint_solver/tsp_cities.ipynb | 14 +- .../tsp_distance_matrix.ipynb | 14 +- examples/notebook/constraint_solver/vrp.ipynb | 14 +- .../constraint_solver/vrp_capacity.ipynb | 12 +- .../vrp_pickup_delivery.ipynb | 12 +- .../constraint_solver/vrp_resources.ipynb | 24 +-- .../constraint_solver/vrp_time_windows.ipynb | 36 ++-- makefiles/Makefile.python.mk | 4 +- ortools/algorithms/knapsack_solver.cc | 2 +- ortools/base/CMakeLists.txt | 60 +++---- tools/README.netstandard | 16 +- tools/check_python_deps.py | 170 ++++++++++-------- tools/export_to_ipynb.py | 71 ++++---- tools/find_dependencies.sh | 4 +- tools/generate_all_notebooks.sh | 6 +- tools/generate_deps.sh | 4 +- tools/{setup.py => setup.py.in} | 0 tools/setup_data.py | 40 ++--- 23 files changed, 285 insertions(+), 248 deletions(-) rename tools/{setup.py => setup.py.in} (100%) diff --git a/cmake/doc/cmake.dot b/cmake/doc/cmake.dot index 372aaba4b2..b65196013d 100644 --- a/cmake/doc/cmake.dot +++ b/cmake/doc/cmake.dot @@ -5,8 +5,8 @@ // F#: indigo @startdot digraph CMake { - //rankdir=BT; - rankdir=TD; + //rankdir=BT; + rankdir=TD; subgraph clusterPrerequisite { node [shape=box, style=rounded]; diff --git a/cmake/doc/generate_image.sh b/cmake/doc/generate_image.sh index 3b3969cd03..da0d2103d4 100755 --- a/cmake/doc/generate_image.sh +++ b/cmake/doc/generate_image.sh @@ -3,6 +3,6 @@ set -ex rm -f *.svg *.png for i in *.dot; do - plantuml -Tpng $i; - plantuml -Tsvg $i; + plantuml -Tpng "$i"; + plantuml -Tsvg "$i"; done diff --git a/cmake/docker/alpine/Dockerfile b/cmake/docker/alpine/Dockerfile index c58dc6f828..16e587763c 100644 --- a/cmake/docker/alpine/Dockerfile +++ b/cmake/docker/alpine/Dockerfile @@ -68,7 +68,7 @@ FROM env AS dotnet # Swig install RUN apk add --no-cache swig # Add dependencies for disabling invariant mode (set in base image) -RUN apk add --no-cache wget icu-libs libintl +RUN apk add --no-cache wget icu-libs libintl # .NET install RUN dotnet_sdk_version=3.1.101 \ && wget -O dotnet.tar.gz https://dotnetcli.azureedge.net/dotnet/Sdk/$dotnet_sdk_version/dotnet-sdk-$dotnet_sdk_version-linux-musl-x64.tar.gz \ diff --git a/cmake/docker/manylinux/build_manylinux.sh b/cmake/docker/manylinux/build_manylinux.sh index aa2a73e1ec..1c557b0978 100644 --- a/cmake/docker/manylinux/build_manylinux.sh +++ b/cmake/docker/manylinux/build_manylinux.sh @@ -9,12 +9,12 @@ do PYTAG=$(basename "${PYROOT}") echo "$PYTAG" # Clean the build dir - rm -rf cache/manylinux/build_$PYTAG + rm -rf "cache/manylinux/build_$PYTAG" PATH=${PYROOT}/bin:${PATH_BCKP} python -m pip install --user virtualenv - cmake -H. -Bcache/manylinux/build_$PYTAG \ - -DBUILD_PYTHON=ON -DPYTHON_LIBRARY=${PYROOT}/lib/ -DPYTHON_INCLUDE_DIR=${PYROOT}/include/ + cmake -H. "-Bcache/manylinux/build_$PYTAG" \ + -DBUILD_PYTHON=ON "-DPYTHON_LIBRARY=${PYROOT}/lib/" "-DPYTHON_INCLUDE_DIR=${PYROOT}/include/" done diff --git a/examples/notebook/constraint_solver/tsp_circuit_board.ipynb b/examples/notebook/constraint_solver/tsp_circuit_board.ipynb index 0d34113fa5..9e4c98f598 100644 --- a/examples/notebook/constraint_solver/tsp_circuit_board.ipynb +++ b/examples/notebook/constraint_solver/tsp_circuit_board.ipynb @@ -108,16 +108,16 @@ "\n", "\n", "# [START solution_printer]\n", - "def print_solution(manager, routing, assignment):\n", - " \"\"\"Prints assignment on console.\"\"\"\n", - " print('Objective: {}'.format(assignment.ObjectiveValue()))\n", + "def print_solution(manager, routing, solution):\n", + " \"\"\"Prints solution on console.\"\"\"\n", + " print('Objective: {}'.format(solution.ObjectiveValue()))\n", " index = routing.Start(0)\n", " plan_output = 'Route:\\n'\n", " route_distance = 0\n", " while not routing.IsEnd(index):\n", " plan_output += ' {} ->'.format(manager.IndexToNode(index))\n", " previous_index = index\n", - " index = assignment.Value(routing.NextVar(index))\n", + " index = solution.Value(routing.NextVar(index))\n", " route_distance += routing.GetArcCostForVehicle(previous_index, index, 0)\n", " plan_output += ' {}\\n'.format(manager.IndexToNode(index))\n", " print(plan_output)\n", @@ -169,13 +169,13 @@ "\n", "# Solve the problem.\n", "# [START solve]\n", - "assignment = routing.SolveWithParameters(search_parameters)\n", + "solution = routing.SolveWithParameters(search_parameters)\n", "# [END solve]\n", "\n", "# Print solution on console.\n", "# [START print_solution]\n", - "if assignment:\n", - " print_solution(manager, routing, assignment)\n", + "if solution:\n", + " print_solution(manager, routing, solution)\n", "# [END print_solution]\n", "\n" ] diff --git a/examples/notebook/constraint_solver/tsp_cities.ipynb b/examples/notebook/constraint_solver/tsp_cities.ipynb index e3fd95bb85..4d732dd85b 100644 --- a/examples/notebook/constraint_solver/tsp_cities.ipynb +++ b/examples/notebook/constraint_solver/tsp_cities.ipynb @@ -55,16 +55,16 @@ "\n", "\n", "# [START solution_printer]\n", - "def print_solution(manager, routing, assignment):\n", - " \"\"\"Prints assignment on console.\"\"\"\n", - " print('Objective: {} miles'.format(assignment.ObjectiveValue()))\n", + "def print_solution(manager, routing, solution):\n", + " \"\"\"Prints solution on console.\"\"\"\n", + " print('Objective: {} miles'.format(solution.ObjectiveValue()))\n", " index = routing.Start(0)\n", " plan_output = 'Route for vehicle 0:\\n'\n", " route_distance = 0\n", " while not routing.IsEnd(index):\n", " plan_output += ' {} ->'.format(manager.IndexToNode(index))\n", " previous_index = index\n", - " index = assignment.Value(routing.NextVar(index))\n", + " index = solution.Value(routing.NextVar(index))\n", " route_distance += routing.GetArcCostForVehicle(previous_index, index, 0)\n", " plan_output += ' {}\\n'.format(manager.IndexToNode(index))\n", " print(plan_output)\n", @@ -115,13 +115,13 @@ "\n", "# Solve the problem.\n", "# [START solve]\n", - "assignment = routing.SolveWithParameters(search_parameters)\n", + "solution = routing.SolveWithParameters(search_parameters)\n", "# [END solve]\n", "\n", "# Print solution on console.\n", "# [START print_solution]\n", - "if assignment:\n", - " print_solution(manager, routing, assignment)\n", + "if solution:\n", + " print_solution(manager, routing, solution)\n", "# [END print_solution]\n", "\n" ] diff --git a/examples/notebook/constraint_solver/tsp_distance_matrix.ipynb b/examples/notebook/constraint_solver/tsp_distance_matrix.ipynb index 44edee9603..748bed4e7e 100644 --- a/examples/notebook/constraint_solver/tsp_distance_matrix.ipynb +++ b/examples/notebook/constraint_solver/tsp_distance_matrix.ipynb @@ -109,16 +109,16 @@ "\n", "\n", "# [START solution_printer]\n", - "def print_solution(manager, routing, assignment):\n", - " \"\"\"Prints assignment on console.\"\"\"\n", - " print('Objective: {}'.format(assignment.ObjectiveValue()))\n", + "def print_solution(manager, routing, solution):\n", + " \"\"\"Prints solution on console.\"\"\"\n", + " print('Objective: {}'.format(solution.ObjectiveValue()))\n", " index = routing.Start(0)\n", " plan_output = 'Route for vehicle 0:\\n'\n", " route_distance = 0\n", " while not routing.IsEnd(index):\n", " plan_output += ' {} ->'.format(manager.IndexToNode(index))\n", " previous_index = index\n", - " index = assignment.Value(routing.NextVar(index))\n", + " index = solution.Value(routing.NextVar(index))\n", " route_distance += routing.GetArcCostForVehicle(previous_index, index, 0)\n", " plan_output += ' {}\\n'.format(manager.IndexToNode(index))\n", " plan_output += 'Distance of the route: {}m\\n'.format(route_distance)\n", @@ -170,13 +170,13 @@ "\n", "# Solve the problem.\n", "# [START solve]\n", - "assignment = routing.SolveWithParameters(search_parameters)\n", + "solution = routing.SolveWithParameters(search_parameters)\n", "# [END solve]\n", "\n", "# Print solution on console.\n", "# [START print_solution]\n", - "if assignment:\n", - " print_solution(manager, routing, assignment)\n", + "if solution:\n", + " print_solution(manager, routing, solution)\n", "# [END print_solution]\n", "\n" ] diff --git a/examples/notebook/constraint_solver/vrp.ipynb b/examples/notebook/constraint_solver/vrp.ipynb index 6bcf12cf0f..82b880a0b8 100644 --- a/examples/notebook/constraint_solver/vrp.ipynb +++ b/examples/notebook/constraint_solver/vrp.ipynb @@ -109,9 +109,9 @@ "\n", "\n", "# [START solution_printer]\n", - "def print_solution(data, manager, routing, assignment):\n", - " \"\"\"Prints assignment on console.\"\"\"\n", - " print('Objective: {}'.format(assignment.ObjectiveValue()))\n", + "def print_solution(data, manager, routing, solution):\n", + " \"\"\"Prints solution on console.\"\"\"\n", + " print('Objective: {}'.format(solution.ObjectiveValue()))\n", " total_distance = 0\n", " for vehicle_id in range(data['num_vehicles']):\n", " index = routing.Start(vehicle_id)\n", @@ -120,7 +120,7 @@ " while not routing.IsEnd(index):\n", " plan_output += ' {} ->'.format(manager.IndexToNode(index))\n", " previous_index = index\n", - " index = assignment.Value(routing.NextVar(index))\n", + " index = solution.Value(routing.NextVar(index))\n", " route_distance += routing.GetArcCostForVehicle(\n", " previous_index, index, vehicle_id)\n", " plan_output += ' {}\\n'.format(manager.IndexToNode(index))\n", @@ -175,13 +175,13 @@ "\n", "# Solve the problem.\n", "# [START solve]\n", - "assignment = routing.SolveWithParameters(search_parameters)\n", + "solution = routing.SolveWithParameters(search_parameters)\n", "# [END solve]\n", "\n", "# Print solution on console.\n", "# [START print_solution]\n", - "if assignment:\n", - " print_solution(data, manager, routing, assignment)\n", + "if solution:\n", + " print_solution(data, manager, routing, solution)\n", "# [END print_solution]\n", "\n" ] diff --git a/examples/notebook/constraint_solver/vrp_capacity.ipynb b/examples/notebook/constraint_solver/vrp_capacity.ipynb index 952c8a898d..10c9380476 100644 --- a/examples/notebook/constraint_solver/vrp_capacity.ipynb +++ b/examples/notebook/constraint_solver/vrp_capacity.ipynb @@ -113,8 +113,8 @@ "\n", "\n", "# [START solution_printer]\n", - "def print_solution(data, manager, routing, assignment):\n", - " \"\"\"Prints assignment on console.\"\"\"\n", + "def print_solution(data, manager, routing, solution):\n", + " \"\"\"Prints solution on console.\"\"\"\n", " total_distance = 0\n", " total_load = 0\n", " for vehicle_id in range(data['num_vehicles']):\n", @@ -127,7 +127,7 @@ " route_load += data['demands'][node_index]\n", " plan_output += ' {0} Load({1}) -> '.format(node_index, route_load)\n", " previous_index = index\n", - " index = assignment.Value(routing.NextVar(index))\n", + " index = solution.Value(routing.NextVar(index))\n", " route_distance += routing.GetArcCostForVehicle(\n", " previous_index, index, vehicle_id)\n", " plan_output += ' {0} Load({1})\\n'.format(manager.IndexToNode(index),\n", @@ -205,13 +205,13 @@ "\n", "# Solve the problem.\n", "# [START solve]\n", - "assignment = routing.SolveWithParameters(search_parameters)\n", + "solution = routing.SolveWithParameters(search_parameters)\n", "# [END solve]\n", "\n", "# Print solution on console.\n", "# [START print_solution]\n", - "if assignment:\n", - " print_solution(data, manager, routing, assignment)\n", + "if solution:\n", + " print_solution(data, manager, routing, solution)\n", "# [END print_solution]\n", "\n" ] diff --git a/examples/notebook/constraint_solver/vrp_pickup_delivery.ipynb b/examples/notebook/constraint_solver/vrp_pickup_delivery.ipynb index cdfa7c8fd8..975c70802a 100644 --- a/examples/notebook/constraint_solver/vrp_pickup_delivery.ipynb +++ b/examples/notebook/constraint_solver/vrp_pickup_delivery.ipynb @@ -121,8 +121,8 @@ "\n", "\n", "# [START solution_printer]\n", - "def print_solution(data, manager, routing, assignment):\n", - " \"\"\"Prints assignment on console.\"\"\"\n", + "def print_solution(data, manager, routing, solution):\n", + " \"\"\"Prints solution on console.\"\"\"\n", " total_distance = 0\n", " for vehicle_id in range(data['num_vehicles']):\n", " index = routing.Start(vehicle_id)\n", @@ -131,7 +131,7 @@ " while not routing.IsEnd(index):\n", " plan_output += ' {} -> '.format(manager.IndexToNode(index))\n", " previous_index = index\n", - " index = assignment.Value(routing.NextVar(index))\n", + " index = solution.Value(routing.NextVar(index))\n", " route_distance += routing.GetArcCostForVehicle(\n", " previous_index, index, vehicle_id)\n", " plan_output += '{}\\n'.format(manager.IndexToNode(index))\n", @@ -209,13 +209,13 @@ "\n", "# Solve the problem.\n", "# [START solve]\n", - "assignment = routing.SolveWithParameters(search_parameters)\n", + "solution = routing.SolveWithParameters(search_parameters)\n", "# [END solve]\n", "\n", "# Print solution on console.\n", "# [START print_solution]\n", - "if assignment:\n", - " print_solution(data, manager, routing, assignment)\n", + "if solution:\n", + " print_solution(data, manager, routing, solution)\n", "# [END print_solution]\n", "\n" ] diff --git a/examples/notebook/constraint_solver/vrp_resources.ipynb b/examples/notebook/constraint_solver/vrp_resources.ipynb index 3f56ab4dfe..36720dbbc2 100644 --- a/examples/notebook/constraint_solver/vrp_resources.ipynb +++ b/examples/notebook/constraint_solver/vrp_resources.ipynb @@ -82,8 +82,8 @@ "\n", "\n", "# [START solution_printer]\n", - "def print_solution(data, manager, routing, assignment):\n", - " \"\"\"Prints assignment on console.\"\"\"\n", + "def print_solution(data, manager, routing, solution):\n", + " \"\"\"Prints solution on console.\"\"\"\n", " time_dimension = routing.GetDimensionOrDie('Time')\n", " total_time = 0\n", " for vehicle_id in range(data['num_vehicles']):\n", @@ -92,17 +92,17 @@ " while not routing.IsEnd(index):\n", " time_var = time_dimension.CumulVar(index)\n", " plan_output += '{0} Time({1},{2}) -> '.format(\n", - " manager.IndexToNode(index), assignment.Min(time_var),\n", - " assignment.Max(time_var))\n", - " index = assignment.Value(routing.NextVar(index))\n", + " manager.IndexToNode(index), solution.Min(time_var),\n", + " solution.Max(time_var))\n", + " index = solution.Value(routing.NextVar(index))\n", " time_var = time_dimension.CumulVar(index)\n", " plan_output += '{0} Time({1},{2})\\n'.format(manager.IndexToNode(index),\n", - " assignment.Min(time_var),\n", - " assignment.Max(time_var))\n", + " solution.Min(time_var),\n", + " solution.Max(time_var))\n", " plan_output += 'Time of the route: {}min\\n'.format(\n", - " assignment.Min(time_var))\n", + " solution.Min(time_var))\n", " print(plan_output)\n", - " total_time += assignment.Min(time_var)\n", + " total_time += solution.Min(time_var)\n", " print('Total time of all routes: {}min'.format(total_time))\n", " # [END solution_printer]\n", "\n", @@ -207,13 +207,13 @@ "\n", "# Solve the problem.\n", "# [START solve]\n", - "assignment = routing.SolveWithParameters(search_parameters)\n", + "solution = routing.SolveWithParameters(search_parameters)\n", "# [END solve]\n", "\n", "# Print solution on console.\n", "# [START print_solution]\n", - "if assignment:\n", - " print_solution(data, manager, routing, assignment)\n", + "if solution:\n", + " print_solution(data, manager, routing, solution)\n", "# [END print_solution]\n", "else:\n", " print('No solution found !')\n", diff --git a/examples/notebook/constraint_solver/vrp_time_windows.ipynb b/examples/notebook/constraint_solver/vrp_time_windows.ipynb index ac99bb354b..a5c62629c1 100644 --- a/examples/notebook/constraint_solver/vrp_time_windows.ipynb +++ b/examples/notebook/constraint_solver/vrp_time_windows.ipynb @@ -55,20 +55,20 @@ " (0, 5), # depot\n", " (7, 12), # 1\n", " (10, 15), # 2\n", - " (5, 14), # 3\n", - " (5, 13), # 4\n", + " (16, 18), # 3\n", + " (10, 13), # 4\n", " (0, 5), # 5\n", " (5, 10), # 6\n", - " (0, 10), # 7\n", + " (0, 4), # 7\n", " (5, 10), # 8\n", - " (0, 5), # 9\n", + " (0, 3), # 9\n", " (10, 16), # 10\n", " (10, 15), # 11\n", " (0, 5), # 12\n", " (5, 10), # 13\n", - " (7, 12), # 14\n", + " (7, 8), # 14\n", " (10, 15), # 15\n", - " (5, 15), # 16\n", + " (11, 15), # 16\n", " ]\n", " data['num_vehicles'] = 4\n", " data['depot'] = 0\n", @@ -77,8 +77,8 @@ "\n", "\n", "# [START solution_printer]\n", - "def print_solution(data, manager, routing, assignment):\n", - " \"\"\"Prints assignment on console.\"\"\"\n", + "def print_solution(data, manager, routing, solution):\n", + " \"\"\"Prints solution on console.\"\"\"\n", " time_dimension = routing.GetDimensionOrDie('Time')\n", " total_time = 0\n", " for vehicle_id in range(data['num_vehicles']):\n", @@ -87,17 +87,17 @@ " while not routing.IsEnd(index):\n", " time_var = time_dimension.CumulVar(index)\n", " plan_output += '{0} Time({1},{2}) -> '.format(\n", - " manager.IndexToNode(index), assignment.Min(time_var),\n", - " assignment.Max(time_var))\n", - " index = assignment.Value(routing.NextVar(index))\n", + " manager.IndexToNode(index), solution.Min(time_var),\n", + " solution.Max(time_var))\n", + " index = solution.Value(routing.NextVar(index))\n", " time_var = time_dimension.CumulVar(index)\n", " plan_output += '{0} Time({1},{2})\\n'.format(manager.IndexToNode(index),\n", - " assignment.Min(time_var),\n", - " assignment.Max(time_var))\n", + " solution.Min(time_var),\n", + " solution.Max(time_var))\n", " plan_output += 'Time of the route: {}min\\n'.format(\n", - " assignment.Min(time_var))\n", + " solution.Min(time_var))\n", " print(plan_output)\n", - " total_time += assignment.Min(time_var)\n", + " total_time += solution.Min(time_var)\n", " print('Total time of all routes: {}min'.format(total_time))\n", " # [END solution_printer]\n", "\n", @@ -178,13 +178,13 @@ "\n", "# Solve the problem.\n", "# [START solve]\n", - "assignment = routing.SolveWithParameters(search_parameters)\n", + "solution = routing.SolveWithParameters(search_parameters)\n", "# [END solve]\n", "\n", "# Print solution on console.\n", "# [START print_solution]\n", - "if assignment:\n", - " print_solution(data, manager, routing, assignment)\n", + "if solution:\n", + " print_solution(data, manager, routing, solution)\n", "# [END print_solution]\n", "\n" ] diff --git a/makefiles/Makefile.python.mk b/makefiles/Makefile.python.mk index b91307a434..42e057ac92 100644 --- a/makefiles/Makefile.python.mk +++ b/makefiles/Makefile.python.mk @@ -993,8 +993,8 @@ OR_TOOLS_PYTHON_VERSION := $(OR_TOOLS_MAJOR).$(OR_TOOLS_MINOR)b$(GIT_REVISION) endif -$(PYPI_ARCHIVE_TEMP_DIR)/ortools/setup.py: tools/setup.py | $(PYPI_ARCHIVE_TEMP_DIR)/ortools - $(COPY) tools$Ssetup.py $(PYPI_ARCHIVE_TEMP_DIR)$Sortools +$(PYPI_ARCHIVE_TEMP_DIR)/ortools/setup.py: tools/setup.py.in | $(PYPI_ARCHIVE_TEMP_DIR)/ortools + $(COPY) tools$Ssetup.py.in $(PYPI_ARCHIVE_TEMP_DIR)$Sortools $(SED) -i -e 's/ORTOOLS_PYTHON_VERSION/ortools$(PYPI_OS)/' $(PYPI_ARCHIVE_TEMP_DIR)$Sortools$Ssetup.py $(SED) -i -e 's/VVVV/$(OR_TOOLS_PYTHON_VERSION)/' $(PYPI_ARCHIVE_TEMP_DIR)$Sortools$Ssetup.py $(SED) -i -e 's/PROTOBUF_TAG/$(PROTOBUF_TAG)/' $(PYPI_ARCHIVE_TEMP_DIR)$Sortools$Ssetup.py diff --git a/ortools/algorithms/knapsack_solver.cc b/ortools/algorithms/knapsack_solver.cc index 24941d3453..bcf6b74493 100644 --- a/ortools/algorithms/knapsack_solver.cc +++ b/ortools/algorithms/knapsack_solver.cc @@ -984,7 +984,7 @@ int64 KnapsackDynamicProgrammingSolver::SolveSubProblem(int64 capacity, int num_items) { const int64 capacity_plus_1 = capacity + 1; std::fill_n(selected_item_ids_.begin(), capacity_plus_1, 0); - std::fill_n(computed_profits_.begin(), capacity_plus_1, 0LL); + std::fill_n(computed_profits_.begin(), capacity_plus_1, int64{0}); for (int item_id = 0; item_id < num_items; ++item_id) { const int64 item_weight = weights_[item_id]; const int64 item_profit = profits_[item_id]; diff --git a/ortools/base/CMakeLists.txt b/ortools/base/CMakeLists.txt index f645e175ad..bc944cc276 100644 --- a/ortools/base/CMakeLists.txt +++ b/ortools/base/CMakeLists.txt @@ -9,7 +9,7 @@ set_target_properties(${NAME} PROPERTIES CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF POSITION_INDEPENDENT_CODE ON -) + ) # CMake < 3.12: CMakeError: Object library may not link to anything. #target_link_libraries(${NAME} PRIVATE # ZLIB::ZLIB @@ -18,39 +18,39 @@ set_target_properties(${NAME} PROPERTIES # protobuf::libprotobuf # ${PROJECT_NAME}::proto) target_include_directories(${NAME} PRIVATE - ${PROJECT_SOURCE_DIR} - ${PROJECT_BINARY_DIR} - $ - $ - $ - $ - $ - $ - $ - $) + ${PROJECT_SOURCE_DIR} + ${PROJECT_BINARY_DIR} + $ + $ + $ + $ + $ + $ + $ + $) target_compile_options(${NAME} PRIVATE - $ - $ - $ - $ - $ - $ - $ - $ - ) + $ + $ + $ + $ + $ + $ + $ + $ + ) target_compile_definitions(${NAME} PRIVATE -DOR_TOOLS_MAJOR=${PROJECT_VERSION_MAJOR} -DOR_TOOLS_MINOR=${PROJECT_VERSION_MINOR} - $ - $ - $ - $ - $ - $ - $ - $ - ) + $ + $ + $ + $ + $ + $ + $ + $ + ) add_dependencies(${NAME} - ZLIB::ZLIB + ZLIB::ZLIB absl::base absl::strings absl::str_format gflags::gflags glog::glog protobuf::libprotobuf diff --git a/tools/README.netstandard b/tools/README.netstandard index a2e3a55c8f..6a05626462 100644 --- a/tools/README.netstandard +++ b/tools/README.netstandard @@ -27,9 +27,9 @@ dotnet run * Using NuGet Package Directly -To use the nuget package directly a local feed is required. Create a folder where the packages +To use the nuget package directly a local feed is required. Create a folder where the packages will be stored. Create a nuget.config that references this folder. Copy the nupkg file to the -package folder. +package folder. @@ -46,9 +46,9 @@ dotnet restore * Referencing Directly Or-Tools for .netstandard includes two libraries, a library containing managed code and a libraries containing native code. -If a reference is made directly to the managed library, Visual Studio will not copy the native dll to the output folder. +If a reference is made directly to the managed library, Visual Studio will not copy the native dll to the output folder. -A post build step is required to copy the file. In Visual Studio this can be added by selecting the "Build Events" tab in +A post build step is required to copy the file. In Visual Studio this can be added by selecting the "Build Events" tab in project properties. Use the copy command example below to copy the file: xcopy /Y "..\..\lib\ortools\Google.OrTools.Native.dll" "$(TargetDir)" @@ -73,12 +73,14 @@ https://github.com/dotnet/core/blob/master/release-notes/download-archives/2.0.0 Alternatively the command below can be used to install the SDK: curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 2.0 -The build will attempt to detect the SDK path. If there are any issues please check the +The build will attempt to detect the SDK path. If there are any issues please check the DOTNET_INSTALL_PATH variable in the Makefile.local file: DOTNET_INSTALL_PATH=C:\Program Files\dotnet -The dotnet restore command will not update the nuget packages if the version does not change. This +The dotnet restore command will not update the nuget packages if the version does not change. This can cause confusion when testing local builds. Use the command below to clear the package: -dotnet nuget locals all --clear \ No newline at end of file +```sh +dotnet nuget locals all --clear +``` diff --git a/tools/check_python_deps.py b/tools/check_python_deps.py index 3e25b32756..df75e43754 100644 --- a/tools/check_python_deps.py +++ b/tools/check_python_deps.py @@ -1,103 +1,133 @@ -import logging, sys, inspect -from optparse import OptionParser +#!/usr/bin/env python3 +"""Check user python installation.""" +import inspect +import logging +import optparse +import sys -#try to import setuptools +# try to import setuptools try: - from setuptools import setup, Extension - from setuptools.command import easy_install + from setuptools import setup # pylint: disable=g-import-not-at-top,unused-import + from setuptools import Extension # pylint: disable=g-import-not-at-top,unused-import + from setuptools.command import easy_install # pylint: disable=g-import-not-at-top,unused-import except ImportError: - raise ImportError("""setuptools is not installed for \"""" + sys.executable + """\" + raise ImportError("""setuptools is not installed for \"""" + sys.executable + + """\" Follow this link for installing instructions : https://pypi.python.org/pypi/setuptools make sure you use \"""" + sys.executable + """\" during the installation""") - raise SystemExit -from pkg_resources import parse_version +from pkg_resources import parse_version # pylint: disable=g-import-not-at-top,unused-import required_ortools_version = "VVVV" required_protobuf_version = "PROTOBUF_TAG" + def notinstalled(modulename): - return modulename + """ is not installed for \"""" + sys.executable + """\" + return modulename + """ is not installed for \"""" + sys.executable + """\" Run \"""" + sys.executable + """ setup.py install --user\" to install it""" + def absent_version(module, modulename): - return """You are using a """ + modulename + """ module that doesn't have a __version__ attribute : """ + inspect.getfile(module) + """\" + return """You are using a """ + modulename + """ module that doesn't have a __version__ attribute : """ + inspect.getfile( + module) + """\" Run \"""" + sys.executable + """ setup.py install --user\" to upgrade. -If the problem persists, remove the site-package that contains \"""" + inspect.getfile(module) + """\". You can do so either manually or by using pip.""" +If the problem persists, remove the site-package that contains \"""" + inspect.getfile( + module) + """\". You can do so either manually or by using pip.""" + def wrong_version(module, modulename, required_version, installed_version): - return """You are using """ + modulename + """-""" + installed_version + """ : """ + inspect.getfile(module) + """, while the required version is : """ + required_version + """ + return """You are using """ + modulename + """-""" + installed_version + """ : """ + inspect.getfile( + module + ) + """, while the required version is : """ + required_version + """ Run \"""" + sys.executable + """ setup.py install --user\" to upgrade. -If the problem persists, remove the site-package that contains \"""" + inspect.getfile(module) + """\". You can do so either manually or by using pip.""" +If the problem persists, remove the site-package that contains \"""" + inspect.getfile( + module) + """\". You can do so either manually or by using pip.""" + def log_error_and_exit(error_message): - logging.error(error_message) - raise SystemExit + logging.error(error_message) + raise SystemExit + def check_absent_version(module, modulename): - if not hasattr(module, '__version__'): - log_error_and_exit(absent_version(module, modulename)) + if not hasattr(module, "__version__"): + log_error_and_exit(absent_version(module, modulename)) -if __name__ == '__main__': - parser = OptionParser('Log level') - parser.add_option('-l','--log',type='string',help='Available levels are CRITICAL (3), ERROR (2), WARNING (1), INFO (0), DEBUG (-1)',default='INFO') - options,args = parser.parse_args() - #Create the logger - try: - loglevel = getattr(logging,options.log.upper()) - except AttributeError: - loglevel = {3:logging.CRITICAL, - 2:logging.ERROR, - 1:logging.WARNING, - 0:logging.INFO, - -1:logging.DEBUG, - }[int(options.log)] +if __name__ == "__main__": + parser = optparse.OptionParser("Log level") + parser.add_option( + "-l", + "--log", + type="string", + help="Available levels are CRITICAL (3), ERROR (2), WARNING (1), INFO (0), DEBUG (-1)", + default="INFO") + options, args = parser.parse_args() - logging.basicConfig(format='[%(levelname)s] %(message)s', stream=sys.stdout, level=loglevel) + # Create the logger + try: + loglevel = getattr(logging, options.log.upper()) + except AttributeError: + loglevel = { + 3: logging.CRITICAL, + 2: logging.ERROR, + 1: logging.WARNING, + 0: logging.INFO, + -1: logging.DEBUG, + }[int(options.log)] - #Display Python Version and path - logging.info("Python path : " + sys.executable) - logging.info("Python version : " + sys.version) + logging.basicConfig( + format="[%(levelname)s] %(message)s", stream=sys.stdout, level=loglevel) - #Choose the pypi package - ortools_name = "ortools" + # Display Python Version and path + logging.info(f"Python path : {sys.executable}") + logging.info(f"Python version : {sys.version}") - #try to import ortools - try: - import ortools - except ImportError: - log_error_and_exit(notinstalled(ortools_name)) + # Choose the pypi package + ortools_name = "ortools" - #try to import protobuf - try: - import google.protobuf - except ImportError: - log_error_and_exit(notinstalled("protobuf")) + # try to import ortools + try: + import ortools # pylint: disable=g-import-not-at-top + except ImportError: + log_error_and_exit(notinstalled(ortools_name)) - #check ortools version - try: - check_absent_version(ortools, "ortools") - if required_ortools_version != ortools.__version__: - raise Exception - logging.info("or-tools version : " + ortools.__version__ + "\n" + inspect.getfile(ortools)) - except (AttributeError, Exception): - log_error_and_exit(wrong_version(ortools, ortools_name, required_ortools_version, ortools.__version__)) + # try to import protobuf + try: + import google.protobuf # pylint: disable=g-import-not-at-top + except ImportError: + log_error_and_exit(notinstalled("protobuf")) - #check protobuf version - try: - check_absent_version(google.protobuf, "protobuf") - if required_protobuf_version != google.protobuf.__version__: - raise Exception - logging.info("protobuf version : " + google.protobuf.__version__+ "\n" + inspect.getfile(google.protobuf) ) - except (AttributeError, Exception): - log_error_and_exit(wrong_version(google.protobuf, "protobuf", required_protobuf_version, google.protobuf.__version__)) + # check ortools version + try: + check_absent_version(ortools, "ortools") + if required_ortools_version != ortools.__version__: + raise Exception + logging.info("or-tools version : " + ortools.__version__ + "\n" + + inspect.getfile(ortools)) + except (AttributeError, Exception): # pylint: disable=broad-except + log_error_and_exit( + wrong_version(ortools, ortools_name, required_ortools_version, + ortools.__version__)) - # Check if python can load the libraries' modules - # this is useful when the library architecture is not compatbile with the python executable, - # or when the library's dependencies are not available or not compatible. - from ortools.constraint_solver import _pywrapcp - from ortools.linear_solver import _pywraplp - from ortools.algorithms import _pywrapknapsack_solver - from ortools.graph import _pywrapgraph + # check protobuf version + try: + check_absent_version(google.protobuf, "protobuf") + if required_protobuf_version != google.protobuf.__version__: + raise Exception + logging.info("protobuf version : " + google.protobuf.__version__ + "\n" + + inspect.getfile(google.protobuf)) + except (AttributeError, Exception): # pylint: disable=broad-except + log_error_and_exit( + wrong_version(google.protobuf, "protobuf", required_protobuf_version, + google.protobuf.__version__)) + + # Check if python can load the libraries' modules + # this is useful when the library architecture is not compatbile with the + # python executable, or when the library's dependencies are not available or + # not compatible. + from ortools.constraint_solver import _pywrapcp # pylint: disable=g-import-not-at-top,unused-import + from ortools.linear_solver import _pywraplp # pylint: disable=g-import-not-at-top,unused-import + from ortools.algorithms import _pywrapknapsack_solver # pylint: disable=g-import-not-at-top,unused-import + from ortools.graph import _pywrapgraph # pylint: disable=g-import-not-at-top,unused-import diff --git a/tools/export_to_ipynb.py b/tools/export_to_ipynb.py index 926cd90780..c04041d9cc 100755 --- a/tools/export_to_ipynb.py +++ b/tools/export_to_ipynb.py @@ -1,56 +1,63 @@ #!/usr/bin/env python3 +"""Transform any Python sample or example to Python NoteBook.""" import ast -from nbformat import v3, v4 import sys +from nbformat import v3 +from nbformat import v4 -input = sys.argv[1] -print('reading %s' % input) -with open(input) as fpin: - text = fpin.read() +input_file = sys.argv[1] +print('reading %s' % input_file) +with open(input_file) as fpin: + text = fpin.read() nbook = v3.reads_py('') nbook = v4.upgrade(nbook) # Upgrade v3 to v4 all_blocks = ast.parse(text).body -line_start = [c.lineno-1 for c in all_blocks] +line_start = [c.lineno - 1 for c in all_blocks] line_start[0] = 0 lines = text.split('\n') full_text = '' -for c_block, s, e in zip(all_blocks, line_start, line_start[1:]+[len(lines)]): - c_text = '\n'.join(lines[s:e]) - if isinstance(c_block, ast.If) and c_block.test.comparators[0].s=='__main__': - print('Skip if main', lines[s:e]) - elif isinstance(c_block, ast.FunctionDef) and c_block.name=='main': - # remove start and de-indent lines - c_lines = lines[s+1:e] - spaces_to_delete = c_block.body[0].col_offset - fixed_lines = [n_line[spaces_to_delete:] if n_line.startswith(' '*spaces_to_delete) - else n_line for n_line in c_lines] - fixed_text = '\n'.join(fixed_lines) - print('Unwrapping main function') - full_text += fixed_text - else: - print('appending', c_block) - full_text += c_text + '\n' +for c_block, s, e in zip(all_blocks, line_start, line_start[1:] + [len(lines)]): + c_text = '\n'.join(lines[s:e]) + if isinstance(c_block, + ast.If) and c_block.test.comparators[0].s == '__main__': + print('Skip if main', lines[s:e]) + elif isinstance(c_block, ast.FunctionDef) and c_block.name == 'main': + # remove start and de-indent lines + c_lines = lines[s + 1:e] + spaces_to_delete = c_block.body[0].col_offset + fixed_lines = [ + n_line[spaces_to_delete:] + if n_line.startswith(' ' * spaces_to_delete) else n_line + for n_line in c_lines + ] + fixed_text = '\n'.join(fixed_lines) + print('Unwrapping main function') + full_text += fixed_text + else: + print('appending', c_block) + full_text += c_text + '\n' nbook['cells'].append(v4.new_code_cell(full_text)) - jsonform = v4.writes(nbook) + '\n' -output = input -output = output.replace('.py', '.ipynb') +output_file = input_file +output_file = output_file.replace('.py', '.ipynb') # For example/python/foo.py -> example/notebook/examples/foo.ipynb -output = output.replace('examples/python', 'examples/notebook/examples') +output_file = output_file.replace('examples/python', + 'examples/notebook/examples') # For example/contrib/foo.py -> example/notebook/contrib/foo.ipynb -output = output.replace('examples/contrib', 'examples/notebook/contrib') +output_file = output_file.replace('examples/contrib', + 'examples/notebook/contrib') # For ortools/*/samples/foo.py -> example/notebook/*/foo.ipynb -output = output.replace('ortools', 'examples/notebook') -output = output.replace('samples/', '') +output_file = output_file.replace('ortools', 'examples/notebook') +output_file = output_file.replace('samples/', '') -print('writing %s' % output) -with open(output, "w") as fpout: - fpout.write(jsonform) +print('writing %s' % output_file) +with open(output_file, 'w') as fpout: + fpout.write(jsonform) diff --git a/tools/find_dependencies.sh b/tools/find_dependencies.sh index 3cf8adc441..efee66644f 100755 --- a/tools/find_dependencies.sh +++ b/tools/find_dependencies.sh @@ -1,4 +1,4 @@ -for deps in `grep -e "\#include \"$dir" src/$1/*.h src/$1/*cc | cut -d '"' -f 2 | sort -u` +for deps in $(grep -e "\#include \"$dir" "src/$1/*.h" "src/$1/*.cc" | cut -d '"' -f 2 | sort -u) do - echo $deps + echo "$deps" done diff --git a/tools/generate_all_notebooks.sh b/tools/generate_all_notebooks.sh index 2dfacc06e1..a63d1f5fc8 100755 --- a/tools/generate_all_notebooks.sh +++ b/tools/generate_all_notebooks.sh @@ -35,7 +35,7 @@ done for FILE in examples/contrib/*.py; do # if no files found do nothing [[ -e "$FILE" ]] || continue - if [ $(basename "$FILE") == "word_square.py" ]; then continue; fi + if [[ $(basename "$FILE") == "word_square.py" ]]; then continue; fi mkdir -p examples/notebook/contrib echo "Generating ${FILE%.py}.ipynb" ./tools/export_to_ipynb.py "$FILE"; @@ -47,8 +47,8 @@ done for FILE in ortools/*/samples/*.py ; do # if no files found do nothing [[ -e "$FILE" ]] || continue - D=$(dirname $(dirname "${FILE}")) - mkdir -p ${D/ortools/examples\/notebook} + D=$(dirname "$(dirname "${FILE}")") + mkdir -p "${D/ortools/examples\/notebook}" echo "Generating ${FILE%.py}.ipynb" ./tools/export_to_ipynb.py "$FILE" done diff --git a/tools/generate_deps.sh b/tools/generate_deps.sh index 717ec96978..e416e23555 100755 --- a/tools/generate_deps.sh +++ b/tools/generate_deps.sh @@ -41,7 +41,7 @@ function print_paths { # Output: all the files these files depend on (given by their #include, # by their "import" for proto files). function get_dependencies { - grep -e "^\(#include\|import\) \"ortools/" $* \ + grep -e "^\(#include\|import\) \"ortools/" "$*" \ | cut -d '"' -f 2 | LC_COLLATE=C sort -u } @@ -49,7 +49,7 @@ function get_dependencies { # Output: dependencies command for that file: # objs/sub_dir/filename.o : ortools/ function print_dependencies { - cmd=$(gcc -MM -MT objs/${2}/${1}.o -c ortools/${2}/${1}.cc -I. -Iortools/gen \ + cmd=$(gcc -MM -MT "objs/${2}/${1}.o" -c "ortools/${2}/${1}.cc" -I. -Iortools/gen \ -isystem dependencies/install/include \ -isystem dependencies/install/include/coin \ -DUSE_GLOP -DUSE_BOP -DUSE_CLP -DUSE_CBC \ diff --git a/tools/setup.py b/tools/setup.py.in similarity index 100% rename from tools/setup.py rename to tools/setup.py.in diff --git a/tools/setup_data.py b/tools/setup_data.py index a0ce40375c..31f9ec2426 100644 --- a/tools/setup_data.py +++ b/tools/setup_data.py @@ -1,18 +1,16 @@ -from sys import executable +"""Setup.py for data package.""" +from os import path +import sys -setuptools_import_error_message = """setuptools is not installed for """ + executable + """ +setuptools_import_error_message = """setuptools is not installed for """ + sys.executable + """ Please follow this link for installing instructions : https://pypi.python.org/pypi/setuptools -make sure you use \"""" + executable + """\" during the installation""" +make sure you use \"""" + sys.executable + """\" during the installation""" try: - from setuptools import setup, Extension + from setuptools import setup # pylint: disable=g-import-not-at-top except ImportError: - raise ImportError(setuptools_import_error_message) - -from os.path import join as pjoin -from os.path import dirname -from sys import version_info + raise ImportError(setuptools_import_error_message) # Utility function to read the README file. @@ -20,23 +18,23 @@ from sys import version_info # README file and 2) it's easier to type in the README file than to put a raw # string in below ... def read(fname): - return open(pjoin(dirname(__file__), fname)).read() + return open(path.join(path.dirname(__file__), fname)).read() -install_requires = ["ortoolsXXXX == VVVV"] +install_requires = ['ortoolsXXXX == VVVV'] setup( name='ortools_examples', version='VVVV', - install_requires = install_requires, + install_requires=install_requires, license='Apache 2.0', - author = 'Google Inc', - author_email = 'lperron@google.com', - description = 'Google OR-Tools python libraries and modules', - keywords = ('operations research, constraint programming, ' + - 'linear programming,' + 'flow algorithms,' + - 'python'), - url = 'https://developers.google.com/optimization/', - classifiers = [ + author='Google Inc', + author_email='lperron@google.com', + description='Google OR-Tools python libraries and modules', + keywords=('operations research, constraint programming, ' + + 'linear programming,' + 'flow algorithms,' + + 'python'), + url='https://developers.google.com/optimization/', + classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'License :: OSI Approved :: Apache Software License', @@ -52,5 +50,5 @@ setup( 'Topic :: Scientific/Engineering', 'Topic :: Scientific/Engineering :: Mathematics', 'Topic :: Software Development :: Libraries :: Python Modules'], - long_description = read('README.txt'), + long_description=read('README.txt'), )