diff --git a/ortools/glop/revised_simplex.h b/ortools/glop/revised_simplex.h index 277fb854d0..095f9e1244 100644 --- a/ortools/glop/revised_simplex.h +++ b/ortools/glop/revised_simplex.h @@ -50,9 +50,6 @@ // s1 is an m1-vector (m1 being the height of A1), // s2 is an m2-vector (m2 being the height of A2). // -// See Design Document at -// or search for "Google Linear Programming" in Docs -// // The following are very good references for terminology, data structures, // and algorithms. They all contain a wealth of references. // diff --git a/ortools/lp_data/lp_data.cc b/ortools/lp_data/lp_data.cc index e9e1a7ab2a..04194b3dbf 100644 --- a/ortools/lp_data/lp_data.cc +++ b/ortools/lp_data/lp_data.cc @@ -641,7 +641,7 @@ void LinearProgram::AddSlackVariablesWhereNecessary( // Clean up the matrix. We're going to add entries, but we'll only be adding // them to new columns, and only one entry per column, which does not // invalidate the "cleanness" of the matrix. - matrix_.CleanUp(); + CleanUp(); // Detect which constraints produce an integer slack variable. A constraint // has an integer slack variable, if it contains only integer variables with @@ -682,6 +682,8 @@ void LinearProgram::AddSlackVariablesWhereNecessary( SetCoefficient(row, slack_col, 1.0); SetConstraintBounds(row, 0.0, 0.0); } + + columns_are_known_to_be_clean_ = true; transpose_matrix_is_consistent_ = false; if (first_slack_variable_ == kInvalidCol) { first_slack_variable_ = original_num_variables; diff --git a/ortools/lp_data/lp_data.h b/ortools/lp_data/lp_data.h index 9eb310c032..eddd7e00de 100644 --- a/ortools/lp_data/lp_data.h +++ b/ortools/lp_data/lp_data.h @@ -521,6 +521,16 @@ class LinearProgram { // integer bounds. bool BoundsOfIntegerConstraintsAreInteger(Fractional tolerance) const; + // Advanced usage. Bypass the costly call to CleanUp() when we known that the + // change we made kept the matrix columns "clean" (see the comment of + // CleanUp()). This is unsafe but can save a big chunk of the running time + // when one does a small amount of incremental changes to the problem (like + // adding a new row with no duplicates or zero entries). + void NotifyThatColumnsAreClean() { + DCHECK(matrix_.IsCleanedUp()); + columns_are_known_to_be_clean_ = true; + } + private: // A helper function that updates the vectors integer_variables_list_, // binary_variables_list_, and non_binary_variables_list_. diff --git a/ortools/sat/linear_programming_constraint.cc b/ortools/sat/linear_programming_constraint.cc index 3106784399..13531432e8 100644 --- a/ortools/sat/linear_programming_constraint.cc +++ b/ortools/sat/linear_programming_constraint.cc @@ -239,6 +239,7 @@ bool LinearProgrammingConstraint::Propagate() { if (num_new_cuts > 0) { num_cuts_ += num_new_cuts; VLOG(1) << "#cuts " << num_cuts_; + lp_data_.NotifyThatColumnsAreClean(); lp_data_.AddSlackVariablesWhereNecessary(false); const auto status = simplex_.Solve(lp_data_, time_limit_); CHECK(status.ok()) << "LinearProgrammingConstraint encountered an error: "