clingo
|
Class implementing smodels-like cardinality- and weight constraints. More...
#include <weight_constraint.h>
Classes | |
class | CPair |
Public Types | |
enum | CreationFlags { create_explicit = 1u, create_no_add = 3u, create_sat = 4u, create_no_freeze = 8u, create_no_share =16u, create_eq_bound =32u, create_only_btb =64u, create_only_bfb =128u } |
enum | ActiveConstraint { FFB_BTB = 0, FTB_BFB = 1 } |
Public Member Functions | |
Constraint * | cloneAttach (Solver &) |
Returns a clone of this and adds necessary watches to the given solver. More... | |
bool | simplify (Solver &s, bool=false) |
void | destroy (Solver *, bool) |
Default is to call delete this. More... | |
PropResult | propagate (Solver &s, Literal p, uint32 &data) |
void | reason (Solver &, Literal p, LitVec &lits) |
bool | minimize (Solver &s, Literal p, CCMinRecursive *r) |
void | undoLevel (Solver &s) |
Called when the solver undid a decision level watched by this constraint. More... | |
uint32 | estimateComplexity (const Solver &s) const |
Returns an estimate of the constraint's complexity relative to a clause (complexity = 1). More... | |
Literal | lit (uint32 i, ActiveConstraint c) const |
weight_t | weight (uint32 i) const |
Returns the weight of the i'th literal or 1 if constraint is a cardinality constraint. More... | |
uint32 | size () const |
Returns the number of literals in this constraint (including W). More... | |
bool | isWeight () const |
Returns false if constraint is a cardinality constraint. More... | |
uint32 | getBpIndex () const |
Public Member Functions inherited from Clasp::Constraint | |
Constraint () | |
virtual ConstraintType | type () const |
Returns the type of this constraint. More... | |
virtual ClauseHead * | clause () |
Shall return this if constraint is a clause, otherwise 0. More... | |
virtual bool | valid (Solver &s) |
Shall return whether the constraint is valid (i.e. not conflicting) w.r.t the current assignment in s. More... | |
Static Public Member Functions | |
static CPair | create (Solver &s, Literal W, WeightLitVec &lits, weight_t bound, uint32 creationFlags=0) |
Creates a new weight constraint from the given weight literals. More... | |
static CPair | create (Solver &s, Literal W, WeightLitsRep rep, uint32 creationFlags) |
Additional Inherited Members | |
Protected Member Functions inherited from Clasp::Constraint | |
virtual | ~Constraint () |
Class implementing smodels-like cardinality- and weight constraints.
This class represents a constraint of type W == w1*x1 ... wn*xn >= B, where W and each xi are literals and B and each wi are strictly positive integers. The class is used to represent smodels-like weight constraint, i.e. the body of a basic weight rule. In this case W is the literal associated with the body. A cardinality constraint is handled like a weight constraint where all weights are equal to 1.
The class implements the following four inference rules: Let L be the set of literals of the constraint, let sumTrue be the sum of the weights of all literals l in L that are currently true, let sumReach be the sum of the weights of all literals l in L that are currently not false, let U = {l in L | value(l.var()) == value_free}
Logically, we distinguish two constraints: FFB_BTB for handling forward false body and backward true body and FTB_BFB for handling forward true body and backward false body. Physically, we store the literals in one array: ~W=1, l0=w0,...,ln-1=wn-1.
Enumerator | |
---|---|
FFB_BTB |
(SumW-bound)+1 [~W=1, l0=w0,..., ln-1=wn-1]; |
FTB_BFB |
bound [ W=1,~l0=w0,...,~ln-1=wn-1] |
|
virtual |
Returns a clone of this and adds necessary watches to the given solver.
The function shall create and return a copy of this constraint to be used in the given solver. Furthermore, it shall add necessary watches to the given solver.
Implements Clasp::Constraint.
|
static |
Creates a new weight constraint from the given weight literals.
If the right hand side of the weight constraint is initially true/false (FTB/FFB), W is assigned appropriately but no constraint is created. Otherwise, the new weight constraint is added to s unless creationFlags contains create_no_add.
s | Solver in which the new constraint is to be used. |
W | The literal that is associated with the constraint. |
lits | The literals of the weight constraint. |
bound | The lower bound of the weight constraint. |
|
static |
|
virtual |
Default is to call delete this.
Reimplemented from Clasp::Constraint.
|
virtual |
Returns an estimate of the constraint's complexity relative to a clause (complexity = 1).
Reimplemented from Clasp::Constraint.
|
inline |
|
inline |
Returns false if constraint is a cardinality constraint.
|
inline |
Returns the i'th literal of constraint c, i.e. li, iff c == FFB_BTB ~li, iff c == FTB_BFB.
|
virtual |
Called during minimization of learnt clauses.
Reimplemented from Clasp::Constraint.
|
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.
Implements Clasp::Constraint.
|
virtual |
Simplify this constraint.
Reimplemented from Clasp::Constraint.
|
inline |
Returns the number of literals in this constraint (including W).
|
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.
|
inline |
Returns the weight of the i'th literal or 1 if constraint is a cardinality constraint.