Minimization via branch and bound. More...
#include <minimize_constraint.h>
Classes | |
struct | Step |
union | UndoInfo |
Public Member Functions | |
bool | active () const |
bool | attach (Solver &s) |
Attaches the constraint to the given solver. | |
bool | commitLowerBound (const Solver &s, bool upShared) |
Sets the current local upper bound as the lower bound of this constraint. | |
void | commitUpperBound (const Solver &s) |
Sets the current local sum as the global optimum (upper bound). | |
DefaultMinimize (SharedData *d, uint32 strat) | |
void | destroy (Solver *, bool) |
Default is to call delete this. | |
bool | handleModel (Solver &s) |
Shall commit the model in s to the shared data object. | |
bool | handleUnsat (Solver &s, bool up, LitVec &out) |
Shall handle the unsatisfiable path in s. | |
bool | integrate (Solver &s) |
Shall activate the minimize constraint by integrating bounds stored in the shared data object. | |
bool | integrateBound (Solver &s) |
Tries to integrate the next tentative bound into this constraint. | |
bool | minimize (Solver &s, Literal p, CCMinRecursive *r) |
bool | more () const |
uint32 | numRules () const |
Number of minimize statements contained in this constraint. | |
PropResult | propagate (Solver &s, Literal p, uint32 &data) |
void | reason (Solver &s, Literal p, LitVec &lits) |
bool | relax (Solver &, bool reset) |
Shall relax this constraint (i.e. remove any bounds). | |
bool | relaxBound (bool full=false) |
Removes the local upper bound of this constraint and therefore disables it. | |
wsum_t | sum (uint32 i, bool adjust) const |
void | undoLevel (Solver &s) |
Called when the solver undid a decision level watched by this constraint. | |
Private Types | |
typedef const WeightLiteral * | Iter |
enum | PropMode { propagate_new_sum, propagate_new_opt } |
Private Member Functions | |
void | assign (wsum_t *lhs, wsum_t *rhs) const |
uint32 | computeImplicationSet (const Solver &s, const WeightLiteral &it, uint32 &undoPos) |
wsum_t * | end () const |
bool | greater (wsum_t *lhs, wsum_t *rhs, uint32 len, uint32 &aLev) const |
uint32 | lastUndoLevel (const Solver &s) const |
bool | litSeen (uint32 i) const |
wsum_t * | opt () const |
bool | propagateImpl (Solver &s, PropMode m) |
void | pushUndo (Solver &s, uint32 litIdx) |
void | stepInit (uint32 n) |
wsum_t & | stepLow () const |
wsum_t * | sum () const |
wsum_t * | temp () const |
bool | updateBounds (bool applyStep) |
~DefaultMinimize () | |
Private Attributes | |
uint32 | actLev_ |
wsum_t * | bounds_ |
Iter | pos_ |
uint32 | posTop_ |
const uint32 | size_ |
struct Clasp::DefaultMinimize::Step | step_ |
UndoInfo * | undo_ |
uint32 | undoTop_ |
Minimization via branch and bound.
The class supports both basic branch and bound as well as hierarchical branch and bound (with or without varying step sizes).
Definition at line 311 of file minimize_constraint.h.
typedef const WeightLiteral* Clasp::DefaultMinimize::Iter [private] |
Definition at line 388 of file minimize_constraint.h.
enum Clasp::DefaultMinimize::PropMode [private] |
Definition at line 387 of file minimize_constraint.h.
Clasp::DefaultMinimize::DefaultMinimize | ( | SharedData * | d, |
uint32 | strat | ||
) | [explicit] |
Definition at line 183 of file minimize_constraint.cpp.
Clasp::DefaultMinimize::~DefaultMinimize | ( | ) | [private] |
Definition at line 196 of file minimize_constraint.cpp.
bool Clasp::DefaultMinimize::active | ( | ) | const [inline] |
Definition at line 333 of file minimize_constraint.h.
void Clasp::DefaultMinimize::assign | ( | wsum_t * | lhs, |
wsum_t * | rhs | ||
) | const [private] |
Definition at line 275 of file minimize_constraint.cpp.
bool Clasp::DefaultMinimize::attach | ( | Solver & | s | ) | [virtual] |
Attaches the constraint to the given solver.
Implements Clasp::MinimizeConstraint.
Definition at line 214 of file minimize_constraint.cpp.
bool Clasp::DefaultMinimize::commitLowerBound | ( | const Solver & | s, |
bool | upShared | ||
) |
Sets the current local upper bound as the lower bound of this constraint.
commitLowerBound() shall be called on unsat. The function stores the local upper bound as new lower bound in this constraint. If upShared is true, the lower bound is also copied to the shared data object.
Once the local bound is committed, the function integrateBound() has to be called in order to continue optimization.
Definition at line 412 of file minimize_constraint.cpp.
void Clasp::DefaultMinimize::commitUpperBound | ( | const Solver & | s | ) |
Sets the current local sum as the global optimum (upper bound).
commitUpperBound() shall be called whenever the solver finds a model. The current local sum is recorded as new optimum in the shared data object. Once the local bound is committed, the function integrateBound() has to be called in order to continue optimization.
Definition at line 408 of file minimize_constraint.cpp.
uint32 Clasp::DefaultMinimize::computeImplicationSet | ( | const Solver & | s, |
const WeightLiteral & | it, | ||
uint32 & | undoPos | ||
) | [private] |
Definition at line 293 of file minimize_constraint.cpp.
void Clasp::DefaultMinimize::destroy | ( | Solver * | s, |
bool | detach | ||
) | [virtual] |
Default is to call delete this.
Reimplemented from Clasp::MinimizeConstraint.
Definition at line 201 of file minimize_constraint.cpp.
wsum_t* Clasp::DefaultMinimize::end | ( | ) | const [inline, private] |
Definition at line 395 of file minimize_constraint.h.
bool Clasp::DefaultMinimize::greater | ( | wsum_t * | lhs, |
wsum_t * | rhs, | ||
uint32 | len, | ||
uint32 & | aLev | ||
) | const [private] |
Definition at line 279 of file minimize_constraint.cpp.
bool Clasp::DefaultMinimize::handleModel | ( | Solver & | s | ) | [inline, virtual] |
Shall commit the model in s to the shared data object.
The return value indicates whether the model is valid w.r.t the costs stored in the shared data object.
Implements Clasp::MinimizeConstraint.
Definition at line 324 of file minimize_constraint.h.
bool Clasp::DefaultMinimize::handleUnsat | ( | Solver & | s, |
bool | upShared, | ||
LitVec & | restore | ||
) | [virtual] |
Shall handle the unsatisfiable path in s.
Implements Clasp::MinimizeConstraint.
Definition at line 424 of file minimize_constraint.cpp.
bool Clasp::DefaultMinimize::integrate | ( | Solver & | s | ) | [inline, virtual] |
Shall activate the minimize constraint by integrating bounds stored in the shared data object.
Implements Clasp::MinimizeConstraint.
Definition at line 322 of file minimize_constraint.h.
bool Clasp::DefaultMinimize::integrateBound | ( | Solver & | s | ) |
Tries to integrate the next tentative bound into this constraint.
Starting from the current optimum stored in the shared data object, the function tries to integrate the next candidate bound into this constraint.
Definition at line 451 of file minimize_constraint.cpp.
uint32 Clasp::DefaultMinimize::lastUndoLevel | ( | const Solver & | s | ) | const [private] |
Definition at line 243 of file minimize_constraint.cpp.
bool Clasp::DefaultMinimize::litSeen | ( | uint32 | i | ) | const [private] |
Definition at line 248 of file minimize_constraint.cpp.
bool Clasp::DefaultMinimize::minimize | ( | Solver & | s, |
Literal | p, | ||
CCMinRecursive * | rec | ||
) | [virtual] |
Called during minimization of learnt clauses.
Reimplemented from Clasp::Constraint.
Definition at line 389 of file minimize_constraint.cpp.
bool Clasp::DefaultMinimize::more | ( | ) | const [inline] |
Definition at line 382 of file minimize_constraint.h.
uint32 Clasp::DefaultMinimize::numRules | ( | ) | const [inline] |
Number of minimize statements contained in this constraint.
Definition at line 335 of file minimize_constraint.h.
wsum_t* Clasp::DefaultMinimize::opt | ( | ) | const [inline, private] |
Definition at line 392 of file minimize_constraint.h.
Constraint::PropResult Clasp::DefaultMinimize::propagate | ( | Solver & | s, |
Literal | p, | ||
uint32 & | data | ||
) | [virtual] |
Propagate is called for each constraint that watches p. It shall enqueue all consequences of p becoming true.
s | The solver in which p became true. |
p | A literal watched by this constraint that recently became true. |
data | The data-blob that this constraint passed when the watch for p was registered. |
Implements Clasp::Constraint.
Definition at line 284 of file minimize_constraint.cpp.
bool Clasp::DefaultMinimize::propagateImpl | ( | Solver & | s, |
PropMode | m | ||
) | [private] |
Definition at line 315 of file minimize_constraint.cpp.
void Clasp::DefaultMinimize::pushUndo | ( | Solver & | s, |
uint32 | litIdx | ||
) | [private] |
Definition at line 253 of file minimize_constraint.cpp.
void Clasp::DefaultMinimize::reason | ( | Solver & | s, |
Literal | p, | ||
LitVec & | lits | ||
) | [virtual] |
Implements Clasp::Constraint.
Definition at line 375 of file minimize_constraint.cpp.
bool Clasp::DefaultMinimize::relax | ( | Solver & | s, |
bool | reset | ||
) | [inline, virtual] |
Shall relax this constraint (i.e. remove any bounds).
If reset is true, shall also remove search-path related state.
Implements Clasp::MinimizeConstraint.
Definition at line 323 of file minimize_constraint.h.
bool Clasp::DefaultMinimize::relaxBound | ( | bool | full = false | ) |
Removes the local upper bound of this constraint and therefore disables it.
If full is true, also removes search-path related state.
Definition at line 436 of file minimize_constraint.cpp.
void Clasp::DefaultMinimize::stepInit | ( | uint32 | n | ) | [private] |
Definition at line 444 of file minimize_constraint.cpp.
wsum_t& Clasp::DefaultMinimize::stepLow | ( | ) | const [inline, private] |
Definition at line 406 of file minimize_constraint.h.
wsum_t Clasp::DefaultMinimize::sum | ( | uint32 | i, |
bool | adjust | ||
) | const [inline] |
Definition at line 385 of file minimize_constraint.h.
wsum_t* Clasp::DefaultMinimize::sum | ( | ) | const [inline, private] |
Definition at line 393 of file minimize_constraint.h.
wsum_t* Clasp::DefaultMinimize::temp | ( | ) | const [inline, private] |
Definition at line 394 of file minimize_constraint.h.
void Clasp::DefaultMinimize::undoLevel | ( | Solver & | s | ) | [virtual] |
Called when the solver undid a decision level watched by this constraint.
s | the solver in which the decision level is undone. |
Reimplemented from Clasp::Constraint.
Definition at line 355 of file minimize_constraint.cpp.
bool Clasp::DefaultMinimize::updateBounds | ( | bool | applyStep | ) | [private] |
Definition at line 485 of file minimize_constraint.cpp.
uint32 Clasp::DefaultMinimize::actLev_ [private] |
Definition at line 414 of file minimize_constraint.h.
wsum_t* Clasp::DefaultMinimize::bounds_ [private] |
Definition at line 408 of file minimize_constraint.h.
Iter Clasp::DefaultMinimize::pos_ [private] |
Definition at line 409 of file minimize_constraint.h.
uint32 Clasp::DefaultMinimize::posTop_ [private] |
Definition at line 412 of file minimize_constraint.h.
const uint32 Clasp::DefaultMinimize::size_ [private] |
Definition at line 413 of file minimize_constraint.h.
struct Clasp::DefaultMinimize::Step Clasp::DefaultMinimize::step_ [private] |
UndoInfo* Clasp::DefaultMinimize::undo_ [private] |
Definition at line 410 of file minimize_constraint.h.
uint32 Clasp::DefaultMinimize::undoTop_ [private] |
Definition at line 411 of file minimize_constraint.h.