Class CardinalityConstraint
- java.lang.Object
-
- org.tweetyproject.logics.pl.syntax.PlFormula
-
- org.tweetyproject.logics.pl.syntax.CardinalityConstraint
-
- All Implemented Interfaces:
Formula,ClassicalFormula,Conjunctable,Disjunctable,Invertable,ProbabilityAware,SimpleLogicalFormula
public class CardinalityConstraint extends PlFormula
This class represents a cardinality constraint, i.e. a constraint of the form "at most n out of {a1,...,ak} are true", where a1 ... ak are propositions and n is an integer. It also includes methods that generate SAT encodings for cardinality constraints.- Author:
- Anna Gessler
-
-
Constructor Summary
Constructors Constructor Description CardinalityConstraint(java.util.Collection<Proposition> atoms, int atMost)Create a new at-most-n cardinality constraint with the given set of atoms and the given n.
-
Method Summary
Modifier and Type Method Description PlFormulaclone()Creates a deep copy of this formulaPlFormulacollapseAssociativeFormulas()This method collapses all associative operations appearing in this term, e.g.booleanequals(java.lang.Object obj)java.util.Set<Proposition>getAtoms()Processes the set of all atoms which appear in this formulastatic PlBeliefSetgetBinomialEncoding(java.util.Collection<Proposition> atoms, int atMost)Returns a naive SAT encoding of the given cardinality constraint.java.util.Set<PlFormula>getLiterals()Returns all literals, i.e.java.util.Set<PossibleWorld>getModels(PlSignature sig)Returns the set of models of this formula wrt.static ConjunctiongetNaiveAtMostOneEncoding(java.util.Collection<Proposition> atoms)Returns a naive at-most-1 encoding for the given set of atoms.java.util.Set<PlPredicate>getPredicates()Processes the set of all predicates which appear in this formulaPlBeliefSetgetSatEncoding()Returns a SAT encoding of this cardinality constraint.PlBeliefSetgetSatEncoding(java.lang.String name)Returns a SAT encoding of this cardinality constraint.static PlBeliefSetgetSequentialCounterEncoding(java.util.Collection<Proposition> atoms, int atMost, java.lang.String name)Returns a SAT encoding of the given cardinality constraint based on the method of [Sinz.inthashCode()intnumberOfOccurrences(Proposition p)Returns the number of occurrences of the given proposition within this formulaCardinalityConstraintreplace(Proposition p, PlFormula f, int i)Replaces the ith instance of the proposition p by f.ConjunctiontoCnf()This method returns this formula in conjunctive normal form (CNF).PlFormulatoNnf()This method returns this formula in negation normal form (NNF).java.lang.StringtoString()PlFormulatrim()Removes duplicates (identical formulas) from conjunctions and disjunctions and removes duplicate negations.-
Methods inherited from class org.tweetyproject.logics.pl.syntax.PlFormula
combineWithAnd, combineWithOr, complement, getModels, getPredicateCls, getPrimeImplicants, getSignature, getUniformProbability, isClause, isConjunctiveClause, isLiteral, resolvableWith, resolveWith, toBlakeCanonicalForm, toDnf
-
-
-
-
Constructor Detail
-
CardinalityConstraint
public CardinalityConstraint(java.util.Collection<Proposition> atoms, int atMost)
Create a new at-most-n cardinality constraint with the given set of atoms and the given n.- Parameters:
atoms- the atomsatMost- n
-
-
Method Detail
-
getSatEncoding
public PlBeliefSet getSatEncoding(java.lang.String name)
Returns a SAT encoding of this cardinality constraint.- Parameters:
name- prefix for auxiliary variables- Returns:
- encoding
-
getSatEncoding
public PlBeliefSet getSatEncoding()
Returns a SAT encoding of this cardinality constraint.- Returns:
- encoding
-
getBinomialEncoding
public static PlBeliefSet getBinomialEncoding(java.util.Collection<Proposition> atoms, int atMost)
Returns a naive SAT encoding of the given cardinality constraint.- Parameters:
atoms- the atomsatMost- the maximal number of true atoms- Returns:
- sat encoding
-
getSequentialCounterEncoding
public static PlBeliefSet getSequentialCounterEncoding(java.util.Collection<Proposition> atoms, int atMost, java.lang.String name)
Returns a SAT encoding of the given cardinality constraint based on the method of [Sinz. "Towards an Optimal {CNF} Encoding of Boolean Cardinality Constraints." Principles and Practice of Constraint Programming, Springer 2005].- Parameters:
atoms- the atomsatMost- the maximal number of true atomsname- for auxiliary variables- Returns:
- SAT encoding of constraint
-
getNaiveAtMostOneEncoding
public static Conjunction getNaiveAtMostOneEncoding(java.util.Collection<Proposition> atoms)
Returns a naive at-most-1 encoding for the given set of atoms.- Parameters:
atoms- the atoms- Returns:
- at-most-1 encoding
-
getAtoms
public java.util.Set<Proposition> getAtoms()
Description copied from interface:SimpleLogicalFormulaProcesses the set of all atoms which appear in this formula- Specified by:
getAtomsin interfaceSimpleLogicalFormula- Specified by:
getAtomsin classPlFormula- Returns:
- The set of all atoms
-
getLiterals
public java.util.Set<PlFormula> getLiterals()
Description copied from class:PlFormulaReturns all literals, i.e. all formulas of the form "a" or "!a" where "a" is a proposition, that appear in this formula.- Specified by:
getLiteralsin classPlFormula- Returns:
- all literals appearing in this formula.
-
collapseAssociativeFormulas
public PlFormula collapseAssociativeFormulas()
Description copied from class:PlFormulaThis method collapses all associative operations appearing in this term, e.g. every a||(b||c) becomes a||b||c.- Specified by:
collapseAssociativeFormulasin classPlFormula- Returns:
- the collapsed formula.
-
getPredicates
public java.util.Set<PlPredicate> getPredicates()
Description copied from interface:SimpleLogicalFormulaProcesses the set of all predicates which appear in this formula- Specified by:
getPredicatesin interfaceSimpleLogicalFormula- Specified by:
getPredicatesin classPlFormula- Returns:
- all predicates that appear in this formula
-
trim
public PlFormula trim()
Description copied from class:PlFormulaRemoves duplicates (identical formulas) from conjunctions and disjunctions and removes duplicate negations. Simplifies equivalences and implications with equivalent formulas (A=>A, A<=>A) to tautologies.
-
toNnf
public PlFormula toNnf()
Description copied from class:PlFormulaThis method returns this formula in negation normal form (NNF). A formula is in NNF iff negations occur only directly in front of a proposition.
-
toCnf
public Conjunction toCnf()
Description copied from class:PlFormulaThis method returns this formula in conjunctive normal form (CNF). A formula is in CNF iff it is a conjunction of disjunctions and in NNF. The CNF generated by this method is not necessarily minimal.
-
getModels
public java.util.Set<PossibleWorld> getModels(PlSignature sig)
Description copied from class:PlFormulaReturns the set of models of this formula wrt. the given signature.
-
numberOfOccurrences
public int numberOfOccurrences(Proposition p)
Description copied from class:PlFormulaReturns the number of occurrences of the given proposition within this formula- Specified by:
numberOfOccurrencesin classPlFormula- Parameters:
p- some proposition- Returns:
- the number of occurrences of the given proposition within this formula
-
replace
public CardinalityConstraint replace(Proposition p, PlFormula f, int i)
Description copied from class:PlFormulaReplaces the ith instance of the proposition p by f.
-
equals
public boolean equals(java.lang.Object obj)
- Specified by:
equalsin interfaceSimpleLogicalFormula- Specified by:
equalsin classPlFormula
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceSimpleLogicalFormula- Specified by:
hashCodein classPlFormula
-
clone
public PlFormula clone()
Description copied from interface:SimpleLogicalFormulaCreates a deep copy of this formula- Specified by:
clonein interfaceSimpleLogicalFormula- Specified by:
clonein classPlFormula- Returns:
- the cloned formula
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-