Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
lp_data_utils.h
Go to the documentation of this file.
1// Copyright 2010-2024 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
14// Utility helpers for manipulating LinearProgram and other types defined in
15// lp_data.
16
17#ifndef OR_TOOLS_LP_DATA_LP_DATA_UTILS_H_
18#define OR_TOOLS_LP_DATA_LP_DATA_UTILS_H_
19
20#include "ortools/glop/parameters.pb.h"
25
26namespace operations_research {
27namespace glop {
28
29// For all constraints in linear_program, if the constraint has a slack
30// variable, change its value in *values so that the constraints itself is
31// satisfied.
32// Note that this obviously won't always imply that the bounds of the slack
33// variable itself will be satisfied.
34// The code assumes (and DCHECKs) that all constraints with a slack variable
35// have their upper and lower bounds both set to 0. This is ensured by
36// LinearProgram::AddSlackVariablesWhereNecessary().
37void ComputeSlackVariablesValues(const LinearProgram& linear_program,
38 DenseRow* values);
39
40// This is separated from LinearProgram class because of a cyclic dependency
41// when scaling as an LP.
42void Scale(LinearProgram* lp, SparseMatrixScaler* scaler,
43 GlopParameters::ScalingAlgorithm scaling_method);
44
45// A convenience method for above providing a default algorithm for callers that
46// don't specify one.
47void Scale(LinearProgram* lp, SparseMatrixScaler* scaler);
48
49// Class to facilitate the conversion between an original "unscaled" LP problem
50// and its scaled version. It is easy to get the direction wrong, so it make
51// sense to have a single place where all the scaling formulas are kept.
53 public:
54 // Scale the given LP.
55 void Scale(LinearProgram* lp);
56 void Scale(const GlopParameters& params, LinearProgram* lp);
57
58 // Clear all scaling coefficients.
59 void Clear();
60
61 // Transforms value from unscaled domain to the scaled one.
66
67 // Transforms corresponding value from the scaled domain to the original one.
72
73 // Unscale a row vector v such that v.B = unit_row. When basis_col is the
74 // index of the Column that correspond to the unit position in matrix B.
75 void UnscaleUnitRowLeftSolve(ColIndex basis_col,
76 ScatteredRow* left_inverse) const;
77
78 // Unscale a col vector v such that B.c = matrix_column_col.
79 void UnscaleColumnRightSolve(const RowToColMapping& basis, ColIndex col,
80 ScatteredColumn* right_inverse) const;
81
82 // A variable value in the original domain must be multiplied by this factor
83 // to be in the scaled domain.
84 Fractional VariableScalingFactor(ColIndex col) const;
85
86 // Visible for testing. All objective coefficients of the original LP where
87 // multiplied by this factor. Nothing else changed.
88 Fractional BoundsScalingFactor() const { return bound_scaling_factor_; }
89
90 // Visible for testing. All variable/constraint bounds of the original LP
91 // where multiplied by this factor. Nothing else changed.
93 return objective_scaling_factor_;
94 }
95
96 private:
97 SparseMatrixScaler scaler_;
98 Fractional bound_scaling_factor_ = 1.0;
99 Fractional objective_scaling_factor_ = 1.0;
100};
101
102} // namespace glop
103} // namespace operations_research
104
105#endif // OR_TOOLS_LP_DATA_LP_DATA_UTILS_H_
void UnscaleUnitRowLeftSolve(ColIndex basis_col, ScatteredRow *left_inverse) const
Fractional ScaleVariableValue(ColIndex col, Fractional value) const
Transforms value from unscaled domain to the scaled one.
Fractional UnscaleDualValue(RowIndex row, Fractional value) const
Fractional UnscaleConstraintActivity(RowIndex row, Fractional value) const
void Clear()
Clear all scaling coefficients.
Fractional ScaleDualValue(RowIndex row, Fractional value) const
void Scale(LinearProgram *lp)
Scale the given LP.
Fractional ScaleConstraintActivity(RowIndex row, Fractional value) const
Fractional UnscaleReducedCost(ColIndex col, Fractional value) const
Fractional VariableScalingFactor(ColIndex col) const
Fractional UnscaleVariableValue(ColIndex col, Fractional value) const
Transforms corresponding value from the scaled domain to the original one.
Fractional ScaleReducedCost(ColIndex col, Fractional value) const
void UnscaleColumnRightSolve(const RowToColMapping &basis, ColIndex col, ScatteredColumn *right_inverse) const
Unscale a col vector v such that B.c = matrix_column_col.
int64_t value
ColIndex col
Definition markowitz.cc:187
RowIndex row
Definition markowitz.cc:186
void ComputeSlackVariablesValues(const LinearProgram &linear_program, DenseRow *values)
void Scale(LinearProgram *lp, SparseMatrixScaler *scaler)
StrictITIVector< ColIndex, Fractional > DenseRow
Row-vector types. Row-vector types are indexed by a column index.
Definition lp_types.h:353
In SWIG mode, we don't want anything besides these top-level includes.