Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5205471
Add constraints and adjust dual simplex to warm start from the curren…
chris-maes Nov 17, 2025
0584337
Style fixes
chris-maes Nov 17, 2025
74fff99
Remove debugging
chris-maes Nov 17, 2025
099a1df
Merge remote-tracking branch 'cuopt-nvidia/main' into cuts
chris-maes Nov 17, 2025
1882892
Fix issues in adding cuts. Add gomory cuts. Temporarily disable MIP h…
chris-maes Nov 25, 2025
96ed386
Fix unit test
chris-maes Nov 25, 2025
6ff7952
Fix issue when computing nonzeros in C_B
chris-maes Nov 25, 2025
20b5777
Check solution values at end of unit test
chris-maes Nov 25, 2025
ca571a0
Enable c-MIR cuts
chris-maes Nov 25, 2025
9dea7ce
Add integer infeasibility info. Remove inactive cuts. Add mip_cut_pas…
chris-maes Nov 26, 2025
42af00c
Remove small coefficients from cut
chris-maes Dec 2, 2025
dddf42d
CI crash fixes (#691)
aliceb-nv Dec 11, 2025
d97ff6b
REL v25.12.00 release
AyodeAwe Dec 11, 2025
f341e34
Fix incorrect infeasible list
chris-maes Dec 12, 2025
b8e9959
Style fixes
chris-maes Dec 12, 2025
3c36836
Separate out cuts logic into several classes
chris-maes Dec 18, 2025
369e755
Only perform cuts on the original variables. Substitute out slack var…
chris-maes Dec 19, 2025
b48e05b
Knapsack cuts from before the winter break
chris-maes Jan 5, 2026
78cb1dc
Turn off sub-mip. Fix edge norms which was leading to crazy depth on …
chris-maes Jan 6, 2026
1e17743
Check for reduced cost variable fixings
chris-maes Jan 6, 2026
ec883a0
Merge remote-tracking branch 'cuopt-nvidia/main' into cuts
chris-maes Jan 6, 2026
3744548
Also try to improve continuous variables with reduced cost strengthening
chris-maes Jan 6, 2026
f8e6fbe
Fix performance bug in set_quadratic_objective_matrix
chris-maes Jan 7, 2026
6fc7e99
Fix cut scoring when keeping around old cuts that may not be violated
chris-maes Jan 7, 2026
67b57c7
Reenable MIR cuts. Print out types of cut after root node.
chris-maes Jan 8, 2026
b704390
Fix bug in crossover leading to crash on glass-sc. Add node_limit and…
chris-maes Jan 8, 2026
89dafc2
More info on primal infeasibility and trial branching
chris-maes Jan 9, 2026
49bdd7f
Merge branch 'fix_incorrect_infeasible_list' into cuts
chris-maes Jan 9, 2026
f11838d
Add aggregation for MIR cuts
chris-maes Jan 13, 2026
fb85947
Fix bug in knapsack cuts
chris-maes Jan 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cpp/include/cuopt/linear_programming/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
#define CUOPT_MIP_HEURISTICS_ONLY "mip_heuristics_only"
#define CUOPT_MIP_SCALING "mip_scaling"
#define CUOPT_MIP_PRESOLVE "mip_presolve"
#define CUOPT_MIP_CUT_PASSES "mip_cut_passes"
#define CUOPT_MIP_NODE_LIMIT "mip_node_limit"
#define CUOPT_MIP_RELIABILITY_BRANCHING "mip_reliability_branching"
#define CUOPT_SOLUTION_FILE "solution_file"
#define CUOPT_NUM_CPU_THREADS "num_cpu_threads"
#define CUOPT_NUM_GPUS "num_gpus"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ class mip_solver_settings_t {
tolerances_t tolerances;

f_t time_limit = std::numeric_limits<f_t>::infinity();
i_t node_limit = std::numeric_limits<i_t>::max();
i_t reliability_branching = -1;
bool heuristics_only = false;
i_t num_cpu_threads = -1; // -1 means use default number of threads in branch and bound
i_t max_cut_passes = 10; // number of cut passes to make
i_t num_gpus = 1;
bool log_to_console = true;
std::string log_file;
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/dual_simplex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(DUAL_SIMPLEX_SRC_FILES
${CMAKE_CURRENT_SOURCE_DIR}/basis_updates.cpp
${CMAKE_CURRENT_SOURCE_DIR}/bound_flipping_ratio_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/branch_and_bound.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cuts.cpp
${CMAKE_CURRENT_SOURCE_DIR}/crossover.cpp
${CMAKE_CURRENT_SOURCE_DIR}/folding.cpp
${CMAKE_CURRENT_SOURCE_DIR}/initial_basis.cpp
Expand All @@ -34,7 +35,7 @@ set(DUAL_SIMPLEX_SRC_FILES
)

# Uncomment to enable debug info
#set_source_files_properties(${DUAL_SIMPLEX_SRC_FILES} DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTIES COMPILE_OPTIONS "-g1")
set_source_files_properties(${DUAL_SIMPLEX_SRC_FILES} DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTIES COMPILE_OPTIONS "-g1")

set(CUOPT_SRC_FILES ${CUOPT_SRC_FILES}
${DUAL_SIMPLEX_SRC_FILES} PARENT_SCOPE)
14 changes: 13 additions & 1 deletion cpp/src/dual_simplex/basis_solves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@ i_t factorize_basis(const csc_matrix_t<i_t, f_t>& A,
template <typename i_t, typename f_t>
i_t basis_repair(const csc_matrix_t<i_t, f_t>& A,
const simplex_solver_settings_t<i_t, f_t>& settings,
const std::vector<f_t>& lower,
const std::vector<f_t>& upper,
const std::vector<i_t>& deficient,
const std::vector<i_t>& slacks_needed,
std::vector<i_t>& basis_list,
Expand Down Expand Up @@ -658,7 +660,15 @@ i_t basis_repair(const csc_matrix_t<i_t, f_t>& A,
nonbasic_list[nonbasic_map[replace_j]] = bad_j;
vstatus[replace_j] = variable_status_t::BASIC;
// This is the main issue. What value should bad_j take on.
vstatus[bad_j] = variable_status_t::NONBASIC_FREE;
if (lower[bad_j] == -inf && upper[bad_j] == inf) {
vstatus[bad_j] = variable_status_t::NONBASIC_FREE;
} else if (lower[bad_j] > -inf) {
vstatus[bad_j] = variable_status_t::NONBASIC_LOWER;
} else if (upper[bad_j] < inf) {
vstatus[bad_j] = variable_status_t::NONBASIC_UPPER;
} else {
assert(1 == 0);
}
}

return 0;
Expand Down Expand Up @@ -849,6 +859,8 @@ template int factorize_basis<int>(const csc_matrix_t<int, double>& A,

template int basis_repair<int, double>(const csc_matrix_t<int, double>& A,
const simplex_solver_settings_t<int, double>& settings,
const std::vector<double>& lower,
const std::vector<double>& upper,
const std::vector<int>& deficient,
const std::vector<int>& slacks_needed,
std::vector<int>& basis_list,
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/dual_simplex/basis_solves.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ i_t factorize_basis(const csc_matrix_t<i_t, f_t>& A,
template <typename i_t, typename f_t>
i_t basis_repair(const csc_matrix_t<i_t, f_t>& A,
const simplex_solver_settings_t<i_t, f_t>& settings,
const std::vector<f_t>& lower,
const std::vector<f_t>& upper,
const std::vector<i_t>& deficient,
const std::vector<i_t>& slacks_needed,
std::vector<i_t>& basis_list,
Expand Down
211 changes: 210 additions & 1 deletion cpp/src/dual_simplex/basis_updates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,212 @@ i_t basis_update_t<i_t, f_t>::lower_triangular_multiply(const csc_matrix_t<i_t,
return new_nz;
}

// Start of middle product form: basis_update_mpf_t

template <typename i_t, typename f_t>
i_t basis_update_mpf_t<i_t, f_t>::append_cuts(const csr_matrix_t<i_t, f_t>& cuts_basic)
{
const i_t m = L0_.m;

// Solve for U^T W^T = C_B^T
// We do this one row at a time of C_B
csc_matrix_t<i_t, f_t> WT(m, cuts_basic.m, 0);

i_t WT_nz = 0;
for (i_t k = 0; k < cuts_basic.m; k++) {
sparse_vector_t<i_t, f_t> rhs(cuts_basic, k);
u_transpose_solve(rhs);
WT.col_start[k] = WT_nz;
for (i_t q = 0; q < rhs.i.size(); q++) {
WT.i.push_back(rhs.i[q]);
WT.x.push_back(rhs.x[q]);
WT_nz++;
}
}
WT.col_start[cuts_basic.m] = WT_nz;


#ifdef CHECK_W
{
for (i_t k = 0; k < cuts_basic.m; k++) {
std::vector<f_t> WT_col(m, 0.0);
WT.load_a_column(k, WT_col);
std::vector<f_t> CBT_col(m, 0.0);
matrix_transpose_vector_multiply(U0_, 1.0, WT_col, 0.0, CBT_col);
sparse_vector_t<i_t, f_t> CBT_col_sparse(cuts_basic, k);
std::vector<f_t> CBT_col_dense(m);
CBT_col_sparse.to_dense(CBT_col_dense);
for (i_t h = 0; h < m; h++) {
if (std::abs(CBT_col_dense[h] - CBT_col[h]) > 1e-6) {
printf("col %d CBT_col_dense[%d] = %e CBT_col[%d] = %e\n", k, h, CBT_col_dense[h], h, CBT_col[h]);
exit(1);
}
}
}
}
#endif

csc_matrix_t<i_t, f_t> V(cuts_basic.m, m, 0);
if (num_updates_ > 0) {
// W = V T_0 ... T_{num_updates_ - 1}
// or V = W T_{num_updates_ - 1}^{-1} ... T_0^{-1}
// or V^T = T_0^{-T} ... T_{num_updates_ - 1}^{-T} W^T
// We can compute V^T column by column so that we have
// V^T(:, h) = T_0^{-T} ... T_{num_updates_ - 1}^{-T} W^T(:, h)
// or
// V(h, :) = T_0^{-T} ... T_{num_updates_ - 1}^{-T} W^T(:, h)
// So we can form V row by row in CSR and then covert it to CSC
// for appending to L0

csr_matrix_t<i_t, f_t> V_row(cuts_basic.m, m, 0);
i_t V_nz = 0;
const f_t zero_tol = 1e-13;
for (i_t h = 0; h < cuts_basic.m; h++) {
sparse_vector_t<i_t, f_t> rhs(WT, h);
scatter_into_workspace(rhs);
i_t nz = rhs.i.size();
for (i_t k = num_updates_ - 1; k >= 0; --k) {
// T_k^{-T} = ( I - v u^T/(1 + u^T v))
// T_k^{-T} * b = b - v * (u^T * b) / (1 + u^T * v) = b - theta * v, theta = u^T b / mu

const i_t u_col = 2 * k;
const i_t v_col = 2 * k + 1;
const f_t mu = mu_values_[k];

// dot = u^T * b
f_t dot = dot_product(u_col, xi_workspace_, x_workspace_);
const f_t theta = dot / mu;
if (std::abs(theta) > zero_tol) {
add_sparse_column(S_, v_col, -theta, xi_workspace_, nz, x_workspace_);
}
}
gather_into_sparse_vector(nz, rhs);
V_row.row_start[h] = V_nz;
for (i_t q = 0; q < rhs.i.size(); q++) {
V_row.j.push_back(rhs.i[q]);
V_row.x.push_back(rhs.x[q]);
V_nz++;
}
}
V_row.row_start[cuts_basic.m] = V_nz;

V_row.to_compressed_col(V);


#ifdef CHECK_V
csc_matrix_t<i_t, f_t> CB_col(cuts_basic.m, m, 0);
cuts_basic.to_compressed_col(CB_col);
for (i_t k = 0; k < m; k++) {
std::vector<f_t> U_col(m, 0.0);
U0_.load_a_column(k, U_col);
for (i_t h = num_updates_ - 1; h >= 0; --h) {
// T_h = ( I + u_h v_h^T)
// T_h * x = x + u_h * v_h^T * x = x + theta * u_h
const i_t u_col = 2 * h;
const i_t v_col = 2 * h + 1;
f_t theta = dot_product(v_col, U_col);
const i_t col_start = S_.col_start[u_col];
const i_t col_end = S_.col_start[u_col + 1];
for (i_t p = col_start; p < col_end; ++p) {
const i_t i = S_.i[p];
U_col[i] += theta * S_.x[p];
}
}
std::vector<f_t> CB_column(cuts_basic.m, 0.0);
matrix_vector_multiply(V, 1.0, U_col, 0.0, CB_column);
std::vector<f_t> CB_col_dense(cuts_basic.m);
CB_col.load_a_column(k, CB_col_dense);
for (i_t l = 0; l < cuts_basic.m; l++) {
if (std::abs(CB_col_dense[l] - CB_column[l]) > 1e-6) {
printf("col %d CB_col_dense[%d] = %e CB_column[%d] = %e\n", k, l, CB_col_dense[l], l, CB_column[l]);
exit(1);
}
}
}
#endif
} else {
// W = V
WT.transpose(V);
}

// Extend u_i, v_i for i = 0, ..., num_updates_ - 1
S_.m += cuts_basic.m;

// Adjust L and U
// L = [ L0 0 ]
// [ V I ]

i_t V_nz = V.col_start[m];
i_t L_nz = L0_.col_start[m];
csc_matrix_t<i_t, f_t> new_L(m + cuts_basic.m, m + cuts_basic.m, L_nz + V_nz + cuts_basic.m);
i_t predicted_nz = L_nz + V_nz + cuts_basic.m;
L_nz = 0;
for (i_t j = 0; j < m; ++j) {
new_L.col_start[j] = L_nz;
const i_t col_start = L0_.col_start[j];
const i_t col_end = L0_.col_start[j + 1];
for (i_t p = col_start; p < col_end; ++p) {
new_L.i[L_nz] = L0_.i[p];
new_L.x[L_nz] = L0_.x[p];
L_nz++;
}
const i_t V_col_start = V.col_start[j];
const i_t V_col_end = V.col_start[j + 1];
for (i_t p = V_col_start; p < V_col_end; ++p) {
new_L.i[L_nz] = V.i[p] + m;
new_L.x[L_nz] = V.x[p];
L_nz++;
}
}
for (i_t j = m; j < m + cuts_basic.m; ++j) {
new_L.col_start[j] = L_nz;
new_L.i[L_nz] = j;
new_L.x[L_nz] = 1.0;
L_nz++;
}
new_L.col_start[m + cuts_basic.m] = L_nz;
if (L_nz != predicted_nz) {
printf("L_nz %d predicted_nz %d\n", L_nz, predicted_nz);
exit(1);
}
Comment on lines +1275 to +1278
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Replace exit(1) with error propagation.

Lines 1276-1277 unconditionally call exit(1) when an internal consistency check fails. This terminates the application in production builds and prevents proper error recovery.

🔎 Apply this diff to propagate the error
   if (L_nz != predicted_nz) {
-    printf("L_nz %d predicted_nz %d\n", L_nz, predicted_nz);
-    exit(1);
+    settings.log.printf("Internal consistency error: L_nz %d != predicted_nz %d\n", L_nz, predicted_nz);
+    return -1;
   }

Based on coding guidelines: Verify error propagation from internal functions to user-facing APIs.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In @cpp/src/dual_simplex/basis_updates.cpp around lines 1275 - 1278, The
consistency check comparing L_nz and predicted_nz currently calls exit(1) which
aborts the process; instead propagate an error up from the routine that performs
this check (the basis update code that computes L_nz/predicted_nz) by replacing
the printf+exit with an error return or thrown exception consistent with the
project's error-handling convention, include the mismatch details in the
returned/raised error so callers can handle or log it, and update callers of the
function to propagate or handle that error instead of relying on process
termination.


L0_ = new_L;

// Adjust U
// U = [ U0 0 ]
// [ 0 I ]

i_t U_nz = U0_.col_start[m];
U0_.col_start.resize(m + cuts_basic.m + 1);
U0_.i.resize(U_nz + cuts_basic.m);
U0_.x.resize(U_nz + cuts_basic.m);
for (i_t k = m; k < m + cuts_basic.m; ++k) {
U0_.col_start[k] = U_nz;
U0_.i[U_nz] = k;
U0_.x[U_nz] = 1.0;
U_nz++;
}
U0_.col_start[m + cuts_basic.m] = U_nz;
U0_.n = m + cuts_basic.m;
U0_.m = m + cuts_basic.m;

compute_transposes();

// Adjust row_permutation_ and inverse_row_permutation_
row_permutation_.resize(m + cuts_basic.m);
inverse_row_permutation_.resize(m + cuts_basic.m);
for (i_t k = m; k < m + cuts_basic.m; ++k) {
row_permutation_[k] = k;
}
inverse_permutation(row_permutation_, inverse_row_permutation_);

// Adjust workspace sizes
xi_workspace_.resize(2 * (m + cuts_basic.m), 0);
x_workspace_.resize(m + cuts_basic.m, 0.0);

return 0;
}
Comment on lines +1111 to +1315
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Replace exit(1)/printf in append_cuts() with proper error propagation (and validate dimensions).

This is solver-core code and can run in multi-threaded contexts; exit(1) will hard-kill the host process and is not acceptable for a library. Please:

  • replace exit(1) with returning a non-zero status (and let callers map it to lp_status_t::NUMERICAL_ISSUES or similar),
  • route diagnostics via settings.log (or gate printf behind a dedicated debug macro),
  • add fast precondition checks (debug asserts are fine) like cuts_basic.n == L0_.m and consistent index bounds.
Sketch (convert hard exits to status returns)
-          printf("col %d CBT_col_dense[%d] = %e CBT_col[%d] = %e\n", k, h, CBT_col_dense[h], h, CBT_col[h]);
-          exit(1);
+          settings.log.printf(
+            "append_cuts CHECK_W failed: col %d row %d expected %e got %e\n",
+            k, h, CBT_col_dense[h], CBT_col[h]);
+          return 1;
...
-    printf("L_nz %d predicted_nz %d\n", L_nz, predicted_nz);
-    exit(1);
+    settings.log.printf("append_cuts: L nnz mismatch %d predicted %d\n", L_nz, predicted_nz);
+    return 1;

Committable suggestion skipped: line range outside the PR's diff.


template <typename i_t, typename f_t>
void basis_update_mpf_t<i_t, f_t>::gather_into_sparse_vector(i_t nz,
sparse_vector_t<i_t, f_t>& out) const
Expand Down Expand Up @@ -2046,6 +2252,8 @@ template <typename i_t, typename f_t>
int basis_update_mpf_t<i_t, f_t>::refactor_basis(
const csc_matrix_t<i_t, f_t>& A,
const simplex_solver_settings_t<i_t, f_t>& settings,
const std::vector<f_t>& lower,
const std::vector<f_t>& upper,
std::vector<i_t>& basic_list,
std::vector<i_t>& nonbasic_list,
std::vector<variable_status_t>& vstatus)
Expand All @@ -2066,7 +2274,8 @@ int basis_update_mpf_t<i_t, f_t>::refactor_basis(
deficient,
slacks_needed) == -1) {
settings.log.debug("Initial factorization failed\n");
basis_repair(A, settings, deficient, slacks_needed, basic_list, nonbasic_list, vstatus);
basis_repair(
A, settings, lower, upper, deficient, slacks_needed, basic_list, nonbasic_list, vstatus);

#ifdef CHECK_BASIS_REPAIR
const i_t m = A.m;
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/dual_simplex/basis_updates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ class basis_update_mpf_t {
reset_stats();
}

i_t append_cuts(const csr_matrix_t<i_t, f_t>& cuts_basic);

f_t estimate_solution_density(f_t rhs_nz, f_t sum, i_t& num_calls, bool& use_hypersparse) const
{
num_calls++;
Expand Down Expand Up @@ -373,6 +375,8 @@ class basis_update_mpf_t {
// Compute L*U = A(p, basic_list)
int refactor_basis(const csc_matrix_t<i_t, f_t>& A,
const simplex_solver_settings_t<i_t, f_t>& settings,
const std::vector<f_t>& lower,
const std::vector<f_t>& upper,
std::vector<i_t>& basic_list,
std::vector<i_t>& nonbasic_list,
std::vector<variable_status_t>& vstatus);
Expand Down
Loading