- java.lang.Object
-
- org.logicng.formulas.Formula
-
- org.logicng.formulas.PBConstraint
-
- Direct Known Subclasses:
CardinalityConstraint
public class PBConstraint extends Formula
A pseudo-Boolean constraint of the formc_1 * l_1 + ... + c_n * l_n R kwhereRis one of=, >, >=, <, <=.- Since:
- 1.0
- Version:
- 2.3.2
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int[]coefficients()Returns the coefficients of this constraint.CTypecomparator()Returns the comparator of this constraint.booleancontainsNode(Formula formula)Returnstrueif this formula contains a given node,falseotherwise.booleancontainsVariable(Variable variable)Returnstrueif a given variable name is found in this formula,falseotherwise.booleanequals(Object other)booleanevaluate(Assignment assignment)Evaluates this formula with a given assignment.List<Formula>getEncoding()Encodes this constraint as CNF and stores the result, if the encoding does not already exist.inthashCode()booleanisAmo()Returnstrueif this constraint is an at-most-one cardinality constraint,falseotherwise.booleanisAtomicFormula()Returns whether this formula is an atomic formula (constant, literal, pseudo Boolean constraint), or not.booleanisCC()Returnstrueif this constraint is a cardinality constraint,falseotherwise.booleanisConstantFormula()Returns whether this formula is a constant formula ("True" or "False").booleanisExo()Returnstrueif this constraint is an exactly-one cardinality constraint,falseotherwise.Iterator<Formula>iterator()intmaxWeight()Returns the maximal coefficient of this constraint.Formulanegate()Returns a negated copy of this formula.Formulanormalize()Normalizes this constraint s.t.intnumberOfOperands()Returns the number of operands of this formula.Literal[]operands()Returns the literals of this constraint.Formularestrict(Assignment assignment)Restricts this formula with a given assignment.intrhs()Returns the right-hand side of this constraint.Stream<Formula>stream()Returns a stream of this formula's operands.Formulasubstitute(Substitution substitution)Performs a given substitution on this formula.-
Methods inherited from class org.logicng.formulas.Formula
apply, apply, bdd, bdd, clearCaches, cnf, containsVariable, factory, functionCacheEntry, holds, holds, implies, isCNF, isContradiction, isDNF, isEquivalentTo, isImpliedBy, isNNF, isSatisfiable, isTautology, literals, nnf, numberOfAtoms, numberOfInternalNodes, numberOfNodes, predicateCacheEntry, setFunctionCacheEntry, setPredicateCacheEntry, setPredicateCacheEntry, setTransformationCacheEntry, substitute, toString, transform, transform, transformationCacheEntry, type, variables
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
operands
public Literal[] operands()
Returns the literals of this constraint.- Returns:
- the literals of this constraint
-
coefficients
public int[] coefficients()
Returns the coefficients of this constraint.- Returns:
- the coefficients of this constraint
-
comparator
public CType comparator()
Returns the comparator of this constraint.- Returns:
- the comparator of this constraint
-
rhs
public int rhs()
Returns the right-hand side of this constraint.- Returns:
- the right-hand side of this constraint
-
isCC
public boolean isCC()
Returnstrueif this constraint is a cardinality constraint,falseotherwise.- Returns:
trueif this constraint is a cardinality constraint
-
isAmo
public boolean isAmo()
Returnstrueif this constraint is an at-most-one cardinality constraint,falseotherwise.- Returns:
trueif this constraint is an at-most-one cardinality constraint
-
isExo
public boolean isExo()
Returnstrueif this constraint is an exactly-one cardinality constraint,falseotherwise.- Returns:
trueif this constraint is an excatly-one cardinality constraint
-
maxWeight
public int maxWeight()
Returns the maximal coefficient of this constraint.- Returns:
- the maximal coefficient of this constraint
-
normalize
public Formula normalize()
Normalizes this constraint s.t. it can be converted to CNF.- Returns:
- the normalized constraint
-
numberOfOperands
public int numberOfOperands()
Description copied from class:FormulaReturns the number of operands of this formula.- Specified by:
numberOfOperandsin classFormula- Returns:
- the number of operands of this formula
-
isConstantFormula
public boolean isConstantFormula()
Description copied from class:FormulaReturns whether this formula is a constant formula ("True" or "False").- Specified by:
isConstantFormulain classFormula- Returns:
trueif this formula is a constant formula,falseotherwise
-
isAtomicFormula
public boolean isAtomicFormula()
Description copied from class:FormulaReturns whether this formula is an atomic formula (constant, literal, pseudo Boolean constraint), or not.- Specified by:
isAtomicFormulain classFormula- Returns:
trueif this formula is an atomic formula,falseotherwise
-
containsVariable
public boolean containsVariable(Variable variable)
Description copied from class:FormulaReturnstrueif a given variable name is found in this formula,falseotherwise.- Specified by:
containsVariablein classFormula- Parameters:
variable- the variable to search for- Returns:
trueif a given variable is found in this formula
-
evaluate
public boolean evaluate(Assignment assignment)
Description copied from class:FormulaEvaluates this formula with a given assignment. A literal not covered by the assignment evaluates tofalseif it is positive, otherwise it evaluates totrue.
-
restrict
public Formula restrict(Assignment assignment)
Description copied from class:FormulaRestricts this formula with a given assignment.
-
containsNode
public boolean containsNode(Formula formula)
Description copied from class:FormulaReturnstrueif this formula contains a given node,falseotherwise.In particular, a
Literalnode~adoes NOT contain the nodea.- Specified by:
containsNodein classFormula- Parameters:
formula- the node- Returns:
trueif this formula contains a given node
-
substitute
public Formula substitute(Substitution substitution)
Description copied from class:FormulaPerforms a given substitution on this formula.- Specified by:
substitutein classFormula- Parameters:
substitution- the substitution- Returns:
- a new substituted formula
-
negate
public Formula negate()
Description copied from class:FormulaReturns a negated copy of this formula.
-
getEncoding
public List<Formula> getEncoding()
Encodes this constraint as CNF and stores the result, if the encoding does not already exist.- Returns:
- the encoding
-
stream
public Stream<Formula> stream()
Description copied from class:FormulaReturns a stream of this formula's operands.Most times streams have worse performance then iterating over the formula per iterator. Since internally formulas store their operands, a costly call to
Arrays.stream()is necessary. So if performance matters - avoid using streams.
-
-