OR-Tools  8.2
variables_info.cc
Go to the documentation of this file.
1// Copyright 2010-2018 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
15
16namespace operations_research {
17namespace glop {
18
20 const DenseRow& lower_bound,
21 const DenseRow& upper_bound)
22 : matrix_(matrix),
23 lower_bound_(lower_bound),
24 upper_bound_(upper_bound),
25 boxed_variables_are_relevant_(true) {}
26
28 const ColIndex num_cols = matrix_.num_cols();
29 can_increase_.ClearAndResize(num_cols);
30 can_decrease_.ClearAndResize(num_cols);
31 is_basic_.ClearAndResize(num_cols);
32 not_basic_.ClearAndResize(num_cols);
33 non_basic_boxed_variables_.ClearAndResize(num_cols);
34
35 num_entries_in_relevant_columns_ = 0;
36 boxed_variables_are_relevant_ = true;
37 relevance_.ClearAndResize(num_cols);
38
39 variable_status_.resize(num_cols, VariableStatus::FREE);
40 variable_type_.resize(num_cols, VariableType::UNCONSTRAINED);
41 for (ColIndex col(0); col < num_cols; ++col) {
42 variable_type_[col] = ComputeVariableType(col);
43 }
44}
45
47 if (value == boxed_variables_are_relevant_) return;
48 boxed_variables_are_relevant_ = value;
49 if (value) {
50 for (const ColIndex col : non_basic_boxed_variables_) {
51 SetRelevance(col, variable_type_[col] != VariableType::FIXED_VARIABLE);
52 }
53 } else {
54 for (const ColIndex col : non_basic_boxed_variables_) {
55 SetRelevance(col, false);
56 }
57 }
58}
59
61 if (status == VariableStatus::BASIC) {
63 } else {
65 }
66}
67
69 variable_status_[col] = VariableStatus::BASIC;
70 is_basic_.Set(col, true);
71 not_basic_.Set(col, false);
72 can_increase_.Set(col, false);
73 can_decrease_.Set(col, false);
74 non_basic_boxed_variables_.Set(col, false);
75 SetRelevance(col, false);
76}
77
79 VariableStatus status) {
81 variable_status_[col] = status;
82 is_basic_.Set(col, false);
83 not_basic_.Set(col, true);
84 can_increase_.Set(col, status == VariableStatus::AT_LOWER_BOUND ||
85 status == VariableStatus::FREE);
86 can_decrease_.Set(col, status == VariableStatus::AT_UPPER_BOUND ||
87 status == VariableStatus::FREE);
88
89 const bool boxed =
91 non_basic_boxed_variables_.Set(col, boxed);
92 const bool relevance = status != VariableStatus::FIXED_VALUE &&
93 (boxed_variables_are_relevant_ || !boxed);
94 SetRelevance(col, relevance);
95}
96
98 return variable_type_;
99}
100
102 return variable_status_;
103}
104
106 return can_increase_;
107}
108
110 return can_decrease_;
111}
112
114 return relevance_;
115}
116
117const DenseBitRow& VariablesInfo::GetIsBasicBitRow() const { return is_basic_; }
118
120 return not_basic_;
121}
122
124 return non_basic_boxed_variables_;
125}
126
128 return num_entries_in_relevant_columns_;
129}
130
131VariableType VariablesInfo::ComputeVariableType(ColIndex col) const {
132 DCHECK_LE(lower_bound_[col], upper_bound_[col]);
133 if (lower_bound_[col] == -kInfinity) {
134 if (upper_bound_[col] == kInfinity) {
136 }
138 } else if (upper_bound_[col] == kInfinity) {
140 } else if (lower_bound_[col] == upper_bound_[col]) {
142 } else {
144 }
145}
146
147void VariablesInfo::SetRelevance(ColIndex col, bool relevance) {
148 if (relevance_.IsSet(col) == relevance) return;
149 if (relevance) {
150 relevance_.Set(col);
151 num_entries_in_relevant_columns_ += matrix_.ColumnNumEntries(col);
152 } else {
153 relevance_.Clear(col);
154 num_entries_in_relevant_columns_ -= matrix_.ColumnNumEntries(col);
155 }
156}
157
158} // namespace glop
159} // namespace operations_research
#define DCHECK_LE(val1, val2)
Definition: base/logging.h:887
#define DCHECK_NE(val1, val2)
Definition: base/logging.h:886
void ClearAndResize(IndexType size)
Definition: bitset.h:436
void Clear(IndexType i)
Definition: bitset.h:453
void Set(IndexType i)
Definition: bitset.h:491
bool IsSet(IndexType i) const
Definition: bitset.h:481
EntryIndex ColumnNumEntries(ColIndex col) const
Definition: sparse.h:335
const DenseBitRow & GetIsBasicBitRow() const
const DenseBitRow & GetNonBasicBoxedVariables() const
const DenseBitRow & GetCanIncreaseBitRow() const
const DenseBitRow & GetCanDecreaseBitRow() const
const VariableTypeRow & GetTypeRow() const
void UpdateToNonBasicStatus(ColIndex col, VariableStatus status)
const DenseBitRow & GetNotBasicBitRow() const
VariablesInfo(const CompactSparseMatrix &matrix, const DenseRow &lower_bound, const DenseRow &upper_bound)
const VariableStatusRow & GetStatusRow() const
const DenseBitRow & GetIsRelevantBitRow() const
void Update(ColIndex col, VariableStatus status)
int64 value
ColIndex col
Definition: markowitz.cc:176
const double kInfinity
Definition: lp_types.h:83
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...