diff --git a/benchmarks/linear_programming/run_mps_files.sh b/benchmarks/linear_programming/run_mps_files.sh index e409cacaa..b731eb469 100755 --- a/benchmarks/linear_programming/run_mps_files.sh +++ b/benchmarks/linear_programming/run_mps_files.sh @@ -1,6 +1,6 @@ #!/bin/bash -# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 @@ -74,6 +74,7 @@ Optional Arguments: --n-batches Number of batches --log-to-console Log to console --model-list File containing a list of models to run + --pdlp-tolerances Tolerances for PDLP solver (default: 1e-4) -h, --help Show this help message and exit Examples: @@ -187,6 +188,11 @@ while [[ $# -gt 0 ]]; do MODEL_LIST="$2" shift 2 ;; + --pdlp-tolerances) + echo "PDLP_TOLERANCES: $2" + PDLP_TOLERANCES="$2" + shift 2 + ;; *) echo "Unknown argument: $1" print_help @@ -214,6 +220,7 @@ BATCH_NUM=${BATCH_NUM:-0} N_BATCHES=${N_BATCHES:-1} LOG_TO_CONSOLE=${LOG_TO_CONSOLE:-true} MODEL_LIST=${MODEL_LIST:-} +PDLP_TOLERANCES=${PDLP_TOLERANCES:-1e-4} # Validate GPUS_PER_INSTANCE if [[ "$GPUS_PER_INSTANCE" != "1" && "$GPUS_PER_INSTANCE" != "2" ]]; then @@ -413,6 +420,9 @@ worker() { if [ -n "$METHOD" ]; then args="$args --method $METHOD" fi + if [ -n "$PDLP_TOLERANCES" ]; then + args="$args --absolute-primal-tolerance $PDLP_TOLERANCES --absolute-dual-tolerance $PDLP_TOLERANCES --relative-primal-tolerance $PDLP_TOLERANCES --relative-dual-tolerance $PDLP_TOLERANCES --absolute-gap-tolerance $PDLP_TOLERANCES --relative-gap-tolerance $PDLP_TOLERANCES" + fi CUDA_VISIBLE_DEVICES=$gpu_devices cuopt_cli "$mps_file" --time-limit $TIME_LIMIT $args done diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index b6f9a12e1..af7b7c1c3 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -230,6 +230,24 @@ option(LUSOL "Disable LUSOL" OFF) FetchContent_MakeAvailable(papilo) +# PSLP - Lightweight C presolver for linear programs +# https://github.com/dance858/PSLP +FetchContent_Declare( + pslp + GIT_REPOSITORY "https://github.com/dance858/PSLP.git" + GIT_TAG "v0.0.4" + GIT_PROGRESS TRUE + EXCLUDE_FROM_ALL + SYSTEM +) + +# Build PSLP as static to embed in cuopt (avoids runtime library path issues) +set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS}) +set(BUILD_SHARED_LIBS OFF) +FetchContent_MakeAvailable(pslp) +set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED}) + + include(${rapids-cmake-dir}/cpm/rapids_logger.cmake) # generate logging macros rapids_cpm_rapids_logger(BUILD_EXPORT_SET cuopt-exports INSTALL_EXPORT_SET cuopt-exports) @@ -287,7 +305,11 @@ add_library(cuopt::cuopt ALIAS cuopt) # - include paths --------------------------------------------------------------------------------- message(STATUS "target include directories CUDSS_INCLUDES = ${CUDSS_INCLUDE}") -target_include_directories(cuopt SYSTEM PRIVATE "${papilo_SOURCE_DIR}/src" "${papilo_BINARY_DIR}") +target_include_directories(cuopt SYSTEM PRIVATE + "${papilo_SOURCE_DIR}/src" + "${papilo_BINARY_DIR}" + "${pslp_SOURCE_DIR}/include" +) target_include_directories(cuopt PRIVATE @@ -303,6 +325,10 @@ target_include_directories(cuopt ${CUDSS_INCLUDE} ) +# Link PSLP by file to avoid export dependency tracking +target_link_libraries(cuopt PRIVATE $) +add_dependencies(cuopt PSLP) + # ################################################################################################## # - link libraries -------------------------------------------------------------------------------- diff --git a/cpp/include/cuopt/linear_programming/constants.h b/cpp/include/cuopt/linear_programming/constants.h index c52c22c85..223e09ab4 100644 --- a/cpp/include/cuopt/linear_programming/constants.h +++ b/cpp/include/cuopt/linear_programming/constants.h @@ -129,4 +129,9 @@ #define CUOPT_OUT_OF_MEMORY 5 #define CUOPT_RUNTIME_ERROR 6 +#define CUOPT_PRESOLVE_DEFAULT -1 +#define CUOPT_PRESOLVE_OFF 0 +#define CUOPT_PRESOLVE_PAPILO 1 +#define CUOPT_PRESOLVE_PSLP 2 + #endif // CUOPT_CONSTANTS_H diff --git a/cpp/include/cuopt/linear_programming/mip/solver_settings.hpp b/cpp/include/cuopt/linear_programming/mip/solver_settings.hpp index c5c26884f..44842ac82 100644 --- a/cpp/include/cuopt/linear_programming/mip/solver_settings.hpp +++ b/cpp/include/cuopt/linear_programming/mip/solver_settings.hpp @@ -107,7 +107,7 @@ class mip_solver_settings_t { /** Initial primal solutions */ std::vector>> initial_solutions; bool mip_scaling = false; - bool presolve = true; + presolver_t presolver{presolver_t::Default}; // this is for extracting info from different places of the solver during // benchmarks benchmark_info_t* benchmark_info_ptr = nullptr; diff --git a/cpp/include/cuopt/linear_programming/pdlp/solver_settings.hpp b/cpp/include/cuopt/linear_programming/pdlp/solver_settings.hpp index 3b94fee14..33da038b9 100644 --- a/cpp/include/cuopt/linear_programming/pdlp/solver_settings.hpp +++ b/cpp/include/cuopt/linear_programming/pdlp/solver_settings.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -225,7 +226,7 @@ class pdlp_solver_settings_t { bool eliminate_dense_columns{true}; bool save_best_primal_so_far{false}; bool first_primal_feasible{false}; - bool presolve{false}; + presolver_t presolver{presolver_t::Default}; bool dual_postsolve{true}; int num_gpus{1}; method_t method{method_t::Concurrent}; diff --git a/cpp/include/cuopt/linear_programming/utilities/internals.hpp b/cpp/include/cuopt/linear_programming/utilities/internals.hpp index 7c0e42ede..fc90dec04 100644 --- a/cpp/include/cuopt/linear_programming/utilities/internals.hpp +++ b/cpp/include/cuopt/linear_programming/utilities/internals.hpp @@ -12,6 +12,7 @@ #include #include +#include namespace cuopt { namespace internals { @@ -111,5 +112,23 @@ struct parameter_info_t { std::string default_value; }; +/** + * @brief Enum representing the different presolvers that can be used to solve the + * linear programming problem. + * + * Default: Use the default presolver. + * None: No presolver. + * Papilo: Use the Papilo presolver. + * PSLP: Use the PSLP presolver. + * + * @note Default presolver is None. + */ +enum presolver_t : int { + Default = CUOPT_PRESOLVE_DEFAULT, + None = CUOPT_PRESOLVE_OFF, + Papilo = CUOPT_PRESOLVE_PAPILO, + PSLP = CUOPT_PRESOLVE_PSLP +}; + } // namespace linear_programming } // namespace cuopt diff --git a/cpp/src/dual_simplex/barrier.cu b/cpp/src/dual_simplex/barrier.cu index 5eef97bb8..b727cb506 100644 --- a/cpp/src/dual_simplex/barrier.cu +++ b/cpp/src/dual_simplex/barrier.cu @@ -1153,14 +1153,14 @@ class iteration_data_t { } #ifdef HISTOGRAM settings.log.printf("Row Nz # rows\n"); - for (i_t k = 0; k < m; k++) { + for (i_t k = 0; k < n; k++) { if (histogram_row[k] > 0) { settings.log.printf("%6d %6d\n", k, histogram_row[k]); } } #endif n_dense_rows = 0; for (i_t k = 0; k < m; k++) { - if (histogram_row[k] > .1 * n) { n_dense_rows++; } + if (row_nz[k] > .1 * n) { n_dense_rows++; } } for (i_t k = 0; k < m; k++) { diff --git a/cpp/src/dual_simplex/folding.cpp b/cpp/src/dual_simplex/folding.cpp index c59d827c5..f851e51d7 100644 --- a/cpp/src/dual_simplex/folding.cpp +++ b/cpp/src/dual_simplex/folding.cpp @@ -9,7 +9,9 @@ #include +#include #include +#include #include #include @@ -181,13 +183,13 @@ void compute_sums(const csc_matrix_t& A, } template -void find_colors_to_split(const std::vector colors_to_update, - const std::vector>& colors, - const std::vector>& vertices_to_refine_by_color, - const std::vector& vertex_to_sum, - std::vector& max_sum_by_color, - std::vector& min_sum_by_color, - std::vector& colors_to_split) +i_t find_colors_to_split(const std::vector& colors_to_update, + const std::vector>& colors, + const std::vector>& vertices_to_refine_by_color, + const std::vector& vertex_to_sum, + std::vector& max_sum_by_color, + std::vector& min_sum_by_color, + std::vector& colors_to_split) { for (i_t color : colors_to_update) { min_sum_by_color[color] = max_sum_by_color[color]; @@ -213,30 +215,31 @@ void find_colors_to_split(const std::vector colors_to_update, color, max_sum_by_color[color], min_sum_by_color[color]); - exit(1); + return -1; } if (min_sum_by_color[color] < max_sum_by_color[color]) { colors_to_split.push_back(color); } } + return 0; } template -void split_colors(i_t color, - i_t refining_color, - int8_t side_being_split, - std::vector& vertex_to_sum, - std::unordered_map>& color_sums, - std::unordered_map& sum_to_sizes, - std::vector>& colors, - std::vector& color_stack, - std::vector& color_in_stack, - std::vector& color_map_B, - std::vector& marked_vertices, - std::vector>& vertices_to_refine_by_color, - std::vector& min_sum_by_color, - std::vector& max_sum_by_color, - i_t& num_colors, - i_t& num_side_colors, - i_t& total_colors_seen) +i_t split_colors(i_t color, + i_t refining_color, + int8_t side_being_split, + std::vector& vertex_to_sum, + std::map>& color_sums, + std::map& sum_to_sizes, + std::vector>& colors, + std::vector& color_stack, + std::vector& color_in_stack, + std::vector& color_map_B, + std::vector& marked_vertices, + std::vector>& vertices_to_refine_by_color, + std::vector& min_sum_by_color, + std::vector& max_sum_by_color, + i_t& num_colors, + i_t& num_side_colors, + i_t& total_colors_seen) { bool in_stack = color_in_stack[color]; @@ -259,10 +262,10 @@ void split_colors(i_t color, for (i_t v : vertices_to_refine_by_color[color]) { printf("Vertex %d\n", v); } - exit(1); + return -1; } sum_to_sizes[0.0] += remaining_size; - color_sums[0.0] = std::vector(); + if (color_sums.count(0.0) == 0) { color_sums[0.0] = std::vector(); } } i_t max_size = -1; @@ -283,54 +286,78 @@ void split_colors(i_t color, color, color_sums.size(), in_stack); - exit(1); + return -1; + } + + // Paige-Tarjan O(n log n) optimization: + // The largest part keeps the original color id and inherits its stack slot. + // All other parts (smaller) become new colors and are added to the stack. + + bool largest_is_sum_zero = (max_sum == 0.0); + bool adjust_color_sums_zero = !largest_is_sum_zero && color_sums.count(0.0) > 0; + + // Collect sum==0.0 vertices in colors[color].vertices but not in vertices_to_refine_by_color + if (adjust_color_sums_zero) { + for (i_t v : color_sums[0.0]) { + vertex_to_sum[v] = std::numeric_limits::quiet_NaN(); + } + for (i_t v : colors[color].vertices) { + if (vertex_to_sum[v] == 0.0) { color_sums[0.0].push_back(v); } + } } i_t vertices_considered = 0; for (auto& [sum, vertices] : color_sums) { i_t size = vertices.size(); + if (sum == 0.0) { - const i_t additional_size = - (colors[color].vertices.size() - vertices_to_refine_by_color[color].size()); - size += additional_size; + i_t additional_size = + colors[color].vertices.size() - vertices_to_refine_by_color[color].size(); + if (!adjust_color_sums_zero) { size += additional_size; } } + bool is_largest = (sum == max_sum && size == max_size); vertices_considered += size; - if (sum == 0.0) { - // Push the current color back onto the stack - if (!in_stack && max_size != size && max_sum != sum) { - color_stack.push_back(color); - color_in_stack[color] = 1; - } - } else { - // Create a new color - colors.emplace_back(side_being_split, kActive, total_colors_seen, vertices); - // Push the new color onto the stack - if (in_stack || !(max_size == size && max_sum == sum)) { - color_stack.push_back(total_colors_seen); - color_in_stack[total_colors_seen] = 1; - } + if (is_largest) { + // Largest part keeps the original color id and inherits its stack slot, so it is not added to + // the stack + continue; + } - for (i_t v : vertices) { - color_map_B[v] = total_colors_seen; - } + colors.emplace_back(side_being_split, kActive, total_colors_seen, vertices); + + // All non-largest parts are added to the stack + color_stack.push_back(total_colors_seen); + color_in_stack[total_colors_seen] = 1; - total_colors_seen++; - num_colors++; - num_side_colors++; + for (i_t v : vertices) { + color_map_B[v] = total_colors_seen; } + + total_colors_seen++; + num_colors++; + num_side_colors++; } + if (vertices_considered != colors[color].vertices.size()) { printf("Vertices considered %d does not match color size %ld\n", vertices_considered, colors[color].vertices.size()); - exit(1); + return -1; } + // Remove vertices that moved to new colors from the original color for (i_t v : vertices_to_refine_by_color[color]) { if (color_map_B[v] != color) { colors[color].vertices.erase(v); } } + // Also remove sum=0 vertices if they were moved (sum=0 wasn't the largest) + if (!largest_is_sum_zero) { + for (i_t v : color_sums[0.0]) { + colors[color].vertices.erase(v); + } + } + if (colors[color].vertices.size() == 0) { colors[color].active = kInactive; num_colors--; @@ -340,6 +367,7 @@ void split_colors(i_t color, vertices_to_refine_by_color[color].clear(); max_sum_by_color[color] = std::numeric_limits::quiet_NaN(); min_sum_by_color[color] = std::numeric_limits::quiet_NaN(); + return 0; } template @@ -460,8 +488,8 @@ coloring_status_t color_graph(const csc_matrix_t& A, color_in_stack[0] = 1; color_in_stack[1] = 1; - std::unordered_map> color_sums; - std::unordered_map sum_to_sizes; + std::map> color_sums; + std::map sum_to_sizes; std::vector> vertices_to_refine_by_color(max_colors); std::vector max_sum_by_color(max_colors, std::numeric_limits::quiet_NaN()); @@ -500,57 +528,60 @@ coloring_status_t color_graph(const csc_matrix_t& A, max_sum_by_color); colors_to_split.clear(); - find_colors_to_split(colors_to_update, - colors, - vertices_to_refine_by_color, - vertex_to_sum, - max_sum_by_color, - min_sum_by_color, - colors_to_split); + i_t status = find_colors_to_split(colors_to_update, + colors, + vertices_to_refine_by_color, + vertex_to_sum, + max_sum_by_color, + min_sum_by_color, + colors_to_split); + if (status != 0) { return coloring_status_t::COLORING_FAILED; } // We now need to split the current colors into new colors if (refining_color.row_or_column == kRow) { // Refining color is a row color. // See if we need to split the column colors for (i_t color : colors_to_split) { - split_colors(color, - colors[refining_color_index].color, - kCol, - vertex_to_sum, - color_sums, - sum_to_sizes, - colors, - color_stack, - color_in_stack, - col_color_map, - marked_vertices, - vertices_to_refine_by_color, - min_sum_by_color, - max_sum_by_color, - num_colors, - num_col_colors, - total_colors_seen); + i_t status = split_colors(color, + colors[refining_color_index].color, + kCol, + vertex_to_sum, + color_sums, + sum_to_sizes, + colors, + color_stack, + color_in_stack, + col_color_map, + marked_vertices, + vertices_to_refine_by_color, + min_sum_by_color, + max_sum_by_color, + num_colors, + num_col_colors, + total_colors_seen); + if (status != 0) { return coloring_status_t::COLORING_FAILED; } } } else { // Refining color is a column color. // See if we need to split the row colors for (i_t color : colors_to_split) { - split_colors(color, - colors[refining_color_index].color, - kRow, - vertex_to_sum, - color_sums, - sum_to_sizes, - colors, - color_stack, - color_in_stack, - row_color_map, - marked_vertices, - vertices_to_refine_by_color, - min_sum_by_color, - max_sum_by_color, - num_colors, - num_row_colors, - total_colors_seen); + i_t status = split_colors(color, + colors[refining_color_index].color, + kRow, + vertex_to_sum, + color_sums, + sum_to_sizes, + colors, + color_stack, + color_in_stack, + row_color_map, + marked_vertices, + vertices_to_refine_by_color, + min_sum_by_color, + max_sum_by_color, + num_colors, + num_row_colors, + total_colors_seen); + if (status != 0) { return coloring_status_t::COLORING_FAILED; } } } @@ -674,11 +705,11 @@ coloring_status_t color_graph(const csc_matrix_t& A, #endif if (toc(last_log_time) > 1.0) { - last_log_time = tic(); - settings.log.printf("Folding: %d refinements %d colors in %.2fs", - num_refinements, - num_row_colors + num_col_colors, - toc(start_time)); + f_t elapsed = toc(start_time); + i_t current_colors = num_row_colors + num_col_colors; + last_log_time = tic(); + settings.log.printf( + "Folding: %d refinements %d colors in %.2fs\n", num_refinements, current_colors, elapsed); #ifdef PRINT_INFO settings.log.debug( "Number of refinements %8d. Number of colors %d (row colors %d, col colors %d) stack size " @@ -691,7 +722,7 @@ coloring_status_t color_graph(const csc_matrix_t& A, color_stack.size(), colors_per_refinement, projected_colors, - toc(start_time)); + elapsed); #endif } if (num_row_colors >= max_vertices) { @@ -1095,6 +1126,7 @@ void folding(lp_problem_t& problem, csc_matrix_t& C_s = presolve_info.folding_info.C_s; C_s_row.to_compressed_col(C_s); settings.log.debug("Folding: Completed C^s\n"); + #ifdef DEBUG fid = fopen("C_s.txt", "w"); C_s.write_matrix_market(fid); @@ -1180,6 +1212,7 @@ void folding(lp_problem_t& problem, fclose(fid); #endif +// Define DEBUG to enable expensive D^s D = I verification #ifdef DEBUG // Verify that D^s D = I csc_matrix_t D_product(reduced_cols, reduced_cols, 1); @@ -1199,6 +1232,7 @@ void folding(lp_problem_t& problem, return; } +#ifdef BUILD_MATRIX_X_AND_Y // Construct the matrix X // X = C C^s settings.log.debug("Folding: Constructing X\n"); @@ -1263,8 +1297,72 @@ void folding(lp_problem_t& problem, } } settings.log.printf("Folding: Verified Y is doubly stochastic\n"); +#else + // Verify X = Pi_P × C_s is doubly stochastic without forming X explicitly + // Row sums: X_row_sums = X × e = Pi_P × (C_s × e), e = ones(previous_rows) + // Column sums: X_col_sums = X^T × e = C_s^T × (Pi_P^T × e) + settings.log.printf("Folding: Verifying X is doubly stochastic (without forming X)\n"); + + // Row sums: X_row_sums = Pi_P × (C_s × e) + std::vector e_prev_rows(previous_rows, 1.0); + std::vector C_s_times_e(reduced_rows, 0.0); + matrix_vector_multiply(C_s, 1.0, e_prev_rows, 0.0, C_s_times_e); + std::vector X_row_sums(previous_rows, 0.0); + matrix_vector_multiply(Pi_P, 1.0, C_s_times_e, 0.0, X_row_sums); + for (i_t i = 0; i < previous_rows; i++) { + if (std::abs(X_row_sums[i] - 1.0) > 1e-6) { + settings.log.printf("Folding: X_row_sums[%d] = %f\n", i, X_row_sums[i]); + return; + } + } + + // Column sums: X_col_sums = C_s^T × (Pi_P^T × e) + std::vector Pi_P_T_times_e(reduced_rows, 0.0); + matrix_transpose_vector_multiply(Pi_P, 1.0, e_prev_rows, 0.0, Pi_P_T_times_e); + std::vector X_col_sums(previous_rows, 0.0); + matrix_transpose_vector_multiply(C_s, 1.0, Pi_P_T_times_e, 0.0, X_col_sums); + for (i_t j = 0; j < previous_rows; j++) { + if (std::abs(X_col_sums[j] - 1.0) > 1e-6) { + settings.log.printf("Folding: X_col_sums[%d] = %f\n", j, X_col_sums[j]); + return; + } + } + settings.log.printf("Folding: Verified X is doubly stochastic\n"); + + // Verify Y = D × D_s is doubly stochastic without forming Y explicitly + // Row sums: Y_row_sums = Y × e = D × (D_s × e), e = ones(previous_cols) + // Column sums: Y_col_sums = Y^T × e = D_s^T × (D^T × e) + settings.log.printf("Folding: Verifying Y is doubly stochastic (without forming Y)\n"); + + // Row sums: Y_row_sums = D × (D_s × e) + std::vector e_prev_cols(previous_cols, 1.0); + std::vector D_s_times_e(reduced_cols, 0.0); + matrix_vector_multiply(D_s, 1.0, e_prev_cols, 0.0, D_s_times_e); + std::vector Y_row_sums(previous_cols, 0.0); + matrix_vector_multiply(D, 1.0, D_s_times_e, 0.0, Y_row_sums); + for (i_t i = 0; i < previous_cols; i++) { + if (std::abs(Y_row_sums[i] - 1.0) > 1e-6) { + settings.log.printf("Folding: Y_row_sums[%d] = %f\n", i, Y_row_sums[i]); + return; + } + } + + // Column sums: Y_col_sums = D_s^T × (D^T × e) + std::vector D_T_times_e(reduced_cols, 0.0); + matrix_transpose_vector_multiply(D, 1.0, e_prev_cols, 0.0, D_T_times_e); + std::vector Y_col_sums(previous_cols, 0.0); + matrix_transpose_vector_multiply(D_s, 1.0, D_T_times_e, 0.0, Y_col_sums); + for (i_t j = 0; j < previous_cols; j++) { + if (std::abs(Y_col_sums[j] - 1.0) > 1e-6) { + settings.log.printf("Folding: Y_col_sums[%d] = %f\n", j, Y_col_sums[j]); + return; + } + } + settings.log.printf("Folding: Verified Y is doubly stochastic\n"); +#endif #endif - // Construct the matrix A_tilde + + // Construct the matrix A_tilde settings.log.debug("Folding: Constructing A_tilde\n"); i_t A_nnz = problem.A.col_start[n]; csc_matrix_t A_tilde = augmented; @@ -1284,6 +1382,7 @@ void folding(lp_problem_t& problem, csr_matrix_t A_tilde_row(A_tilde.m, A_tilde.n, A_tilde.col_start[A_tilde.n]); A_tilde.to_compressed_row(A_tilde_row); +// Define DEBUG to enable expensive partition verification #ifdef DEBUG std::vector row_to_color(A_tilde.m, -1); for (i_t k = 0; k < total_colors_seen; k++) { @@ -1307,129 +1406,112 @@ void folding(lp_problem_t& problem, } } - // Check that the partition is equitable - for (i_t k = 0; k < total_colors_seen; k++) { - const color_t col_color = colors[k]; - if (col_color.active == kActive) { - if (col_color.row_or_column == kCol) { - // Check sum_{w in color} Avw = sum_{w in color} Avprimew for all (v, vprime) in row color P - for (i_t h = 0; h < total_colors_seen; h++) { - const color_t row_color = colors[h]; - if (row_color.active == kActive && row_color.row_or_column == kRow) { - for (i_t u : row_color.vertices) { - for (i_t v : row_color.vertices) { - if (u != v) { - f_t sum_Av = 0.0; - f_t sum_Avprime = 0.0; - for (i_t p = A_tilde_row.row_start[u]; p < A_tilde_row.row_start[u + 1]; p++) { - const i_t j = A_tilde_row.j[p]; - if (col_to_color[j] == k) { sum_Av += A_tilde_row.x[p]; } - } - for (i_t p = A_tilde_row.row_start[v]; p < A_tilde_row.row_start[v + 1]; p++) { - const i_t j = A_tilde_row.j[p]; - if (col_to_color[j] == k) { sum_Avprime += A_tilde_row.x[p]; } - } - if (std::abs(sum_Av - sum_Avprime) > 1e-12) { - settings.log.printf( - "Folding: u %d v %d row color %d sum_A%d: %f sum_A%d: = %f\n", - u, - v, - h, - u, - sum_Av, - v, - sum_Avprime); - settings.log.printf("Folding: row color %d vertices: ", h); - for (i_t u : row_color.vertices) { - settings.log.printf("%d(%d) ", u, row_to_color[u]); - } - settings.log.printf("\n"); - settings.log.printf("col color %d vertices: ", k); - for (i_t v : col_color.vertices) { - settings.log.printf("%d(%d) ", v, col_to_color[v]); - } - settings.log.printf("\n"); - settings.log.printf("row %d\n", u); - for (i_t p = A_tilde_row.row_start[u]; p < A_tilde_row.row_start[u + 1]; p++) { - const i_t j = A_tilde_row.j[p]; - settings.log.printf("row %d col %d column color %d value %e\n", - u, - j, - col_to_color[j], - A_tilde_row.x[p]); - if (col_to_color[j] == k) { sum_Av += A_tilde_row.x[p]; } - } - settings.log.printf("row %d\n", v); - for (i_t p = A_tilde_row.row_start[v]; p < A_tilde_row.row_start[v + 1]; p++) { - const i_t j = A_tilde_row.j[p]; - settings.log.printf("row %d col %d column color %d value %e\n", - v, - j, - col_to_color[j], - A_tilde_row.x[p]); - if (col_to_color[j] == k) { sum_Avprime += A_tilde_row.x[p]; } - } - settings.log.printf("total colors seen %d\n", total_colors_seen); - return; - } - } - } - } - } - } + // Verify partition is equitable (only in DEBUG mode - expensive for large problems) + f_t equitability_tol = 1e-12; + settings.log.printf("Folding: Checking partition equitability (tolerance = %.2e)\n", + equitability_tol); + + f_t max_col_partition_error = 0.0; + f_t max_row_partition_error = 0.0; + i_t col_partition_violations = 0; + i_t row_partition_violations = 0; + + // Step 1: Precompute row_col_color_sum[row][col_color] + std::vector> row_col_color_sum(A_tilde.m); + for (i_t row = 0; row < A_tilde.m; row++) { + for (i_t p = A_tilde_row.row_start[row]; p < A_tilde_row.row_start[row + 1]; p++) { + i_t col = A_tilde_row.j[p]; + i_t cc = col_to_color[col]; + if (cc >= 0) { row_col_color_sum[row][cc] += A_tilde_row.x[p]; } + } + } + + // Step 2: Verify column partition + for (i_t h = 0; h < total_colors_seen; h++) { + const color_t& row_color = colors[h]; + if (row_color.active != kActive || row_color.row_or_column != kRow) continue; + if (row_color.vertices.size() < 2) continue; + + auto it = row_color.vertices.begin(); + i_t ref_row = *it; + ++it; + for (; it != row_color.vertices.end(); ++it) { + i_t u = *it; + for (auto& [cc, ref_sum] : row_col_color_sum[ref_row]) { + f_t u_sum = row_col_color_sum[u][cc]; + f_t diff = std::abs(ref_sum - u_sum); + if (diff > max_col_partition_error) max_col_partition_error = diff; + if (diff > equitability_tol) col_partition_violations++; } + for (auto& [cc, u_sum] : row_col_color_sum[u]) { + f_t ref_sum = row_col_color_sum[ref_row][cc]; + f_t diff = std::abs(ref_sum - u_sum); + if (diff > max_col_partition_error) max_col_partition_error = diff; + if (diff > equitability_tol) col_partition_violations++; + } + } + } + settings.log.printf("Folding: Column partition max error = %.2e, violations = %d\n", + max_col_partition_error, + col_partition_violations); + + // Step 3: Precompute col_row_color_sum[col][row_color] + std::vector> col_row_color_sum(A_tilde.n); + for (i_t col = 0; col < A_tilde.n; col++) { + for (i_t p = A_tilde.col_start[col]; p < A_tilde.col_start[col + 1]; p++) { + i_t row = A_tilde.i[p]; + i_t rc = row_to_color[row]; + if (rc >= 0) { col_row_color_sum[col][rc] += A_tilde.x[p]; } } } - settings.log.printf("Folding: Verified that the column partition is equitable\n"); - for (i_t k = 0; k < num_colors; k++) { - const color_t& row_color = colors[k]; - if (row_color.active == kActive) { - if (row_color.row_or_column == kRow) { - for (i_t h = 0; h < num_colors; h++) { - const color_t& col_color = colors[h]; - if (col_color.active == kActive && col_color.row_or_column == kCol) { - for (i_t u : col_color.vertices) { - for (i_t v : col_color.vertices) { - if (u != v) { - f_t sum_A_u = 0.0; - f_t sum_A_v = 0.0; - for (i_t p = A_tilde.col_start[u]; p < A_tilde.col_start[u + 1]; p++) { - const i_t i = A_tilde.i[p]; - if (row_to_color[i] == k) { sum_A_u += A_tilde.x[p]; } - } - for (i_t p = A_tilde.col_start[v]; p < A_tilde.col_start[v + 1]; p++) { - const i_t i = A_tilde.i[p]; - if (row_to_color[i] == k) { sum_A_v += A_tilde.x[p]; } - } - if (std::abs(sum_A_u - sum_A_v) > 1e-12) { - settings.log.printf( - "Folding: u %d v %d row color %d sum_A%d: %f sum_A%d: = %f\n", - u, - v, - k, - u, - sum_A_u, - v, - sum_A_v); - return; - } - } - } - } - } - } + // Step 4: Verify row partition + for (i_t k = 0; k < total_colors_seen; k++) { + const color_t& col_color = colors[k]; + if (col_color.active != kActive || col_color.row_or_column != kCol) continue; + if (col_color.vertices.size() < 2) continue; + + auto it = col_color.vertices.begin(); + i_t ref_col = *it; + ++it; + for (; it != col_color.vertices.end(); ++it) { + i_t v = *it; + for (auto& [rc, ref_sum] : col_row_color_sum[ref_col]) { + f_t v_sum = 0.0; + auto it_v = col_row_color_sum[v].find(rc); + if (it_v != col_row_color_sum[v].end()) { v_sum = it_v->second; } + f_t diff = std::abs(ref_sum - v_sum); + if (diff > max_row_partition_error) max_row_partition_error = diff; + if (diff > equitability_tol) row_partition_violations++; + } + for (auto& [rc, v_sum] : col_row_color_sum[v]) { + f_t ref_sum = col_row_color_sum[ref_col][rc]; + f_t diff = std::abs(ref_sum - v_sum); + if (diff > max_row_partition_error) max_row_partition_error = diff; + if (diff > equitability_tol) row_partition_violations++; } } } - settings.log.printf("Folding: Verified that the row partition is equitable\n"); + settings.log.printf("Folding: Row partition max error = %.2e, violations = %d\n", + max_row_partition_error, + row_partition_violations); + if (col_partition_violations == 0 && row_partition_violations == 0) { + settings.log.printf("Folding: Partition is equitable within tolerance\n"); + } else { + settings.log.printf("Folding: Partition has %d column + %d row violations\n", + col_partition_violations, + row_partition_violations); + } + +#ifdef BUILD_MATRIX_X_AND_Y fid = fopen("X.txt", "w"); X.write_matrix_market(fid); fclose(fid); fid = fopen("Y.txt", "w"); Y.write_matrix_market(fid); fclose(fid); +#endif #endif if (A_tilde.m != previous_rows || A_tilde.n != previous_cols) { @@ -1443,7 +1525,10 @@ void folding(lp_problem_t& problem, settings.log.debug("Folding: partial A_tilde nz %d predicted %d\n", nnz, A_nnz + 2 * nz_ub); +// Define DEBUG to enable expensive XA=AY verification #ifdef DEBUG +#ifdef BUILD_MATRIX_X_AND_Y + FILE* fid; // Verify that XA = AY csc_matrix_t XA(previous_rows, previous_cols, 1); multiply(X, A_tilde, XA); @@ -1458,8 +1543,86 @@ void folding(lp_problem_t& problem, csc_matrix_t XA_AY_error(previous_rows, previous_cols, 1); add(XA, AY, 1.0, -1.0, XA_AY_error); printf("|| XA - AY ||_1 = %f\n", XA_AY_error.norm1()); +#else + settings.log.printf("Folding: Verifying that XA = AY\n"); + + // Instead of computing XA and AY and checking for equality entrywise, + // repeatedly generate a random vector v, compute XA*v and AY*v, and check if they are close. + + { + settings.log.printf("Folding: Verifying that XA*v = AY*v for random vectors v\n"); + int num_trials = 5; + std::vector v(previous_cols, 0.0); + std::vector x1(previous_rows, 0.0); + std::vector x2(previous_rows, 0.0); + + std::mt19937 rng(42); // fixed seed for repeatability + std::uniform_real_distribution dist(-1.0, 1.0); + + for (int trial = 0; trial < num_trials; ++trial) { + f_t norm_v = 0.0; + // Generate random vector v + for (i_t i = 0; i < previous_cols; ++i) { + v[i] = dist(rng); + norm_v += v[i] * v[i]; + } + norm_v = std::sqrt(norm_v); + // Compute x1 = XA * v = Pi_P * (C_s * (A_tilde * v)) + matrix_vector_multiply(A_tilde, 1.0, v, 0.0, x1); // x1 = A_tilde * v + std::vector C_s_x1(reduced_rows, 0.0); + matrix_vector_multiply(C_s, 1.0, x1, 0.0, C_s_x1); // C_s * (A_tilde * v) + std::vector xa_v(previous_rows, 0.0); + matrix_vector_multiply(Pi_P, 1.0, C_s_x1, 0.0, xa_v); // Pi_P * (C_s * (A_tilde * v)) + + // Compute x2 = AY * v = A_tilde * (D * (D_s * v)) + std::vector D_s_v(reduced_cols, 0.0); + matrix_vector_multiply(D_s, 1.0, v, 0.0, D_s_v); // D_s * v + std::vector yv(previous_cols, 0.0); + matrix_vector_multiply(D, 1.0, D_s_v, 0.0, yv); // D * (D_s * v) + std::vector ay_v(previous_rows, 0.0); + matrix_vector_multiply(A_tilde, 1.0, yv, 0.0, ay_v); // AY*v = A_tilde * (D * (D_s * v)) + + // Compute norm-2 difference + f_t diff = 0.0; + for (i_t i = 0; i < previous_rows; ++i) { + diff += (xa_v[i] - ay_v[i]) * (xa_v[i] - ay_v[i]); + } + diff = std::sqrt(diff); + settings.log.printf( + "Folding: Trial %d: ||XA*v - AY*v||_2 = %e, ||v||_2 = %e\n", trial, diff, norm_v); + + if (diff > 1e-7 * norm_v) { + settings.log.printf("Folding: Large difference detected in XA*v vs AY*v, ||diff||_2 = %e\n", + diff); + // Find and print worst offending rows + std::vector> diffs_with_idx(previous_rows); + for (i_t i = 0; i < previous_rows; ++i) { + diffs_with_idx[i] = {std::abs(xa_v[i] - ay_v[i]), i}; + } + std::partial_sort(diffs_with_idx.begin(), + diffs_with_idx.begin() + std::min((i_t)5, previous_rows), + diffs_with_idx.end(), + std::greater>()); + for (i_t k = 0; k < std::min((i_t)5, previous_rows); ++k) { + i_t i = diffs_with_idx[k].second; + settings.log.printf(" i=%d: (XA*v)[%d]=%e (AY*v)[%d]=%e diff=%e\n", + i, + i, + xa_v[i], + i, + ay_v[i], + xa_v[i] - ay_v[i]); + } + return; + } + } + settings.log.printf( + "Folding: All random vector multiplication checks (XA*v==AY*v) succeeded!\n"); + } #endif - // Construct the matrix A_prime +#endif + + // Construct the matrix A_prime settings.log.debug("Folding: Constructing A_prime\n"); csc_matrix_t A_prime(reduced_rows, reduced_cols, 1); csc_matrix_t AD(previous_rows, reduced_cols, 1); @@ -1539,7 +1702,8 @@ void folding(lp_problem_t& problem, settings.log.printf("Folding: time %.2f seconds\n", toc(start_time)); #ifdef SOLVE_REDUCED_PROBLEM - // Solve the reduced problem + // Solve the reduced problem immediately after folding, instead of after presolve is complete. + // Useful for verifying that the folding is correct. lp_solution_t reduced_solution(reduced_rows, reduced_cols); simplex_solver_settings_t reduced_settings; reduced_settings.folding = false; diff --git a/cpp/src/dual_simplex/iterative_refinement.hpp b/cpp/src/dual_simplex/iterative_refinement.hpp index 001e68a39..3ee717928 100644 --- a/cpp/src/dual_simplex/iterative_refinement.hpp +++ b/cpp/src/dual_simplex/iterative_refinement.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include "dual_simplex/dense_vector.hpp" @@ -217,6 +218,13 @@ f_t iterative_refinement_gmres(T& op, // Z[k] = M^{-1} V[k], i.e., apply right preconditioner and store op.solve(V[k], Z[k]); + // Check if solve produced NaN (indicates cuDSS failure) + f_t z_norm = vector_norm_inf(Z[k]); + if (!std::isfinite(z_norm)) { + CUOPT_LOG_INFO("GMRES IR: solve at k=%d produced NaN, terminating", k); + return std::numeric_limits::quiet_NaN(); + } + // w = A * Z[k] op.a_multiply(1.0, Z[k], 0.0, V[k + 1]); @@ -241,19 +249,31 @@ f_t iterative_refinement_gmres(T& op, } // H[k+1][k] = ||w|| - f_t h_k1k = vector_norm2(V[k + 1]); - H[k + 1][k] = h_k1k; - if (h_k1k != 0.0) { - // V[k+1] = V[k+1] / H[k+1][k] - f_t inv_h = f_t(1) / h_k1k; - thrust::transform(op.data_.handle_ptr->get_thrust_policy(), - V[k + 1].data(), - V[k + 1].data() + x.size(), - V[k + 1].data(), - scale_op{inv_h}); - RAFT_CHECK_CUDA(op.data_.handle_ptr->get_stream()); + f_t h_k1k = vector_norm2(V[k + 1]); + + // Check for "lucky breakdown" BEFORE using h_k1k - Krylov subspace has converged + // When h_k1k is zero, very small, or NaN, V[k+1] is in span of previous V's + // Must check before storing in H to avoid NaN propagation in Givens rotations + if (!std::isfinite(h_k1k) || h_k1k < 1e-14) { + if (show_info) { + CUOPT_LOG_INFO("GMRES IR: lucky breakdown at k=%d, h_k1k=%e (before Givens)", k, h_k1k); + } + // Don't store NaN in H, don't update Givens - just exit with current solution + // k iterations are already complete and usable + break; } + H[k + 1][k] = h_k1k; + + // V[k+1] = V[k+1] / H[k+1][k] + f_t inv_h = f_t(1) / h_k1k; + thrust::transform(op.data_.handle_ptr->get_thrust_policy(), + V[k + 1].data(), + V[k + 1].data() + x.size(), + V[k + 1].data(), + scale_op{inv_h}); + RAFT_CHECK_CUDA(op.data_.handle_ptr->get_stream()); + // Apply Given's rotations to new column for (int i = 0; i < k; ++i) { f_t temp = cs[i] * H[i][k] + sn[i] * H[i + 1][k]; diff --git a/cpp/src/dual_simplex/solve.cpp b/cpp/src/dual_simplex/solve.cpp index 37297d9be..ca54333a9 100644 --- a/cpp/src/dual_simplex/solve.cpp +++ b/cpp/src/dual_simplex/solve.cpp @@ -298,9 +298,9 @@ lp_status_t solve_linear_program_with_advanced_basis( template lp_status_t solve_linear_program_with_barrier(const user_problem_t& user_problem, const simplex_solver_settings_t& settings, + f_t start_time, lp_solution_t& solution) { - f_t start_time = tic(); lp_status_t status = lp_status_t::UNSET; lp_problem_t original_lp(user_problem.handle_ptr, 1, 1, 1); @@ -620,12 +620,21 @@ lp_status_t solve_linear_program_with_barrier(const user_problem_t& us return barrier_status; } +template +lp_status_t solve_linear_program_with_barrier(const user_problem_t& user_problem, + const simplex_solver_settings_t& settings, + lp_solution_t& solution) +{ + f_t start_time = tic(); + return solve_linear_program_with_barrier(user_problem, settings, start_time, solution); +} + template lp_status_t solve_linear_program(const user_problem_t& user_problem, const simplex_solver_settings_t& settings, + f_t start_time, lp_solution_t& solution) { - f_t start_time = tic(); lp_problem_t original_lp(user_problem.handle_ptr, 1, 1, 1); std::vector new_slacks; dualize_info_t dualize_info; @@ -647,6 +656,15 @@ lp_status_t solve_linear_program(const user_problem_t& user_problem, return status; } +template +lp_status_t solve_linear_program(const user_problem_t& user_problem, + const simplex_solver_settings_t& settings, + lp_solution_t& solution) +{ + f_t start_time = tic(); + return solve_linear_program(user_problem, settings, start_time, solution); +} + template i_t solve(const user_problem_t& problem, const simplex_solver_settings_t& settings, @@ -744,8 +762,19 @@ template lp_status_t solve_linear_program_with_barrier( const simplex_solver_settings_t& settings, lp_solution_t& solution); +template lp_status_t solve_linear_program_with_barrier( + const user_problem_t& user_problem, + const simplex_solver_settings_t& settings, + double start_time, + lp_solution_t& solution); + +template lp_status_t solve_linear_program(const user_problem_t& user_problem, + const simplex_solver_settings_t& settings, + lp_solution_t& solution); + template lp_status_t solve_linear_program(const user_problem_t& user_problem, const simplex_solver_settings_t& settings, + double start_time, lp_solution_t& solution); template int solve(const user_problem_t& user_problem, diff --git a/cpp/src/dual_simplex/solve.hpp b/cpp/src/dual_simplex/solve.hpp index 6292df637..0ce43d161 100644 --- a/cpp/src/dual_simplex/solve.hpp +++ b/cpp/src/dual_simplex/solve.hpp @@ -82,9 +82,21 @@ lp_status_t solve_linear_program_with_barrier(const user_problem_t& us const simplex_solver_settings_t& settings, lp_solution_t& solution); +template +lp_status_t solve_linear_program_with_barrier(const user_problem_t& user_problem, + const simplex_solver_settings_t& settings, + f_t start_time, + lp_solution_t& solution); + +template +lp_status_t solve_linear_program(const user_problem_t& user_problem, + const simplex_solver_settings_t& settings, + lp_solution_t& solution); + template lp_status_t solve_linear_program(const user_problem_t& user_problem, const simplex_solver_settings_t& settings, + f_t start_time, lp_solution_t& solution); template diff --git a/cpp/src/linear_programming/solve.cu b/cpp/src/linear_programming/solve.cu index db15eed82..751c07420 100644 --- a/cpp/src/linear_programming/solve.cu +++ b/cpp/src/linear_programming/solve.cu @@ -416,7 +416,7 @@ run_barrier(dual_simplex::user_problem_t& user_problem, dual_simplex::lp_solution_t solution(user_problem.num_rows, user_problem.num_cols); auto status = dual_simplex::solve_linear_program_with_barrier( - user_problem, barrier_settings, solution); + user_problem, barrier_settings, timer.get_tic_start(), solution); CUOPT_LOG_CONDITIONAL_INFO( !settings.inside_mip, "Barrier finished in %.2f seconds", timer.elapsed_time()); @@ -474,12 +474,11 @@ run_dual_simplex(dual_simplex::user_problem_t& user_problem, pdlp_solver_settings_t const& settings, const timer_t& timer) { - timer_t timer_dual_simplex(timer.remaining_time()); f_t norm_user_objective = dual_simplex::vector_norm2(user_problem.objective); f_t norm_rhs = dual_simplex::vector_norm2(user_problem.rhs); dual_simplex::simplex_solver_settings_t dual_simplex_settings; - dual_simplex_settings.time_limit = timer.remaining_time(); + dual_simplex_settings.time_limit = settings.time_limit; dual_simplex_settings.iteration_limit = settings.iteration_limit; dual_simplex_settings.concurrent_halt = settings.concurrent_halt; if (dual_simplex_settings.concurrent_halt != nullptr) { @@ -488,13 +487,11 @@ run_dual_simplex(dual_simplex::user_problem_t& user_problem, } dual_simplex::lp_solution_t solution(user_problem.num_rows, user_problem.num_cols); - auto status = - dual_simplex::solve_linear_program(user_problem, dual_simplex_settings, solution); + auto status = dual_simplex::solve_linear_program( + user_problem, dual_simplex_settings, timer.get_tic_start(), solution); - CUOPT_LOG_CONDITIONAL_INFO(!settings.inside_mip, - "Dual simplex finished in %.2f seconds, total time %.2f", - timer_dual_simplex.elapsed_time(), - timer.elapsed_time()); + CUOPT_LOG_CONDITIONAL_INFO( + !settings.inside_mip, "Dual simplex finished in %.2f seconds", timer.elapsed_time()); if (settings.concurrent_halt != nullptr && (status == dual_simplex::lp_status_t::OPTIMAL || status == dual_simplex::lp_status_t::UNBOUNDED || @@ -551,21 +548,18 @@ optimization_problem_solution_t run_pdlp(detail::problem_t& bool is_batch_mode) { auto start_solver = std::chrono::high_resolution_clock::now(); - f_t start_time = dual_simplex::tic(); timer_t timer_pdlp(timer.remaining_time()); auto sol = run_pdlp_solver(problem, settings, timer, is_batch_mode); auto pdlp_solve_time = timer_pdlp.elapsed_time(); sol.set_solve_time(timer.elapsed_time()); CUOPT_LOG_CONDITIONAL_INFO(!settings.inside_mip, "PDLP finished"); if (sol.get_termination_status() != pdlp_termination_status_t::ConcurrentLimit) { - CUOPT_LOG_CONDITIONAL_INFO( - !settings.inside_mip, - "Status: %s Objective: %.8e Iterations: %d Time: %.3fs, Total time %.3fs", - sol.get_termination_status_string().c_str(), - sol.get_objective_value(), - sol.get_additional_termination_information().number_of_steps_taken, - pdlp_solve_time, - sol.get_solve_time()); + CUOPT_LOG_CONDITIONAL_INFO(!settings.inside_mip, + "Status: %s Objective: %.8e Iterations: %d Time: %.3fs", + sol.get_termination_status_string().c_str(), + sol.get_objective_value(), + sol.get_additional_termination_information().number_of_steps_taken, + sol.get_solve_time()); } const bool do_crossover = settings.crossover; @@ -577,13 +571,13 @@ optimization_problem_solution_t run_pdlp(detail::problem_t& dual_simplex::lp_solution_t initial_solution(1, 1); translate_to_crossover_problem(problem, sol, lp, initial_solution); dual_simplex::simplex_solver_settings_t dual_simplex_settings; - dual_simplex_settings.time_limit = timer.remaining_time(); + dual_simplex_settings.time_limit = settings.time_limit; dual_simplex_settings.iteration_limit = settings.iteration_limit; dual_simplex_settings.concurrent_halt = settings.concurrent_halt; dual_simplex::lp_solution_t vertex_solution(lp.num_rows, lp.num_cols); std::vector vstatus(lp.num_cols); dual_simplex::crossover_status_t crossover_status = dual_simplex::crossover( - lp, dual_simplex_settings, initial_solution, start_time, vertex_solution, vstatus); + lp, dual_simplex_settings, initial_solution, timer.get_tic_start(), vertex_solution, vstatus); pdlp_termination_status_t termination_status = pdlp_termination_status_t::TimeLimit; auto to_termination_status = [](dual_simplex::crossover_status_t status) { switch (status) { @@ -759,7 +753,7 @@ optimization_problem_solution_t run_batch_pdlp( pdlp_solver_settings_t warm_start_settings = settings; warm_start_settings.new_bounds.clear(); warm_start_settings.method = cuopt::linear_programming::method_t::PDLP; - warm_start_settings.presolve = false; + warm_start_settings.presolver = cuopt::linear_programming::presolver_t::None; warm_start_settings.pdlp_solver_mode = pdlp_solver_mode_t::Stable3; warm_start_settings.detect_infeasibility = false; warm_start_settings.iteration_limit = iteration_limit; @@ -790,7 +784,7 @@ optimization_problem_solution_t run_batch_pdlp( pdlp_solver_settings_t batch_settings = settings; const auto original_new_bounds = batch_settings.new_bounds; batch_settings.method = cuopt::linear_programming::method_t::PDLP; - batch_settings.presolve = false; + batch_settings.presolver = presolver_t::None; batch_settings.pdlp_solver_mode = pdlp_solver_mode_t::Stable3; batch_settings.detect_infeasibility = false; batch_settings.iteration_limit = iteration_limit; @@ -903,7 +897,7 @@ optimization_problem_solution_t run_concurrent( const timer_t& timer, bool is_batch_mode) { - CUOPT_LOG_CONDITIONAL_INFO(!settings.inside_mip, "Running concurrent\n"); + CUOPT_LOG_CONDITIONAL_INFO(!settings.inside_mip, "Running concurrent (showing only PDLP log)\n"); timer_t timer_concurrent(timer.remaining_time()); // Copy the settings so that we can set the concurrent halt pointer @@ -1003,10 +997,7 @@ optimization_problem_solution_t run_concurrent( 1); f_t end_time = timer.elapsed_time(); - CUOPT_LOG_CONDITIONAL_INFO(!settings.inside_mip, - "Concurrent time: %.3fs, total time %.3fs", - timer_concurrent.elapsed_time(), - end_time); + CUOPT_LOG_CONDITIONAL_INFO(!settings.inside_mip, "Concurrent time: %.3fs", end_time); // Check status to see if we should return the pdlp solution or the dual simplex solution if (!settings.inside_mip && (sol_dual_simplex.get_termination_status() == pdlp_termination_status_t::Optimal || @@ -1022,6 +1013,16 @@ optimization_problem_solution_t run_concurrent( sol_pdlp.get_objective_value(), sol_pdlp.get_additional_termination_information().number_of_steps_taken, end_time); + CUOPT_LOG_CONDITIONAL_INFO( + !settings.inside_mip, + "Primal residual (abs/rel): %8.2e/%8.2e", + sol_pdlp.get_additional_termination_information().l2_primal_residual, + sol_pdlp.get_additional_termination_information().l2_relative_primal_residual); + CUOPT_LOG_CONDITIONAL_INFO( + !settings.inside_mip, + "Dual residual (abs/rel): %8.2e/%8.2e", + sol_pdlp.get_additional_termination_information().l2_dual_residual, + sol_pdlp.get_additional_termination_information().l2_relative_dual_residual); return sol_pdlp; } else if (sol_barrier.get_termination_status() == pdlp_termination_status_t::Optimal) { CUOPT_LOG_CONDITIONAL_INFO(!settings.inside_mip, "Solved with barrier"); @@ -1034,6 +1035,16 @@ optimization_problem_solution_t run_concurrent( sol_pdlp.get_objective_value(), sol_pdlp.get_additional_termination_information().number_of_steps_taken, end_time); + CUOPT_LOG_CONDITIONAL_INFO( + !settings.inside_mip, + "Primal residual (abs/rel): %8.2e/%8.2e", + sol_pdlp.get_additional_termination_information().l2_primal_residual, + sol_pdlp.get_additional_termination_information().l2_relative_primal_residual); + CUOPT_LOG_CONDITIONAL_INFO( + !settings.inside_mip, + "Dual residual (abs/rel): %8.2e/%8.2e", + sol_pdlp.get_additional_termination_information().l2_dual_residual, + sol_pdlp.get_additional_termination_information().l2_relative_dual_residual); return sol_pdlp; } else if (sol_pdlp.get_termination_status() == pdlp_termination_status_t::Optimal) { CUOPT_LOG_CONDITIONAL_INFO(!settings.inside_mip, "Solved with PDLP"); @@ -1087,8 +1098,8 @@ optimization_problem_solution_t solve_lp( if (op_problem.has_quadratic_objective()) { CUOPT_LOG_INFO("Problem has a quadratic objective. Using Barrier."); - settings.method = method_t::Barrier; - settings.presolve = false; + settings.method = method_t::Barrier; + settings.presolver = presolver_t::None; // check for sense of the problem if (op_problem.get_sense()) { CUOPT_LOG_ERROR("Quadratic problems must be minimized"); @@ -1127,9 +1138,15 @@ optimization_problem_solution_t solve_lp( auto lp_timer = cuopt::timer_t(settings.time_limit); detail::problem_t problem(op_problem); + // handle default presolve + if (settings.presolver == presolver_t::Default) { + settings.presolver = presolver_t::PSLP; + CUOPT_LOG_INFO("Using PSLP presolver"); + } + [[maybe_unused]] double presolve_time = 0.0; std::unique_ptr> presolver; - auto run_presolve = settings.presolve; + auto run_presolve = settings.presolver != presolver_t::None; run_presolve = run_presolve && settings.get_pdlp_warm_start_data().total_pdlp_iterations_ == -1; if (!run_presolve && !settings_const.inside_mip) { CUOPT_LOG_INFO("Third-party presolve is disabled, skipping"); @@ -1145,6 +1162,7 @@ optimization_problem_solution_t solve_lp( presolver = std::make_unique>(); auto result = presolver->apply(op_problem, cuopt::linear_programming::problem_category_t::LP, + settings.presolver, settings.dual_postsolve, settings.tolerances.absolute_primal_tolerance, settings.tolerances.relative_primal_tolerance, @@ -1153,9 +1171,63 @@ optimization_problem_solution_t solve_lp( return optimization_problem_solution_t( pdlp_termination_status_t::PrimalInfeasible, op_problem.get_handle_ptr()->get_stream()); } + + // Handle case where presolve completely solved the problem (reduced to 0 rows/cols) + // Must check before constructing problem_t since it fails on empty problems + if (result->reduced_problem.get_n_variables() == 0 && + result->reduced_problem.get_n_constraints() == 0) { + CUOPT_LOG_INFO("Presolve completely solved the problem"); + presolve_time = lp_timer.elapsed_time(); + CUOPT_LOG_INFO("%s presolve time: %.2fs", + settings.presolver == presolver_t::PSLP ? "PSLP" : "Papilo", + presolve_time); + + // Create empty solution vectors for the reduced problem + rmm::device_uvector empty_primal(0, op_problem.get_handle_ptr()->get_stream()); + rmm::device_uvector empty_dual(0, op_problem.get_handle_ptr()->get_stream()); + rmm::device_uvector empty_reduced_costs(0, op_problem.get_handle_ptr()->get_stream()); + + // Run postsolve to get the full solution + presolver->undo(empty_primal, + empty_dual, + empty_reduced_costs, + cuopt::linear_programming::problem_category_t::LP, + false, // status_to_skip + settings.dual_postsolve, + op_problem.get_handle_ptr()->get_stream()); + + // Create termination info with the objective from presolve + typename optimization_problem_solution_t::additional_termination_information_t + term_info; + term_info.primal_objective = result->reduced_problem.get_objective_offset(); + term_info.dual_objective = result->reduced_problem.get_objective_offset(); + term_info.number_of_steps_taken = 0; + term_info.solve_time = presolve_time; + term_info.l2_primal_residual = 0.0; + term_info.l2_dual_residual = 0.0; + term_info.gap = 0.0; + + std::vector< + typename optimization_problem_solution_t::additional_termination_information_t> + term_vec{term_info}; + std::vector status_vec{pdlp_termination_status_t::Optimal}; + + CUOPT_LOG_INFO("Status: Optimal Objective: %f", term_info.primal_objective); + return optimization_problem_solution_t(empty_primal, + empty_dual, + empty_reduced_costs, + op_problem.get_objective_name(), + op_problem.get_variable_names(), + op_problem.get_row_names(), + std::move(term_vec), + std::move(status_vec)); + } + problem = detail::problem_t(result->reduced_problem); presolve_time = lp_timer.elapsed_time(); - CUOPT_LOG_INFO("Papilo presolve time: %f", presolve_time); + CUOPT_LOG_INFO("%s presolve time: %.2fs", + settings.presolver == presolver_t::PSLP ? "PSLP" : "Papilo", + presolve_time); } if (!settings_const.inside_mip) { diff --git a/cpp/src/math_optimization/solver_settings.cu b/cpp/src/math_optimization/solver_settings.cu index 0858bb75a..317b09f11 100644 --- a/cpp/src/math_optimization/solver_settings.cu +++ b/cpp/src/math_optimization/solver_settings.cu @@ -98,6 +98,8 @@ solver_settings_t::solver_settings_t() : pdlp_settings(), mip_settings {CUOPT_NUM_GPUS, &pdlp_settings.num_gpus, 1, 2, 1}, {CUOPT_NUM_GPUS, &mip_settings.num_gpus, 1, 2, 1}, {CUOPT_MIP_BATCH_PDLP_STRONG_BRANCHING, &mip_settings.mip_batch_pdlp_strong_branching, 0, 1, 0}, + {CUOPT_PRESOLVE, reinterpret_cast(&pdlp_settings.presolver), CUOPT_PRESOLVE_DEFAULT, CUOPT_PRESOLVE_PSLP, CUOPT_PRESOLVE_DEFAULT}, + {CUOPT_PRESOLVE, reinterpret_cast(&mip_settings.presolver), CUOPT_PRESOLVE_DEFAULT, CUOPT_PRESOLVE_PSLP, CUOPT_PRESOLVE_DEFAULT}, {CUOPT_MIP_RELIABILITY_BRANCHING, &mip_settings.reliability_branching, -1, std::numeric_limits::max(), -1} }; @@ -115,8 +117,6 @@ solver_settings_t::solver_settings_t() : pdlp_settings(), mip_settings {CUOPT_CROSSOVER, &pdlp_settings.crossover, false}, {CUOPT_ELIMINATE_DENSE_COLUMNS, &pdlp_settings.eliminate_dense_columns, true}, {CUOPT_CUDSS_DETERMINISTIC, &pdlp_settings.cudss_deterministic, false}, - {CUOPT_PRESOLVE, &pdlp_settings.presolve, false}, - {CUOPT_PRESOLVE, &mip_settings.presolve, true}, {CUOPT_DUAL_POSTSOLVE, &pdlp_settings.dual_postsolve, true} }; // String parameters diff --git a/cpp/src/mip/diversity/diversity_manager.cu b/cpp/src/mip/diversity/diversity_manager.cu index f01675327..d5bc37b36 100644 --- a/cpp/src/mip/diversity/diversity_manager.cu +++ b/cpp/src/mip/diversity/diversity_manager.cu @@ -201,7 +201,7 @@ bool diversity_manager_t::run_presolve(f_t time_limit) trivial_presolve(*problem_ptr, remap_cache_ids); if (!problem_ptr->empty && !check_bounds_sanity(*problem_ptr)) { return false; } // May overconstrain if Papilo presolve has been run before - if (!context.settings.presolve) { + if (context.settings.presolver == presolver_t::None) { if (!problem_ptr->empty) { // do the resizing no-matter what, bounds presolve might not change the bounds but initial // trivial presolve might have @@ -359,6 +359,7 @@ solution_t diversity_manager_t::run_solver() pdlp_settings.inside_mip = true; pdlp_settings.pdlp_solver_mode = pdlp_solver_mode_t::Stable2; pdlp_settings.num_gpus = context.settings.num_gpus; + pdlp_settings.presolver = presolver_t::None; timer_t lp_timer(lp_time_limit); auto lp_result = solve_lp_with_method(*problem_ptr, pdlp_settings, lp_timer); diff --git a/cpp/src/mip/presolve/third_party_presolve.cpp b/cpp/src/mip/presolve/third_party_presolve.cpp index b60747c57..56fc69b27 100644 --- a/cpp/src/mip/presolve/third_party_presolve.cpp +++ b/cpp/src/mip/presolve/third_party_presolve.cpp @@ -5,33 +5,25 @@ */ /* clang-format on */ +#include +#include +#include #include #include #include #include #include +#include #include #include -#if !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstringop-overflow" // ignore boost error for pip wheel build -#endif -#include -#include -#if !defined(__clang__) -#pragma GCC diagnostic pop -#endif - namespace cuopt::linear_programming::detail { -static papilo::PostsolveStorage post_solve_storage_; -static bool maximize_ = false; - template papilo::Problem build_papilo_problem(const optimization_problem_t& op_problem, - problem_category_t category) + problem_category_t category, + bool maximize) { raft::common::nvtx::range fun_scope("Build papilo problem"); // Build papilo problem from optimization problem @@ -82,8 +74,7 @@ papilo::Problem build_papilo_problem(const optimization_problem_t std::vector h_var_types(var_types.size()); raft::copy(h_var_types.data(), var_types.data(), var_types.size(), stream_view); - maximize_ = op_problem.get_sense(); - if (maximize_) { + if (maximize) { for (size_t i = 0; i < h_obj_coeffs.size(); ++i) { h_obj_coeffs[i] = -h_obj_coeffs[i]; } @@ -109,8 +100,8 @@ papilo::Problem build_papilo_problem(const optimization_problem_t builder.setNumRows(num_rows); builder.setObjAll(h_obj_coeffs); - builder.setObjOffset(maximize_ ? -op_problem.get_objective_offset() - : op_problem.get_objective_offset()); + builder.setObjOffset(maximize ? -op_problem.get_objective_offset() + : op_problem.get_objective_offset()); if (!h_var_lb.empty() && !h_var_ub.empty()) { builder.setColLbAll(h_var_lb); @@ -187,18 +178,193 @@ papilo::Problem build_papilo_problem(const optimization_problem_t return problem; } +struct PSLPContext { + Presolver* presolver = nullptr; + Settings* settings = nullptr; + PresolveStatus status = PresolveStatus_::UNCHANGED; +}; + +template +PSLPContext build_and_run_pslp_presolver(const optimization_problem_t& op_problem, + bool maximize, + const double time_limit) +{ + PSLPContext ctx; + raft::common::nvtx::range fun_scope("Build and run PSLP presolver"); + + // Get problem dimensions + const i_t num_cols = op_problem.get_n_variables(); + const i_t num_rows = op_problem.get_n_constraints(); + const i_t nnz = op_problem.get_nnz(); + + // Get problem data from optimization problem + const auto& coefficients = op_problem.get_constraint_matrix_values(); + const auto& offsets = op_problem.get_constraint_matrix_offsets(); + const auto& variables = op_problem.get_constraint_matrix_indices(); + const auto& obj_coeffs = op_problem.get_objective_coefficients(); + const auto& var_lb = op_problem.get_variable_lower_bounds(); + const auto& var_ub = op_problem.get_variable_upper_bounds(); + const auto& bounds = op_problem.get_constraint_bounds(); + const auto& row_types = op_problem.get_row_types(); + const auto& constr_lb = op_problem.get_constraint_lower_bounds(); + const auto& constr_ub = op_problem.get_constraint_upper_bounds(); + const auto& var_types = op_problem.get_variable_types(); + + // Copy data to host + std::vector h_coefficients(coefficients.size()); + auto stream_view = op_problem.get_handle_ptr()->get_stream(); + raft::copy(h_coefficients.data(), coefficients.data(), coefficients.size(), stream_view); + std::vector h_offsets(offsets.size()); + raft::copy(h_offsets.data(), offsets.data(), offsets.size(), stream_view); + std::vector h_variables(variables.size()); + raft::copy(h_variables.data(), variables.data(), variables.size(), stream_view); + std::vector h_obj_coeffs(obj_coeffs.size()); + raft::copy(h_obj_coeffs.data(), obj_coeffs.data(), obj_coeffs.size(), stream_view); + std::vector h_var_lb(var_lb.size()); + raft::copy(h_var_lb.data(), var_lb.data(), var_lb.size(), stream_view); + std::vector h_var_ub(var_ub.size()); + raft::copy(h_var_ub.data(), var_ub.data(), var_ub.size(), stream_view); + std::vector h_bounds(bounds.size()); + raft::copy(h_bounds.data(), bounds.data(), bounds.size(), stream_view); + std::vector h_row_types(row_types.size()); + raft::copy(h_row_types.data(), row_types.data(), row_types.size(), stream_view); + std::vector h_constr_lb(constr_lb.size()); + raft::copy(h_constr_lb.data(), constr_lb.data(), constr_lb.size(), stream_view); + std::vector h_constr_ub(constr_ub.size()); + raft::copy(h_constr_ub.data(), constr_ub.data(), constr_ub.size(), stream_view); + std::vector h_var_types(var_types.size()); + raft::copy(h_var_types.data(), var_types.data(), var_types.size(), stream_view); + + stream_view.synchronize(); + if (maximize) { + for (size_t i = 0; i < h_obj_coeffs.size(); ++i) { + h_obj_coeffs[i] = -h_obj_coeffs[i]; + } + } + + auto constr_bounds_empty = h_constr_lb.empty() && h_constr_ub.empty(); + if (constr_bounds_empty) { + for (size_t i = 0; i < h_row_types.size(); ++i) { + if (h_row_types[i] == 'L') { + h_constr_lb.push_back(-std::numeric_limits::infinity()); + h_constr_ub.push_back(h_bounds[i]); + } else if (h_row_types[i] == 'G') { + h_constr_lb.push_back(h_bounds[i]); + h_constr_ub.push_back(std::numeric_limits::infinity()); + } else if (h_row_types[i] == 'E') { + h_constr_lb.push_back(h_bounds[i]); + h_constr_ub.push_back(h_bounds[i]); + } + } + } + + // handle empty variable bounds + if (h_var_lb.empty()) { + h_var_lb = std::vector(num_cols, -std::numeric_limits::infinity()); + } + if (h_var_ub.empty()) { + h_var_ub = std::vector(num_cols, std::numeric_limits::infinity()); + } + + // Call PSLP presolver + ctx.settings = default_settings(); + ctx.settings->verbose = false; + ctx.settings->max_time = time_limit; + auto start_time = std::chrono::high_resolution_clock::now(); + ctx.presolver = new_presolver(h_coefficients.data(), + h_variables.data(), + h_offsets.data(), + num_rows, + num_cols, + nnz, + h_constr_lb.data(), + h_constr_ub.data(), + h_var_lb.data(), + h_var_ub.data(), + h_obj_coeffs.data(), + ctx.settings); + + assert(ctx.presolver != nullptr && "Presolver initialization failed"); + ctx.status = run_presolver(ctx.presolver); + auto end_time = std::chrono::high_resolution_clock::now(); + auto duration = std::chrono::duration_cast(end_time - start_time); + CUOPT_LOG_DEBUG("PSLP presolver time: %d milliseconds", duration.count()); + CUOPT_LOG_INFO("PSLP Presolved problem: %d constraints, %d variables, %d non-zeros", + ctx.presolver->stats->n_rows_reduced, + ctx.presolver->stats->n_cols_reduced, + ctx.presolver->stats->nnz_reduced); + + return ctx; +} + +template +optimization_problem_t build_optimization_problem_from_pslp( + Presolver* pslp_presolver, + raft::handle_t const* handle_ptr, + bool maximize, + f_t original_obj_offset) +{ + raft::common::nvtx::range fun_scope("Build optimization problem from PSLP"); + cuopt_expects(pslp_presolver != nullptr && pslp_presolver->reduced_prob != nullptr, + error_type_t::RuntimeError, + "PSLP presolver is not initialized"); + auto reduced_prob = pslp_presolver->reduced_prob; + int n_rows = reduced_prob->m; + int n_cols = reduced_prob->n; + int nnz = reduced_prob->nnz; + double obj_offset = reduced_prob->obj_offset; + + optimization_problem_t op_problem(handle_ptr); + + obj_offset = maximize ? -obj_offset : obj_offset; + + // PSLP does not allow setting the objective offset, so we add the original objective offset to + // the reduced objective offset + obj_offset += original_obj_offset; + op_problem.set_objective_offset(obj_offset); + op_problem.set_maximize(maximize); + op_problem.set_problem_category(problem_category_t::LP); + + // Handle empty reduced problem (presolve completely solved it) + if (n_cols == 0 && n_rows == 0) { + // Set empty constraint matrix with proper offsets + std::vector empty_offsets = {0}; + op_problem.set_csr_constraint_matrix(nullptr, 0, nullptr, 0, empty_offsets.data(), 1); + return op_problem; + } + + op_problem.set_csr_constraint_matrix( + reduced_prob->Ax, nnz, reduced_prob->Ai, nnz, reduced_prob->Ap, n_rows + 1); + + std::vector h_obj_coeffs(n_cols); + std::copy(reduced_prob->c, reduced_prob->c + n_cols, h_obj_coeffs.begin()); + if (maximize) { + for (size_t i = 0; i < n_cols; ++i) { + h_obj_coeffs[i] = -h_obj_coeffs[i]; + } + } + op_problem.set_objective_coefficients(h_obj_coeffs.data(), n_cols); + op_problem.set_constraint_lower_bounds(reduced_prob->lhs, n_rows); + op_problem.set_constraint_upper_bounds(reduced_prob->rhs, n_rows); + op_problem.set_variable_lower_bounds(reduced_prob->lbs, n_cols); + op_problem.set_variable_upper_bounds(reduced_prob->ubs, n_cols); + + return op_problem; +} + template optimization_problem_t build_optimization_problem( papilo::Problem const& papilo_problem, raft::handle_t const* handle_ptr, - problem_category_t category) + problem_category_t category, + bool maximize) { raft::common::nvtx::range fun_scope("Build optimization problem"); optimization_problem_t op_problem(handle_ptr); auto obj = papilo_problem.getObjective(); - op_problem.set_objective_offset(maximize_ ? -obj.offset : obj.offset); - op_problem.set_maximize(maximize_); + op_problem.set_objective_offset(maximize ? -obj.offset : obj.offset); + op_problem.set_maximize(maximize); op_problem.set_problem_category(category); if (papilo_problem.getNRows() == 0 && papilo_problem.getNCols() == 0) { @@ -215,7 +381,7 @@ optimization_problem_t build_optimization_problem( return op_problem; } - if (maximize_) { + if (maximize) { for (size_t i = 0; i < obj.coefficients.size(); ++i) { obj.coefficients[i] = -obj.coefficients[i]; } @@ -392,17 +558,54 @@ void set_presolve_parameters(papilo::Presolve& presolver, } } +template +std::optional> third_party_presolve_t::apply_pslp( + optimization_problem_t const& op_problem, const double time_limit) +{ + f_t original_obj_offset = op_problem.get_objective_offset(); + auto ctx = build_and_run_pslp_presolver(op_problem, maximize_, time_limit); + + // Free previously allocated presolver and settings + if (pslp_presolver_ != nullptr) { free_presolver(pslp_presolver_); } + if (pslp_stgs_ != nullptr) { free_settings(pslp_stgs_); } + + pslp_presolver_ = ctx.presolver; + pslp_stgs_ = ctx.settings; + + if (ctx.status == PresolveStatus_::INFEASIBLE || ctx.status == PresolveStatus_::UNBNDORINFEAS) { + return std::nullopt; + } + + auto opt_problem = build_optimization_problem_from_pslp( + pslp_presolver_, op_problem.get_handle_ptr(), maximize_, original_obj_offset); + + return std::make_optional(third_party_presolve_result_t{opt_problem, {}}); +} + template std::optional> third_party_presolve_t::apply( optimization_problem_t const& op_problem, problem_category_t category, + cuopt::linear_programming::presolver_t presolver, bool dual_postsolve, f_t absolute_tolerance, f_t relative_tolerance, double time_limit, i_t num_cpu_threads) { - papilo::Problem papilo_problem = build_papilo_problem(op_problem, category); + presolver_ = presolver; + maximize_ = op_problem.get_sense(); + if (category == problem_category_t::MIP && + presolver == cuopt::linear_programming::presolver_t::PSLP) { + cuopt_expects( + false, error_type_t::RuntimeError, "PSLP presolver is not supported for MIP problems"); + } + + if (presolver == cuopt::linear_programming::presolver_t::PSLP) { + return apply_pslp(op_problem, time_limit); + } + + papilo::Problem papilo_problem = build_papilo_problem(op_problem, category, maximize_); CUOPT_LOG_INFO("Original problem: %d constraints, %d variables, %d nonzeros", papilo_problem.getNRows(), @@ -411,9 +614,9 @@ std::optional> third_party_presolve_t presolver; - set_presolve_methods(presolver, category, dual_postsolve); - set_presolve_options(presolver, + papilo::Presolve papilo_presolver; + set_presolve_methods(papilo_presolver, category, dual_postsolve); + set_presolve_options(papilo_presolver, category, absolute_tolerance, relative_tolerance, @@ -421,18 +624,18 @@ std::optional> third_party_presolve_t( - presolver, category, op_problem.get_n_constraints(), op_problem.get_n_variables()); + papilo_presolver, category, op_problem.get_n_constraints(), op_problem.get_n_variables()); // Disable papilo logs - presolver.setVerbosityLevel(papilo::VerbosityLevel::kQuiet); + papilo_presolver.setVerbosityLevel(papilo::VerbosityLevel::kQuiet); - auto result = presolver.apply(papilo_problem); + auto result = papilo_presolver.apply(papilo_problem); check_presolve_status(result.status); if (result.status == papilo::PresolveStatus::kInfeasible || result.status == papilo::PresolveStatus::kUnbndOrInfeas) { return std::nullopt; } - post_solve_storage_ = result.postsolve; + papilo_post_solve_storage_ = result.postsolve; CUOPT_LOG_INFO("Presolve removed: %d constraints, %d variables, %d nonzeros", op_problem.get_n_constraints() - papilo_problem.getNRows(), op_problem.get_n_variables() - papilo_problem.getNCols(), @@ -447,8 +650,8 @@ std::optional> third_party_presolve_t(papilo_problem, op_problem.get_handle_ptr(), category); + auto opt_problem = build_optimization_problem( + papilo_problem, op_problem.get_handle_ptr(), category, maximize_); auto col_flags = papilo_problem.getColFlags(); std::vector implied_integer_indices; for (size_t i = 0; i < col_flags.size(); i++) { @@ -478,6 +681,11 @@ void third_party_presolve_t::undo(rmm::device_uvector& primal_sol bool dual_postsolve, rmm::cuda_stream_view stream_view) { + if (presolver_ == cuopt::linear_programming::presolver_t::PSLP) { + undo_pslp(primal_solution, dual_solution, reduced_costs, stream_view); + return; + } + if (status_to_skip) { return; } std::vector primal_sol_vec_h(primal_solution.size()); raft::copy(primal_sol_vec_h.data(), primal_solution.data(), primal_solution.size(), stream_view); @@ -495,10 +703,10 @@ void third_party_presolve_t::undo(rmm::device_uvector& primal_sol papilo::Message Msg{}; Msg.setVerbosityLevel(papilo::VerbosityLevel::kQuiet); - papilo::Postsolve post_solver{Msg, post_solve_storage_.getNum()}; + papilo::Postsolve post_solver{Msg, papilo_post_solve_storage_.getNum()}; bool is_optimal = false; - auto status = post_solver.undo(reduced_sol, full_sol, post_solve_storage_, is_optimal); + auto status = post_solver.undo(reduced_sol, full_sol, papilo_post_solve_storage_, is_optimal); check_postsolve_status(status); primal_solution.resize(full_sol.primal.size(), stream_view); @@ -510,22 +718,67 @@ void third_party_presolve_t::undo(rmm::device_uvector& primal_sol reduced_costs.data(), full_sol.reducedCosts.data(), full_sol.reducedCosts.size(), stream_view); } +template +void third_party_presolve_t::undo_pslp(rmm::device_uvector& primal_solution, + rmm::device_uvector& dual_solution, + rmm::device_uvector& reduced_costs, + rmm::cuda_stream_view stream_view) +{ + std::vector h_primal_solution(primal_solution.size()); + std::vector h_dual_solution(dual_solution.size()); + std::vector h_reduced_costs(reduced_costs.size()); + raft::copy(h_primal_solution.data(), primal_solution.data(), primal_solution.size(), stream_view); + raft::copy(h_dual_solution.data(), dual_solution.data(), dual_solution.size(), stream_view); + raft::copy(h_reduced_costs.data(), reduced_costs.data(), reduced_costs.size(), stream_view); + + postsolve( + pslp_presolver_, h_primal_solution.data(), h_dual_solution.data(), h_reduced_costs.data()); + + auto uncrushed_sol = pslp_presolver_->sol; + int n_cols = uncrushed_sol->dim_x; + int n_rows = uncrushed_sol->dim_y; + + primal_solution.resize(n_cols, stream_view); + dual_solution.resize(n_rows, stream_view); + reduced_costs.resize(n_cols, stream_view); + raft::copy(primal_solution.data(), uncrushed_sol->x, n_cols, stream_view); + raft::copy(dual_solution.data(), uncrushed_sol->y, n_rows, stream_view); + raft::copy(reduced_costs.data(), uncrushed_sol->z, n_cols, stream_view); + + stream_view.synchronize(); +} + template void third_party_presolve_t::uncrush_primal_solution( const std::vector& reduced_primal, std::vector& full_primal) const { + if (presolver_ == cuopt::linear_programming::presolver_t::PSLP) { + cuopt_expects(false, + error_type_t::RuntimeError, + "This code path should be never called, as this is meant for callbacks and they " + "are not supported for LPs"); + return; + } + papilo::Solution reduced_sol(reduced_primal); papilo::Solution full_sol; papilo::Message Msg{}; Msg.setVerbosityLevel(papilo::VerbosityLevel::kQuiet); - papilo::Postsolve post_solver{Msg, post_solve_storage_.getNum()}; + papilo::Postsolve post_solver{Msg, papilo_post_solve_storage_.getNum()}; bool is_optimal = false; - auto status = post_solver.undo(reduced_sol, full_sol, post_solve_storage_, is_optimal); + auto status = post_solver.undo(reduced_sol, full_sol, papilo_post_solve_storage_, is_optimal); check_postsolve_status(status); full_primal = std::move(full_sol.primal); } +template +third_party_presolve_t::~third_party_presolve_t() +{ + if (pslp_presolver_ != nullptr) { free_presolver(pslp_presolver_); } + if (pslp_stgs_ != nullptr) { free_settings(pslp_stgs_); } +} + #if MIP_INSTANTIATE_FLOAT template class third_party_presolve_t; #endif diff --git a/cpp/src/mip/presolve/third_party_presolve.hpp b/cpp/src/mip/presolve/third_party_presolve.hpp index 67b338bee..94578a6a5 100644 --- a/cpp/src/mip/presolve/third_party_presolve.hpp +++ b/cpp/src/mip/presolve/third_party_presolve.hpp @@ -12,6 +12,18 @@ #include +#include + +#if !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overflow" // ignore boost error for pip wheel build +#endif +#include +#include +#if !defined(__clang__) +#pragma GCC diagnostic pop +#endif + namespace cuopt::linear_programming::detail { template @@ -28,9 +40,17 @@ class third_party_presolve_t { public: third_party_presolve_t() = default; + // Delete copy constructor, copy assignment operator, move constructor, and move assignment + // operator This is because we are using PSLP pointers + third_party_presolve_t(const third_party_presolve_t&) = delete; + third_party_presolve_t& operator=(const third_party_presolve_t&) = delete; + third_party_presolve_t(third_party_presolve_t&&) = delete; + third_party_presolve_t& operator=(third_party_presolve_t&&) = delete; + std::optional> apply( optimization_problem_t const& op_problem, problem_category_t category, + cuopt::linear_programming::presolver_t presolver, bool dual_postsolve, f_t absolute_tolerance, f_t relative_tolerance, @@ -50,7 +70,26 @@ class third_party_presolve_t { const std::vector& get_reduced_to_original_map() const { return reduced_to_original_map_; } const std::vector& get_original_to_reduced_map() const { return original_to_reduced_map_; } + ~third_party_presolve_t(); + private: + std::optional> apply_pslp( + optimization_problem_t const& op_problem, const double time_limit); + + void undo_pslp(rmm::device_uvector& primal_solution, + rmm::device_uvector& dual_solution, + rmm::device_uvector& reduced_costs, + rmm::cuda_stream_view stream_view); + + bool maximize_ = false; + cuopt::linear_programming::presolver_t presolver_ = cuopt::linear_programming::presolver_t::PSLP; + // PSLP settings + Settings* pslp_stgs_{nullptr}; + Presolver* pslp_presolver_{nullptr}; + + // Papilo postsolve storage + papilo::PostsolveStorage papilo_post_solve_storage_; + std::vector reduced_to_original_map_{}; std::vector original_to_reduced_map_{}; }; diff --git a/cpp/src/mip/relaxed_lp/relaxed_lp.cu b/cpp/src/mip/relaxed_lp/relaxed_lp.cu index 4842a986a..c7e574cd2 100644 --- a/cpp/src/mip/relaxed_lp/relaxed_lp.cu +++ b/cpp/src/mip/relaxed_lp/relaxed_lp.cu @@ -1,6 +1,6 @@ /* clang-format off */ /* - * SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 */ /* clang-format on */ @@ -53,6 +53,7 @@ optimization_problem_solution_t get_relaxed_lp_solution( pdlp_settings.per_constraint_residual = settings.per_constraint_residual; pdlp_settings.first_primal_feasible = settings.return_first_feasible; pdlp_settings.pdlp_solver_mode = pdlp_solver_mode_t::Stable2; + pdlp_settings.presolver = presolver_t::None; set_pdlp_solver_mode(pdlp_settings); // TODO: set Stable3 here? pdlp_solver_t lp_solver(op_problem, pdlp_settings); diff --git a/cpp/src/mip/solve.cu b/cpp/src/mip/solve.cu index ee852fb29..4476a68eb 100644 --- a/cpp/src/mip/solve.cu +++ b/cpp/src/mip/solve.cu @@ -172,9 +172,17 @@ mip_solution_t run_mip(detail::problem_t& problem, template mip_solution_t solve_mip(optimization_problem_t& op_problem, - mip_solver_settings_t const& settings) + mip_solver_settings_t const& settings_const) { try { + mip_solver_settings_t settings(settings_const); + if (settings.presolver == presolver_t::Default || settings.presolver == presolver_t::PSLP) { + if (settings.presolver == presolver_t::PSLP) { + CUOPT_LOG_INFO( + "PSLP presolver is not supported for MIP problems, using Papilo presolver instead"); + } + settings.presolver = presolver_t::Papilo; + } constexpr f_t max_time_limit = 1000000000; f_t time_limit = (settings.time_limit == 0 || settings.time_limit == std::numeric_limits::infinity() || @@ -217,7 +225,7 @@ mip_solution_t solve_mip(optimization_problem_t& op_problem, std::optional> presolve_result; detail::problem_t problem(op_problem, settings.get_tolerances()); - auto run_presolve = settings.presolve; + auto run_presolve = settings.presolver != presolver_t::None; run_presolve = run_presolve && settings.initial_solutions.size() == 0; bool has_set_solution_callback = false; for (auto callback : settings.get_mip_callbacks()) { @@ -243,6 +251,7 @@ mip_solution_t solve_mip(optimization_problem_t& op_problem, presolver = std::make_unique>(); auto result = presolver->apply(op_problem, cuopt::linear_programming::problem_category_t::MIP, + settings.presolver, dual_postsolve, settings.tolerances.absolute_tolerance, settings.tolerances.relative_tolerance, @@ -311,8 +320,8 @@ mip_solution_t solve_mip(optimization_problem_t& op_problem, // add third party presolve time to cuopt presolve time full_stats.presolve_time += presolve_time; - // FIXME:: reduced_solution.get_stats() is not correct, we need to compute the stats for the - // full problem + // FIXME:: reduced_solution.get_stats() is not correct, we need to compute the stats for + // the full problem full_sol.post_process_completed = true; // hack sol = full_sol.get_solution(true, full_stats); } diff --git a/cpp/src/mip/solver.cu b/cpp/src/mip/solver.cu index 8583a76f8..7d3f8be8b 100644 --- a/cpp/src/mip/solver.cu +++ b/cpp/src/mip/solver.cu @@ -107,7 +107,7 @@ solution_t mip_solver_t::run_solver() return sol; } dm.timer = timer_; - const bool run_presolve = context.settings.presolve; + const bool run_presolve = context.settings.presolver != presolver_t::None; bool presolve_success = run_presolve ? dm.run_presolve(timer_.remaining_time()) : true; if (!presolve_success) { CUOPT_LOG_INFO("Problem proven infeasible in presolve"); @@ -137,6 +137,7 @@ solution_t mip_solver_t::run_solver() settings.time_limit = timer_.remaining_time(); auto lp_timer = timer_t(settings.time_limit); settings.method = method_t::Concurrent; + settings.presolver = presolver_t::None; auto opt_sol = solve_lp_with_method(*context.problem_ptr, settings, lp_timer); diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index fb8f0e26b..0cfde3872 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -1,5 +1,5 @@ # cmake-format: off -# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 # cmake-format: on @@ -42,6 +42,9 @@ function(ConfigureTest CMAKE_TEST_NAME) "${CUOPT_TEST_DIR}/../src" "${CUOPT_TEST_DIR}/../libmps_parser/src" "${CUOPT_TEST_DIR}" + "${papilo_SOURCE_DIR}/src" + "${papilo_BINARY_DIR}" + "${pslp_SOURCE_DIR}/include" ) target_link_libraries(${CMAKE_TEST_NAME} diff --git a/cpp/tests/linear_programming/CMakeLists.txt b/cpp/tests/linear_programming/CMakeLists.txt index 40e284baf..aaf3e5c9f 100644 --- a/cpp/tests/linear_programming/CMakeLists.txt +++ b/cpp/tests/linear_programming/CMakeLists.txt @@ -6,6 +6,7 @@ ConfigureTest(LP_UNIT_TEST ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/optimization_problem_test.cu ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/solver_settings_test.cu + ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/presolve_test.cu )# ################################################################################################## # - Linear programming PDLP tests ---------------------------------------------------------------------- ConfigureTest(PDLP_TEST diff --git a/cpp/tests/linear_programming/pdlp_test.cu b/cpp/tests/linear_programming/pdlp_test.cu index 994fa89fe..28dd26c2c 100644 --- a/cpp/tests/linear_programming/pdlp_test.cu +++ b/cpp/tests/linear_programming/pdlp_test.cu @@ -211,14 +211,17 @@ TEST(pdlp_class, run_sub_mittleman) auto settings = pdlp_solver_settings_t{}; settings.pdlp_solver_mode = solver_mode; settings.dual_postsolve = false; - for (auto [presolve, epsilon] : {std::pair{true, 1e-1}, std::pair{false, 1e-6}}) { - settings.presolve = presolve; - settings.method = cuopt::linear_programming::method_t::PDLP; + for (auto [presolver, epsilon] : + {std::pair{presolver_t::Papilo, 1e-1}, std::pair{presolver_t::None, 1e-6}}) { + settings.presolver = presolver; + settings.method = cuopt::linear_programming::method_t::PDLP; const raft::handle_t handle_{}; optimization_problem_solution_t solution = solve_lp(&handle_, op_problem, settings); - printf( - "running %s mode %d presolve? %d\n", name.c_str(), (int)solver_mode, settings.presolve); + printf("running %s mode %d presolver %d\n", + name.c_str(), + (int)solver_mode, + (int)settings.presolver); EXPECT_EQ((int)solution.get_termination_status(), CUOPT_TERIMINATION_STATUS_OPTIMAL); EXPECT_FALSE(is_incorrect_objective( expected_objective_value, @@ -231,7 +234,7 @@ TEST(pdlp_class, run_sub_mittleman) solution.get_additional_termination_information(0), solution.get_primal_solution(), epsilon, - presolve); + presolver); } } } @@ -842,6 +845,7 @@ TEST(pdlp_class, warm_start) solver_settings.set_optimality_tolerance(1e-2); solver_settings.detect_infeasibility = false; solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.presolver = presolver_t::None; cuopt::mps_parser::mps_data_model_t mps_data_model = cuopt::mps_parser::parse_mps(path); @@ -883,6 +887,7 @@ TEST(pdlp_class, warm_start_stable3_not_supported) solver_settings.set_optimality_tolerance(1e-2); solver_settings.detect_infeasibility = false; solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.presolver = presolver_t::None; cuopt::mps_parser::mps_data_model_t mps_data_model = cuopt::mps_parser::parse_mps(path); @@ -903,9 +908,9 @@ TEST(pdlp_class, dual_postsolve_size) cuopt::mps_parser::mps_data_model_t op_problem = cuopt::mps_parser::parse_mps(path, true); - auto solver_settings = pdlp_solver_settings_t{}; - solver_settings.method = cuopt::linear_programming::method_t::PDLP; - solver_settings.presolve = true; + auto solver_settings = pdlp_solver_settings_t{}; + solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.presolver = presolver_t::Papilo; { solver_settings.dual_postsolve = true; @@ -928,7 +933,8 @@ TEST(dual_simplex, afiro) { cuopt::linear_programming::pdlp_solver_settings_t settings = cuopt::linear_programming::pdlp_solver_settings_t{}; - settings.method = cuopt::linear_programming::method_t::DualSimplex; + settings.method = cuopt::linear_programming::method_t::DualSimplex; + settings.presolver = presolver_t::None; const raft::handle_t handle_{}; @@ -951,8 +957,9 @@ TEST(pdlp_class, run_empty_matrix_pdlp) cuopt::mps_parser::mps_data_model_t op_problem = cuopt::mps_parser::parse_mps(path); - auto solver_settings = pdlp_solver_settings_t{}; - solver_settings.method = cuopt::linear_programming::method_t::PDLP; + auto solver_settings = pdlp_solver_settings_t{}; + solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.presolver = presolver_t::None; optimization_problem_solution_t solution = solve_lp(&handle_, op_problem, solver_settings); @@ -968,8 +975,9 @@ TEST(pdlp_class, run_empty_matrix_dual_simplex) cuopt::mps_parser::mps_data_model_t op_problem = cuopt::mps_parser::parse_mps(path); - auto solver_settings = pdlp_solver_settings_t{}; - solver_settings.method = cuopt::linear_programming::method_t::Concurrent; + auto solver_settings = pdlp_solver_settings_t{}; + solver_settings.method = cuopt::linear_programming::method_t::Concurrent; + solver_settings.presolver = presolver_t::None; optimization_problem_solution_t solution = solve_lp(&handle_, op_problem, solver_settings); @@ -988,6 +996,7 @@ TEST(pdlp_class, test_max) auto solver_settings = pdlp_solver_settings_t{}; solver_settings.method = cuopt::linear_programming::method_t::PDLP; solver_settings.pdlp_solver_mode = cuopt::linear_programming::pdlp_solver_mode_t::Stable2; + solver_settings.presolver = presolver_t::None; optimization_problem_solution_t solution = solve_lp(&handle_, op_problem, solver_settings); @@ -1004,8 +1013,9 @@ TEST(pdlp_class, test_max_with_offset) cuopt::mps_parser::mps_data_model_t op_problem = cuopt::mps_parser::parse_mps(path); - auto solver_settings = pdlp_solver_settings_t{}; - solver_settings.method = cuopt::linear_programming::method_t::PDLP; + auto solver_settings = pdlp_solver_settings_t{}; + solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.presolver = presolver_t::None; optimization_problem_solution_t solution = solve_lp(&handle_, op_problem, solver_settings); @@ -1022,7 +1032,8 @@ TEST(pdlp_class, test_lp_no_constraints) cuopt::mps_parser::mps_data_model_t op_problem = cuopt::mps_parser::parse_mps(path); - auto solver_settings = pdlp_solver_settings_t{}; + auto solver_settings = pdlp_solver_settings_t{}; + solver_settings.presolver = presolver_t::None; optimization_problem_solution_t solution = solve_lp(&handle_, op_problem, solver_settings); @@ -1048,8 +1059,9 @@ TEST(pdlp_class, simple_batch_afiro) cuopt::mps_parser::mps_data_model_t op_problem = cuopt::mps_parser::parse_mps(path, true); - auto solver_settings = pdlp_solver_settings_t{}; - solver_settings.method = cuopt::linear_programming::method_t::PDLP; + auto solver_settings = pdlp_solver_settings_t{}; + solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.presolver = presolver_t::None; constexpr int batch_size = 5; @@ -1131,8 +1143,9 @@ TEST(pdlp_class, simple_batch_different_bounds) cuopt::mps_parser::mps_data_model_t op_problem = cuopt::mps_parser::parse_mps(path, true); - auto solver_settings = pdlp_solver_settings_t{}; - solver_settings.method = cuopt::linear_programming::method_t::PDLP; + auto solver_settings = pdlp_solver_settings_t{}; + solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.presolver = presolver_t::None; const std::vector& variable_lower_bounds = op_problem.get_variable_lower_bounds(); const std::vector& variable_upper_bounds = op_problem.get_variable_upper_bounds(); @@ -1186,8 +1199,9 @@ TEST(pdlp_class, more_complex_batch_different_bounds) cuopt::mps_parser::mps_data_model_t op_problem = cuopt::mps_parser::parse_mps(path, true); - auto solver_settings = pdlp_solver_settings_t{}; - solver_settings.method = cuopt::linear_programming::method_t::PDLP; + auto solver_settings = pdlp_solver_settings_t{}; + solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.presolver = presolver_t::None; constexpr int batch_size = 5; @@ -1396,8 +1410,9 @@ TEST(pdlp_class, new_bounds) cuopt::mps_parser::mps_data_model_t op_problem = cuopt::mps_parser::parse_mps(path, true); - auto solver_settings = pdlp_solver_settings_t{}; - solver_settings.method = cuopt::linear_programming::method_t::PDLP; + auto solver_settings = pdlp_solver_settings_t{}; + solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.presolver = presolver_t::None; // Manually changing the bounds and doing it through the solver settings should give the same // result @@ -1440,8 +1455,9 @@ TEST(pdlp_class, big_batch_afiro) cuopt::mps_parser::mps_data_model_t op_problem = cuopt::mps_parser::parse_mps(path, true); - auto solver_settings = pdlp_solver_settings_t{}; - solver_settings.method = cuopt::linear_programming::method_t::PDLP; + auto solver_settings = pdlp_solver_settings_t{}; + solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.presolver = presolver_t::None; constexpr int batch_size = 1000; @@ -1529,6 +1545,7 @@ TEST(pdlp_class, DISABLED_simple_batch_optimal_and_infeasible) auto solver_settings = pdlp_solver_settings_t{}; solver_settings.method = cuopt::linear_programming::method_t::PDLP; solver_settings.detect_infeasibility = true; + solver_settings.presolver = presolver_t::None; const std::vector& variable_lower_bounds = op_problem.get_variable_lower_bounds(); const std::vector& variable_upper_bounds = op_problem.get_variable_upper_bounds(); @@ -1609,7 +1626,7 @@ TEST(pdlp_class, strong_branching_test) auto solver_settings = pdlp_solver_settings_t{}; solver_settings.method = cuopt::linear_programming::method_t::PDLP; solver_settings.pdlp_solver_mode = pdlp_solver_mode_t::Stable3; - solver_settings.presolve = false; + solver_settings.presolver = cuopt::linear_programming::presolver_t::None; const int n_fractional = fractional.size(); const int batch_size = n_fractional * 2; @@ -1736,10 +1753,11 @@ TEST(pdlp_class, many_different_bounds) // Solve each variant using PDLP for (int i = 0; i < batch_size; ++i) { - const auto& bounds = custom_bounds[i]; - auto solver_settings = pdlp_solver_settings_t{}; - solver_settings.method = cuopt::linear_programming::method_t::PDLP; - auto ref_prob = op_problem; + const auto& bounds = custom_bounds[i]; + auto solver_settings = pdlp_solver_settings_t{}; + solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.presolver = presolver_t::None; + auto ref_prob = op_problem; ref_prob.get_variable_lower_bounds()[std::get<0>(bounds)] = std::get<1>(bounds); ref_prob.get_variable_upper_bounds()[std::get<0>(bounds)] = std::get<2>(bounds); ref_problems.push_back(ref_prob); @@ -1750,8 +1768,9 @@ TEST(pdlp_class, many_different_bounds) host_copy(solution.get_primal_solution(), solution.get_primal_solution().stream()); } - auto solver_settings = pdlp_solver_settings_t{}; - solver_settings.method = cuopt::linear_programming::method_t::PDLP; + auto solver_settings = pdlp_solver_settings_t{}; + solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.presolver = presolver_t::None; for (int i = 0; i < batch_size; ++i) { solver_settings.new_bounds.push_back(custom_bounds[i]); } @@ -1817,6 +1836,7 @@ TEST(pdlp_class, some_climber_hit_iteration_limit) auto solver_settings = pdlp_solver_settings_t{}; solver_settings.method = cuopt::linear_programming::method_t::PDLP; solver_settings.iteration_limit = 500; + solver_settings.presolver = presolver_t::None; auto ref_prob = op_problem; ref_prob.get_variable_lower_bounds()[std::get<0>(bounds)] = std::get<1>(bounds); ref_prob.get_variable_upper_bounds()[std::get<0>(bounds)] = std::get<2>(bounds); @@ -1830,6 +1850,7 @@ TEST(pdlp_class, some_climber_hit_iteration_limit) auto solver_settings = pdlp_solver_settings_t{}; solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.presolver = presolver_t::None; solver_settings.iteration_limit = 500; for (int i = 0; i < batch_size; ++i) { solver_settings.new_bounds.push_back(custom_bounds[i]); diff --git a/cpp/tests/linear_programming/unit_tests/presolve_test.cu b/cpp/tests/linear_programming/unit_tests/presolve_test.cu new file mode 100644 index 000000000..3fd05d97f --- /dev/null +++ b/cpp/tests/linear_programming/unit_tests/presolve_test.cu @@ -0,0 +1,390 @@ +/* clang-format off */ +/* + * SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +/* clang-format on */ + +#include "../utilities/pdlp_test_utilities.cuh" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include + +namespace cuopt::linear_programming::test { + +// Helper function to compute constraint residuals for the original problem +static void compute_constraint_residuals(const std::vector& coefficients, + const std::vector& indices, + const std::vector& offsets, + const std::vector& solution, + std::vector& residuals) +{ + size_t n_constraints = offsets.size() - 1; + residuals.resize(n_constraints, 0.0); + // CSR SpMV: A * x + for (size_t i = 0; i < n_constraints; ++i) { + residuals[i] = 0.0; + for (int j = offsets[i]; j < offsets[i + 1]; ++j) { + residuals[i] += coefficients[j] * solution[indices[j]]; + } + } +} + +// Helper function to compute the objective value +static double compute_objective(const std::vector& objective_coeffs, + const std::vector& solution, + double obj_offset) +{ + double obj = obj_offset; + for (size_t i = 0; i < objective_coeffs.size(); ++i) { + obj += objective_coeffs[i] * solution[i]; + } + return obj; +} + +// Helper function to check constraint satisfaction +static void check_constraint_satisfaction(const std::vector& residuals, + const std::vector& lower_bounds, + const std::vector& upper_bounds, + double tolerance) +{ + for (size_t i = 0; i < residuals.size(); ++i) { + double lb = lower_bounds[i]; + double ub = upper_bounds[i]; + + // Check lower bound + if (lb != -std::numeric_limits::infinity()) { + EXPECT_GE(residuals[i], lb - tolerance) << "Constraint " << i << " violates lower bound"; + } + // Check upper bound + if (ub != std::numeric_limits::infinity()) { + EXPECT_LE(residuals[i], ub + tolerance) << "Constraint " << i << " violates upper bound"; + } + } +} + +// Helper function to check variable bounds +static void check_variable_bounds(const std::vector& solution, + const std::vector& lower_bounds, + const std::vector& upper_bounds, + double tolerance) +{ + for (size_t i = 0; i < solution.size(); ++i) { + double lb = lower_bounds[i]; + double ub = upper_bounds[i]; + + if (lb != -std::numeric_limits::infinity()) { + EXPECT_GE(solution[i], lb - tolerance) << "Variable " << i << " violates lower bound"; + } + if (ub != std::numeric_limits::infinity()) { + EXPECT_LE(solution[i], ub + tolerance) << "Variable " << i << " violates upper bound"; + } + } +} + +// Test PSLP presolver postsolve accuracy using afiro problem +TEST(pslp_presolve, postsolve_accuracy_afiro) +{ + const raft::handle_t handle_{}; + constexpr double tolerance = 1e-5; + constexpr double expected_obj = -464.75314; // Known optimal objective for afiro + + auto path = make_path_absolute("linear_programming/afiro_original.mps"); + auto mps_data_model = cuopt::mps_parser::parse_mps(path, true); + + // Store original problem data for later verification + const auto& orig_coefficients = mps_data_model.get_constraint_matrix_values(); + const auto& orig_indices = mps_data_model.get_constraint_matrix_indices(); + const auto& orig_offsets = mps_data_model.get_constraint_matrix_offsets(); + const auto& orig_obj_coeffs = mps_data_model.get_objective_coefficients(); + const auto& orig_var_lb = mps_data_model.get_variable_lower_bounds(); + const auto& orig_var_ub = mps_data_model.get_variable_upper_bounds(); + const auto& orig_constr_lb = mps_data_model.get_constraint_lower_bounds(); + const auto& orig_constr_ub = mps_data_model.get_constraint_upper_bounds(); + const double orig_obj_offset = mps_data_model.get_objective_offset(); + const int orig_n_vars = mps_data_model.get_n_variables(); + const int orig_n_constraints = mps_data_model.get_n_constraints(); + + // Solve with PSLP presolve enabled + auto solver_settings = pdlp_solver_settings_t{}; + solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.tolerances.relative_primal_tolerance = 1e-6; + solver_settings.tolerances.relative_dual_tolerance = 1e-6; + solver_settings.tolerances.absolute_primal_tolerance = 1e-6; + solver_settings.tolerances.absolute_dual_tolerance = 1e-6; + solver_settings.tolerances.absolute_gap_tolerance = 1e-6; + solver_settings.tolerances.relative_gap_tolerance = 1e-6; + solver_settings.presolver = presolver_t::PSLP; + + optimization_problem_solution_t solution = + solve_lp(&handle_, mps_data_model, solver_settings); + + EXPECT_EQ((int)solution.get_termination_status(), CUOPT_TERIMINATION_STATUS_OPTIMAL); + + // Get the postsolved primal solution + auto h_primal_solution = host_copy(solution.get_primal_solution(), handle_.get_stream()); + + // Verify solution size matches original problem + EXPECT_EQ(h_primal_solution.size(), orig_n_vars) + << "Postsolved solution size should match original problem"; + + // Verify objective value + double computed_obj = compute_objective(orig_obj_coeffs, h_primal_solution, orig_obj_offset); + EXPECT_NEAR(computed_obj, expected_obj, 1.0) + << "Postsolved objective should match expected optimal"; + + // Verify variable bounds + check_variable_bounds(h_primal_solution, orig_var_lb, orig_var_ub, tolerance); + + // Verify constraint satisfaction + std::vector residuals; + compute_constraint_residuals( + orig_coefficients, orig_indices, orig_offsets, h_primal_solution, residuals); + EXPECT_EQ(residuals.size(), orig_n_constraints); + check_constraint_satisfaction(residuals, orig_constr_lb, orig_constr_ub, tolerance); +} + +// Test PSLP postsolve dual solution accuracy +TEST(pslp_presolve, postsolve_dual_accuracy_afiro) +{ + const raft::handle_t handle_{}; + constexpr double tolerance = 1e-5; + + auto path = make_path_absolute("linear_programming/afiro_original.mps"); + auto mps_data_model = cuopt::mps_parser::parse_mps(path, true); + + const int orig_n_vars = mps_data_model.get_n_variables(); + const int orig_n_constraints = mps_data_model.get_n_constraints(); + + // Solve with PSLP presolve and dual postsolve enabled + auto solver_settings = pdlp_solver_settings_t{}; + solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.presolver = presolver_t::PSLP; + + optimization_problem_solution_t solution = + solve_lp(&handle_, mps_data_model, solver_settings); + + EXPECT_EQ((int)solution.get_termination_status(), CUOPT_TERIMINATION_STATUS_OPTIMAL); + + // Get postsolved solutions + auto h_primal = host_copy(solution.get_primal_solution(), handle_.get_stream()); + auto h_dual = host_copy(solution.get_dual_solution(), handle_.get_stream()); + + // Verify sizes + EXPECT_EQ(h_primal.size(), orig_n_vars) << "Postsolved primal size should match original"; + EXPECT_EQ(h_dual.size(), orig_n_constraints) << "Postsolved dual size should match original"; + + // Verify primal and dual objectives are close (weak duality check) + double primal_obj = solution.get_additional_termination_information().primal_objective; + double dual_obj = solution.get_additional_termination_information().dual_objective; + EXPECT_NEAR(primal_obj, dual_obj, 1.0) << "Primal and dual objectives should be close at optimum"; +} + +// Test PSLP postsolve with a larger problem +TEST(pslp_presolve, postsolve_accuracy_larger_problem) +{ + const raft::handle_t handle_{}; + constexpr double tolerance = 1e-4; + + auto path = make_path_absolute("linear_programming/ex10/ex10.mps"); + auto mps_data_model = cuopt::mps_parser::parse_mps(path, false); + + // Store original problem dimensions + const auto& orig_coefficients = mps_data_model.get_constraint_matrix_values(); + const auto& orig_indices = mps_data_model.get_constraint_matrix_indices(); + const auto& orig_offsets = mps_data_model.get_constraint_matrix_offsets(); + const auto& orig_var_lb = mps_data_model.get_variable_lower_bounds(); + const auto& orig_var_ub = mps_data_model.get_variable_upper_bounds(); + const auto& orig_constr_lb = mps_data_model.get_constraint_lower_bounds(); + const auto& orig_constr_ub = mps_data_model.get_constraint_upper_bounds(); + const int orig_n_vars = mps_data_model.get_n_variables(); + const int orig_n_constraints = mps_data_model.get_n_constraints(); + + // Solve with PSLP presolve + auto solver_settings = pdlp_solver_settings_t{}; + solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.presolver = presolver_t::PSLP; + solver_settings.tolerances.relative_primal_tolerance = 1e-6; + solver_settings.tolerances.relative_dual_tolerance = 1e-6; + solver_settings.tolerances.absolute_primal_tolerance = 1e-6; + solver_settings.tolerances.absolute_dual_tolerance = 1e-6; + solver_settings.tolerances.absolute_gap_tolerance = 1e-6; + solver_settings.tolerances.relative_gap_tolerance = 1e-6; + + optimization_problem_solution_t solution = + solve_lp(&handle_, mps_data_model, solver_settings); + + EXPECT_EQ((int)solution.get_termination_status(), CUOPT_TERIMINATION_STATUS_OPTIMAL); + + auto h_primal = host_copy(solution.get_primal_solution(), handle_.get_stream()); + + // Verify solution dimension + EXPECT_EQ(h_primal.size(), orig_n_vars); + + // Verify variable bounds + check_variable_bounds(h_primal, orig_var_lb, orig_var_ub, tolerance); + + // Verify constraint satisfaction + std::vector residuals; + compute_constraint_residuals(orig_coefficients, orig_indices, orig_offsets, h_primal, residuals); + check_constraint_satisfaction(residuals, orig_constr_lb, orig_constr_ub, tolerance); +} + +// Test that PSLP and no presolve give similar objective values +TEST(pslp_presolve, compare_with_no_presolve) +{ + const raft::handle_t handle_{}; + constexpr double obj_tolerance = 1e-3; + + auto path = make_path_absolute("linear_programming/afiro_original.mps"); + auto mps_data_model = cuopt::mps_parser::parse_mps(path, true); + + // Solve without presolve + auto settings_no_presolve = pdlp_solver_settings_t{}; + settings_no_presolve.method = cuopt::linear_programming::method_t::PDLP; + settings_no_presolve.presolver = presolver_t::None; + settings_no_presolve.tolerances.relative_primal_tolerance = 1e-6; + settings_no_presolve.tolerances.relative_dual_tolerance = 1e-6; + settings_no_presolve.tolerances.absolute_primal_tolerance = 1e-6; + settings_no_presolve.tolerances.absolute_dual_tolerance = 1e-6; + settings_no_presolve.tolerances.absolute_gap_tolerance = 1e-6; + settings_no_presolve.tolerances.relative_gap_tolerance = 1e-6; + + optimization_problem_solution_t solution_no_presolve = + solve_lp(&handle_, mps_data_model, settings_no_presolve); + + // Solve with PSLP presolve + auto settings_pslp = pdlp_solver_settings_t{}; + settings_pslp.method = cuopt::linear_programming::method_t::PDLP; + settings_pslp.presolver = presolver_t::PSLP; + settings_pslp.tolerances.relative_primal_tolerance = 1e-6; + settings_pslp.tolerances.relative_dual_tolerance = 1e-6; + settings_pslp.tolerances.absolute_primal_tolerance = 1e-6; + settings_pslp.tolerances.absolute_dual_tolerance = 1e-6; + settings_pslp.tolerances.absolute_gap_tolerance = 1e-6; + settings_pslp.tolerances.relative_gap_tolerance = 1e-6; + + optimization_problem_solution_t solution_pslp = + solve_lp(&handle_, mps_data_model, settings_pslp); + + // Both should be optimal + EXPECT_EQ((int)solution_no_presolve.get_termination_status(), CUOPT_TERIMINATION_STATUS_OPTIMAL); + EXPECT_EQ((int)solution_pslp.get_termination_status(), CUOPT_TERIMINATION_STATUS_OPTIMAL); + + // Objective values should match + double obj_no_presolve = + solution_no_presolve.get_additional_termination_information().primal_objective; + double obj_pslp = solution_pslp.get_additional_termination_information().primal_objective; + + EXPECT_NEAR(obj_no_presolve, obj_pslp, obj_tolerance * fabs(obj_no_presolve)) + << "PSLP presolve should give same objective as no presolve"; + + // Also test the solution vector (primal) and dual solution vector for equality + + // Get the primal solution for both solves + auto h_primal_no_presolve = + host_copy(solution_no_presolve.get_primal_solution(), handle_.get_stream()); + auto h_primal_pslp = host_copy(solution_pslp.get_primal_solution(), handle_.get_stream()); + + ASSERT_EQ(h_primal_no_presolve.size(), h_primal_pslp.size()) + << "Primal solution sizes must match"; + // Compute relative L2 error between h_primal_no_presolve and h_primal_pslp + double num = 0.0; + double denom = 0.0; + for (size_t i = 0; i < h_primal_no_presolve.size(); ++i) { + double diff = h_primal_no_presolve[i] - h_primal_pslp[i]; + num += diff * diff; + denom += h_primal_no_presolve[i] * h_primal_no_presolve[i]; + } + double rel_l2_err = denom > 0 ? sqrt(num) / sqrt(denom) : sqrt(num); + EXPECT_LT(rel_l2_err, 1e-2) << "Relative L2 error in primal solution is too large (" << rel_l2_err + << ")"; +} + +// Test PSLP postsolve with reduced costs +TEST(pslp_presolve, postsolve_reduced_costs) +{ + const raft::handle_t handle_{}; + + auto path = make_path_absolute("linear_programming/afiro_original.mps"); + auto mps_data_model = cuopt::mps_parser::parse_mps(path, true); + + const int orig_n_vars = mps_data_model.get_n_variables(); + + // Solve with PSLP and dual postsolve + auto solver_settings = pdlp_solver_settings_t{}; + solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.presolver = presolver_t::PSLP; + + optimization_problem_solution_t solution = + solve_lp(&handle_, mps_data_model, solver_settings); + + EXPECT_EQ((int)solution.get_termination_status(), CUOPT_TERIMINATION_STATUS_OPTIMAL); + + // Get postsolved reduced costs + auto h_reduced_costs = host_copy(solution.get_reduced_cost(), handle_.get_stream()); + + // Verify reduced costs size matches original problem + EXPECT_EQ(h_reduced_costs.size(), orig_n_vars) + << "Postsolved reduced costs size should match original problem variables"; +} + +// Test PSLP postsolve on multiple problems to ensure consistency +TEST(pslp_presolve, postsolve_multiple_problems) +{ + const raft::handle_t handle_{}; + constexpr double tolerance = 1e-4; + + std::vector> instances{ + {"afiro_original", -464.75314}, + {"ex10/ex10", 100.0003411893773}, + }; + + for (const auto& [name, expected_obj] : instances) { + auto path = make_path_absolute("linear_programming/" + name + ".mps"); + auto mps_data_model = cuopt::mps_parser::parse_mps(path, name == "afiro_original"); + + const int orig_n_vars = mps_data_model.get_n_variables(); + const int orig_n_constraints = mps_data_model.get_n_constraints(); + + auto solver_settings = pdlp_solver_settings_t{}; + solver_settings.method = cuopt::linear_programming::method_t::PDLP; + solver_settings.presolver = presolver_t::PSLP; + + optimization_problem_solution_t solution = + solve_lp(&handle_, mps_data_model, solver_settings); + + EXPECT_EQ((int)solution.get_termination_status(), CUOPT_TERIMINATION_STATUS_OPTIMAL) + << "Problem " << name << " should be optimal"; + + auto h_primal = host_copy(solution.get_primal_solution(), handle_.get_stream()); + EXPECT_EQ(h_primal.size(), orig_n_vars) + << "Problem " << name << " postsolved solution size mismatch"; + + double primal_obj = solution.get_additional_termination_information().primal_objective; + double rel_error = std::abs((primal_obj - expected_obj) / expected_obj); + EXPECT_LT(rel_error, 0.01) << "Problem " << name << " objective mismatch"; + } +} + +} // namespace cuopt::linear_programming::test + +CUOPT_TEST_PROGRAM_MAIN() diff --git a/cpp/tests/mip/cuts_test.cu b/cpp/tests/mip/cuts_test.cu index 72b9acd47..1a360b41e 100644 --- a/cpp/tests/mip/cuts_test.cu +++ b/cpp/tests/mip/cuts_test.cu @@ -154,7 +154,7 @@ TEST(cuts, test_cuts_2) settings.time_limit = test_time_limit; settings.max_cut_passes = 10; - settings.presolve = false; + settings.presolver = presolver_t::None; mip_solution_t solution = solve_mip(&handle_, problem, settings); EXPECT_EQ(solution.get_termination_status(), mip_termination_status_t::Optimal); diff --git a/cpp/tests/mip/doc_example_test.cu b/cpp/tests/mip/doc_example_test.cu index 78ca76927..9c3722ed5 100644 --- a/cpp/tests/mip/doc_example_test.cu +++ b/cpp/tests/mip/doc_example_test.cu @@ -1,6 +1,6 @@ /* clang-format off */ /* - * SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 */ /* clang-format on */ @@ -125,7 +125,7 @@ TEST(docs, user_problem_file) settings.time_limit = test_time_limit; settings.user_problem_file = user_problem_path; - settings.presolve = false; + settings.presolver = cuopt::linear_programming::presolver_t::None; EXPECT_EQ(solve_mip(&handle_, problem, settings).get_termination_status(), mip_termination_status_t::Optimal); diff --git a/cpp/tests/mip/incumbent_callback_test.cu b/cpp/tests/mip/incumbent_callback_test.cu index 3fc06a8ad..a9593fa55 100644 --- a/cpp/tests/mip/incumbent_callback_test.cu +++ b/cpp/tests/mip/incumbent_callback_test.cu @@ -119,7 +119,7 @@ void test_incumbent_callback(std::string test_instance, bool include_set_callbac auto settings = mip_solver_settings_t{}; settings.time_limit = 30.; - settings.presolve = true; + settings.presolver = presolver_t::Papilo; int user_data = 42; std::vector, double>> solutions; test_get_solution_callback_t get_solution_callback( diff --git a/cpp/tests/mip/integer_with_real_bounds.cu b/cpp/tests/mip/integer_with_real_bounds.cu index 2ba799026..092a72dfd 100644 --- a/cpp/tests/mip/integer_with_real_bounds.cu +++ b/cpp/tests/mip/integer_with_real_bounds.cu @@ -1,6 +1,6 @@ /* clang-format off */ /* - * SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 */ /* clang-format on */ @@ -18,9 +18,9 @@ TEST(mip_solve, integer_with_real_bounds_test) { auto time_limit = 1; auto heuristics_only = true; - auto presolve = false; + auto presolver = cuopt::linear_programming::presolver_t::None; auto [termination_status, obj_val, lb] = - test_mps_file("mip/integer-with-real-bounds.mps", time_limit, heuristics_only, presolve); + test_mps_file("mip/integer-with-real-bounds.mps", time_limit, heuristics_only, presolver); EXPECT_EQ(termination_status, mip_termination_status_t::Optimal); EXPECT_NEAR(obj_val, 4, 1e-5); } diff --git a/cpp/tests/mip/mip_utils.cuh b/cpp/tests/mip/mip_utils.cuh index 3bb4a2729..13ae85fce 100644 --- a/cpp/tests/mip/mip_utils.cuh +++ b/cpp/tests/mip/mip_utils.cuh @@ -160,9 +160,9 @@ static void test_constraint_sanity_per_row( static std::tuple test_mps_file( std::string test_instance, - double time_limit = 1, - bool heuristics_only = true, - bool presolve = true) + double time_limit = 1, + bool heuristics_only = true, + presolver_t presolver = presolver_t::Default) { const raft::handle_t handle_{}; @@ -173,7 +173,7 @@ static std::tuple test_mps_file( mip_solver_settings_t settings; settings.time_limit = time_limit; settings.heuristics_only = heuristics_only; - settings.presolve = presolve; + settings.presolver = presolver; mip_solution_t solution = solve_mip(&handle_, problem, settings); return std::make_tuple(solution.get_termination_status(), solution.get_objective_value(), diff --git a/cpp/tests/mip/presolve_test.cu b/cpp/tests/mip/presolve_test.cu index 893602e20..07ccdb872 100644 --- a/cpp/tests/mip/presolve_test.cu +++ b/cpp/tests/mip/presolve_test.cu @@ -37,8 +37,14 @@ TEST(problem, find_implied_integers) auto mps_data_model = cuopt::mps_parser::parse_mps(path, false); auto op_problem = mps_data_model_to_optimization_problem(&handle_, mps_data_model); auto presolver = std::make_unique>(); - auto result = presolver->apply( - op_problem, cuopt::linear_programming::problem_category_t::MIP, false, 1e-6, 1e-12, 20, 1); + auto result = presolver->apply(op_problem, + cuopt::linear_programming::problem_category_t::MIP, + cuopt::linear_programming::presolver_t::Papilo, + false, + 1e-6, + 1e-12, + 20, + 1); ASSERT_TRUE(result.has_value()); auto problem = detail::problem_t(result->reduced_problem); diff --git a/cpp/tests/mip/unit_test.cu b/cpp/tests/mip/unit_test.cu index f9d76611d..29b58b736 100644 --- a/cpp/tests/mip/unit_test.cu +++ b/cpp/tests/mip/unit_test.cu @@ -195,7 +195,7 @@ TEST(LPTest, TestSampleLP) cuopt::linear_programming::pdlp_solver_settings_t settings{}; settings.set_optimality_tolerance(1e-4); settings.time_limit = 5; - settings.presolve = false; + settings.presolver = cuopt::linear_programming::presolver_t::None; auto result = cuopt::linear_programming::solve_lp(&handle, problem, settings); @@ -210,7 +210,7 @@ TEST(ErrorTest, TestError) cuopt::linear_programming::mip_solver_settings_t settings{}; settings.time_limit = 5; - settings.presolve = false; + settings.presolver = cuopt::linear_programming::presolver_t::None; // Set constraint bounds std::vector lower_bounds = {1.0}; @@ -242,7 +242,7 @@ TEST_P(MILPTestParams, TestSampleMILP) settings.time_limit = 5; settings.mip_scaling = scaling; settings.heuristics_only = heuristics_only; - settings.presolve = false; + settings.presolver = cuopt::linear_programming::presolver_t::None; auto result = cuopt::linear_programming::solve_mip(&handle, problem, settings); @@ -263,7 +263,7 @@ TEST_P(MILPTestParams, TestSingleVarMILP) settings.time_limit = 5; settings.mip_scaling = scaling; settings.heuristics_only = heuristics_only; - settings.presolve = false; + settings.presolver = cuopt::linear_programming::presolver_t::None; auto result = cuopt::linear_programming::solve_mip(&handle, problem, settings); diff --git a/docs/cuopt/source/cuopt-server/examples/lp/examples/warmstart_example.py b/docs/cuopt/source/cuopt-server/examples/lp/examples/warmstart_example.py index aea4b557c..a408b86d2 100644 --- a/docs/cuopt/source/cuopt-server/examples/lp/examples/warmstart_example.py +++ b/docs/cuopt/source/cuopt-server/examples/lp/examples/warmstart_example.py @@ -53,6 +53,7 @@ def main(): "solver_config": { "tolerances": {"optimality": 0.0001}, "pdlp_solver_mode": 1, # Stable2 + "presolve": 0, }, } diff --git a/docs/cuopt/source/faq.rst b/docs/cuopt/source/faq.rst index f288f3f38..2ecdf7285 100644 --- a/docs/cuopt/source/faq.rst +++ b/docs/cuopt/source/faq.rst @@ -372,8 +372,7 @@ Linear Programming FAQs .. dropdown:: Does cuOpt implement presolve reductions? - We use PaPILO presolve at the root node. It is enabled by default for MIP and disabled by default for LP. - For LP, dual postsolve is not supported, for this reason dual solution and reduced costs are filled with Nans. + cuOpt supports presolve reductions using PSLP or Papilo for linear programming (LP) problems, and Papilo for mixed-integer programming (MIP) problems. For MIP problems, Papilo presolve is always enabled by default. For LP problems, PSLP presolve is always enabled by default. Presolve is controlled by the ``CUOPT_PRESOLVE`` setting. Mixed Integer Linear Programming FAQs diff --git a/docs/cuopt/source/lp-qp-features.rst b/docs/cuopt/source/lp-qp-features.rst index fde57017e..3dbed1489 100644 --- a/docs/cuopt/source/lp-qp-features.rst +++ b/docs/cuopt/source/lp-qp-features.rst @@ -120,8 +120,8 @@ Crossover allows you to obtain a high-quality basic solution from the results of Presolve -------- -Presolve procedure is applied to the problem before the solver is called. It can be used to reduce the problem size and improve solve time. It is enabled by default for MIP problems, and disabled by default for LP problems. -Furthermore, for LP problems, when the dual solution is not needed, additional presolve procedures can be applied to further improve solve times. This is achieved by turning off dual postsolve with the ``CUOPT_DUAL_POSTSOLVE`` setting. +Presolve procedure is applied to the problem before the solver is called. It can be used to reduce the problem size and improve solve time. cuOpt supports presolve reductions using PSLP or Papilo for linear programming (LP) problems, and Papilo for mixed-integer programming (MIP) problems. For MIP problems, Papilo presolve is always enabled by default. For LP problems, PSLP presolve is always enabled by default. Users can manually select to disable presolve by setting this parameter to 0, enable Papilo presolve by setting this parameter to 1, or enable PSLP presolve by setting this parameter to 2. +Furthermore, for LP problems with Papilo presolver, when the dual solution is not needed, additional presolve procedures can be applied to further improve solve times. This is achieved by turning off dual postsolve with the ``CUOPT_DUAL_POSTSOLVE`` setting. Logging diff --git a/docs/cuopt/source/lp-qp-milp-settings.rst b/docs/cuopt/source/lp-qp-milp-settings.rst index 592cdd025..37b362eea 100644 --- a/docs/cuopt/source/lp-qp-milp-settings.rst +++ b/docs/cuopt/source/lp-qp-milp-settings.rst @@ -63,12 +63,13 @@ parallel parts of the solvers. Presolve ^^^^^^^^ -``CUOPT_PRESOLVE`` controls whether presolve is enabled. Presolve can reduce problem size and improve solve time. Enabled by default for MIP, disabled by default for LP. +``CUOPT_PRESOLVE`` controls which presolver to use for presolve reductions. +cuOpt provides presolve reductions for linear programming (LP) problems using either PSLP or Papilo, and for mixed-integer programming (MIP) problems using Papilo. By default, Papilo presolve is always enabled for MIP problems. For LP problems, PSLP presolve is always enabled by default. You can explicitly control the presolver by setting this parameter to 0 (disable presolve), 1 (Papilo), or 2 (PSLP). Dual Postsolve ^^^^^^^^^^^^^^ -``CUOPT_DUAL_POSTSOLVE`` controls whether dual postsolve is enabled. Disabling dual postsolve can improve solve time at the expense of not having -access to the dual solution. Enabled by default for LP when presolve is enabled. This is not relevant for MIP problems. +``CUOPT_DUAL_POSTSOLVE`` controls whether dual postsolve is enabled when using Papilo presolver for LP problems. Disabling dual postsolve can improve solve time at the expense of not having +access to the dual solution. Enabled by default for LP when Papilo presolve is selected. This is not relevant for MIP problems. Linear Programming ------------------ diff --git a/python/cuopt/cuopt/tests/linear_programming/test_incumbent_callbacks.py b/python/cuopt/cuopt/tests/linear_programming/test_incumbent_callbacks.py index e86391505..c8d8fa78f 100644 --- a/python/cuopt/cuopt/tests/linear_programming/test_incumbent_callbacks.py +++ b/python/cuopt/cuopt/tests/linear_programming/test_incumbent_callbacks.py @@ -92,6 +92,7 @@ def set_solution( assert ( solution.get_termination_status() == MILPTerminationStatus.FeasibleFound + or MILPTerminationStatus.Optimal ) for sol in get_callback.solutions: diff --git a/python/cuopt/cuopt/tests/linear_programming/test_lp_solver.py b/python/cuopt/cuopt/tests/linear_programming/test_lp_solver.py index 09f3c42f4..c26f10851 100644 --- a/python/cuopt/cuopt/tests/linear_programming/test_lp_solver.py +++ b/python/cuopt/cuopt/tests/linear_programming/test_lp_solver.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-FileCopyrightText: Copyright (c) 2023-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 import os @@ -19,7 +19,6 @@ CUOPT_METHOD, CUOPT_MIP_HEURISTICS_ONLY, CUOPT_PDLP_SOLVER_MODE, - CUOPT_PRESOLVE, CUOPT_PRIMAL_INFEASIBLE_TOLERANCE, CUOPT_RELATIVE_DUAL_TOLERANCE, CUOPT_RELATIVE_GAP_TOLERANCE, @@ -27,6 +26,7 @@ CUOPT_SOLUTION_FILE, CUOPT_TIME_LIMIT, CUOPT_USER_PROBLEM_FILE, + CUOPT_PRESOLVE, ) from cuopt.linear_programming.solver.solver_wrapper import ( ErrorStatus, @@ -66,6 +66,7 @@ def test_solver(): settings.set_parameter(CUOPT_METHOD, SolverMethod.PDLP) # FIXME: Stable3 infinite-loops on this sample trivial problem settings.set_parameter(CUOPT_PDLP_SOLVER_MODE, PDLPSolverMode.Stable2) + settings.set_parameter(CUOPT_PRESOLVE, 0) solution = solver.Solve(data_model_obj, settings) assert solution.get_termination_reason() == "Optimal" @@ -414,6 +415,7 @@ def test_parse_var_names(): settings = solver_settings.SolverSettings() settings.set_parameter(CUOPT_METHOD, SolverMethod.PDLP) settings.set_parameter(CUOPT_PDLP_SOLVER_MODE, PDLPSolverMode.Stable2) + settings.set_parameter(CUOPT_PRESOLVE, 0) solution = solver.Solve(data_model_obj, settings) expected_dict = { @@ -502,6 +504,7 @@ def test_warm_start(): settings.set_parameter(CUOPT_PDLP_SOLVER_MODE, PDLPSolverMode.Stable2) settings.set_optimality_tolerance(1e-3) settings.set_parameter(CUOPT_INFEASIBILITY_DETECTION, False) + settings.set_parameter(CUOPT_PRESOLVE, 0) # Solving from scratch until 1e-3 solution = solver.Solve(data_model_obj, settings) @@ -533,6 +536,7 @@ def test_warm_start_other_problem(): settings.set_parameter(CUOPT_PDLP_SOLVER_MODE, PDLPSolverMode.Stable2) settings.set_optimality_tolerance(1e-1) settings.set_parameter(CUOPT_INFEASIBILITY_DETECTION, False) + settings.set_parameter(CUOPT_PRESOLVE, 0) solution = solver.Solve(data_model_obj, settings) file_path = ( @@ -578,7 +582,6 @@ def test_dual_simplex(): settings = solver_settings.SolverSettings() settings.set_parameter(CUOPT_METHOD, SolverMethod.DualSimplex) - settings.set_parameter(CUOPT_PRESOLVE, True) settings.set_parameter(CUOPT_DUAL_POSTSOLVE, False) solution = solver.Solve(data_model_obj, settings) @@ -613,6 +616,7 @@ def test_barrier(): settings = solver_settings.SolverSettings() settings.set_parameter(CUOPT_METHOD, SolverMethod.Barrier) + settings.set_parameter(CUOPT_PRESOLVE, 0) solution = solver.Solve(data_model_obj, settings) assert solution.get_termination_reason() == "Optimal" diff --git a/python/cuopt/cuopt/tests/linear_programming/test_python_API.py b/python/cuopt/cuopt/tests/linear_programming/test_python_API.py index 156c7ed69..efd792a75 100644 --- a/python/cuopt/cuopt/tests/linear_programming/test_python_API.py +++ b/python/cuopt/cuopt/tests/linear_programming/test_python_API.py @@ -33,6 +33,7 @@ CUOPT_METHOD, CUOPT_ORDERING, CUOPT_PDLP_SOLVER_MODE, + CUOPT_PRESOLVE, ) from cuopt.linear_programming.solver_settings import ( PDLPSolverMode, @@ -416,6 +417,8 @@ def test_warm_start(): settings = SolverSettings() settings.set_parameter(CUOPT_PDLP_SOLVER_MODE, PDLPSolverMode.Stable2) settings.set_parameter(CUOPT_METHOD, SolverMethod.PDLP) + # warm start works only with presolve disabled + settings.set_parameter(CUOPT_PRESOLVE, 0) settings.set_optimality_tolerance(1e-3) settings.set_parameter(CUOPT_INFEASIBILITY_DETECTION, False) diff --git a/python/cuopt_server/cuopt_server/tests/test_pdlp_warmstart.py b/python/cuopt_server/cuopt_server/tests/test_pdlp_warmstart.py index 9bcff1ca0..497a9665c 100644 --- a/python/cuopt_server/cuopt_server/tests/test_pdlp_warmstart.py +++ b/python/cuopt_server/cuopt_server/tests/test_pdlp_warmstart.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 import os @@ -11,6 +11,7 @@ CUOPT_INFEASIBILITY_DETECTION, CUOPT_METHOD, CUOPT_PDLP_SOLVER_MODE, + CUOPT_PRESOLVE, ) from cuopt.linear_programming.solver_settings import ( PDLPSolverMode, @@ -38,6 +39,7 @@ def test_warmstart(cuoptproc): # noqa settings.set_parameter(CUOPT_INFEASIBILITY_DETECTION, False) settings.set_parameter(CUOPT_PDLP_SOLVER_MODE, PDLPSolverMode.Stable2) settings.set_parameter(CUOPT_METHOD, SolverMethod.PDLP) + settings.set_parameter(CUOPT_PRESOLVE, 0) data["solver_config"] = settings.toDict() headers = {"CLIENT-VERSION": "custom"} diff --git a/python/cuopt_server/cuopt_server/utils/linear_programming/data_definition.py b/python/cuopt_server/cuopt_server/utils/linear_programming/data_definition.py index 198b115d4..298e10e65 100644 --- a/python/cuopt_server/cuopt_server/utils/linear_programming/data_definition.py +++ b/python/cuopt_server/cuopt_server/utils/linear_programming/data_definition.py @@ -500,11 +500,11 @@ class SolverConfig(StrictModel): default=False, description="Set True to use crossover, False to not use crossover.", ) - presolve: Optional[bool] = Field( + presolve: Optional[int] = Field( default=None, - description="Set True to enable presolve, False to disable presolve. " - "Presolve can reduce problem size and improve solve time. " - "Default is True for MIP problems and False for LP problems.", + description="Set presolve mode: 0 to disable presolve, 1 for Papilo presolve for MIP or LPs, " # noqa + "2 for PSLP LP presolve. Presolve can reduce problem size and improve solve time. " # noqa + "Default is 1 for MIP problems and 2 for LP problems.", ) dual_postsolve: Optional[bool] = Field( default=None, diff --git a/python/cuopt_server/cuopt_server/utils/linear_programming/solver.py b/python/cuopt_server/cuopt_server/utils/linear_programming/solver.py index 5b49e25d7..e7a89ec2d 100644 --- a/python/cuopt_server/cuopt_server/utils/linear_programming/solver.py +++ b/python/cuopt_server/cuopt_server/utils/linear_programming/solver.py @@ -352,9 +352,9 @@ def is_mip(var_types): if solver_config.presolve is None: if is_mip(LP_data.variable_types): - solver_config.presolve = True + solver_config.presolve = 1 else: - solver_config.presolve = False + solver_config.presolve = 2 if solver_config.presolve is not None: solver_settings.set_parameter( diff --git a/thirdparty/THIRD_PARTY_LICENSES b/thirdparty/THIRD_PARTY_LICENSES index 6bce42d31..b52f81a53 100644 --- a/thirdparty/THIRD_PARTY_LICENSES +++ b/thirdparty/THIRD_PARTY_LICENSES @@ -28,858 +28,419 @@ THE SOFTWARE. ----------------------------------------------------------------------------------------- -== papilo LGPL-3.0 - -Files: cpp/build/_deps/papilo-src - - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. - +== PSLP Apache-2.0 + +Files: cpp/build/_deps/pslp-src + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. ----------------------------------------------------------------------------------------- -== papilo GPL-3.0 -Files: cpp/build/_deps/papilo-src - - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. +== papilo Apache-2.0 +Files: cpp/build/_deps/papilo-src + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. ----------------------------------------------------------------------------------------- == bzip2