- java.lang.Object
-
- org.logicng.datastructures.Assignment
-
public final class Assignment extends Object
A Boolean assignment.Note: the internal data structure is a plain list - no checking of the model is performed e.g. if contradictory literals are added. Since assignments are used e.g. in the model enumeration of the SAT solvers these checks would be too costly.
- Since:
- 1.0
- Version:
- 2.3.1
-
-
Constructor Summary
Constructors Constructor Description Assignment()Constructs a new empty assignment (without fast evaluation).Assignment(boolean fastEvaluable)Constructs a new empty assignment.Assignment(Collection<? extends Literal> lits)Constructs a new assignment for a given collection of literals (without fast evaluation).Assignment(Collection<? extends Literal> lits, boolean fastEvaluable)Constructs a new assignment for a given collection of literals.Assignment(Literal lit)Constructs a new assignment with a single literal assignment (without fast evaluation).Assignment(Literal... lits)Constructs a new assignment for a given array of literals (without fast evaluation).Assignment(Literal lit, boolean fastEvaluable)Constructs a new assignment with a single literal assignment.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLiteral(Literal lit)Add a single literal to this assignment.FormulablockingClause(FormulaFactory f)Creates the blocking clause for this assignment.FormulablockingClause(FormulaFactory f, Collection<? extends Literal> literals)Creates the blocking clause for this assignment wrt.voidconvertToFastEvaluable()Converts this assignment to a fast evaluable assignment.booleanequals(Object other)booleanevaluateLit(Literal lit)Evaluates a given literal.booleanfastEvaluable()Returns whether this assignment is fast evaluable or not.Formulaformula(FormulaFactory f)Returns the assignment as a formula.inthashCode()SortedSet<Literal>literals()Returns all literals of this assignment.List<Literal>negativeLiterals()Returns the negative literals of this assignment.List<Variable>negativeVariables()Returns the negative literals of this assignment as variables.List<Variable>positiveVariables()Returns the positive literals of this assignment as variables.FormularestrictLit(Literal lit)Restricts a given literal to a constant.intsize()Returns the number of literals in this assignment.StringtoString()
-
-
-
Constructor Detail
-
Assignment
public Assignment()
Constructs a new empty assignment (without fast evaluation).
-
Assignment
public Assignment(boolean fastEvaluable)
Constructs a new empty assignment.- Parameters:
fastEvaluable- indicates whether this assignment should be evaluable fast. If this parameter is set totruethe internal data structures will be optimized for fast evaluation but creation of the object or adding literals can take longer.
-
Assignment
public Assignment(Collection<? extends Literal> lits)
Constructs a new assignment for a given collection of literals (without fast evaluation).- Parameters:
lits- a new assignment for a given collection of literals
-
Assignment
public Assignment(Literal... lits)
Constructs a new assignment for a given array of literals (without fast evaluation).- Parameters:
lits- a new assignment for a given array of literals
-
Assignment
public Assignment(Collection<? extends Literal> lits, boolean fastEvaluable)
Constructs a new assignment for a given collection of literals.- Parameters:
lits- a new assignment for a given collection of literalsfastEvaluable- indicates whether this assignment should be evaluable fast. If this parameter is set totruethe internal data structures will be optimized for fast evaluation but creation of the object or adding literals can take longer.
-
Assignment
public Assignment(Literal lit)
Constructs a new assignment with a single literal assignment (without fast evaluation).- Parameters:
lit- the literal
-
Assignment
public Assignment(Literal lit, boolean fastEvaluable)
Constructs a new assignment with a single literal assignment.- Parameters:
lit- the literalfastEvaluable- indicates whether this assignment should be evaluable fast. If this parameter is set totruethe internal data structures will be optimized for fast evaluation but creation of the object or adding literals can take longer.
-
-
Method Detail
-
convertToFastEvaluable
public void convertToFastEvaluable()
Converts this assignment to a fast evaluable assignment.
-
fastEvaluable
public boolean fastEvaluable()
Returns whether this assignment is fast evaluable or not.- Returns:
trueif this assignment is fast evaluable,falseotherwise
-
size
public int size()
Returns the number of literals in this assignment.- Returns:
- the number of literals in this assignment
-
positiveVariables
public List<Variable> positiveVariables()
Returns the positive literals of this assignment as variables.- Returns:
- the positive literals of this assignment
-
negativeLiterals
public List<Literal> negativeLiterals()
Returns the negative literals of this assignment.- Returns:
- the negative literals of this assignment
-
negativeVariables
public List<Variable> negativeVariables()
Returns the negative literals of this assignment as variables.- Returns:
- the negative literals of this assignment
-
literals
public SortedSet<Literal> literals()
Returns all literals of this assignment.- Returns:
- all literals of this assignment
-
addLiteral
public void addLiteral(Literal lit)
Add a single literal to this assignment.- Parameters:
lit- the literal
-
evaluateLit
public boolean evaluateLit(Literal lit)
Evaluates a given literal. A literal not covered by the assignment evaluates tofalseif it is positive, otherwise it evaluates totrue.- Parameters:
lit- the literal- Returns:
- the evaluation of the literal
-
restrictLit
public Formula restrictLit(Literal lit)
Restricts a given literal to a constant. Returns the literal itself, if the literal's variable is not known.- Parameters:
lit- the literal- Returns:
- the restriction of the literal or the literal itself, if the literal's variable is not known
-
formula
public Formula formula(FormulaFactory f)
Returns the assignment as a formula.- Parameters:
f- the formula factory- Returns:
- the assignment as a formula
-
blockingClause
public Formula blockingClause(FormulaFactory f)
Creates the blocking clause for this assignment.- Parameters:
f- the formula factory- Returns:
- the blocking clause for this assignment
-
blockingClause
public Formula blockingClause(FormulaFactory f, Collection<? extends Literal> literals)
Creates the blocking clause for this assignment wrt. a given set of literals. If the set isnull, all literals are considered relevant.- Parameters:
f- the formula factoryliterals- the set of literals- Returns:
- the blocking clause for this assignment
-
-