24#ifndef OR_TOOLS_LP_DATA_LP_DATA_H_
25#define OR_TOOLS_LP_DATA_LP_DATA_H_
34#include "absl/container/flat_hash_map.h"
35#include "absl/container/flat_hash_set.h"
36#include "absl/log/check.h"
37#include "absl/strings/string_view.h"
40#include "ortools/glop/parameters.pb.h"
51class SparseMatrixScaler;
83 const std::string&
name()
const {
return name_; }
94 const std::string&
name);
224 return constraint_lower_bounds_;
227 return constraint_upper_bounds_;
232 return objective_coefficients_;
238 return variable_lower_bounds_;
241 return variable_upper_bounds_;
246 return variable_types_;
270 return objective_scaling_factor_;
312 std::string
Dump()
const;
463 bool detect_integer_constraints_for_slack);
553 columns_are_known_to_be_clean_ =
true;
562 return &constraint_lower_bounds_;
565 return &constraint_upper_bounds_;
574 void UpdateAllIntegerVariableLists()
const;
578 std::string ProblemStatFormatter(absl::string_view format)
const;
582 std::string NonZeroStatFormatter(absl::string_view format)
const;
585 void ResizeRowsIfNeeded(RowIndex
row);
590 void PopulateNameObjectiveAndVariablesFromLinearProgram(
616 mutable std::vector<ColIndex> integer_variables_list_;
619 mutable std::vector<ColIndex> binary_variables_list_;
623 mutable std::vector<ColIndex> non_binary_variables_list_;
626 absl::flat_hash_map<std::string, ColIndex> variable_table_;
629 absl::flat_hash_map<std::string, RowIndex> constraint_table_;
642 mutable bool columns_are_known_to_be_clean_;
645 mutable bool transpose_matrix_is_consistent_;
649 mutable bool integer_variables_list_is_consistent_;
656 ColIndex first_slack_variable_;
659 bool dcheck_bounds_ =
true;
662 GlopParameters::ScalingAlgorithm scaling_method);
669struct ProblemSolution {
void SetName(absl::string_view name)
Name setter and getter.
bool BoundsOfIntegerConstraintsAreInteger(Fractional tolerance) const
std::string GetDimensionString() const
A short string with the problem dimension.
const DenseRow & objective_coefficients() const
Returns the objective coefficients (or cost) of variables as a row vector.
void Clear()
Clears, i.e. reset the object to its initial value.
void SetConstraintName(RowIndex row, absl::string_view name)
const std::vector< ColIndex > & NonBinaryVariablesList() const
friend void Scale(LinearProgram *lp, SparseMatrixScaler *scaler, GlopParameters::ScalingAlgorithm scaling_method)
@ INTEGER
The variable must only take integer values.
StrictITIVector< ColIndex, VariableType > variable_types() const
Returns a row vector of VariableType representing types of variables.
std::string GetPrettyNonZeroStats() const
void NotifyThatColumnsAreClean()
void DeleteColumns(const DenseBooleanRow &columns_to_delete)
void RemoveNearZeroEntries(Fractional threshold)
Removes objective and coefficient with magnitude <= threshold.
bool BoundsOfIntegerVariablesAreInteger(Fractional tolerance) const
void ComputeSlackVariableValues(DenseRow *solution) const
bool IsValid(Fractional max_valid_magnitude=kInfinity) const
Fractional GetObjectiveCoefficientForMinimizationVersion(ColIndex col) const
void PopulateFromPermutedLinearProgram(const LinearProgram &lp, const RowPermutation &row_permutation, const ColumnPermutation &col_permutation)
void PopulateFromLinearProgramVariables(const LinearProgram &linear_program)
bool SolutionIsInteger(const DenseRow &solution, Fractional absolute_tolerance) const
void SetObjectiveOffset(Fractional objective_offset)
std::string GetConstraintName(RowIndex row) const
DenseColumn * mutable_constraint_upper_bounds()
void SetObjectiveCoefficient(ColIndex col, Fractional value)
bool SolutionIsLPFeasible(const DenseRow &solution, Fractional absolute_tolerance) const
std::string GetPrettyProblemStats() const
void Scale(SparseMatrixScaler *scaler)
Scales the problem using the given scaler.
const std::string & name() const
bool SolutionIsWithinVariableBounds(const DenseRow &solution, Fractional absolute_tolerance) const
Checks if each variable respects its bounds, nothing else.
Fractional RemoveObjectiveScalingAndOffset(Fractional value) const
void SetObjectiveScalingFactor(Fractional objective_scaling_factor)
bool IsInEquationForm() const
const DenseColumn & constraint_lower_bounds() const
const SparseMatrix & GetTransposeSparseMatrix() const
void AddSlackVariablesWhereNecessary(bool detect_integer_constraints)
void ClearTransposeMatrix()
Release the memory used by the transpose matrix.
const DenseRow & variable_lower_bounds() const
void SetVariableBounds(ColIndex col, Fractional lower_bound, Fractional upper_bound)
ColIndex GetSlackVariable(RowIndex row) const
const std::vector< ColIndex > & BinaryVariablesList() const
EntryIndex num_entries() const
Returns the number of entries in the linear program matrix.
DenseColumn * mutable_constraint_lower_bounds()
SparseMatrix * GetMutableTransposeSparseMatrix()
void DeleteSlackVariables()
bool IsMaximizationProblem() const
SparseColumn * GetMutableSparseColumn(ColIndex col)
Gets a pointer to the underlying SparseColumn with the given index.
const SparseMatrix & GetSparseMatrix() const
void AddConstraintsWithSlackVariables(const SparseMatrix &coefficients, const DenseColumn &left_hand_sides, const DenseColumn &right_hand_sides, const StrictITIVector< RowIndex, std::string > &names, bool detect_integer_constraints_for_slack)
const std::vector< ColIndex > & IntegerVariablesList() const
std::string GetProblemStats() const
bool IsVariableBinary(ColIndex col) const
Returns whether the variable at column col must take binary values or not.
Fractional ScaleObjective(GlopParameters::CostScalingAlgorithm method)
void Swap(LinearProgram *linear_program)
void DeleteRows(const DenseBooleanColumn &rows_to_delete)
void SetVariableType(ColIndex col, VariableType type)
Set the type of the variable.
ColIndex FindOrCreateVariable(absl::string_view variable_id)
std::string DumpSolution(const DenseRow &variable_values) const
bool SolutionIsMIPFeasible(const DenseRow &solution, Fractional absolute_tolerance) const
Tests if the solution is both LP-feasible and integer within the tolerance.
void SetConstraintBounds(RowIndex row, Fractional lower_bound, Fractional upper_bound)
void SetCoefficient(RowIndex row, ColIndex col, Fractional value)
Defines the coefficient for col / row.
void UseTransposeMatrixAsReference()
std::string GetVariableName(ColIndex col) const
LinearProgram(const LinearProgram &)=delete
This type is neither copyable nor movable.
const DenseRow & variable_upper_bounds() const
void AddConstraints(const SparseMatrix &coefficients, const DenseColumn &left_hand_sides, const DenseColumn &right_hand_sides, const StrictITIVector< RowIndex, std::string > &names)
void SetVariableName(ColIndex col, absl::string_view name)
ColIndex CreateNewSlackVariable(bool is_integer_slack_variable, Fractional lower_bound, Fractional upper_bound, const std::string &name)
VariableType GetVariableType(ColIndex col) const
Returns the type of variable.
const DenseColumn & constraint_upper_bounds() const
std::string GetNonZeroStats() const
RowIndex CreateNewConstraint()
const SparseColumn & GetSparseColumn(ColIndex col) const
bool IsVariableInteger(ColIndex col) const
Returns whether the variable at column col is constrained to be integer.
void PopulateFromLinearProgram(const LinearProgram &linear_program)
Populates the calling object with the given LinearProgram.
bool UpdateVariableBoundsToIntersection(const DenseRow &variable_lower_bounds, const DenseRow &variable_upper_bounds)
LinearProgram & operator=(const LinearProgram &)=delete
void SetDcheckBounds(bool dcheck_bounds)
If true, checks bound validity in debug mode.
Fractional objective_scaling_factor() const
Fractional ApplyObjectiveScalingAndOffset(Fractional value) const
ColIndex num_variables() const
Returns the number of variables.
ColIndex GetFirstSlackVariable() const
std::string GetObjectiveStatsString() const
A short line with some stats on the problem coefficients.
ColIndex CreateNewVariable()
Fractional objective_offset() const
Returns the objective offset and scaling factor.
RowIndex num_constraints() const
Returns the number of constraints.
std::string GetBoundsStatsString() const
RowIndex FindOrCreateConstraint(absl::string_view constraint_id)
void PopulateFromDual(const LinearProgram &dual, RowToColMapping *duplicated_rows)
void SetMaximizationProblem(bool maximize)
bool IsCleanedUp() const
Call IsCleanedUp() on all columns, useful for doing a DCHECK.
RowIndex num_rows() const
Return the matrix dimension.
ColIndex num_cols() const
EntryIndex num_entries() const
absl::Span< const double > coefficients
bool AreBoundsValid(Fractional lower_bound, Fractional upper_bound)
VariableType
Different types of variables.
ProblemStatus
Different statuses for a given problem.
In SWIG mode, we don't want anything besides these top-level includes.
ConstraintStatusColumn constraint_statuses
std::string DebugString() const
VariableStatusRow variable_statuses
ProblemSolution(RowIndex num_rows, ColIndex num_cols)
ProblemStatus status
The solution status.