Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <linear_constraint_manager.h>
Classes | |
struct | ConstraintInfo |
Public Member Functions | |
LinearConstraintManager (Model *model) | |
~LinearConstraintManager () | |
DEFINE_STRONG_INDEX_TYPE (ConstraintIndex) | |
ConstraintIndex | Add (LinearConstraint ct, bool *added=nullptr) |
bool | AddCut (LinearConstraint ct, std::string type_name, std::string extra_info="") |
bool | UpdateConstraintLb (glop::RowIndex index_in_lp, IntegerValue new_lb) |
These must be level zero bounds. | |
bool | UpdateConstraintUb (glop::RowIndex index_in_lp, IntegerValue new_ub) |
void | SetObjectiveCoefficient (IntegerVariable var, IntegerValue coeff) |
bool | ChangeLp (glop::BasisState *solution_state, int *num_new_constraints=nullptr) |
void | AddAllConstraintsToLp () |
const util_intops::StrongVector< ConstraintIndex, ConstraintInfo > & | AllConstraints () const |
All the constraints managed by this class. | |
const std::vector< ConstraintIndex > & | LpConstraints () const |
const util_intops::StrongVector< IntegerVariable, double > & | LpValues () |
To simplify CutGenerator api. | |
int64_t | num_constraints () const |
Stats. | |
int64_t | num_constraint_updates () const |
int64_t | num_simplifications () const |
int64_t | num_merged_constraints () const |
int64_t | num_shortened_constraints () const |
int64_t | num_split_constraints () const |
int64_t | num_coeff_strenghtening () const |
int64_t | num_cuts () const |
int64_t | num_add_cut_calls () const |
const absl::btree_map< std::string, int > & | type_to_num_cuts () const |
bool | DebugCheckConstraint (const LinearConstraint &cut) |
This class holds a list of globally valid linear constraints and has some logic to decide which one should be part of the LP relaxation. We want more for a better relaxation, but for efficiency we do not want to have too much constraints while solving the LP.
This class is meant to contain all the initial constraints of the LP relaxation and to get new cuts as they are generated. Thus, it can both manage cuts but also only add the initial constraints lazily if there is too many of them.
Definition at line 60 of file linear_constraint_manager.h.
|
inlineexplicit |
Definition at line 96 of file linear_constraint_manager.h.
operations_research::sat::LinearConstraintManager::~LinearConstraintManager | ( | ) |
Definition at line 67 of file linear_constraint_manager.cc.
LinearConstraintManager::ConstraintIndex operations_research::sat::LinearConstraintManager::Add | ( | LinearConstraint | ct, |
bool * | added = nullptr ) |
Because sometimes we split a == constraint in two (>= and <=), it makes sense to detect duplicate constraints and merge bounds. This is also relevant if we regenerate identical cuts for some reason.
If an identical constraint exists, only updates its bound.
Definition at line 132 of file linear_constraint_manager.cc.
void operations_research::sat::LinearConstraintManager::AddAllConstraintsToLp | ( | ) |
This can be called initially to add all the current constraint to the LP returned by GetLp().
Definition at line 764 of file linear_constraint_manager.cc.
bool operations_research::sat::LinearConstraintManager::AddCut | ( | LinearConstraint | ct, |
std::string | type_name, | ||
std::string | extra_info = "" ) |
Same as Add(), but logs some information about the newly added constraint. Cuts are also handled slightly differently than normal constraints.
Returns true if a new cut was added and false if this cut is not efficacious or if it is a duplicate of an already existing one.
Same as Add(), but logs some information about the newly added constraint. Cuts are also handled slightly differently than normal constraints.
Only add cut with sufficient efficacy.
We only mark the constraint as a cut if it is not an update of an already existing one.
Definition at line 236 of file linear_constraint_manager.cc.
|
inline |
All the constraints managed by this class.
Definition at line 150 of file linear_constraint_manager.h.
bool operations_research::sat::LinearConstraintManager::ChangeLp | ( | glop::BasisState * | solution_state, |
int * | num_new_constraints = nullptr ) |
Heuristic to decides what LP is best solved next. We use the model lp solutions as an heuristic, and it should usually be updated with the last known solution before this call.
The current solution state is used for detecting inactive constraints. It is also updated correctly on constraint deletion/addition so that the simplex can be fully iterative on restart by loading this modified state.
Returns true iff LpConstraints() will return a different LP than before.
We keep any constraints that is already present, and otherwise, we add the ones that are currently not satisfied by at least "tolerance" to the set of potential new constraints.
Inprocessing of the constraint.
ComputeActivity() often represent the bulk of the time spent in ChangeLP().
Bump activities of active constraints in LP.
Update the increment counter.
Remove constraints from the current LP that have been inactive for a while. We do that after we computed new_constraints so we do not need to iterate over the just deleted constraints.
On problem crossword_opt_grid-19.05_dict-80_sat with linearization_level=2, new_constraint.size() > 1.5M.
Iterate through all new constraints and select the one with the best score.
Checks the time limit, and returns if the lp has changed.
NOTE(user): It is safe to not add this constraint as the constraint that is almost parallel to this constraint is present in the LP or is inactive for a long time and is removed from the LP. In either case, this constraint is not adding significant value and is only making the LP larger.
Add the best constraint in the LP.
Abort the addition loop.
We update the solution sate to match the new LP size.
The LP changed only if we added new constraints or if some constraints already inside changed (simplification or tighter bounds).
Definition at line 516 of file linear_constraint_manager.cc.
bool operations_research::sat::LinearConstraintManager::DebugCheckConstraint | ( | const LinearConstraint & | cut | ) |
If a debug solution has been loaded, this checks if the given constraint cut it or not. Returns true if and only if everything is fine and the cut does not violate the loaded solution.
Definition at line 772 of file linear_constraint_manager.cc.
operations_research::sat::LinearConstraintManager::DEFINE_STRONG_INDEX_TYPE | ( | ConstraintIndex | ) |
Add a new constraint to the manager. Note that we canonicalize constraints and merge the bounds of constraints with the same terms. We also perform basic preprocessing. If added is given, it will be set to true if this constraint was actually a new one and to false if it was dominated by an already existing one.
|
inline |
The set of constraints indices in AllConstraints() that should be part of the next LP to solve.
Definition at line 156 of file linear_constraint_manager.h.
|
inline |
To simplify CutGenerator api.
Definition at line 161 of file linear_constraint_manager.h.
|
inline |
Definition at line 176 of file linear_constraint_manager.h.
|
inline |
Definition at line 174 of file linear_constraint_manager.h.
|
inline |
Definition at line 167 of file linear_constraint_manager.h.
|
inline |
Stats.
Definition at line 166 of file linear_constraint_manager.h.
|
inline |
Definition at line 175 of file linear_constraint_manager.h.
|
inline |
Definition at line 169 of file linear_constraint_manager.h.
|
inline |
Definition at line 170 of file linear_constraint_manager.h.
|
inline |
Definition at line 168 of file linear_constraint_manager.h.
|
inline |
Definition at line 173 of file linear_constraint_manager.h.
void operations_research::sat::LinearConstraintManager::SetObjectiveCoefficient | ( | IntegerVariable | var, |
IntegerValue | coeff ) |
The objective is used as one of the criterion to score cuts. The more a cut is parallel to the objective, the better its score is.
Currently this should only be called once per IntegerVariable (Checked). It is easy to support dynamic modification if it becomes needed.
Definition at line 341 of file linear_constraint_manager.cc.
|
inline |
Definition at line 178 of file linear_constraint_manager.h.
bool operations_research::sat::LinearConstraintManager::UpdateConstraintLb | ( | glop::RowIndex | index_in_lp, |
IntegerValue | new_lb ) |
These must be level zero bounds.
Definition at line 181 of file linear_constraint_manager.cc.
bool operations_research::sat::LinearConstraintManager::UpdateConstraintUb | ( | glop::RowIndex | index_in_lp, |
IntegerValue | new_ub ) |
Definition at line 192 of file linear_constraint_manager.cc.