24 const ColIndex num_cols = matrix_.
num_cols();
29 if (lower_bounds_ == new_lower_bounds && upper_bounds_ == new_upper_bounds) {
33 lower_bounds_ = new_lower_bounds;
34 upper_bounds_ = new_upper_bounds;
36 for (ColIndex
col(0);
col < num_cols; ++
col) {
37 variable_type_[
col] = ComputeVariableType(
col);
47 const ColIndex num_cols = matrix_.
num_cols();
49 const RowIndex num_rows = constraint_lower_bounds.
size();
51 bool is_unchanged = (num_cols == lower_bounds_.
size());
53 lower_bounds_.
resize(num_cols, 0.0);
54 upper_bounds_.
resize(num_cols, 0.0);
58 for (ColIndex
col(0);
col < num_variables; ++
col) {
64 variable_type_[
col] = ComputeVariableType(
col);
69 for (RowIndex
row(0);
row < num_rows; ++
row) {
71 if (lower_bounds_[
col] != -constraint_upper_bounds[
row] ||
72 upper_bounds_[
col] != -constraint_lower_bounds[
row]) {
73 lower_bounds_[
col] = -constraint_upper_bounds[
row];
74 upper_bounds_[
col] = -constraint_lower_bounds[
row];
76 variable_type_[
col] = ComputeVariableType(
col);
83void VariablesInfo::ResetStatusInfo() {
84 const ColIndex num_cols = matrix_.
num_cols();
100 boxed_variables_are_relevant_ =
true;
101 num_entries_in_relevant_columns_ = 0;
106 ColIndex num_new_cols,
110 const ColIndex num_cols = lower_bounds_.
size();
111 DCHECK_LE(num_new_cols, first_slack_col);
112 const ColIndex first_new_col(first_slack_col - num_new_cols);
116 for (ColIndex
col(0);
col < num_cols; ++
col) {
121 }
else if (
col >= first_slack_col &&
140 if (lower_bounds_[
col] == upper_bounds_[
col]) {
144 ? DefaultVariableStatus(
col)
149 if (lower_bounds_[
col] == upper_bounds_[
col]) {
153 ? DefaultVariableStatus(
col)
165 const ColIndex num_cols = lower_bounds_.
size();
167 for (
const ColIndex
col : basis) {
170 int num_no_longer_in_basis = 0;
171 for (ColIndex
col(0);
col < num_cols; ++
col) {
173 ++num_no_longer_in_basis;
181 return num_no_longer_in_basis;
187 const ColIndex num_cols = lower_bounds_.
size();
188 for (ColIndex
col(0);
col < num_cols; ++
col) {
192 col < starting_values.
size() ? starting_values[
col] : 0.0;
195 if (diff_lb <= diff_ub) {
212 const ColIndex num_cols = lower_bounds_.
size();
213 for (ColIndex
col(0);
col < num_cols; ++
col) {
221 if (lower_bounds_[
col] == upper_bounds_[
col]) {
231 return std::abs(lower_bounds_[
col]) <= std::abs(upper_bounds_[
col])
237 if (
value == boxed_variables_are_relevant_)
return;
238 boxed_variables_are_relevant_ =
value;
240 for (
const ColIndex
col : non_basic_boxed_variables_) {
244 for (
const ColIndex
col : non_basic_boxed_variables_) {
245 SetRelevance(
col,
false);
251 if (in_dual_phase_one_) {
256 variable_type_[
col] = ComputeVariableType(
col);
260 not_basic_.
Set(
col,
false);
261 can_increase_.
Set(
col,
false);
262 can_decrease_.
Set(
col,
false);
263 non_basic_boxed_variables_.
Set(
col,
false);
264 SetRelevance(
col,
false);
271 is_basic_.
Set(
col,
false);
272 not_basic_.
Set(
col,
true);
280 non_basic_boxed_variables_.
Set(
col, boxed);
282 (boxed_variables_are_relevant_ || !boxed);
283 SetRelevance(
col, relevance);
287 return variable_type_;
291 return variable_status_;
295 return can_increase_;
299 return can_decrease_;
313 return non_basic_boxed_variables_;
317 return num_entries_in_relevant_columns_;
329 }
else if (lower_bounds_[
col] == upper_bounds_[
col]) {
336void VariablesInfo::SetRelevance(ColIndex
col,
bool relevance) {
337 if (relevance_.
IsSet(
col) == relevance)
return;
349void VariablesInfo::UpdateStatusForNewType(ColIndex
col) {
350 switch (variable_status_[
col]) {
355 if (lower_bounds_[
col] == upper_bounds_[
col]) {
367 if (lower_bounds_[
col] == upper_bounds_[
col]) {
387 DCHECK(!in_dual_phase_one_);
388 in_dual_phase_one_ =
true;
389 saved_lower_bounds_ = lower_bounds_;
390 saved_upper_bounds_ = upper_bounds_;
396 const ColIndex num_cols = matrix_.
num_cols();
397 for (ColIndex
col(0);
col < num_cols; ++
col) {
398 switch (variable_type_[
col]) {
401 lower_bounds_[
col] = 0.0;
402 upper_bounds_[
col] = 0.0;
406 lower_bounds_[
col] = 0.0;
407 upper_bounds_[
col] = 1.0;
411 lower_bounds_[
col] = -1.0;
412 upper_bounds_[
col] = 0.0;
416 lower_bounds_[
col] = -1000.0;
417 upper_bounds_[
col] = 1000.0;
425 if (reduced_costs[
col] > dual_feasibility_tolerance) {
427 }
else if (reduced_costs[
col] < -dual_feasibility_tolerance) {
432 UpdateStatusForNewType(
col);
438 DCHECK(in_dual_phase_one_);
439 in_dual_phase_one_ =
false;
440 std::swap(saved_lower_bounds_, lower_bounds_);
441 std::swap(saved_upper_bounds_, upper_bounds_);
450 const ColIndex num_cols = matrix_.
num_cols();
451 for (ColIndex
col(0);
col < num_cols; ++
col) {
452 variable_type_[
col] = ComputeVariableType(
col);
461 if (reduced_costs[
col] > dual_feasibility_tolerance) {
463 }
else if (reduced_costs[
col] < -dual_feasibility_tolerance) {
468 UpdateStatusForNewType(
col);
#define DCHECK_LE(val1, val2)
#define DCHECK_NE(val1, val2)
#define DCHECK_GE(val1, val2)
#define DCHECK_LT(val1, val2)
#define DCHECK(condition)
#define DCHECK_EQ(val1, val2)
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
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