25#include "absl/strings/str_cat.h"
26#include "absl/strings/str_format.h"
32#include "ortools/glop/parameters.pb.h"
41ABSL_FLAG(
bool, simplex_display_numbers_as_fractions,
false,
42 "Display numbers as fractions.");
43ABSL_FLAG(
bool, simplex_stop_after_first_basis,
false,
44 "Stop after first basis has been computed.");
45ABSL_FLAG(
bool, simplex_stop_after_feasibility,
false,
46 "Stop after first phase has been completed.");
47ABSL_FLAG(
bool, simplex_display_stats,
false,
"Display algorithm statistics.");
57 explicit Cleanup(std::function<
void()> closure)
58 : closure_(
std::move(closure)) {}
59 ~Cleanup() { closure_(); }
62 std::function<void()> closure_;
66#define DCHECK_COL_BOUNDS(col) \
69 DCHECK_GT(num_cols_, col); \
73#define DCHECK_ROW_BOUNDS(row) \
76 DCHECK_GT(num_rows_, row); \
89 random_(deterministic_random_),
90 basis_factorization_(&compact_matrix_, &basis_),
91 variables_info_(compact_matrix_),
92 primal_edge_norms_(compact_matrix_, variables_info_,
93 basis_factorization_),
94 dual_edge_norms_(basis_factorization_),
95 dual_prices_(random_),
96 variable_values_(parameters_, compact_matrix_, basis_, variables_info_,
97 basis_factorization_, &dual_edge_norms_, &dual_prices_),
98 update_row_(compact_matrix_, transposed_matrix_, variables_info_, basis_,
99 basis_factorization_),
100 reduced_costs_(compact_matrix_,
objective_, basis_, variables_info_,
101 basis_factorization_, random_),
102 entering_variable_(variables_info_, random_, &reduced_costs_),
103 primal_prices_(random_, variables_info_, &primal_edge_norms_,
107 function_stats_(
"SimplexFunctionStats"),
116 variable_starting_values_.
clear();
121 solution_state_ = state;
122 solution_state_has_been_set_externally_ =
true;
127 variable_starting_values_ = values;
131 notify_that_matrix_is_unchanged_ =
true;
138 Cleanup update_deterministic_time_on_return(
141 default_logger_.
EnableLogging(parameters_.log_search_progress());
147 const double start_time =
time_limit->GetElapsedTime();
150 DisplayBasicVariableStatistics();
153 dual_infeasibility_improvement_direction_.
clear();
157 phase_ = Phase::FEASIBILITY;
159 num_feasibility_iterations_ = 0;
160 num_optimization_iterations_ = 0;
161 num_push_iterations_ = 0;
162 feasibility_time_ = 0.0;
163 optimization_time_ = 0.0;
171 solution_state_has_been_set_externally_ =
true;
174 ComputeNumberOfEmptyRows();
175 ComputeNumberOfEmptyColumns();
178 if (absl::GetFlag(FLAGS_simplex_stop_after_first_basis)) {
183 const bool use_dual = parameters_.use_dual_simplex();
188 primal_edge_norms_.
SetPricingRule(parameters_.feasibility_rule());
190 if (parameters_.perturb_costs_in_dual_simplex()) {
194 if (parameters_.use_dedicated_dual_feasibility_algorithm()) {
197 DualMinimize(phase_ == Phase::FEASIBILITY,
time_limit));
214 MakeBoxedVariableDualFeasible(
229 if (initial_infeasibility <
231 SOLVER_LOG(logger_,
"Initial basis is dual feasible.");
233 MakeBoxedVariableDualFeasible(
256 variable_starting_values_);
271 SOLVER_LOG(logger_,
"Infeasible after first phase.");
282 InitializeObjectiveAndTestIfUnchanged(lp);
289 phase_ = Phase::OPTIMIZATION;
290 feasibility_time_ =
time_limit->GetElapsedTime() - start_time;
291 primal_edge_norms_.
SetPricingRule(parameters_.optimization_rule());
292 num_feasibility_iterations_ = num_iterations_;
307 for (
int num_optims = 0;
311 num_optims <= parameters_.max_number_of_reoptimizations() &&
312 !objective_limit_reached_ &&
313 (num_iterations_ == 0 ||
314 num_iterations_ < parameters_.max_number_of_iterations()) &&
316 !absl::GetFlag(FLAGS_simplex_stop_after_feasibility) &&
326 DualMinimize(phase_ == Phase::FEASIBILITY,
time_limit));
337 if (!integrality_scale_.
empty() &&
364 const Fractional tolerance = parameters_.solution_feasibility_tolerance();
369 "PRIMAL_UNBOUNDED was reported, but the residual and/or "
370 "dual infeasibility is above the tolerance");
371 if (parameters_.change_status_to_imprecise()) {
392 double max_magnitude = 0.0;
396 double cost_delta = 0.0;
397 for (ColIndex
col(0);
col < num_cols_; ++
col) {
398 cost_delta += solution_primal_ray_[
col] * objective_[
col];
402 solution_primal_ray_[
col];
404 max_magnitude =
std::max(solution_primal_ray_[
col], max_magnitude);
409 -solution_primal_ray_[
col];
411 max_magnitude =
std::max(-solution_primal_ray_[
col], max_magnitude);
414 SOLVER_LOG(logger_,
"Primal unbounded ray: max blocking magnitude = ",
415 max_magnitude,
", min distance to bound + ", tolerance,
" = ",
416 min_distance,
", ray cost delta = ", cost_delta);
417 if (min_distance * std::abs(cost_delta) < 1 &&
420 "PRIMAL_UNBOUNDED was reported, but the tolerance are good "
421 "and the unbounded ray is not great.");
423 "The difference between unbounded and optimal can depends "
424 "on a slight change of tolerance, trying to see if we are "
425 "at OPTIMAL after postsolve.");
431 const Fractional tolerance = parameters_.solution_feasibility_tolerance();
436 "DUAL_UNBOUNDED was reported, but the residual and/or "
437 "dual infeasibility is above the tolerance");
438 if (parameters_.change_status_to_imprecise()) {
449 parameters_.solution_feasibility_tolerance();
454 if (primal_residual > solution_tolerance ||
455 dual_residual > solution_tolerance) {
457 "OPTIMAL was reported, yet one of the residuals is "
458 "above the solution feasibility tolerance after the "
459 "shift/perturbation are removed.");
460 if (parameters_.change_status_to_imprecise()) {
470 primal_residual, parameters_.primal_feasibility_tolerance());
472 std::max(dual_residual, parameters_.dual_feasibility_tolerance());
477 if (primal_infeasibility > primal_tolerance &&
478 dual_infeasibility > dual_tolerance) {
480 "OPTIMAL was reported, yet both of the infeasibility "
481 "are above the tolerance after the "
482 "shift/perturbation are removed.");
483 if (parameters_.change_status_to_imprecise()) {
486 }
else if (primal_infeasibility > primal_tolerance) {
487 if (num_optims == parameters_.max_number_of_reoptimizations()) {
489 "The primal infeasibility is still higher than the "
490 "requested internal tolerance, but the maximum "
491 "number of optimization is reached.");
495 SOLVER_LOG(logger_,
"Re-optimizing with dual simplex ... ");
497 }
else if (dual_infeasibility > dual_tolerance) {
498 if (num_optims == parameters_.max_number_of_reoptimizations()) {
500 "The dual infeasibility is still higher than the "
501 "requested internal tolerance, but the maximum "
502 "number of optimization is reached.");
506 SOLVER_LOG(logger_,
"Re-optimizing with primal simplex ... ");
517 if (parameters_.change_status_to_imprecise() &&
519 const Fractional tolerance = parameters_.solution_feasibility_tolerance();
538 total_time_ =
time_limit->GetElapsedTime() - start_time;
539 optimization_time_ = total_time_ - feasibility_time_;
540 num_optimization_iterations_ = num_iterations_ - num_feasibility_iterations_;
544 if (!variable_starting_values_.
empty()) {
545 const int num_super_basic = ComputeNumberOfSuperBasicVariables();
546 if (num_super_basic > 0) {
548 "Num super-basic variables left after optimize phase: ",
550 if (parameters_.push_to_vertex()) {
553 phase_ = Phase::PUSH;
559 "Skipping push phase because optimize didn't succeed.");
565 total_time_ =
time_limit->GetElapsedTime() - start_time;
566 push_time_ = total_time_ - feasibility_time_ - optimization_time_;
567 num_push_iterations_ = num_iterations_ - num_feasibility_iterations_ -
568 num_optimization_iterations_;
571 solution_objective_value_ = ComputeInitialProblemObjectiveValue();
584 solution_objective_value_ =
588 solution_objective_value_ = -solution_objective_value_;
592 variable_starting_values_.
clear();
598 return problem_status_;
602 return solution_objective_value_;
606 return num_iterations_;
614 return variable_values_.
Get(
col);
618 return solution_reduced_costs_[
col];
622 return solution_reduced_costs_;
626 return solution_dual_values_[
row];
638 return -variable_values_.
Get(SlackColIndex(
row));
656 return solution_primal_ray_;
660 return solution_dual_ray_;
665 return solution_dual_ray_row_combination_;
672 return basis_factorization_;
675std::string RevisedSimplex::GetPrettySolverStats()
const {
676 return absl::StrFormat(
677 "Problem status : %s\n"
678 "Solving time : %-6.4g\n"
679 "Number of iterations : %u\n"
680 "Time for solvability (first phase) : %-6.4g\n"
681 "Number of iterations for solvability : %u\n"
682 "Time for optimization : %-6.4g\n"
683 "Number of iterations for optimization : %u\n"
684 "Stop after first basis : %d\n",
686 feasibility_time_, num_feasibility_iterations_, optimization_time_,
687 num_optimization_iterations_,
688 absl::GetFlag(FLAGS_simplex_stop_after_first_basis));
701void RevisedSimplex::SetVariableNames() {
702 variable_name_.
resize(num_cols_,
"");
703 for (ColIndex
col(0);
col < first_slack_col_; ++
col) {
704 const ColIndex var_index =
col + 1;
707 for (ColIndex
col(first_slack_col_);
col < num_cols_; ++
col) {
708 const ColIndex var_index =
col - first_slack_col_ + 1;
713void RevisedSimplex::SetNonBasicVariableStatusAndDeriveValue(
719bool RevisedSimplex::BasisIsConsistent()
const {
722 for (RowIndex
row(0);
row < num_rows_; ++
row) {
723 const ColIndex
col = basis_[
row];
724 if (!is_basic.IsSet(
col))
return false;
727 ColIndex cols_in_basis(0);
728 ColIndex cols_not_in_basis(0);
729 for (ColIndex
col(0);
col < num_cols_; ++
col) {
730 cols_in_basis += is_basic.IsSet(
col);
731 cols_not_in_basis += !is_basic.IsSet(
col);
732 if (is_basic.IsSet(
col) !=
738 if (cols_not_in_basis != num_cols_ -
RowToColIndex(num_rows_))
return false;
744void RevisedSimplex::UpdateBasis(ColIndex entering_col, RowIndex basis_row,
753 DCHECK_NE(basis_[basis_row], entering_col);
756 const ColIndex leaving_col = basis_[basis_row];
767 basis_[basis_row] = entering_col;
775class ColumnComparator {
778 bool operator()(ColIndex col_a, ColIndex col_b)
const {
779 return value_[col_a] < value_[col_b];
796void RevisedSimplex::UseSingletonColumnInInitialBasis(
RowToColMapping* basis) {
803 std::vector<ColIndex> singleton_column;
804 DenseRow cost_variation(num_cols_, 0.0);
807 for (ColIndex
col(0);
col < num_cols_; ++
col) {
812 cost_variation[
col] = objective_[
col] / std::abs(slope);
814 cost_variation[
col] = -objective_[
col] / std::abs(slope);
816 singleton_column.push_back(
col);
818 if (singleton_column.empty())
return;
825 ColumnComparator comparator(cost_variation);
826 std::sort(singleton_column.begin(), singleton_column.end(), comparator);
827 DCHECK_LE(cost_variation[singleton_column.front()],
828 cost_variation[singleton_column.back()]);
836 for (
const ColIndex
col : singleton_column) {
848 if (error_[
row] == 0.0)
continue;
874 SetNonBasicVariableStatusAndDeriveValue(
col,
881 SetNonBasicVariableStatusAndDeriveValue(
col,
888bool RevisedSimplex::InitializeMatrixAndTestIfUnchanged(
889 const LinearProgram& lp,
bool lp_is_in_equation_form,
890 bool* only_change_is_new_rows,
bool* only_change_is_new_cols,
891 ColIndex* num_new_cols) {
893 DCHECK(only_change_is_new_rows !=
nullptr);
894 DCHECK(only_change_is_new_cols !=
nullptr);
895 DCHECK(num_new_cols !=
nullptr);
900 const bool old_part_of_matrix_is_unchanged =
902 num_rows_, first_slack_col_, lp.GetSparseMatrix(), compact_matrix_);
905 const ColIndex lp_first_slack =
906 lp_is_in_equation_form ? lp.GetFirstSlackVariable() : lp.num_variables();
911 if (old_part_of_matrix_is_unchanged && lp.num_constraints() == num_rows_ &&
912 lp_first_slack == first_slack_col_) {
918 *only_change_is_new_rows = old_part_of_matrix_is_unchanged &&
919 lp.num_constraints() > num_rows_ &&
920 lp_first_slack == first_slack_col_;
924 *only_change_is_new_cols = old_part_of_matrix_is_unchanged &&
925 lp.num_constraints() == num_rows_ &&
926 lp_first_slack > first_slack_col_;
927 *num_new_cols = *only_change_is_new_cols ? lp_first_slack - first_slack_col_
931 first_slack_col_ = lp_first_slack;
934 num_rows_ = lp.num_constraints();
935 num_cols_ = lp_first_slack +
RowToColIndex(lp.num_constraints());
940 if (lp_is_in_equation_form) {
947 if (parameters_.use_transposed_matrix()) {
955bool RevisedSimplex::OldBoundsAreUnchangedAndNewVariablesHaveOneBoundAtZero(
956 const LinearProgram& lp,
bool lp_is_in_equation_form,
957 ColIndex num_new_cols) {
959 DCHECK_LE(num_new_cols, first_slack_col_);
960 const ColIndex first_new_col(first_slack_col_ - num_new_cols);
965 for (ColIndex
col(0);
col < first_new_col; ++
col) {
973 for (ColIndex
col(first_new_col);
col < first_slack_col_; ++
col) {
974 if (lp.variable_lower_bounds()[
col] != 0.0 &&
975 lp.variable_upper_bounds()[
col] != 0.0) {
981 if (lp_is_in_equation_form) {
982 for (ColIndex
col(first_slack_col_);
col < num_cols_; ++
col) {
989 DCHECK_EQ(num_rows_, lp.num_constraints());
990 for (RowIndex
row(0);
row < num_rows_; ++
row) {
993 -lp.constraint_upper_bounds()[
row] ||
995 -lp.constraint_lower_bounds()[
row]) {
1003bool RevisedSimplex::InitializeObjectiveAndTestIfUnchanged(
1004 const LinearProgram& lp) {
1007 bool objective_is_unchanged =
true;
1008 objective_.
resize(num_cols_, 0.0);
1012 DCHECK_GE(num_cols_, lp.num_variables());
1013 for (ColIndex
col(lp.num_variables());
col < num_cols_; ++
col) {
1014 if (objective_[
col] != 0.0) {
1015 objective_is_unchanged =
false;
1016 objective_[
col] = 0.0;
1020 if (lp.IsMaximizationProblem()) {
1022 for (ColIndex
col(0);
col < lp.num_variables(); ++
col) {
1025 objective_is_unchanged =
false;
1029 objective_offset_ = -lp.objective_offset();
1030 objective_scaling_factor_ = -lp.objective_scaling_factor();
1032 for (ColIndex
col(0);
col < lp.num_variables(); ++
col) {
1035 objective_is_unchanged =
false;
1039 objective_offset_ = lp.objective_offset();
1040 objective_scaling_factor_ = lp.objective_scaling_factor();
1043 return objective_is_unchanged;
1046void RevisedSimplex::InitializeObjectiveLimit(
const LinearProgram& lp) {
1047 objective_limit_reached_ =
false;
1048 DCHECK(std::isfinite(objective_offset_));
1049 DCHECK(std::isfinite(objective_scaling_factor_));
1050 DCHECK_NE(0.0, objective_scaling_factor_);
1053 for (
const bool set_dual : {
true,
false}) {
1065 const Fractional limit = (objective_scaling_factor_ >= 0.0) != set_dual
1066 ? parameters_.objective_lower_limit()
1067 : parameters_.objective_upper_limit();
1069 limit / objective_scaling_factor_ - objective_offset_;
1071 dual_objective_limit_ = shifted_limit;
1073 primal_objective_limit_ = shifted_limit;
1083Status RevisedSimplex::CreateInitialBasis() {
1095 for (RowIndex
row(0);
row < num_rows_; ++
row) {
1096 basis[
row] = SlackColIndex(
row);
1103 if (!parameters_.use_dual_simplex() &&
1104 parameters_.initial_basis() != GlopParameters::MAROS &&
1105 parameters_.exploit_singleton_column_in_initial_basis()) {
1109 for (ColIndex
col(0);
col < num_cols_; ++
col) {
1115 SetNonBasicVariableStatusAndDeriveValue(
col,
1119 SetNonBasicVariableStatusAndDeriveValue(
col,
1126 ComputeVariableValuesError();
1135 UseSingletonColumnInInitialBasis(&basis);
1138 for (RowIndex
row(0);
row < num_rows_; ++
row) {
1140 basis[
row] = SlackColIndex(
row);
1146 if (parameters_.initial_basis() == GlopParameters::NONE) {
1147 return InitializeFirstBasis(basis);
1149 if (parameters_.initial_basis() == GlopParameters::MAROS) {
1150 InitialBasis initial_basis(compact_matrix_, objective_,
lower_bounds,
1152 if (parameters_.use_dual_simplex()) {
1155 initial_basis.GetDualMarosBasis(num_cols_, &basis);
1157 initial_basis.GetPrimalMarosBasis(num_cols_, &basis);
1159 int number_changed = 0;
1160 for (RowIndex
row(0);
row < num_rows_; ++
row) {
1161 if (basis[
row] != SlackColIndex(
row)) {
1165 VLOG(1) <<
"Number of Maros basis changes: " << number_changed;
1166 }
else if (parameters_.initial_basis() == GlopParameters::BIXBY ||
1167 parameters_.initial_basis() == GlopParameters::TRIANGULAR) {
1169 int num_fixed_variables = 0;
1170 for (RowIndex
row(0);
row < basis.size(); ++
row) {
1171 const ColIndex
col = basis[
row];
1174 ++num_fixed_variables;
1178 if (num_fixed_variables == 0) {
1179 SOLVER_LOG(logger_,
"Crash is set to ", parameters_.initial_basis(),
1180 " but there is no equality rows to remove from initial all "
1181 "slack basis. Starting from there.");
1184 SOLVER_LOG(logger_,
"Trying to remove ", num_fixed_variables,
1185 " fixed variables from the initial basis.");
1186 InitialBasis initial_basis(compact_matrix_, objective_,
lower_bounds,
1189 if (parameters_.initial_basis() == GlopParameters::BIXBY) {
1190 if (parameters_.use_scaling()) {
1191 initial_basis.CompleteBixbyBasis(first_slack_col_, &basis);
1193 VLOG(1) <<
"Bixby initial basis algorithm requires the problem "
1194 <<
"to be scaled. Skipping Bixby's algorithm.";
1196 }
else if (parameters_.initial_basis() == GlopParameters::TRIANGULAR) {
1199 if (parameters_.use_dual_simplex()) {
1202 initial_basis.CompleteTriangularDualBasis(num_cols_, &basis);
1204 initial_basis.CompleteTriangularPrimalBasis(num_cols_, &basis);
1207 const Status
status = InitializeFirstBasis(basis);
1213 "Advanced basis algo failed, Reverting to all slack basis.");
1215 for (RowIndex
row(0);
row < num_rows_; ++
row) {
1216 basis[
row] = SlackColIndex(
row);
1222 LOG(
WARNING) <<
"Unsupported initial_basis parameters: "
1223 << parameters_.initial_basis();
1226 return InitializeFirstBasis(basis);
1229Status RevisedSimplex::InitializeFirstBasis(
const RowToColMapping& basis) {
1235 for (RowIndex
row(0);
row < num_rows_; ++
row) {
1237 basis_[
row] = SlackColIndex(
row);
1251 if (condition_number_ub > parameters_.initial_condition_number_threshold()) {
1252 const std::string error_message =
1253 absl::StrCat(
"The matrix condition number upper bound is too high: ",
1254 condition_number_ub);
1260 for (RowIndex
row(0);
row < num_rows_; ++
row) {
1263 DCHECK(BasisIsConsistent());
1272 const Fractional tolerance = parameters_.primal_feasibility_tolerance();
1276 "The primal residual of the initial basis is above the tolerance, ",
1283Status RevisedSimplex::Initialize(
const LinearProgram& lp) {
1284 parameters_ = initial_parameters_;
1285 PropagateParameters();
1293 const bool lp_is_in_equation_form = lp.IsInEquationForm();
1300 ColIndex num_new_cols(0);
1301 bool only_change_is_new_rows =
false;
1302 bool only_change_is_new_cols =
false;
1303 bool matrix_is_unchanged =
true;
1304 bool only_new_bounds =
false;
1305 if (solution_state_.
IsEmpty() || !notify_that_matrix_is_unchanged_) {
1306 matrix_is_unchanged = InitializeMatrixAndTestIfUnchanged(
1307 lp, lp_is_in_equation_form, &only_change_is_new_rows,
1308 &only_change_is_new_cols, &num_new_cols);
1309 only_new_bounds = only_change_is_new_cols && num_new_cols > 0 &&
1310 OldBoundsAreUnchangedAndNewVariablesHaveOneBoundAtZero(
1311 lp, lp_is_in_equation_form, num_new_cols);
1313 CHECK(InitializeMatrixAndTestIfUnchanged(
1314 lp, lp_is_in_equation_form, &only_change_is_new_rows,
1315 &only_change_is_new_cols, &num_new_cols));
1317 notify_that_matrix_is_unchanged_ =
false;
1320 const bool objective_is_unchanged = InitializeObjectiveAndTestIfUnchanged(lp);
1322 const bool bounds_are_unchanged =
1323 lp_is_in_equation_form
1325 lp.variable_lower_bounds(), lp.variable_upper_bounds())
1327 lp.variable_lower_bounds(), lp.variable_upper_bounds(),
1328 lp.constraint_lower_bounds(), lp.constraint_upper_bounds());
1333 if (matrix_is_unchanged && parameters_.allow_simplex_algorithm_change()) {
1334 if (objective_is_unchanged && !bounds_are_unchanged) {
1335 parameters_.set_use_dual_simplex(
true);
1336 PropagateParameters();
1338 if (bounds_are_unchanged && !objective_is_unchanged) {
1339 parameters_.set_use_dual_simplex(
false);
1340 PropagateParameters();
1344 InitializeObjectiveLimit(lp);
1360 bool solve_from_scratch =
true;
1363 if (!solution_state_.
IsEmpty() && !solution_state_has_been_set_externally_) {
1364 if (!parameters_.use_dual_simplex()) {
1369 dual_edge_norms_.
Clear();
1370 dual_pricing_vector_.
clear();
1371 if (matrix_is_unchanged && bounds_are_unchanged) {
1375 solve_from_scratch =
false;
1376 }
else if (only_change_is_new_cols && only_new_bounds) {
1380 variable_starting_values_);
1382 const ColIndex first_new_col(first_slack_col_ - num_new_cols);
1383 for (ColIndex& col_ref : basis_) {
1384 if (col_ref >= first_new_col) {
1385 col_ref += num_new_cols;
1392 primal_edge_norms_.
Clear();
1394 solve_from_scratch =
false;
1400 primal_edge_norms_.
Clear();
1401 if (objective_is_unchanged) {
1402 if (matrix_is_unchanged) {
1403 if (!bounds_are_unchanged) {
1405 first_slack_col_, ColIndex(0), solution_state_);
1407 variable_starting_values_);
1410 solve_from_scratch =
false;
1411 }
else if (only_change_is_new_rows) {
1415 first_slack_col_, ColIndex(0), solution_state_);
1422 dual_pricing_vector_.
clear();
1425 if (InitializeFirstBasis(basis_).ok()) {
1426 solve_from_scratch =
false;
1435 if (solve_from_scratch && !solution_state_.
IsEmpty()) {
1436 basis_factorization_.
Clear();
1438 primal_edge_norms_.
Clear();
1439 dual_edge_norms_.
Clear();
1440 dual_pricing_vector_.
clear();
1448 std::vector<ColIndex> candidates;
1450 candidates.push_back(
col);
1452 SOLVER_LOG(logger_,
"The warm-start state contains ", candidates.size(),
1453 " candidates for the basis (num_rows = ", num_rows_.value(),
1459 if (candidates.size() == num_rows_) {
1461 for (
const ColIndex
col : candidates) {
1462 basis_.push_back(
col);
1468 if (InitializeFirstBasis(basis_).ok()) {
1469 solve_from_scratch =
false;
1473 if (solve_from_scratch) {
1475 const int num_super_basic =
1478 parameters_.crossover_bound_snapping_distance(),
1479 variable_starting_values_);
1481 SOLVER_LOG(logger_,
"The initial basis did not use ",
1482 " BASIC columns from the initial state and used ",
1483 (num_rows_ - (candidates.size() - num_super_basic)).value(),
1484 " slack variables that were not marked BASIC.");
1485 if (num_snapped > 0) {
1487 " of the FREE variables where moved to their bound.");
1491 if (InitializeFirstBasis(basis_).ok()) {
1492 solve_from_scratch =
false;
1495 "RevisedSimplex is not using the warm start "
1496 "basis because it is not factorizable.");
1501 if (solve_from_scratch) {
1502 SOLVER_LOG(logger_,
"Starting basis: create from scratch.");
1503 basis_factorization_.
Clear();
1505 primal_edge_norms_.
Clear();
1506 dual_edge_norms_.
Clear();
1507 dual_pricing_vector_.
clear();
1510 SOLVER_LOG(logger_,
"Starting basis: incremental solve.");
1512 DCHECK(BasisIsConsistent());
1516void RevisedSimplex::DisplayBasicVariableStatistics() {
1519 int num_fixed_variables = 0;
1520 int num_free_variables = 0;
1521 int num_variables_at_bound = 0;
1522 int num_slack_variables = 0;
1523 int num_infeasible_variables = 0;
1529 const Fractional tolerance = parameters_.primal_feasibility_tolerance();
1530 for (RowIndex
row(0);
row < num_rows_; ++
row) {
1531 const ColIndex
col = basis_[
row];
1534 ++num_free_variables;
1538 ++num_infeasible_variables;
1540 if (
col >= first_slack_col_) {
1541 ++num_slack_variables;
1544 ++num_fixed_variables;
1547 ++num_variables_at_bound;
1551 SOLVER_LOG(logger_,
"The matrix with slacks has ",
1552 compact_matrix_.
num_rows().value(),
" rows, ",
1553 compact_matrix_.
num_cols().value(),
" columns, ",
1554 compact_matrix_.
num_entries().value(),
" entries.");
1555 SOLVER_LOG(logger_,
"Number of basic infeasible variables: ",
1556 num_infeasible_variables);
1557 SOLVER_LOG(logger_,
"Number of basic slack variables: ", num_slack_variables);
1559 "Number of basic variables at bound: ", num_variables_at_bound);
1560 SOLVER_LOG(logger_,
"Number of basic fixed variables: ", num_fixed_variables);
1561 SOLVER_LOG(logger_,
"Number of basic free variables: ", num_free_variables);
1562 SOLVER_LOG(logger_,
"Number of super-basic variables: ",
1563 ComputeNumberOfSuperBasicVariables());
1566void RevisedSimplex::SaveState() {
1569 solution_state_has_been_set_externally_ =
false;
1572RowIndex RevisedSimplex::ComputeNumberOfEmptyRows() {
1574 for (ColIndex
col(0);
col < num_cols_; ++
col) {
1576 contains_data[e.row()] =
true;
1579 RowIndex num_empty_rows(0);
1580 for (RowIndex
row(0);
row < num_rows_; ++
row) {
1581 if (!contains_data[
row]) {
1583 VLOG(2) <<
"Row " <<
row <<
" is empty.";
1586 return num_empty_rows;
1589ColIndex RevisedSimplex::ComputeNumberOfEmptyColumns() {
1590 ColIndex num_empty_cols(0);
1591 for (ColIndex
col(0);
col < num_cols_; ++
col) {
1594 VLOG(2) <<
"Column " <<
col <<
" is empty.";
1597 return num_empty_cols;
1600int RevisedSimplex::ComputeNumberOfSuperBasicVariables()
const {
1602 int num_super_basic = 0;
1603 for (ColIndex
col(0);
col < num_cols_; ++
col) {
1605 variable_values_.
Get(
col) != 0.0) {
1609 return num_super_basic;
1612void RevisedSimplex::CorrectErrorsOnVariableValues() {
1624 if (primal_residual >= parameters_.harris_tolerance_ratio() *
1625 parameters_.primal_feasibility_tolerance()) {
1627 VLOG(1) <<
"Primal infeasibility (bounds error) = "
1629 <<
", Primal residual |A.x - b| = "
1634void RevisedSimplex::ComputeVariableValuesError() {
1638 for (ColIndex
col(0);
col < num_cols_; ++
col) {
1644void RevisedSimplex::ComputeDirection(ColIndex
col) {
1648 direction_infinity_norm_ = 0.0;
1651 for (RowIndex
row(0);
row < num_rows_; ++
row) {
1655 direction_infinity_norm_ =
1660 for (
const auto e : direction_) {
1661 direction_infinity_norm_ =
1662 std::max(direction_infinity_norm_, std::abs(e.coefficient()));
1666 num_rows_ == 0 ? 0.0
1667 :
static_cast<double>(direction_.non_zeros.size()) /
1668 static_cast<double>(num_rows_.value())));
1671Fractional RevisedSimplex::ComputeDirectionError(ColIndex
col) {
1674 for (
const auto e : direction_) {
1681template <
bool is_entering_reduced_cost_positive>
1684 RowIndex
row)
const {
1685 const ColIndex
col = basis_[
row];
1690 if (is_entering_reduced_cost_positive) {
1691 if (direction > 0.0) {
1697 if (direction > 0.0) {
1705template <
bool is_entering_reduced_cost_positive>
1706Fractional RevisedSimplex::ComputeHarrisRatioAndLeavingCandidates(
1707 Fractional bound_flip_ratio, SparseColumn* leaving_candidates)
const {
1710 parameters_.harris_tolerance_ratio() *
1711 parameters_.primal_feasibility_tolerance();
1712 const Fractional minimum_delta = parameters_.degenerate_ministep_factor() *
1713 parameters_.primal_feasibility_tolerance();
1719 leaving_candidates->Clear();
1726 ? parameters_.minimum_acceptable_pivot()
1727 : parameters_.ratio_test_zero_threshold();
1731 for (
const auto e : direction_) {
1732 const Fractional magnitude = std::abs(e.coefficient());
1733 if (magnitude <= threshold)
continue;
1736 if (
ratio <= harris_ratio) {
1737 leaving_candidates->SetCoefficient(e.row(),
ratio);
1749 harris_ratio =
std::min(harris_ratio,
1750 std::max(minimum_delta / magnitude,
1751 ratio + harris_tolerance / magnitude));
1754 return harris_ratio;
1767 if (current >= 0.0) {
1768 return candidate >= 0.0 && candidate <= current;
1770 return candidate >= current;
1778Status RevisedSimplex::ChooseLeavingVariableRow(
1779 ColIndex entering_col,
Fractional reduced_cost,
bool* refactorize,
1789 int stats_num_leaving_choices = 0;
1790 equivalent_leaving_choices_.clear();
1794 stats_num_leaving_choices = 0;
1798 const Fractional entering_value = variable_values_.
Get(entering_col);
1800 (reduced_cost > 0.0) ? entering_value -
lower_bounds[entering_col]
1808 (reduced_cost > 0.0) ? ComputeHarrisRatioAndLeavingCandidates<true>(
1809 current_ratio, &leaving_candidates_)
1810 : ComputeHarrisRatioAndLeavingCandidates<false>(
1811 current_ratio, &leaving_candidates_);
1816 if (current_ratio <= harris_ratio) {
1818 *step_length = current_ratio;
1828 stats_num_leaving_choices = 0;
1830 equivalent_leaving_choices_.clear();
1833 if (
ratio > harris_ratio)
continue;
1834 ++stats_num_leaving_choices;
1835 const RowIndex
row = e.row();
1840 const Fractional candidate_magnitude = std::abs(direction_[
row]);
1841 if (candidate_magnitude < pivot_magnitude)
continue;
1842 if (candidate_magnitude == pivot_magnitude) {
1843 if (!IsRatioMoreOrEquallyStable(
ratio, current_ratio))
continue;
1844 if (
ratio == current_ratio) {
1846 equivalent_leaving_choices_.push_back(
row);
1850 equivalent_leaving_choices_.clear();
1851 current_ratio =
ratio;
1852 pivot_magnitude = candidate_magnitude;
1857 if (!equivalent_leaving_choices_.empty()) {
1858 equivalent_leaving_choices_.push_back(*leaving_row);
1860 equivalent_leaving_choices_[std::uniform_int_distribution<int>(
1861 0, equivalent_leaving_choices_.size() - 1)(random_)];
1873 if (current_ratio <= 0.0) {
1877 parameters_.degenerate_ministep_factor() *
1878 parameters_.primal_feasibility_tolerance();
1879 *step_length = minimum_delta / pivot_magnitude;
1881 *step_length = current_ratio;
1888 TestPivot(entering_col, *leaving_row);
1901 if (pivot_magnitude <
1902 parameters_.small_pivot_threshold() * direction_infinity_norm_) {
1907 VLOG(1) <<
"Refactorizing to avoid pivoting by "
1908 << direction_[*leaving_row]
1909 <<
" direction_infinity_norm_ = " << direction_infinity_norm_
1910 <<
" reduced cost = " << reduced_cost;
1911 *refactorize =
true;
1921 VLOG(1) <<
"Couldn't avoid pivoting by " << direction_[*leaving_row]
1922 <<
" direction_infinity_norm_ = " << direction_infinity_norm_
1923 <<
" reduced cost = " << reduced_cost;
1924 DCHECK_GE(std::abs(direction_[*leaving_row]),
1925 parameters_.minimum_acceptable_pivot());
1933 const bool is_reduced_cost_positive = (reduced_cost > 0.0);
1934 const bool is_leaving_coeff_positive = (direction_[*leaving_row] > 0.0);
1935 *
target_bound = (is_reduced_cost_positive == is_leaving_coeff_positive)
1942 ratio_test_stats_.leaving_choices.Add(stats_num_leaving_choices);
1943 if (!equivalent_leaving_choices_.empty()) {
1944 ratio_test_stats_.num_perfect_ties.Add(
1945 equivalent_leaving_choices_.size());
1948 ratio_test_stats_.abs_used_pivot.Add(std::abs(direction_[*leaving_row]));
1970 bool operator<(
const BreakPoint& other)
const {
1971 if (
ratio == other.ratio) {
1973 return row > other.row;
1977 return ratio > other.ratio;
1988void RevisedSimplex::PrimalPhaseIChooseLeavingVariableRow(
1989 ColIndex entering_col,
Fractional reduced_cost,
bool* refactorize,
1990 RowIndex* leaving_row,
Fractional* step_length,
2003 const Fractional entering_value = variable_values_.
Get(entering_col);
2004 Fractional current_ratio = (reduced_cost > 0.0)
2009 std::vector<BreakPoint> breakpoints;
2010 const Fractional tolerance = parameters_.primal_feasibility_tolerance();
2011 for (
const auto e : direction_) {
2013 reduced_cost > 0.0 ? e.coefficient() : -e.coefficient();
2014 const Fractional magnitude = std::abs(direction);
2015 if (magnitude < tolerance)
continue;
2030 const ColIndex
col = basis_[e.row()];
2041 if (to_lower >= 0.0 && to_lower < current_ratio) {
2042 breakpoints.push_back(
2043 BreakPoint(e.row(), to_lower, magnitude,
lower_bound));
2045 if (to_upper >= 0.0 && to_upper < current_ratio) {
2046 breakpoints.push_back(
2047 BreakPoint(e.row(), to_upper, magnitude,
upper_bound));
2053 std::make_heap(breakpoints.begin(), breakpoints.end());
2057 Fractional improvement = std::abs(reduced_cost);
2060 while (!breakpoints.empty()) {
2061 const BreakPoint top = breakpoints.front();
2069 if (top.coeff_magnitude > best_magnitude) {
2070 *leaving_row = top.row;
2071 current_ratio = top.ratio;
2072 best_magnitude = top.coeff_magnitude;
2078 improvement -= top.coeff_magnitude;
2079 if (improvement <= 0.0)
break;
2080 std::pop_heap(breakpoints.begin(), breakpoints.end());
2081 breakpoints.pop_back();
2087 parameters_.small_pivot_threshold() * direction_infinity_norm_;
2088 if (best_magnitude < threshold && !basis_factorization_.
IsRefactorized()) {
2089 *refactorize =
true;
2093 *step_length = current_ratio;
2097Status RevisedSimplex::DualChooseLeavingVariableRow(RowIndex* leaving_row,
2106 if (dual_prices_.
Size() == 0) {
2117 const ColIndex leaving_col = basis_[*leaving_row];
2137 if (
cost == 0.0)
return false;
2147template <
bool use_dense_update>
2148void RevisedSimplex::OnDualPriceChange(
const DenseColumn& squared_norm,
2152 const bool is_candidate =
2153 IsDualPhaseILeavingCandidate(price, type, threshold);
2155 if (use_dense_update) {
2165void RevisedSimplex::DualPhaseIUpdatePrice(RowIndex leaving_row,
2166 ColIndex entering_col) {
2177 dual_pricing_vector_.
empty()) {
2182 const Fractional threshold = parameters_.ratio_test_zero_threshold();
2192 dual_pricing_vector_[leaving_row] / direction_[leaving_row];
2193 for (
const auto e : direction_) {
2194 dual_pricing_vector_[e.row()] -= e.coefficient() * step;
2195 OnDualPriceChange(squared_norms, e.row(), variable_type[basis_[e.row()]],
2198 dual_pricing_vector_[leaving_row] = step;
2202 dual_pricing_vector_[leaving_row] -=
2203 dual_infeasibility_improvement_direction_[entering_col];
2204 if (dual_infeasibility_improvement_direction_[entering_col] != 0.0) {
2205 --num_dual_infeasible_positions_;
2207 dual_infeasibility_improvement_direction_[entering_col] = 0.0;
2210 dual_infeasibility_improvement_direction_[basis_[leaving_row]] = 0.0;
2213 OnDualPriceChange(squared_norms, leaving_row, variable_type[entering_col],
2217template <
typename Cols>
2218void RevisedSimplex::DualPhaseIUpdatePriceOnReducedCostChange(
2221 bool something_to_do =
false;
2226 for (ColIndex
col : cols) {
2229 (can_increase.IsSet(
col) && reduced_cost < -tolerance) ? 1.0
2230 : (can_decrease.IsSet(
col) && reduced_cost > tolerance) ? -1.0
2232 if (sign != dual_infeasibility_improvement_direction_[
col]) {
2234 --num_dual_infeasible_positions_;
2235 }
else if (dual_infeasibility_improvement_direction_[
col] == 0.0) {
2236 ++num_dual_infeasible_positions_;
2238 if (!something_to_do) {
2239 initially_all_zero_scratchpad_.
values.
resize(num_rows_, 0.0);
2241 initially_all_zero_scratchpad_.
non_zeros.clear();
2242 something_to_do =
true;
2246 num_update_price_operations_ +=
2249 col, sign - dual_infeasibility_improvement_direction_[
col],
2250 &initially_all_zero_scratchpad_);
2251 dual_infeasibility_improvement_direction_[
col] = sign;
2254 if (something_to_do) {
2260 const Fractional threshold = parameters_.ratio_test_zero_threshold();
2261 basis_factorization_.
RightSolve(&initially_all_zero_scratchpad_);
2262 if (initially_all_zero_scratchpad_.
non_zeros.empty()) {
2264 for (RowIndex
row(0);
row < num_rows_; ++
row) {
2265 if (initially_all_zero_scratchpad_[
row] == 0.0)
continue;
2266 dual_pricing_vector_[
row] += initially_all_zero_scratchpad_[
row];
2267 OnDualPriceChange<
true>(
2268 squared_norms,
row, variable_type[basis_[
row]], threshold);
2272 for (
const auto e : initially_all_zero_scratchpad_) {
2273 dual_pricing_vector_[e.row()] += e.coefficient();
2274 OnDualPriceChange(squared_norms, e.row(),
2275 variable_type[basis_[e.row()]], threshold);
2276 initially_all_zero_scratchpad_[e.row()] = 0.0;
2279 initially_all_zero_scratchpad_.non_zeros.clear();
2283Status RevisedSimplex::DualPhaseIChooseLeavingVariableRow(
2284 RowIndex* leaving_row,
Fractional* cost_variation,
2304 dual_pricing_vector_.
empty()) {
2306 num_dual_infeasible_positions_ = 0;
2309 dual_infeasibility_improvement_direction_.
AssignToZero(num_cols_);
2310 DualPhaseIUpdatePriceOnReducedCostChange(
2320 if (num_dual_infeasible_positions_ == 0)
return Status::OK();
2327 *cost_variation = dual_pricing_vector_[*leaving_row];
2328 const ColIndex leaving_col = basis_[*leaving_row];
2329 if (*cost_variation < 0.0) {
2338template <
typename BoxedVariableCols>
2339void RevisedSimplex::MakeBoxedVariableDualFeasible(
2340 const BoxedVariableCols& cols,
bool update_basic_values) {
2342 std::vector<ColIndex> changed_cols;
2352 const Fractional dual_feasibility_tolerance =
2355 for (
const ColIndex
col : cols) {
2364 if (reduced_cost > dual_feasibility_tolerance &&
2368 changed_cols.push_back(
col);
2369 }
else if (reduced_cost < -dual_feasibility_tolerance &&
2373 changed_cols.push_back(
col);
2377 if (!changed_cols.empty()) {
2378 iteration_stats_.num_dual_flips.Add(changed_cols.size());
2380 update_basic_values);
2384Fractional RevisedSimplex::ComputeStepToMoveBasicVariableToBound(
2389 const ColIndex leaving_col = basis_[leaving_row];
2390 const Fractional leaving_variable_value = variable_values_.
Get(leaving_col);
2400 return unscaled_step / direction_[leaving_row];
2403bool RevisedSimplex::TestPivot(ColIndex entering_col, RowIndex leaving_row) {
2404 VLOG(1) <<
"Test pivot.";
2406 const ColIndex leaving_col = basis_[leaving_row];
2407 basis_[leaving_row] = entering_col;
2411 CompactSparseMatrixView basis_matrix(&compact_matrix_, &basis_);
2413 basis_[leaving_row] = leaving_col;
2420void RevisedSimplex::PermuteBasis() {
2427 if (col_perm.empty())
return;
2433 if (!dual_pricing_vector_.
empty()) {
2448Status RevisedSimplex::UpdateAndPivot(ColIndex entering_col,
2449 RowIndex leaving_row,
2466 pivot_from_update_row = update_row_.
GetCoefficient(entering_col);
2477 const ColIndex leaving_col = basis_[leaving_row];
2485 ratio_test_stats_.bound_shift.Add(variable_values_.
Get(leaving_col) -
2488 UpdateBasis(entering_col, leaving_row, leaving_variable_status);
2491 const Fractional pivot_from_direction = direction_[leaving_row];
2493 std::abs(pivot_from_update_row - pivot_from_direction);
2494 if (diff > parameters_.refactorization_threshold() *
2495 (1 + std::abs(pivot_from_direction))) {
2496 VLOG(1) <<
"Refactorizing: imprecise pivot " << pivot_from_direction
2497 <<
" diff = " << diff;
2501 basis_factorization_.
Update(entering_col, leaving_row, direction_));
2509Status RevisedSimplex::RefactorizeBasisIfNeeded(
bool* refactorize) {
2516 *refactorize =
false;
2521 if (
col >= integrality_scale_.
size()) {
2522 integrality_scale_.
resize(
col + 1, 0.0);
2524 integrality_scale_[
col] = scale;
2529 Cleanup update_deterministic_time_on_return(
2536 std::vector<ColIndex> candidates;
2542 bool refactorize =
false;
2545 for (
int i = 0; i < 10; ++i) {
2548 if (num_pivots >= 5)
break;
2549 if (candidates.empty())
break;
2553 std::uniform_int_distribution<int>(0, candidates.size() - 1)(random_);
2554 const ColIndex entering_col = candidates[
index];
2556 candidates.pop_back();
2570 ComputeDirection(entering_col);
2572 RowIndex leaving_row;
2574 bool local_refactorize =
false;
2576 ChooseLeavingVariableRow(entering_col, fake_rc, &local_refactorize,
2579 if (local_refactorize)
continue;
2581 if (std::abs(step_length) <= 1e-6)
continue;
2582 if (leaving_row !=
kInvalidRow && std::abs(direction_[leaving_row]) < 0.1) {
2585 const Fractional step = (fake_rc > 0.0) ? -step_length : step_length;
2591 const auto get_diff = [
this](ColIndex
col,
Fractional old_value,
2593 if (
col >= integrality_scale_.
size() || integrality_scale_[
col] == 0.0) {
2597 return (std::abs(new_value * s - std::round(new_value * s)) -
2598 std::abs(old_value * s - std::round(old_value * s)));
2600 Fractional diff = get_diff(entering_col, variable_values_.
Get(entering_col),
2601 variable_values_.
Get(entering_col) + step);
2602 for (
const auto e : direction_) {
2603 const ColIndex
col = basis_[e.row()];
2605 const Fractional new_value = old_value - e.coefficient() * step;
2606 diff += get_diff(
col, old_value, new_value);
2610 if (diff > -1e-2)
continue;
2620 SetNonBasicVariableStatusAndDeriveValue(entering_col,
2622 }
else if (step < 0.0) {
2623 SetNonBasicVariableStatusAndDeriveValue(entering_col,
2630 const ColIndex leaving_col = basis_[leaving_row];
2641 entering_col, leaving_col, leaving_row, direction_, &update_row_);
2643 entering_col, leaving_row, direction_,
2652 const Fractional dir = -direction_[leaving_row] * step;
2653 const bool is_degenerate =
2657 if (!is_degenerate) {
2661 UpdateAndPivot(entering_col, leaving_row,
target_bound));
2664 VLOG(1) <<
"Polish num_pivots: " << num_pivots <<
" gain:" << total_gain;
2683Status RevisedSimplex::PrimalMinimize(TimeLimit*
time_limit) {
2685 Cleanup update_deterministic_time_on_return(
2687 num_consecutive_degenerate_iterations_ = 0;
2688 bool refactorize =
false;
2694 if (phase_ == Phase::FEASIBILITY) {
2715 CorrectErrorsOnVariableValues();
2716 DisplayIterationInfo(
true);
2718 if (phase_ == Phase::FEASIBILITY) {
2730 if (phase_ == Phase::OPTIMIZATION &&
2731 ComputeObjectiveValue() < primal_objective_limit_) {
2732 VLOG(1) <<
"Stopping the primal simplex because"
2733 <<
" the objective limit " << primal_objective_limit_
2734 <<
" has been reached.";
2736 objective_limit_reached_ =
true;
2739 }
else if (phase_ == Phase::FEASIBILITY) {
2752 if (phase_ == Phase::FEASIBILITY) {
2755 if (primal_infeasibility <
2756 parameters_.primal_feasibility_tolerance()) {
2759 VLOG(1) <<
"Infeasible problem! infeasibility = "
2760 << primal_infeasibility;
2769 VLOG(1) <<
"Optimal reached, double checking...";
2778 ComputeDirection(entering_col);
2792 VLOG(1) <<
"Skipping col #" << entering_col
2793 <<
" whose reduced cost is no longer valid under precise reduced "
2804 if (num_iterations_ == parameters_.max_number_of_iterations() ||
2810 RowIndex leaving_row;
2812 if (phase_ == Phase::FEASIBILITY) {
2813 PrimalPhaseIChooseLeavingVariableRow(entering_col, reduced_cost,
2814 &refactorize, &leaving_row,
2818 ChooseLeavingVariableRow(entering_col, reduced_cost, &refactorize,
2821 if (refactorize)
continue;
2826 VLOG(1) <<
"Infinite step length, double checking...";
2830 if (phase_ == Phase::FEASIBILITY) {
2832 VLOG(1) <<
"Unbounded feasibility problem !?";
2835 VLOG(1) <<
"Unbounded problem.";
2838 for (RowIndex
row(0);
row < num_rows_; ++
row) {
2839 const ColIndex
col = basis_[
row];
2840 solution_primal_ray_[
col] = -direction_[
row];
2842 solution_primal_ray_[entering_col] = 1.0;
2850 Fractional step = (reduced_cost > 0.0) ? -step_length : step_length;
2851 if (phase_ == Phase::FEASIBILITY && leaving_row !=
kInvalidRow) {
2861 step = ComputeStepToMoveBasicVariableToBound(leaving_row,
target_bound);
2865 const ColIndex leaving_col =
2871 bool is_degenerate =
false;
2873 Fractional dir = -direction_[leaving_row] * step;
2881 if (!is_degenerate) {
2882 DCHECK_EQ(step, ComputeStepToMoveBasicVariableToBound(leaving_row,
2891 entering_col, basis_[leaving_row], leaving_row, direction_,
2894 direction_, &update_row_);
2896 if (!is_degenerate) {
2905 UpdateAndPivot(entering_col, leaving_row,
target_bound));
2907 if (is_degenerate) {
2908 timer.AlsoUpdate(&iteration_stats_.degenerate);
2910 timer.AlsoUpdate(&iteration_stats_.normal);
2919 SetNonBasicVariableStatusAndDeriveValue(entering_col,
2921 }
else if (step < 0.0) {
2922 SetNonBasicVariableStatusAndDeriveValue(entering_col,
2929 if (phase_ == Phase::FEASIBILITY && leaving_row !=
kInvalidRow) {
2935 &objective_[leaving_col]);
2940 if (step_length == 0.0) {
2941 num_consecutive_degenerate_iterations_++;
2943 if (num_consecutive_degenerate_iterations_ > 0) {
2944 iteration_stats_.degenerate_run_size.Add(
2945 num_consecutive_degenerate_iterations_);
2946 num_consecutive_degenerate_iterations_ = 0;
2951 if (num_consecutive_degenerate_iterations_ > 0) {
2952 iteration_stats_.degenerate_run_size.Add(
2953 num_consecutive_degenerate_iterations_);
2969Status RevisedSimplex::DualMinimize(
bool feasibility_phase,
2971 Cleanup update_deterministic_time_on_return(
2973 num_consecutive_degenerate_iterations_ = 0;
2974 bool refactorize =
false;
2976 bound_flip_candidates_.clear();
2979 RowIndex leaving_row;
2984 ColIndex entering_col;
2993 const bool old_refactorize_value = refactorize;
3014 if (feasibility_phase || old_refactorize_value) {
3026 if (!feasibility_phase) {
3027 MakeBoxedVariableDualFeasible(
3040 if (phase_ == Phase::OPTIMIZATION &&
3042 ComputeObjectiveValue() > dual_objective_limit_) {
3044 "Stopping the dual simplex because"
3045 " the objective limit ",
3046 dual_objective_limit_,
" has been reached.");
3048 objective_limit_reached_ =
true;
3053 DisplayIterationInfo(
false);
3057 if (!feasibility_phase) {
3060 MakeBoxedVariableDualFeasible(bound_flip_candidates_,
3062 bound_flip_candidates_.clear();
3070 if (feasibility_phase) {
3082 VLOG(1) <<
"Optimal reached, double checking.";
3088 if (feasibility_phase) {
3093 if (num_dual_infeasible_positions_ == 0) {
3096 VLOG(1) <<
"DUAL infeasible in dual phase I.";
3107 if (feasibility_phase) {
3114 &bound_flip_candidates_, &entering_col));
3120 VLOG(1) <<
"No entering column. Double checking...";
3126 if (feasibility_phase) {
3128 VLOG(1) <<
"Unbounded dual feasibility problem !?";
3132 solution_dual_ray_ =
3135 solution_dual_ray_row_combination_.
AssignToZero(num_cols_);
3137 solution_dual_ray_row_combination_[
col] =
3140 if (cost_variation < 0) {
3142 ChangeSign(&solution_dual_ray_row_combination_);
3153 if (std::abs(entering_coeff) < parameters_.dual_small_pivot_threshold() &&
3155 VLOG(1) <<
"Trying not to pivot by " << entering_coeff;
3161 ComputeDirection(entering_col);
3167 if (std::abs(direction_[leaving_row]) <
3168 parameters_.small_pivot_threshold() * direction_infinity_norm_) {
3170 VLOG(1) <<
"Trying not pivot by " << entering_coeff <<
" ("
3171 << direction_[leaving_row]
3172 <<
") because the direction has a norm of "
3173 << direction_infinity_norm_;
3185 if (num_iterations_ == parameters_.max_number_of_iterations() ||
3200 const bool increasing_rc_is_needed =
3201 (cost_variation > 0.0) == (entering_coeff > 0.0);
3207 timer.AlsoUpdate(&iteration_stats_.degenerate);
3209 timer.AlsoUpdate(&iteration_stats_.normal);
3221 entering_col, leaving_row, direction_,
3227 if (feasibility_phase) {
3228 DualPhaseIUpdatePrice(leaving_row, entering_col);
3231 ComputeStepToMoveBasicVariableToBound(leaving_row,
target_bound);
3236 const ColIndex leaving_col = basis_[leaving_row];
3238 UpdateAndPivot(entering_col, leaving_row,
target_bound));
3248 if (std::abs(primal_step) * parameters_.primal_feasibility_tolerance() >
3257Status RevisedSimplex::PrimalPush(TimeLimit*
time_limit) {
3259 Cleanup update_deterministic_time_on_return(
3261 bool refactorize =
false;
3265 primal_edge_norms_.
Clear();
3266 dual_edge_norms_.
Clear();
3270 std::vector<ColIndex> super_basic_cols;
3273 variable_values_.
Get(
col) != 0) {
3274 super_basic_cols.push_back(
col);
3278 while (!super_basic_cols.empty()) {
3286 CorrectErrorsOnVariableValues();
3287 DisplayIterationInfo(
true);
3291 ColIndex entering_col = super_basic_cols.back();
3305 const Fractional entering_value = variable_values_.
Get(entering_col);
3306 if (variables_info_.
GetTypeRow()[entering_col] ==
3308 if (entering_value > 0) {
3320 if (diff_lb <= diff_ub) {
3328 ComputeDirection(entering_col);
3331 RowIndex leaving_row;
3335 &refactorize, &leaving_row,
3338 if (refactorize)
continue;
3341 super_basic_cols.pop_back();
3344 if (variables_info_.
GetTypeRow()[entering_col] ==
3346 step_length = std::fabs(entering_value);
3348 VLOG(1) <<
"Infinite step for bounded variable ?!";
3354 const Fractional step = (fake_rc > 0.0) ? -step_length : step_length;
3357 const ColIndex leaving_col =
3366 bool is_degenerate =
false;
3368 Fractional dir = -direction_[leaving_row] * step;
3376 if (!is_degenerate) {
3377 DCHECK_EQ(step, ComputeStepToMoveBasicVariableToBound(leaving_row,
3384 if (!is_degenerate) {
3393 UpdateAndPivot(entering_col, leaving_row,
target_bound));
3395 if (is_degenerate) {
3396 timer.AlsoUpdate(&iteration_stats_.degenerate);
3398 timer.AlsoUpdate(&iteration_stats_.normal);
3405 if (variables_info_.
GetTypeRow()[entering_col] ==
3407 variable_values_.
Set(entering_col, 0.0);
3408 }
else if (step > 0.0) {
3409 SetNonBasicVariableStatusAndDeriveValue(entering_col,
3411 }
else if (step < 0.0) {
3412 SetNonBasicVariableStatusAndDeriveValue(entering_col,
3421 if (!super_basic_cols.empty() > 0) {
3422 SOLVER_LOG(logger_,
"Push terminated early with ", super_basic_cols.size(),
3423 " super-basic variables remaining.");
3433ColIndex RevisedSimplex::SlackColIndex(RowIndex
row)
const {
3440 result.append(iteration_stats_.StatString());
3441 result.append(ratio_test_stats_.StatString());
3442 result.append(entering_variable_.
StatString());
3445 result.append(variable_values_.
StatString());
3446 result.append(primal_edge_norms_.
StatString());
3447 result.append(dual_edge_norms_.
StatString());
3449 result.append(basis_factorization_.
StatString());
3454void RevisedSimplex::DisplayAllStats() {
3455 if (absl::GetFlag(FLAGS_simplex_display_stats)) {
3457 absl::FPrintF(stderr,
"%s", GetPrettySolverStats());
3461Fractional RevisedSimplex::ComputeObjectiveValue()
const {
3467Fractional RevisedSimplex::ComputeInitialProblemObjectiveValue()
const {
3471 return objective_scaling_factor_ * (sum + objective_offset_);
3476 deterministic_random_.seed(
parameters.random_seed());
3480 PropagateParameters();
3483void RevisedSimplex::PropagateParameters() {
3493void RevisedSimplex::DisplayIterationInfo(
bool primal) {
3495 const std::string first_word = primal ?
"Primal " :
"Dual ";
3498 case Phase::FEASIBILITY: {
3499 const int64_t iter = num_iterations_;
3502 if (parameters_.use_dual_simplex()) {
3503 if (parameters_.use_dedicated_dual_feasibility_algorithm()) {
3511 name =
"sum_dual_infeasibilities";
3514 name =
"sum_primal_infeasibilities";
3517 SOLVER_LOG(logger_, first_word,
"feasibility phase, iteration # ", iter,
3518 ", ",
name,
" = ", absl::StrFormat(
"%.15E", objective));
3521 case Phase::OPTIMIZATION: {
3522 const int64_t iter = num_iterations_ - num_feasibility_iterations_;
3528 const Fractional objective = ComputeInitialProblemObjectiveValue();
3529 SOLVER_LOG(logger_, first_word,
"optimization phase, iteration # ", iter,
3530 ", objective = ", absl::StrFormat(
"%.15E", objective));
3534 const int64_t iter = num_iterations_ - num_feasibility_iterations_ -
3535 num_optimization_iterations_;
3536 SOLVER_LOG(logger_, first_word,
"push phase, iteration # ", iter,
3537 ", remaining_variables_to_push = ",
3538 ComputeNumberOfSuperBasicVariables());
3543void RevisedSimplex::DisplayErrors() {
3547 SOLVER_LOG(logger_,
"Primal infeasibility (bounds) = ",
3549 SOLVER_LOG(logger_,
"Primal residual |A.x - b| = ",
3551 SOLVER_LOG(logger_,
"Dual infeasibility (reduced costs) = ",
3553 SOLVER_LOG(logger_,
"Dual residual |c_B - y.B| = ",
3559std::string StringifyMonomialWithFlags(
const Fractional a,
3560 const std::string& x) {
3562 a, x, absl::GetFlag(FLAGS_simplex_display_numbers_as_fractions));
3568std::string StringifyWithFlags(
const Fractional x) {
3570 absl::GetFlag(FLAGS_simplex_display_numbers_as_fractions));
3575std::string RevisedSimplex::SimpleVariableInfo(ColIndex
col)
const {
3581 absl::StrAppendFormat(&output,
"%d (%s) = %s, %s, %s, [%s,%s]",
col.value(),
3582 variable_name_[
col],
3583 StringifyWithFlags(variable_values_.
Get(
col)),
3591void RevisedSimplex::DisplayInfoOnVariables()
const {
3593 for (ColIndex
col(0);
col < num_cols_; ++
col) {
3597 objective_coefficient * variable_value;
3598 VLOG(3) << SimpleVariableInfo(
col) <<
". " << variable_name_[
col] <<
" = "
3599 << StringifyWithFlags(variable_value) <<
" * "
3600 << StringifyWithFlags(objective_coefficient)
3601 <<
"(obj) = " << StringifyWithFlags(objective_contribution);
3603 VLOG(3) <<
"------";
3607void RevisedSimplex::DisplayVariableBounds() {
3612 for (ColIndex
col(0);
col < num_cols_; ++
col) {
3613 switch (variable_type[
col]) {
3617 VLOG(3) << variable_name_[
col]
3621 VLOG(3) << variable_name_[
col]
3626 <<
" <= " << variable_name_[
col]
3630 VLOG(3) << variable_name_[
col] <<
" = "
3634 LOG(DFATAL) <<
"Column " <<
col <<
" has no meaningful status.";
3644 for (ColIndex
col(0);
col < num_cols_; ++
col) {
3645 ComputeDirection(
col);
3646 for (
const auto e : direction_) {
3647 if (column_scales ==
nullptr) {
3648 dictionary[e.row()].SetCoefficient(
col, e.coefficient());
3652 col < column_scales->
size() ? (*column_scales)[
col] : 1.0;
3654 ? (*column_scales)[
GetBasis(e.row())]
3656 dictionary[e.row()].SetCoefficient(
3657 col, direction_[e.row()] * (numerator / denominator));
3669 solution_objective_value_ = ComputeInitialProblemObjectiveValue();
3673void RevisedSimplex::DisplayRevisedSimplexDebugInfo() {
3676 DisplayInfoOnVariables();
3678 std::string output =
"z = " + StringifyWithFlags(ComputeObjectiveValue());
3681 absl::StrAppend(&output, StringifyMonomialWithFlags(reduced_costs[
col],
3682 variable_name_[
col]));
3684 VLOG(3) << output <<
";";
3686 const RevisedSimplexDictionary dictionary(
nullptr,
this);
3688 for (
const SparseRow&
row : dictionary) {
3690 ColIndex basic_col = basis_[r];
3691 absl::StrAppend(&output, variable_name_[basic_col],
" = ",
3692 StringifyWithFlags(variable_values_.
Get(basic_col)));
3693 for (
const SparseRowEntry e :
row) {
3694 if (e.col() != basic_col) {
3695 absl::StrAppend(&output,
3696 StringifyMonomialWithFlags(e.coefficient(),
3697 variable_name_[e.col()]));
3700 VLOG(3) << output <<
";";
3702 VLOG(3) <<
"------";
3703 DisplayVariableBounds();
3708void RevisedSimplex::DisplayProblem()
const {
3712 DisplayInfoOnVariables();
3713 std::string output =
"min: ";
3714 bool has_objective =
false;
3715 for (ColIndex
col(0);
col < num_cols_; ++
col) {
3717 has_objective |= (
coeff != 0.0);
3718 absl::StrAppend(&output,
3719 StringifyMonomialWithFlags(
coeff, variable_name_[
col]));
3721 if (!has_objective) {
3722 absl::StrAppend(&output,
" 0");
3724 VLOG(3) << output <<
";";
3725 for (RowIndex
row(0);
row < num_rows_; ++
row) {
3727 for (ColIndex
col(0);
col < num_cols_; ++
col) {
3728 absl::StrAppend(&output,
3729 StringifyMonomialWithFlags(
3731 variable_name_[
col]));
3733 VLOG(3) << output <<
" = 0;";
3735 VLOG(3) <<
"------";
3739void RevisedSimplex::AdvanceDeterministicTime(TimeLimit*
time_limit) {
3742 const double deterministic_time_delta =
3743 current_deterministic_time - last_deterministic_time_update_;
3744 time_limit->AdvanceDeterministicTime(deterministic_time_delta);
3745 last_deterministic_time_update_ = current_deterministic_time;
3748#undef DCHECK_COL_BOUNDS
3749#undef DCHECK_ROW_BOUNDS
#define DCHECK_LE(val1, val2)
#define DCHECK_NE(val1, val2)
#define DCHECK_GE(val1, val2)
#define DCHECK_GT(val1, val2)
#define DCHECK_LT(val1, val2)
#define DCHECK(condition)
#define DCHECK_EQ(val1, val2)
#define VLOG(verboselevel)
void push_back(const value_type &x)
bool IsSet(IndexType i) const
void SetLogToStdOut(bool enable)
bool LoggingIsEnabled() const
void EnableLogging(bool enable)
std::string StatString() const
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
Fractional ComputeInfinityNormConditionNumberUpperBound() const
ABSL_MUST_USE_RESULT Status Refactorize()
const ColumnPermutation & GetColumnPermutation() const
ABSL_MUST_USE_RESULT Status Initialize()
bool IsRefactorized() const
ABSL_MUST_USE_RESULT Status Update(ColIndex entering_col, RowIndex leaving_variable_row, const ScatteredColumn &direction)
RowToColMapping ComputeInitialBasis(const std::vector< ColIndex > &candidates)
void RightSolveForProblemColumn(ColIndex col, ScatteredColumn *d) const
void SetColumnPermutationToIdentity()
void SetParameters(const GlopParameters ¶meters)
void RightSolve(ScatteredColumn *d) const
double DeterministicTime() const
ABSL_MUST_USE_RESULT Status ForceRefactorization()
std::string StatString() const
Fractional LookUpCoefficient(RowIndex index) const
Fractional EntryCoefficient(EntryIndex i) const
Fractional GetFirstCoefficient() const
RowIndex EntryRow(EntryIndex i) const
EntryIndex num_entries() const
void ColumnCopyToDenseColumn(ColIndex col, DenseColumn *dense_column) const
ColIndex num_cols() const
void ColumnAddMultipleToSparseScatteredColumn(ColIndex col, Fractional multiplier, ScatteredColumn *column) const
RowIndex num_rows() const
void PopulateFromTranspose(const CompactSparseMatrix &input)
Fractional ColumnScalarProduct(ColIndex col, const DenseRow &vector) const
void PopulateFromSparseMatrixAndAddSlacks(const SparseMatrix &input)
void ColumnAddMultipleToDenseColumn(ColIndex col, Fractional multiplier, DenseColumn *dense_column) const
void PopulateFromMatrixView(const MatrixView &input)
EntryIndex num_entries() const
ColumnView column(ColIndex col) const
void UpdateBeforeBasisPivot(ColIndex entering_col, RowIndex leaving_row, const ScatteredColumn &direction, const ScatteredRow &unit_row_left_inverse)
void UpdateDataOnBasisPermutation(const ColumnPermutation &col_perm)
const DenseColumn & GetEdgeSquaredNorms()
void ResizeOnNewRows(RowIndex new_size)
void SetParameters(const GlopParameters ¶meters)
bool NeedsBasisRefactorization() const
std::string StatString() const
void AddOrUpdate(Index position, Fractional value)
void Remove(Index position)
void DenseAddOrUpdate(Index position, Fractional value)
void ClearAndResize(Index n)
std::string StatString() const
ABSL_MUST_USE_RESULT Status DualPhaseIChooseEnteringColumn(bool nothing_to_recompute, const UpdateRow &update_row, Fractional cost_variation, ColIndex *entering_col)
void SetParameters(const GlopParameters ¶meters)
double DeterministicTime() const
std::string StatString() const
ABSL_MUST_USE_RESULT Status DualChooseEnteringColumn(bool nothing_to_recompute, const UpdateRow &update_row, Fractional cost_variation, std::vector< ColIndex > *bound_flip_candidates, ColIndex *entering_col)
bool IsMaximizationProblem() const
ABSL_MUST_USE_RESULT Status ComputeFactorization(const CompactSparseMatrixView &compact_matrix)
void UpdateBeforeBasisPivot(ColIndex entering_col, ColIndex leaving_col, RowIndex leaving_row, const ScatteredColumn &direction, UpdateRow *update_row)
void SetPricingRule(GlopParameters::PricingRule rule)
void TestEnteringEdgeNormPrecision(ColIndex entering_col, const ScatteredColumn &direction)
void SetParameters(const GlopParameters ¶meters)
double DeterministicTime() const
bool NeedsBasisRefactorization() const
std::string StatString() const
void ForceRecomputation()
void SetAndDebugCheckThatColumnIsDualFeasible(ColIndex col)
void UpdateBeforeBasisPivot(ColIndex entering_col, UpdateRow *update_row)
void RecomputePriceAt(ColIndex col)
ColIndex GetBestEnteringColumn()
void ResetForNewObjective()
Fractional TestEnteringReducedCostPrecision(ColIndex entering_col, const ScatteredColumn &direction)
void MakeReducedCostsPrecise()
bool AreReducedCostsRecomputed()
bool AreReducedCostsPrecise()
bool IsValidPrimalEnteringCandidate(ColIndex col) const
void SetNonBasicVariableCostToZero(ColIndex col, Fractional *current_cost)
bool HasCostShift() const
Fractional ComputeMaximumDualInfeasibilityOnNonBoxedVariables()
bool StepIsDualDegenerate(bool increasing_rc_is_needed, ColIndex col)
Fractional ComputeSumOfDualInfeasibilities()
const DenseRow & GetFullReducedCosts()
void UpdateBeforeBasisPivot(ColIndex entering_col, RowIndex leaving_row, const ScatteredColumn &direction, UpdateRow *update_row)
const DenseRow & GetReducedCosts()
Fractional GetDualFeasibilityTolerance() const
const DenseColumn & GetDualValues()
void ClearAndRemoveCostShifts()
Fractional ComputeMaximumDualResidual()
void UpdateDataOnBasisPermutation()
void ShiftCostIfNeeded(bool increasing_rc_is_needed, ColIndex col)
Fractional ComputeMaximumDualInfeasibility()
void SetParameters(const GlopParameters ¶meters)
double DeterministicTime() const
bool NeedsBasisRefactorization() const
std::string StatString() const
const DenseRow & GetDualRayRowCombination() const
Fractional GetVariableValue(ColIndex col) const
void SetIntegralityScale(ColIndex col, Fractional scale)
const DenseRow & GetReducedCosts() const
const DenseRow & GetPrimalRay() const
Fractional GetConstraintActivity(RowIndex row) const
VariableStatus GetVariableStatus(ColIndex col) const
Fractional GetReducedCost(ColIndex col) const
const DenseColumn & GetDualRay() const
ABSL_MUST_USE_RESULT Status Solve(const LinearProgram &lp, TimeLimit *time_limit)
ProblemStatus GetProblemStatus() const
Fractional GetObjectiveValue() const
RowMajorSparseMatrix ComputeDictionary(const DenseRow *column_scales)
Fractional GetDualValue(RowIndex row) const
void NotifyThatMatrixIsUnchangedForNextSolve()
void SetStartingVariableValuesForNextSolve(const DenseRow &values)
ConstraintStatus GetConstraintStatus(RowIndex row) const
void ComputeBasicVariablesForState(const LinearProgram &linear_program, const BasisState &state)
ColIndex GetProblemNumCols() const
void LoadStateForNextSolve(const BasisState &state)
RowIndex GetProblemNumRows() const
void ClearStateForNextSolve()
const BasisFactorization & GetBasisFactorization() const
int64_t GetNumberOfIterations() const
const BasisState & GetState() const
ColIndex GetBasis(RowIndex row) const
void SetParameters(const GlopParameters ¶meters)
double DeterministicTime() const
typename Iterator::Entry Entry
void AssignToZero(IntType size)
void resize(IntType size)
const ScatteredRow & GetUnitRowLeftInverse() const
void ComputeUnitRowLeftInverse(RowIndex leaving_row)
void RecomputeFullUpdateRow(RowIndex leaving_row)
const bool IsComputed() const
const Fractional GetCoefficient(ColIndex col) const
void ComputeUpdateRow(RowIndex leaving_row)
void SetParameters(const GlopParameters ¶meters)
double DeterministicTime() const
const ColIndexVector & GetNonZeroPositions() const
std::string StatString() const
void Set(ColIndex col, Fractional value)
void SetNonBasicVariableValueFromStatus(ColIndex col)
Fractional ComputeMaximumPrimalInfeasibility() const
Fractional ComputeSumOfPrimalInfeasibilities() const
void UpdateGivenNonBasicVariables(const std::vector< ColIndex > &cols_to_update, bool update_basic_variables)
void ResetAllNonBasicVariableValues(const DenseRow &free_initial_values)
void UpdateDualPrices(const std::vector< RowIndex > &row)
void UpdateOnPivoting(const ScatteredColumn &direction, ColIndex entering_col, Fractional step)
const Fractional Get(ColIndex col) const
void RecomputeBasicVariableValues()
Fractional ComputeMaximumPrimalResidual() const
void RecomputeDualPrices()
bool UpdatePrimalPhaseICosts(const Rows &rows, DenseRow *objective)
const DenseRow & GetDenseRow() const
std::string StatString() const
const DenseBitRow & GetIsBasicBitRow() const
int SnapFreeVariablesToBound(Fractional distance, const DenseRow &starting_values)
const DenseRow & GetVariableLowerBounds() const
int ChangeUnusedBasicVariablesToFree(const RowToColMapping &basis)
const DenseBitRow & GetNonBasicBoxedVariables() const
Fractional GetBoundDifference(ColIndex col) const
const DenseBitRow & GetCanIncreaseBitRow() const
const DenseBitRow & GetCanDecreaseBitRow() const
const VariableTypeRow & GetTypeRow() const
void EndDualPhaseI(Fractional dual_feasibility_tolerance, const DenseRow &reduced_costs)
void MakeBoxedVariableRelevant(bool value)
void UpdateToNonBasicStatus(ColIndex col, VariableStatus status)
const DenseBitRow & GetNotBasicBitRow() const
void InitializeToDefaultStatus()
const VariableStatusRow & GetStatusRow() const
void UpdateToBasicStatus(ColIndex col)
const DenseRow & GetVariableUpperBounds() const
const DenseBitRow & GetIsRelevantBitRow() const
void InitializeFromBasisState(ColIndex first_slack, ColIndex num_new_cols, const BasisState &state)
bool LoadBoundsAndReturnTrueIfUnchanged(const DenseRow &new_lower_bounds, const DenseRow &new_upper_bounds)
void TransformToDualPhaseIProblem(Fractional dual_feasibility_tolerance, const DenseRow &reduced_costs)
ModelSharedTimeLimit * time_limit
std::string StringifyMonomial(const Fractional a, const std::string &x, bool fraction)
Fractional Square(Fractional f)
Fractional InfinityNorm(const DenseColumn &v)
const RowIndex kInvalidRow(-1)
std::string Stringify(const Fractional x, bool fraction)
StrictITIVector< ColIndex, VariableType > VariableTypeRow
@ UPPER_AND_LOWER_BOUNDED
Fractional PreciseScalarProduct(const DenseRowOrColumn &u, const DenseRowOrColumn2 &v)
StrictITIVector< ColIndex, Fractional > DenseRow
std::string GetProblemStatusString(ProblemStatus problem_status)
Index ColToIntIndex(ColIndex col)
Permutation< ColIndex > ColumnPermutation
StrictITIVector< ColIndex, VariableStatus > VariableStatusRow
ColIndex RowToColIndex(RowIndex row)
bool IsFinite(Fractional value)
bool AreFirstColumnsAndRowsExactlyEquals(RowIndex num_rows, ColIndex num_cols, const SparseMatrix &matrix_a, const CompactSparseMatrix &matrix_b)
const DenseRow & Transpose(const DenseColumn &col)
Bitset64< ColIndex > DenseBitRow
ConstraintStatus VariableToConstraintStatus(VariableStatus status)
void ChangeSign(StrictITIVector< IndexType, Fractional > *data)
constexpr const uint64_t kDeterministicSeed
StrictITIVector< RowIndex, ColIndex > RowToColMapping
std::string GetVariableTypeString(VariableType variable_type)
void ApplyColumnPermutationToRowIndexedVector(const Permutation< ColIndex > &col_perm, RowIndexedVector *v)
StrictITIVector< RowIndex, Fractional > DenseColumn
StrictITIVector< RowIndex, bool > DenseBooleanColumn
static double DeterministicTimeForFpOperations(int64_t n)
std::string GetVariableStatusString(VariableStatus status)
const ColIndex kInvalidCol(-1)
void swap(IdMap< K, V > &a, IdMap< K, V > &b)
Collection of objects used to extend the Constraint Solver library.
DisabledScopedTimeDistributionUpdater ScopedTimeDistributionUpdater
#define RETURN_IF_NULL(x)
Fractional coeff_magnitude
#define DCHECK_ROW_BOUNDS(row)
ABSL_FLAG(bool, simplex_display_numbers_as_fractions, false, "Display numbers as fractions.")
#define DCHECK_COL_BOUNDS(col)
std::vector< double > lower_bounds
std::vector< double > upper_bounds
#define IF_STATS_ENABLED(instructions)
#define SCOPED_TIME_STAT(stats)
#define GLOP_RETURN_IF_ERROR(function_call)
#define GLOP_RETURN_ERROR_IF_NULL(arg)
VariableStatusRow statuses
void ClearNonZerosIfTooDense(double ratio_for_using_dense_representation)
std::vector< Index > non_zeros
StrictITIVector< Index, Fractional > values
#define SOLVER_LOG(logger,...)
#define VLOG_IS_ON(verboselevel)