![]() |
Google OR-Tools v9.12
a fast and portable software suite for combinatorial optimization
|
#include <linear_programming_constraint.h>
Public Types | |
typedef glop::RowIndex | ConstraintIndex |
Public Member Functions | |
LinearProgrammingConstraint (Model *model, absl::Span< const IntegerVariable > vars) | |
bool | AddLinearConstraint (LinearConstraint ct) |
void | SetObjectiveCoefficient (IntegerVariable ivar, IntegerValue coeff) |
void | SetMainObjectiveVariable (IntegerVariable ivar) |
IntegerVariable | ObjectiveVariable () const |
void | AddCutGenerator (CutGenerator generator) |
Register a new cut generator with this constraint. | |
bool | HasSolution () const |
double | GetSolutionValue (IntegerVariable variable) const |
bool | SolutionIsInteger () const |
bool | AtOptimal () const |
double | ObjectiveLpLowerBound () const |
bool | Propagate () override |
PropagatorInterface API. | |
bool | IncrementalPropagate (const std::vector< int > &watch_indices) override |
void | RegisterWith (Model *model) |
void | SetLevel (int level) override |
ReversibleInterface API. | |
int | NumVariables () const |
From outside, the lp should be seen as containing all extended variables. | |
const std::vector< IntegerVariable > & | integer_variables () const |
std::string | DimensionString () const |
std::function< IntegerLiteral()> | HeuristicLpReducedCostAverageBranching () |
double | average_degeneracy () const |
Average number of nonbasic variables with zero reduced costs. | |
int64_t | total_num_simplex_iterations () const |
Stats. | |
int64_t | total_num_cut_propagations () const |
int64_t | total_num_eq_propagations () const |
int64_t | num_solves () const |
int64_t | num_adjusts () const |
int64_t | num_cut_overflows () const |
int64_t | num_bad_cuts () const |
int64_t | num_scaling_issues () const |
int64_t | num_lp_changes () const |
This can serve as a timestamp to know if a saved basis is out of date. | |
const std::vector< int64_t > & | num_solves_by_status () const |
const LinearConstraintManager & | constraint_manager () const |
IntegerSumLE128 * | LatestOptimalConstraintOrNull () const |
Important: this is only temporarily valid. | |
const std::vector< std::unique_ptr< IntegerSumLE128 > > & | OptimalConstraints () const |
void | EnablePropagation (bool enable) |
bool | PropagationIsEnabled () const |
const glop::BasisState & | GetBasisState () const |
void | LoadBasisState (const glop::BasisState &state) |
template<bool check_overflow> | |
bool | ComputeNewLinearConstraint (absl::Span< const std::pair< RowIndex, IntegerValue > > integer_multipliers, ScatteredIntegerVector *scattered_vector, IntegerValue *upper_bound) const |
![]() | |
PropagatorInterface ()=default | |
virtual | ~PropagatorInterface ()=default |
Definition at line 137 of file linear_programming_constraint.h.
typedef glop::RowIndex operations_research::sat::LinearProgrammingConstraint::ConstraintIndex |
Definition at line 140 of file linear_programming_constraint.h.
operations_research::sat::LinearProgrammingConstraint::LinearProgrammingConstraint | ( | Model * | model, |
absl::Span< const IntegerVariable > | vars ) |
Each linear programming constraint works on a fixed set of variables. We expect the set of variable to be sorted in increasing order.
Tweak the default parameters to make the solve incremental.
Register our local rev int repository.
Register SharedStatistics with the cut helpers.
Initialize the IntegerVariable -> ColIndex mapping.
Complete the extended variables with the orbit afterwards.
We use the "extended" vector for lp_solution_/lp_reduced_cost_.
Definition at line 278 of file linear_programming_constraint.cc.
void operations_research::sat::LinearProgrammingConstraint::AddCutGenerator | ( | CutGenerator | generator | ) |
Register a new cut generator with this constraint.
Definition at line 833 of file linear_programming_constraint.cc.
bool operations_research::sat::LinearProgrammingConstraint::AddLinearConstraint | ( | LinearConstraint | ct | ) |
Add a new linear constraint to this LP. Return false if we prove infeasibility of the global model.
If we added a folded constraints, lets add it to the CP propagators. This is important as this should tighten the bounds of the orbit sum vars.
Definition at line 378 of file linear_programming_constraint.cc.
|
inline |
Returns a valid lp lower bound for the current branch, and indicates if the latest LP solve in that branch was solved to optimality or not. During normal operation, we will always propagate the LP, so this should not refer to an optimality status lower in that branch.
Definition at line 185 of file linear_programming_constraint.h.
|
inline |
Average number of nonbasic variables with zero reduced costs.
Definition at line 214 of file linear_programming_constraint.h.
bool operations_research::sat::LinearProgrammingConstraint::ComputeNewLinearConstraint | ( | absl::Span< const std::pair< RowIndex, IntegerValue > > | integer_multipliers, |
ScatteredIntegerVector * | scattered_vector, | ||
IntegerValue * | upper_bound ) const |
Initialize the new constraint.
Compute the new constraint by taking the linear combination given by integer_multipliers of the integer constraints in integer_lp_.
Update the constraint.
Update the upper bound.
Definition at line 2351 of file linear_programming_constraint.cc.
|
inline |
Definition at line 241 of file linear_programming_constraint.h.
std::string operations_research::sat::LinearProgrammingConstraint::DimensionString | ( | ) | const |
Definition at line 2934 of file linear_programming_constraint.cc.
|
inline |
This api allows to temporarily disable the LP propagator which can be costly during probing or other heavy propagation phase.
Definition at line 258 of file linear_programming_constraint.h.
|
inline |
Definition at line 264 of file linear_programming_constraint.h.
double operations_research::sat::LinearProgrammingConstraint::GetSolutionValue | ( | IntegerVariable | variable | ) | const |
Definition at line 904 of file linear_programming_constraint.cc.
|
inline |
Returns the LP value and reduced cost of a variable in the current solution. These functions should only be called when HasSolution() is true.
Definition at line 177 of file linear_programming_constraint.h.
std::function< IntegerLiteral()> operations_research::sat::LinearProgrammingConstraint::HeuristicLpReducedCostAverageBranching | ( | ) |
Returns a IntegerLiteral guided by the underlying LP constraints.
This computes the mean of reduced costs over successive calls, and tries to fix the variable which has the highest reduced cost. Tie-breaking is done using the variable natural order.
Definition at line 2862 of file linear_programming_constraint.cc.
|
overridevirtual |
This will only be called on a non-empty vector, otherwise Propagate() will be called. The passed vector will contain the "watch index" of all the literals that were given one at registration and that changed since the last call to Propagate(). This is only true when going down in the search tree, on backjump this list will be cleared.
Notes:
If we have a really deep branch, with a lot of LP explanation constraint, we could take a quadratic amount of memory: O(num_var) per number of propagation in that branch. To avoid that, once the memory starts to be over a few GB, we only propagate from time to time. This way we do not need to keep that many constraints around.
We only propagate if we use less that 100 times the number of current integer literal enqueued.
At level zero, if there is still a chance to add cuts or lazy constraints, we re-run the LP.
Check whether the change breaks the current LP solution. If it does, call Propagate() on the current LP.
Remark: Note that if we do the sequence SetBasis() / Propagate() / GetAndSaveBasis() and we are in the case where the solution is still optimal, we should get the basis from when the lp solution was set which should be what we want. Even if we set garbage during SetBasis() it should be ignored.
Reimplemented from operations_research::sat::PropagatorInterface.
Definition at line 837 of file linear_programming_constraint.cc.
|
inline |
Definition at line 200 of file linear_programming_constraint.h.
|
inline |
Important: this is only temporarily valid.
Definition at line 246 of file linear_programming_constraint.h.
|
inline |
Definition at line 265 of file linear_programming_constraint.h.
|
inline |
Definition at line 229 of file linear_programming_constraint.h.
|
inline |
Definition at line 231 of file linear_programming_constraint.h.
|
inline |
Definition at line 230 of file linear_programming_constraint.h.
|
inline |
This can serve as a timestamp to know if a saved basis is out of date.
Definition at line 235 of file linear_programming_constraint.h.
|
inline |
Definition at line 232 of file linear_programming_constraint.h.
|
inline |
Definition at line 228 of file linear_programming_constraint.h.
|
inline |
Definition at line 237 of file linear_programming_constraint.h.
|
inline |
From outside, the lp should be seen as containing all extended variables.
Definition at line 197 of file linear_programming_constraint.h.
|
inline |
Definition at line 186 of file linear_programming_constraint.h.
|
inline |
Definition at line 167 of file linear_programming_constraint.h.
|
inline |
Definition at line 251 of file linear_programming_constraint.h.
|
overridevirtual |
PropagatorInterface API.
We put a limit on the dual objective since there is no point increasing it past our current objective upper-bound (we will already fail as soon as we pass it). Note that this limit is properly transformed using the objective scaling factor and offset stored in lp_data_.
Put an iteration limit on the work we do in the simplex for this call. Note that because we are "incremental", even if we don't solve it this time we will make progress towards a solve in the lower node of the tree search.
Add new constraints to the LP and resolve?
We wait for the first batch of problem constraints to be added before we begin to generate cuts. Note that we rely on num_solves_ since on some problems there is no other constraints than the cuts.
This must be called first.
The "generic" cuts are currently part of this class as they are using data from the current LP.
Try to add cuts.
If we didn't add any new constraint, we delay the next Solve() since likely the optimal didn't change.
Implements operations_research::sat::PropagatorInterface.
Definition at line 2122 of file linear_programming_constraint.cc.
|
inline |
Definition at line 262 of file linear_programming_constraint.h.
void operations_research::sat::LinearProgrammingConstraint::RegisterWith | ( | Model * | model | ) |
Copy objective data to the constraint_manager_.
Note(user): the sort is not really needed but should lead to better cache locality.
Set the LP to its initial content.
Registering it with the trail make sure this class is always in sync when it is used in the decision heuristics.
Definition at line 408 of file linear_programming_constraint.cc.
|
overridevirtual |
ReversibleInterface API.
Get rid of all optimal constraint each time we go back to level zero.
Special case for level zero, we "reload" any previously known optimal solution from that level.
Add the fixed variables. They might have been skipped when we did the linear relaxation of the model, but cut generators expect all variables to have an LP value.
Implements operations_research::ReversibleInterface.
Definition at line 788 of file linear_programming_constraint.cc.
|
inline |
The main objective variable should be equal to the linear sum of the arguments passed to SetObjectiveCoefficient().
Definition at line 157 of file linear_programming_constraint.h.
void operations_research::sat::LinearProgrammingConstraint::SetObjectiveCoefficient | ( | IntegerVariable | ivar, |
IntegerValue | coeff ) |
Set the coefficient of the variable in the objective. Calling it twice will overwrite the previous value.
Definition at line 469 of file linear_programming_constraint.cc.
|
inline |
Definition at line 179 of file linear_programming_constraint.h.
|
inline |
Definition at line 222 of file linear_programming_constraint.h.
|
inline |
Definition at line 225 of file linear_programming_constraint.h.
|
inline |
Stats.
Definition at line 219 of file linear_programming_constraint.h.