26 const ColIndex num_cols = matrix_.
num_cols();
27 DCHECK_EQ(num_cols, new_lower_bounds.
size());
28 DCHECK_EQ(num_cols, new_upper_bounds.
size());
31 if (lower_bounds_ == new_lower_bounds && upper_bounds_ == new_upper_bounds) {
35 lower_bounds_ = new_lower_bounds;
36 upper_bounds_ = new_upper_bounds;
38 for (ColIndex
col(0);
col < num_cols; ++
col) {
39 variable_type_[
col] = ComputeVariableType(
col);
49 const ColIndex num_cols = matrix_.
num_cols();
51 const RowIndex num_rows = constraint_lower_bounds.
size();
53 bool is_unchanged = (num_cols == lower_bounds_.
size());
55 lower_bounds_.
resize(num_cols, 0.0);
56 upper_bounds_.
resize(num_cols, 0.0);
60 for (ColIndex
col(0);
col < num_variables; ++
col) {
66 variable_type_[
col] = ComputeVariableType(
col);
71 for (RowIndex
row(0);
row < num_rows; ++
row) {
73 if (lower_bounds_[
col] != -constraint_upper_bounds[
row] ||
74 upper_bounds_[
col] != -constraint_lower_bounds[
row]) {
75 lower_bounds_[
col] = -constraint_upper_bounds[
row];
76 upper_bounds_[
col] = -constraint_lower_bounds[
row];
78 variable_type_[
col] = ComputeVariableType(
col);
85 void VariablesInfo::ResetStatusInfo() {
86 const ColIndex num_cols = matrix_.
num_cols();
87 DCHECK_EQ(num_cols, lower_bounds_.
size());
88 DCHECK_EQ(num_cols, upper_bounds_.
size());
102 boxed_variables_are_relevant_ =
true;
103 num_entries_in_relevant_columns_ = 0;
108 ColIndex num_new_cols,
112 const ColIndex num_cols = lower_bounds_.
size();
113 DCHECK_LE(num_new_cols, first_slack_col);
114 const ColIndex first_new_col(first_slack_col - num_new_cols);
118 for (ColIndex
col(0);
col < num_cols; ++
col) {
123 }
else if (
col >= first_slack_col &&
142 if (lower_bounds_[
col] == upper_bounds_[
col]) {
146 ? DefaultVariableStatus(
col)
151 if (lower_bounds_[
col] == upper_bounds_[
col]) {
155 ? DefaultVariableStatus(
col)
167 const ColIndex num_cols = lower_bounds_.
size();
169 for (
const ColIndex
col : basis) {
172 int num_no_longer_in_basis = 0;
173 for (ColIndex
col(0);
col < num_cols; ++
col) {
175 ++num_no_longer_in_basis;
183 return num_no_longer_in_basis;
189 const ColIndex num_cols = lower_bounds_.
size();
190 for (ColIndex
col(0);
col < num_cols; ++
col) {
194 col < starting_values.
size() ? starting_values[
col] : 0.0;
197 if (diff_lb <= diff_ub) {
214 const ColIndex num_cols = lower_bounds_.
size();
215 for (ColIndex
col(0);
col < num_cols; ++
col) {
222 DCHECK_LT(
col, lower_bounds_.
size());
223 if (lower_bounds_[
col] == upper_bounds_[
col]) {
233 return std::abs(lower_bounds_[
col]) <= std::abs(upper_bounds_[
col])
239 if (
value == boxed_variables_are_relevant_)
return;
240 boxed_variables_are_relevant_ =
value;
242 for (
const ColIndex
col : non_basic_boxed_variables_) {
246 for (
const ColIndex
col : non_basic_boxed_variables_) {
247 SetRelevance(
col,
false);
253 if (in_dual_phase_one_) {
258 variable_type_[
col] = ComputeVariableType(
col);
262 not_basic_.
Set(
col,
false);
263 can_increase_.
Set(
col,
false);
264 can_decrease_.
Set(
col,
false);
265 non_basic_boxed_variables_.
Set(
col,
false);
266 SetRelevance(
col,
false);
273 is_basic_.
Set(
col,
false);
274 not_basic_.
Set(
col,
true);
282 non_basic_boxed_variables_.
Set(
col, boxed);
284 (boxed_variables_are_relevant_ || !boxed);
285 SetRelevance(
col, relevance);
289 return variable_type_;
293 return variable_status_;
297 return can_increase_;
301 return can_decrease_;
315 return non_basic_boxed_variables_;
319 return num_entries_in_relevant_columns_;
323 DCHECK_LE(lower_bounds_[
col], upper_bounds_[
col]);
331 }
else if (lower_bounds_[
col] == upper_bounds_[
col]) {
338 void VariablesInfo::SetRelevance(ColIndex
col,
bool relevance) {
339 if (relevance_.
IsSet(
col) == relevance)
return;
351 void VariablesInfo::UpdateStatusForNewType(ColIndex
col) {
352 switch (variable_status_[
col]) {
357 if (lower_bounds_[
col] == upper_bounds_[
col]) {
369 if (lower_bounds_[
col] == upper_bounds_[
col]) {
389 DCHECK(!in_dual_phase_one_);
390 in_dual_phase_one_ =
true;
391 saved_lower_bounds_ = lower_bounds_;
392 saved_upper_bounds_ = upper_bounds_;
398 const ColIndex num_cols = matrix_.
num_cols();
399 for (ColIndex
col(0);
col < num_cols; ++
col) {
400 switch (variable_type_[
col]) {
403 lower_bounds_[
col] = 0.0;
404 upper_bounds_[
col] = 0.0;
408 lower_bounds_[
col] = 0.0;
409 upper_bounds_[
col] = 1.0;
413 lower_bounds_[
col] = -1.0;
414 upper_bounds_[
col] = 0.0;
418 lower_bounds_[
col] = -1000.0;
419 upper_bounds_[
col] = 1000.0;
427 if (reduced_costs[
col] > dual_feasibility_tolerance) {
429 }
else if (reduced_costs[
col] < -dual_feasibility_tolerance) {
434 UpdateStatusForNewType(
col);
440 DCHECK(in_dual_phase_one_);
441 in_dual_phase_one_ =
false;
442 std::swap(saved_lower_bounds_, lower_bounds_);
443 std::swap(saved_upper_bounds_, upper_bounds_);
452 const ColIndex num_cols = matrix_.
num_cols();
453 for (ColIndex
col(0);
col < num_cols; ++
col) {
454 variable_type_[
col] = ComputeVariableType(
col);
463 if (reduced_costs[
col] > dual_feasibility_tolerance) {
465 }
else if (reduced_costs[
col] < -dual_feasibility_tolerance) {
470 UpdateStatusForNewType(
col);
void ClearAndResize(IndexType size)
bool IsSet(IndexType i) const
ColIndex num_cols() const
EntryIndex ColumnNumEntries(ColIndex col) const
void resize(IntType size)
const DenseBitRow & GetIsBasicBitRow() const
int SnapFreeVariablesToBound(Fractional distance, const DenseRow &starting_values)
EntryIndex GetNumEntriesInRelevantColumns() const
int ChangeUnusedBasicVariablesToFree(const RowToColMapping &basis)
const DenseBitRow & GetNonBasicBoxedVariables() 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()
VariablesInfo(const CompactSparseMatrix &matrix)
const VariableStatusRow & GetStatusRow() const
void UpdateToBasicStatus(ColIndex col)
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)
@ UPPER_AND_LOWER_BOUNDED
constexpr double kInfinity
ColIndex RowToColIndex(RowIndex row)
bool IsFinite(Fractional value)
void swap(IdMap< K, V > &a, IdMap< K, V > &b)
Collection of objects used to extend the Constraint Solver library.
VariableStatusRow statuses
VectorXd variable_lower_bounds
VectorXd variable_upper_bounds