Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <bop_ls.h>
Classes | |
struct | ConstraintTerm |
Public Member Functions | |
OneFlipConstraintRepairer (const sat::LinearBooleanProblem &problem, const AssignmentAndConstraintFeasibilityMaintainer &maintainer, const sat::VariablesAssignment &sat_assignment) | |
OneFlipConstraintRepairer (const OneFlipConstraintRepairer &)=delete | |
This type is neither copyable nor movable. | |
OneFlipConstraintRepairer & | operator= (const OneFlipConstraintRepairer &)=delete |
ConstraintIndex | ConstraintToRepair () const |
TermIndex | NextRepairingTerm (ConstraintIndex ct_index, TermIndex init_term_index, TermIndex start_term_index) const |
bool | RepairIsValid (ConstraintIndex ct_index, TermIndex term_index) const |
sat::Literal | GetFlip (ConstraintIndex ct_index, TermIndex term_index) const |
Static Public Attributes | |
static const ConstraintIndex | kInvalidConstraint |
static const TermIndex | kInitTerm |
static const TermIndex | kInvalidTerm |
This class is an utility class used to select which infeasible constraint to repair and identify one variable to flip to actually repair the constraint. A constraint 'lb <= sum_i(w_i * x_i) <= ub', with 'lb' the lower bound, 'ub' the upper bound, 'w_i' the weight of the i-th term and 'x_i' the boolean variable appearing in the i-th term, is infeasible for a given assignment iff its value 'sum_i(w_i * x_i)' is outside of the bounds. Repairing-a-constraint-in-one-flip means making the constraint feasible by just flipping the value of one unassigned variable of the current assignment from the AssignmentAndConstraintFeasibilityMaintainer. For performance reasons, the pairs weight / variable (w_i, x_i) are stored in a sparse manner as a vector of terms (w_i, x_i). In the following the TermIndex term_index refers to the position of the term in the vector.
operations_research::bop::OneFlipConstraintRepairer::OneFlipConstraintRepairer | ( | const sat::LinearBooleanProblem & | problem, |
const AssignmentAndConstraintFeasibilityMaintainer & | maintainer, | ||
const sat::VariablesAssignment & | sat_assignment ) |
|
delete |
This type is neither copyable nor movable.
ConstraintIndex operations_research::bop::OneFlipConstraintRepairer::ConstraintToRepair | ( | ) | const |
Returns the index of a constraint to repair. This will always return the index of a constraint that can be repaired in one flip if there is one. Note however that if there is only one possible candidate, it will be returned without checking that it can indeed be repaired in one flip. This is because the later check can be expensive, and is not needed in our context.
Optimization: We inspect the constraints in reverse order because the objective one will always be first (in our current code) and with some luck, we will break early instead of fully exploring it.
Optimization: We return the only candidate without inspecting it. This is critical at the beginning of the search or later if the only candidate is the objective constraint which can be really long.
The constraint can't be repaired in one decision.
sat::Literal operations_research::bop::OneFlipConstraintRepairer::GetFlip | ( | ConstraintIndex | ct_index, |
TermIndex | term_index ) const |
TermIndex operations_research::bop::OneFlipConstraintRepairer::NextRepairingTerm | ( | ConstraintIndex | ct_index, |
TermIndex | init_term_index, | ||
TermIndex | start_term_index ) const |
Returns the index of the next term which repairs the constraint when the value of its variable is flipped. This method explores terms with an index strictly greater than start_term_index and then terms with an index smaller than or equal to init_term_index if any. Returns kInvalidTerm when no reparing terms are found.
|
delete |
bool operations_research::bop::OneFlipConstraintRepairer::RepairIsValid | ( | ConstraintIndex | ct_index, |
TermIndex | term_index ) const |
|
static |
|
static |
|
static |