20#include "absl/base/attributes.h"
21#include "absl/log/check.h"
22#include "absl/types/span.h"
26#include "ortools/glop/parameters.pb.h"
48 variables_info_(variables_info),
49 basis_factorization_(basis_factorization),
50 dual_edge_norms_(dual_edge_norms),
51 dual_prices_(dual_prices),
52 stats_(
"VariableValues") {}
74 LOG(DFATAL) <<
"SetNonBasicVariableValueFromStatus() shouldn't "
75 <<
"be called on a FREE variable.";
78 LOG(DFATAL) <<
"SetNonBasicVariableValueFromStatus() shouldn't "
79 <<
"be called on a BASIC variable.";
87 const DenseRow& free_initial_value) {
91 const ColIndex num_cols = matrix_.
num_cols();
92 variable_values_.
resize(num_cols, 0.0);
93 for (ColIndex
col(0);
col < num_cols; ++
col) {
94 switch (statuses[
col]) {
96 ABSL_FALLTHROUGH_INTENDED;
104 variable_values_[
col] =
105 col < free_initial_value.
size() ? free_initial_value[
col] : 0.0;
116 const RowIndex num_rows = matrix_.
num_rows();
123 basis_factorization_.
RightSolve(&scratchpad_);
124 for (RowIndex
row(0);
row < num_rows; ++
row) {
125 variable_values_[basis_[
row]] = scratchpad_[
row];
129 dual_prices_->
Clear();
136 const ColIndex num_cols = matrix_.
num_cols();
137 for (ColIndex
col(0);
col < num_cols; ++
col) {
147 const ColIndex num_cols = matrix_.
num_cols();
153 for (ColIndex
col(0);
col < num_cols; ++
col) {
156 primal_infeasibility = std::max(primal_infeasibility, infeasibility);
158 return primal_infeasibility;
164 const ColIndex num_cols = matrix_.
num_cols();
170 for (ColIndex
col(0);
col < num_cols; ++
col) {
173 sum += std::max(0.0, infeasibility);
195 auto values = variable_values_.
view();
196 for (
const auto e : direction) {
197 const ColIndex
col = basis[e.row()];
198 values[
col] -= e.coefficient() * step;
200 values[entering_col] += step;
204 absl::Span<const ColIndex> cols_to_update,
bool update_basic_variables) {
206 if (!update_basic_variables) {
207 for (ColIndex
col : cols_to_update) {
213 const RowIndex num_rows = matrix_.
num_rows();
214 initially_all_zero_scratchpad_.
values.
resize(num_rows, 0.0);
217 bool use_dense =
false;
218 for (ColIndex
col : cols_to_update) {
223 col, variable_values_[
col] - old_value,
224 &initially_all_zero_scratchpad_.
values);
227 col, variable_values_[
col] - old_value,
228 &initially_all_zero_scratchpad_);
235 basis_factorization_.
RightSolve(&initially_all_zero_scratchpad_);
236 if (initially_all_zero_scratchpad_.
non_zeros.empty()) {
237 for (RowIndex
row(0);
row < num_rows; ++
row) {
238 variable_values_[basis_[
row]] -= initially_all_zero_scratchpad_[
row];
245 for (
const auto e : initially_all_zero_scratchpad_) {
246 variable_values_[basis_[e.row()]] -= e.coefficient();
247 initially_all_zero_scratchpad_[e.row()] = 0.0;
250 initially_all_zero_scratchpad_.non_zeros.clear();
255 const RowIndex num_rows = matrix_.
num_rows();
259 put_more_importance_on_norm_ = put_more_importance_on_norm;
260 const Fractional tolerance = parameters_.primal_feasibility_tolerance();
269 if (put_more_importance_on_norm) {
270 for (RowIndex
row(0);
row < num_rows; ++
row) {
271 const ColIndex
col = basis[
row];
274 if (infeasibility > tolerance) {
276 row, std::abs(infeasibility) / squared_norms[
row]);
280 for (RowIndex
row(0);
row < num_rows; ++
row) {
281 const ColIndex
col = basis[
row];
284 if (infeasibility > tolerance) {
301 const Fractional tolerance = parameters_.primal_feasibility_tolerance();
310 if (put_more_importance_on_norm_) {
311 for (
const RowIndex
row : rows) {
312 const ColIndex
col = basis[
row];
315 if (infeasibility > tolerance) {
317 std::abs(infeasibility) / squared_norms[
row]);
323 for (
const RowIndex
row : rows) {
324 const ColIndex
col = basis[
row];
327 if (infeasibility > tolerance) {
329 Square(infeasibility) / squared_norms[
row]);
void RightSolve(ScatteredColumn *d) const
Right solves the system B.d = a where the input is the initial value of d.
bool IsRefactorized() const
Returns true if the factorization was just recomputed.
void ColumnAddMultipleToDenseColumn(ColIndex col, Fractional multiplier, DenseColumn::View dense_column) const
RowIndex num_rows() const
ColIndex num_cols() const
void ColumnAddMultipleToSparseScatteredColumn(ColIndex col, Fractional multiplier, ScatteredColumn *column) const
DenseColumn::ConstView GetEdgeSquaredNorms()
void ClearAndResize(Index n)
void DenseAddOrUpdate(Index position, Fractional value)
void Remove(Index position)
Removes the given index from the set of candidates.
void Clear()
Returns the current size n that was used in the last ClearAndResize().
void AddOrUpdate(Index position, Fractional value)
void AssignToZero(IntType size)
ConstView const_view() const
void resize(IntType size)
Fractional ComputeSumOfPrimalInfeasibilities() const
void UpdateOnPivoting(const ScatteredColumn &direction, ColIndex entering_col, Fractional step)
void UpdateGivenNonBasicVariables(absl::Span< const ColIndex > cols_to_update, bool update_basic_variables)
Fractional ComputeMaximumPrimalInfeasibility() const
void RecomputeBasicVariableValues()
VariableValues(const GlopParameters ¶meters, const CompactSparseMatrix &matrix, const RowToColMapping &basis, const VariablesInfo &variables_info, const BasisFactorization &basis_factorization, DualEdgeNorms *dual_edge_norms, DynamicMaximum< RowIndex > *dual_prices)
void ResetAllNonBasicVariableValues(const DenseRow &free_initial_values)
Fractional ComputeMaximumPrimalResidual() const
void RecomputeDualPrices(bool put_more_importance_on_norm=false)
void UpdateDualPrices(absl::Span< const RowIndex > row)
void SetNonBasicVariableValueFromStatus(ColIndex col)
const VariableStatusRow & GetStatusRow() const
const DenseRow & GetVariableLowerBounds() const
Returns the variable bounds.
const DenseRow & GetVariableUpperBounds() const
const DenseBitRow & GetNotBasicBitRow() const
Fractional Square(Fractional f)
bool IsAllZero(const Container &input)
Returns true if the given Fractional container is all zeros.
bool IsFinite(Fractional value)
Fractional InfinityNorm(const DenseColumn &v)
Returns the maximum of the coefficients of 'v'.
In SWIG mode, we don't want anything besides these top-level includes.
std::vector< double > lower_bounds
std::vector< double > upper_bounds
#define SCOPED_TIME_STAT(stats)
void ClearNonZerosIfTooDense(double ratio_for_using_dense_representation)
void ClearSparseMask()
Efficiently clears the is_non_zero vector.
StrictITIVector< Index, Fractional > values
bool ShouldUseDenseIteration(double ratio_for_using_dense_representation) const
std::vector< Index > non_zeros