diff --git a/.github/workflows/amd64_windows_cmake_cpp.yml b/.github/workflows/amd64_windows_cmake_cpp.yml index 05a8917acb..d7904aeee6 100644 --- a/.github/workflows/amd64_windows_cmake_cpp.yml +++ b/.github/workflows/amd64_windows_cmake_cpp.yml @@ -13,7 +13,7 @@ jobs: {generator: "Visual Studio 17 2022", config: Debug, build_target: ALL_BUILD, test_target: RUN_TESTS, install_target: INSTALL}, ] fail-fast: false - name: Windows • ${{ matrix.cmake.generator }} (${{ matrix.cmake.config }}) • C++ + name: Windows • VS 2022 (${{ matrix.cmake.config }}) • C++ runs-on: windows-latest env: CTEST_OUTPUT_ON_FAILURE: 1 diff --git a/.github/workflows/amd64_windows_cmake_dotnet.yml b/.github/workflows/amd64_windows_cmake_dotnet.yml index 4e8e612092..9010ebfd66 100644 --- a/.github/workflows/amd64_windows_cmake_dotnet.yml +++ b/.github/workflows/amd64_windows_cmake_dotnet.yml @@ -12,7 +12,7 @@ jobs: {generator: "Visual Studio 17 2022", config: Release, build_target: ALL_BUILD, test_target: RUN_TESTS, install_target: INSTALL}, ] fail-fast: false - name: Windows • ${{ matrix.cmake.generator }} • .Net + name: Windows • VS 2022 • .Net runs-on: windows-latest env: CTEST_OUTPUT_ON_FAILURE: 1 diff --git a/.github/workflows/amd64_windows_cmake_java.yml b/.github/workflows/amd64_windows_cmake_java.yml index 190ebf7d3f..e1f1b18b3f 100644 --- a/.github/workflows/amd64_windows_cmake_java.yml +++ b/.github/workflows/amd64_windows_cmake_java.yml @@ -28,7 +28,7 @@ jobs: {distrib: 'microsoft', version: '21'}, # 2028/09 ] fail-fast: false - name: Windows • ${{ matrix.cmake.generator }} • ${{ matrix.java.distrib }}-${{ matrix.java.version }} + name: Windows • VS 2022 • ${{ matrix.java.distrib }}-${{ matrix.java.version }} runs-on: windows-latest env: CTEST_OUTPUT_ON_FAILURE: 1 diff --git a/.github/workflows/amd64_windows_cmake_python.yml b/.github/workflows/amd64_windows_cmake_python.yml index 7cc795f5c3..0b6191ccf0 100644 --- a/.github/workflows/amd64_windows_cmake_python.yml +++ b/.github/workflows/amd64_windows_cmake_python.yml @@ -19,7 +19,7 @@ jobs: {version: "3.13", dir: Python313}, ] fail-fast: false - name: Windows • ${{ matrix.cmake.generator }} • Python-${{ matrix.python.version }} + name: Windows • VS 2022 • Python-${{ matrix.python.version }} runs-on: windows-latest env: CTEST_OUTPUT_ON_FAILURE: 1 diff --git a/cmake/dependencies/CMakeLists.txt b/cmake/dependencies/CMakeLists.txt index f2ce806d20..a4a33b9208 100644 --- a/cmake/dependencies/CMakeLists.txt +++ b/cmake/dependencies/CMakeLists.txt @@ -295,6 +295,9 @@ endif() # ############################################################################## # Coin-OR does not support C++17/C++20 (use of 'register' storage class specifier) set(CMAKE_CXX_STANDARD 11) +if(WIN32) + set(BUILD_SHARED_LIBS OFF) +endif() if(BUILD_CoinUtils) message(CHECK_START "Fetching CoinUtils") @@ -388,6 +391,9 @@ if(BUILD_Cbc) message(CHECK_PASS "fetched") endif() +if(WIN32) + set(BUILD_SHARED_LIBS ON) +endif() if(MSVC) set(CMAKE_CXX_STANDARD 20) else() diff --git a/cmake/dotnet.cmake b/cmake/dotnet.cmake index 4f0b006e3b..3c6eca601d 100644 --- a/cmake/dotnet.cmake +++ b/cmake/dotnet.cmake @@ -362,6 +362,26 @@ file(MAKE_DIRECTORY ${DOTNET_PACKAGES_DIR}) # *.csproj.in contains: # CMake variable(s) (@PROJECT_NAME@) that configure_file() can manage and # generator expression ($) that file(GENERATE) can manage. +set(is_not_windows "$>") + +set(need_zlib_lib "$>") + +set(need_absl_lib "$>") + +set(need_re2_lib "$>") + +set(need_protobuf_lib "$>") + +set(need_coinutils_lib "$>") +set(need_osi_lib "$>") +set(need_clp_lib "$>") +set(need_cgl_lib "$>") +set(need_cbc_lib "$>") + +set(need_highs_lib "$>") + +set(is_ortools_shared "$,SHARED_LIBRARY>") + configure_file( ${PROJECT_SOURCE_DIR}/ortools/dotnet/${DOTNET_PACKAGE}.runtime.csproj.in ${DOTNET_NATIVE_PROJECT_DIR}/${DOTNET_NATIVE_PROJECT}.csproj.in diff --git a/cmake/java.cmake b/cmake/java.cmake index 4872d31b29..6721fad6ab 100644 --- a/cmake/java.cmake +++ b/cmake/java.cmake @@ -275,141 +275,163 @@ configure_file( ${JAVA_NATIVE_PROJECT_DIR}/pom.xml @ONLY) +set(is_not_windows "$>") + +set(need_zlib_lib "$>") + +set(need_absl_lib "$>") + +set(need_re2_lib "$>") + +set(need_protobuf_lib "$>") + +set(need_coinutils_lib "$>") +set(need_osi_lib "$>") +set(need_clp_lib "$>") +set(need_cgl_lib "$>") +set(need_cbc_lib "$>") + +set(need_highs_lib "$>") + +set(is_ortools_shared "$,SHARED_LIBRARY>") + add_custom_command( OUTPUT ${JAVA_NATIVE_PROJECT_DIR}/timestamp COMMAND ${CMAKE_COMMAND} -E copy $ - $<$>:$> + $<${is_ortools_shared}:$> ${JAVA_RESSOURCES_PATH}/${JAVA_NATIVE_PROJECT}/ COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> + $ + $<${need_zlib_lib}:$> ${JAVA_RESSOURCES_PATH}/${JAVA_NATIVE_PROJECT}/ COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> + $ + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> ${JAVA_RESSOURCES_PATH}/${JAVA_NATIVE_PROJECT}/ + COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> + $ + $<${need_re2_lib}:$> ${JAVA_RESSOURCES_PATH}/${JAVA_NATIVE_PROJECT}/ + COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> - $<$:$> + $ + $<${need_protobuf_lib}:$> + $<${need_protobuf_lib}:$> ${JAVA_RESSOURCES_PATH}/${JAVA_NATIVE_PROJECT}/ COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> + $ + $<${need_coinutils_lib}:$> ${JAVA_RESSOURCES_PATH}/${JAVA_NATIVE_PROJECT}/ COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> + $ + $<${need_osi_lib}:$> ${JAVA_RESSOURCES_PATH}/${JAVA_NATIVE_PROJECT}/ COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> - $<$:$> - $<$:$> + $ + $<${need_clp_lib}:$> + $<${need_clp_lib}:$> + $<${need_clp_lib}:$> ${JAVA_RESSOURCES_PATH}/${JAVA_NATIVE_PROJECT}/ COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> + $ + $<${need_cgl_lib}:$> ${JAVA_RESSOURCES_PATH}/${JAVA_NATIVE_PROJECT}/ COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> - $<$:$> - $<$:$> + $ + $<${need_cbc_lib}:$> + $<${need_cbc_lib}:$> + $<${need_cbc_lib}:$> ${JAVA_RESSOURCES_PATH}/${JAVA_NATIVE_PROJECT}/ COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> + $ + $<${need_highs_lib}:$> ${JAVA_RESSOURCES_PATH}/${JAVA_NATIVE_PROJECT}/ COMMAND ${MAVEN_EXECUTABLE} compile -B diff --git a/cmake/python.cmake b/cmake/python.cmake index 9f6e60c0c1..13e68c6d70 100644 --- a/cmake/python.cmake +++ b/cmake/python.cmake @@ -430,145 +430,167 @@ configure_file( ${PROJECT_BINARY_DIR}/python/LICENSE COPYONLY) +set(is_not_windows "$>") + +set(need_zlib_lib "$>") + +set(need_absl_lib "$>") + +set(need_re2_lib "$>") + +set(need_protobuf_lib "$>") + +set(need_coinutils_lib "$>") +set(need_osi_lib "$>") +set(need_clp_lib "$>") +set(need_cgl_lib "$>") +set(need_cbc_lib "$>") + +set(need_highs_lib "$>") + +set(is_ortools_shared "$,SHARED_LIBRARY>") + add_custom_command( OUTPUT python/ortools_timestamp COMMAND ${CMAKE_COMMAND} -E remove -f ortools_timestamp COMMAND ${CMAKE_COMMAND} -E make_directory ${PYTHON_PROJECT}/.libs # Don't need to copy static lib on Windows. COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> + $ + $<${need_zlib_lib}:$> ${PYTHON_PROJECT}/.libs COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> - $<$:$> + $ + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> + $<${need_absl_lib}:$> ${PYTHON_PROJECT}/.libs + COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> + $ + $<${need_re2_lib}:$> ${PYTHON_PROJECT}/.libs + COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> - $<$:$> + $ + $<${need_protobuf_lib}:$> + $<${need_protobuf_lib}:$> ${PYTHON_PROJECT}/.libs COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> + $ + $<${need_coinutils_lib}:$> ${PYTHON_PROJECT}/.libs COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> + $ + $<${need_osi_lib}:$> ${PYTHON_PROJECT}/.libs COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> - $<$:$> - $<$:$> + $ + $<${need_clp_lib}:$> + $<${need_clp_lib}:$> + $<${need_clp_lib}:$> ${PYTHON_PROJECT}/.libs COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> + $ + $<${need_cgl_lib}:$> ${PYTHON_PROJECT}/.libs COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> - $<$:$> - $<$:$> + $ + $<${need_cbc_lib}:$> + $<${need_cbc_lib}:$> + $<${need_cbc_lib}:$> ${PYTHON_PROJECT}/.libs COMMAND ${CMAKE_COMMAND} -E - $,copy,true> - $<$:$> + $ + $<${need_highs_lib}:$> ${PYTHON_PROJECT}/.libs COMMAND ${CMAKE_COMMAND} -E - $,SHARED_LIBRARY>,copy,true> - $<$,SHARED_LIBRARY>:$> + $ + $<${is_ortools_shared}:$> ${PYTHON_PROJECT}/.libs COMMAND ${CMAKE_COMMAND} -E touch ${PROJECT_BINARY_DIR}/python/ortools_timestamp MAIN_DEPENDENCY diff --git a/ortools/algorithms/binary_search_test.cc b/ortools/algorithms/binary_search_test.cc index be670d2646..458e3b85b8 100644 --- a/ortools/algorithms/binary_search_test.cc +++ b/ortools/algorithms/binary_search_test.cc @@ -35,7 +35,7 @@ namespace operations_research { // Correctly picking the midpoint of two integers in all cases isn't trivial! -template <> +template <> inline int BinarySearchMidpoint(int x, int y) { if (x > y) std::swap(x, y); if (x >= 0 || y < 0) return x + (y - x) / 2; @@ -181,7 +181,7 @@ TEST(BinarySearchDeathTest, DiesIfEitherBoundaryConditionViolatedInFastbuild) { // Note that template specializations must be exactly in the same namespace, // hence the presence of these tests outside the unnamed namespace. -template <> +template <> inline absl::Time BinarySearchMidpoint(absl::Time x, absl::Time y) { return x + (y - x) / 2; } diff --git a/ortools/dotnet/Google.OrTools.runtime.csproj.in b/ortools/dotnet/Google.OrTools.runtime.csproj.in index 74ab70cc19..b00871d634 100644 --- a/ortools/dotnet/Google.OrTools.runtime.csproj.in +++ b/ortools/dotnet/Google.OrTools.runtime.csproj.in @@ -26,105 +26,105 @@ runtimes/@DOTNET_RID@/native/%(Filename)%(Extension) true diff --git a/ortools/graph/christofides_test.cc b/ortools/graph/christofides_test.cc index e142af8aa7..975787f883 100644 --- a/ortools/graph/christofides_test.cc +++ b/ortools/graph/christofides_test.cc @@ -275,12 +275,12 @@ void BM_ChristofidesPathSolver(benchmark::State& state) { costs[i][j] = std::abs(x_i - x_j) + std::abs(y_i - y_j); } } - auto cost = [&costs](int i, int j) { return costs[i][j]; }; - using Cost = decltype(cost); + std::function cost = [&costs](int i, int j) -> int { return costs[i][j]; }; + using MatchingAlgorithm = - typename ChristofidesPathSolver::MatchingAlgorithm; + typename ChristofidesPathSolver::MatchingAlgorithm; for (auto _ : state) { - ChristofidesPathSolver chris_solver(num_nodes, cost); + ChristofidesPathSolver chris_solver(num_nodes, cost); if (use_minimal_matching) { chris_solver.SetMatchingAlgorithm( MatchingAlgorithm::MINIMAL_WEIGHT_MATCHING); diff --git a/ortools/graph/shortest_paths_test.cc b/ortools/graph/shortest_paths_test.cc index a590805746..ffc00e6770 100644 --- a/ortools/graph/shortest_paths_test.cc +++ b/ortools/graph/shortest_paths_test.cc @@ -264,8 +264,8 @@ TYPED_TEST_SUITE(GraphShortestPathsTest, GraphTypesForShortestPathsTesting); // Test on an empty graph. TYPED_TEST(GraphShortestPathsDeathTest, ShortestPathsEmptyGraph) { - const int kExpectedPaths[] = {}; - const PathDistance kExpectedDistances[] = {}; + const auto kExpectedPaths = nullptr; + const auto kExpectedDistances = nullptr; TypeParam graph; std::vector lengths; TestShortestPathsFromGraph(graph, lengths, kExpectedPaths, diff --git a/ortools/math_opt/python/model_storage_test.py b/ortools/math_opt/python/model_storage_test.py index b8c5e23da7..e68daaa8cc 100644 --- a/ortools/math_opt/python/model_storage_test.py +++ b/ortools/math_opt/python/model_storage_test.py @@ -873,22 +873,34 @@ def test_nans_pass_through(self, storage_class: _StorageClass) -> None: self.assertCountEqual([c], storage.get_linear_constraints_with_variable(x)) self.assertCountEqual([c, d], storage.get_linear_constraints_with_variable(y)) - self.assertCountEqual( - [ - _MatEntry(linear_constraint_id=c, variable_id=x, coefficient=nan), - _MatEntry(linear_constraint_id=c, variable_id=y, coefficient=1.0), - _MatEntry(linear_constraint_id=d, variable_id=y, coefficient=nan), - ], - storage.get_linear_constraint_matrix_entries(), - ) - - self.assertCountEqual( - [ - _ObjEntry(variable_id=x, coefficient=1.0), - _ObjEntry(variable_id=y, coefficient=nan), - ], - storage.get_linear_objective_coefficients(), - ) + mat_entries = {} + for e in storage.get_linear_constraint_matrix_entries(): + key = (e.linear_constraint_id, e.variable_id) + self.assertNotIn( + key, + mat_entries, + msg=f"found key:{key} twice, e:{e} mat_entries:{mat_entries}", + ) + mat_entries[key] = e.coefficient + self.assertSetEqual(set(mat_entries.keys()), set(((c, x), (c, y), (d, y)))) + self._assert_nan(mat_entries[(c, x)]) + self.assertEqual(mat_entries[(c, y)], 1.0) + self._assert_nan(mat_entries[(d, y)]) + + obj_entries = {} + for e in storage.get_linear_objective_coefficients(): + self.assertNotIn( + e.variable_id, + obj_entries, + msg=( + f"found variable:{e.variable_id} twice," + f" e:{e} obj_entries:{obj_entries}" + ), + ) + obj_entries[e.variable_id] = e.coefficient + self.assertSetEqual(set(obj_entries.keys()), set((x, y))) + self.assertEqual(obj_entries[x], 1.0) + self._assert_nan(obj_entries[y]) # Export to proto expected = model_pb2.ModelProto( diff --git a/ortools/math_opt/solver_tests/ip_multiple_solutions_tests.cc b/ortools/math_opt/solver_tests/ip_multiple_solutions_tests.cc index 9b56227d5c..cc66c66112 100644 --- a/ortools/math_opt/solver_tests/ip_multiple_solutions_tests.cc +++ b/ortools/math_opt/solver_tests/ip_multiple_solutions_tests.cc @@ -51,16 +51,16 @@ TEST_P(IpMultipleSolutionsTest, FindTwoSolutionsUsingHint) { model_parameters.solution_hints.emplace_back(hint); const Solution expected1 = { - .primal_solution = std::make_optional( - {.variable_values = {{x1, 0.0}, {x2, 1.0}}, - .objective_value = 3.0, - .feasibility_status = SolutionStatus::kFeasible})}; + .primal_solution = + PrimalSolution{.variable_values = {{x1, 0.0}, {x2, 1.0}}, + .objective_value = 3.0, + .feasibility_status = SolutionStatus::kFeasible}}; const Solution expected2 = { - .primal_solution = std::make_optional( - {.variable_values = {{x1, 1.0}, {x2, 0.0}}, - .objective_value = 1.0, - .feasibility_status = SolutionStatus::kFeasible})}; + .primal_solution = + PrimalSolution{.variable_values = {{x1, 1.0}, {x2, 0.0}}, + .objective_value = 1.0, + .feasibility_status = SolutionStatus::kFeasible}}; for (int32_t solution_pool_size : {1, 2}) { SCOPED_TRACE(absl::StrCat("Solution pool size: ", solution_pool_size));