Class DefinitionalCNFTransform
- java.lang.Object
-
- net.sf.tweety.arg.adf.transform.DefinitionalCNFTransform
-
- All Implemented Interfaces:
Transform<Disjunction,Proposition>
public class DefinitionalCNFTransform extends java.lang.Object implements Transform<Disjunction,Proposition>
An implementation of a definitional (resp. Tseitin) CNF transformation algorithm. It avoids potential exponential blowup by the idea of naming subformulas. This works via the introduction of fresh propositional variables which are then defined s.t. their truth values match their corresponding subformulas.Example:
Formula: a v b
Fresh variable: n
Define n: n <-> a v b
Clauses: (-n v a v b), (-a v n), (-b v n)
Now n is defined and can be used at occurences of (a v b). For instance, instead of generating clauses for (a v b) -> c, we can continue generating clauses for n -> c.Note that this implementation also provides an optimized version which is disabled by default but can be enabled with a constructor parameter. This optimization does not always generate full definitions, i.e. n <-> (a v b), but based on the polarity either n -> (a v b) resp. (a v b) -> n. This generates less clauses but does not guarantee satisfiability-equivalence if it is used in the context of other formulas. It should therefore only be used if the transformed formula does not appear in the context of other formulas or if it appears only at positions with positive polarity.
Example: Let f be an arbitrary formula which we translate using this implementation. We then get a name to f, say fn, and a set of clauses which represents f, say Cf. If we plan to use fn in some context like (fn -> a) v (-fn -> b) together with Cf, we are fine if we use the non-optimized version. However, the optimized version makes assumptions on the positions of the subformulas, if we thus change the context, these assumptions may no longer be true. In this example fn is used at a positive and at a negative position, which is not permitted.
- Author:
- Mathias Hofer
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.function.Function<Argument,Proposition>
argumentToProposition
private boolean
optimize
-
Constructor Summary
Constructors Constructor Description DefinitionalCNFTransform(java.util.function.Function<Argument,Proposition> argumentToProposition)
Constructs a non-optimized version of the definitional (resp.DefinitionalCNFTransform(java.util.function.Function<Argument,Proposition> argumentToProposition, boolean optimize)
Constructs a possibly optimized version of the definitional (resp.
-
Method Summary
Modifier and Type Method Description Proposition
transformArgument(java.util.function.Consumer<Disjunction> consumer, Argument argument, int polarity)
Proposition
transformConjunction(java.util.function.Consumer<Disjunction> consumer, java.util.Collection<Proposition> subconditions, int polarity)
This method is visited by theConjunctionAcceptanceConditions
of the acceptance condition on which we apply thisTransform
.Proposition
transformContradiction(java.util.function.Consumer<Disjunction> consumer, int polarity)
This method is visited by theContradictionAcceptanceConditions
of the acceptance condition on which we apply thisTransform
.Proposition
transformDisjunction(java.util.function.Consumer<Disjunction> consumer, java.util.Collection<Proposition> subconditions, int polarity)
This method is visited by theDisjunctionAcceptanceConditions
of the acceptance condition on which we apply thisTransform
.Proposition
transformEquivalence(java.util.function.Consumer<Disjunction> consumer, Proposition left, Proposition right, int polarity)
This method is visited by theEquivalenceAcceptanceConditions
of the acceptance condition on which we apply thisTransform
.Proposition
transformExclusiveDisjunction(java.util.function.Consumer<Disjunction> consumer, Proposition left, Proposition right, int polarity)
This method is visited by theExclusiveDisjunctionAcceptanceConditions
of the acceptance condition on which we apply thisTransform
.Proposition
transformImplication(java.util.function.Consumer<Disjunction> consumer, Proposition left, Proposition right, int polarity)
This method is visited by theImplicationAcceptanceConditions
of the acceptance condition on which we apply thisTransform
.Proposition
transformNegation(java.util.function.Consumer<Disjunction> consumer, Proposition sub, int polarity)
This method is visited by theNegationAcceptanceConditions
of the acceptance condition on which we apply thisTransform
.Proposition
transformTautology(java.util.function.Consumer<Disjunction> consumer, int polarity)
This method is visited by theTautologyAcceptanceConditions
of the acceptance condition on which we apply thisTransform
.
-
-
-
Field Detail
-
argumentToProposition
private java.util.function.Function<Argument,Proposition> argumentToProposition
-
optimize
private boolean optimize
-
-
Constructor Detail
-
DefinitionalCNFTransform
public DefinitionalCNFTransform(java.util.function.Function<Argument,Proposition> argumentToProposition)
Constructs a non-optimized version of the definitional (resp. Tseitin) CNF transformation algorithm.- Parameters:
argumentToProposition
- mapping used to transform the arguments to propositions.
-
DefinitionalCNFTransform
public DefinitionalCNFTransform(java.util.function.Function<Argument,Proposition> argumentToProposition, boolean optimize)
Constructs a possibly optimized version of the definitional (resp. Tseitin) CNF transformation algorithm.The optimization generates only the necessary parts of the definitions based on the polarity of the subformulas, i.e. <- or -> (or both for polarity = 0) instead of always <->.
- Parameters:
argumentToProposition
- mapping used to transform the arguments to propositions.optimize
- true enables the optimized definition
-
-
Method Detail
-
transformDisjunction
public Proposition transformDisjunction(java.util.function.Consumer<Disjunction> consumer, java.util.Collection<Proposition> subconditions, int polarity)
Description copied from interface:Transform
This method is visited by theDisjunctionAcceptanceConditions
of the acceptance condition on which we apply thisTransform
.- Specified by:
transformDisjunction
in interfaceTransform<Disjunction,Proposition>
- Parameters:
consumer
- the consumer of the computed return valuessubconditions
- the subconditions of this disjunction, e.g. {a, b} if this = or(a,b)polarity
- polarity < 0: negative global position of this disjunction, e.g. this -> a
polarity = 0: neutral global position of this disjunction, e.g. this <-> a
polarity > 0: positive global position of this disjunction, e.g. a -> this- Returns:
- the result which we want to return to the parent-formula of this disjunction
-
transformConjunction
public Proposition transformConjunction(java.util.function.Consumer<Disjunction> consumer, java.util.Collection<Proposition> subconditions, int polarity)
Description copied from interface:Transform
This method is visited by theConjunctionAcceptanceConditions
of the acceptance condition on which we apply thisTransform
.- Specified by:
transformConjunction
in interfaceTransform<Disjunction,Proposition>
- Parameters:
consumer
- the consumer of the computed return valuessubconditions
- the subconditions of this conjunction, e.g. {a, b} if this = and(a,b)polarity
- polarity < 0: negative global position of this conjunction, e.g. this -> a
polarity = 0: neutral global position of this conjunction, e.g. this <-> a
polarity > 0: positive global position of this conjunction, e.g. a -> this- Returns:
- the result which we want to return to the parent-formula of this conjunction
-
transformImplication
public Proposition transformImplication(java.util.function.Consumer<Disjunction> consumer, Proposition left, Proposition right, int polarity)
Description copied from interface:Transform
This method is visited by theImplicationAcceptanceConditions
of the acceptance condition on which we apply thisTransform
.- Specified by:
transformImplication
in interfaceTransform<Disjunction,Proposition>
- Parameters:
consumer
- the consumer of the computed return valuesleft
- the left part of the implicationright
- the right part of the implicationpolarity
- polarity < 0: negative global position of this implication, e.g. this -> a
polarity = 0: neutral global position of this implication, e.g. this <-> a
polarity > 0: positive global position of this implication, e.g. a -> this- Returns:
- the result which we want to return to the parent-formula of this implication
-
transformEquivalence
public Proposition transformEquivalence(java.util.function.Consumer<Disjunction> consumer, Proposition left, Proposition right, int polarity)
Description copied from interface:Transform
This method is visited by theEquivalenceAcceptanceConditions
of the acceptance condition on which we apply thisTransform
.- Specified by:
transformEquivalence
in interfaceTransform<Disjunction,Proposition>
- Parameters:
consumer
- the consumer of the computed return valuesleft
- the left part of the equivalenceright
- the right part of the equivalencepolarity
- polarity < 0: negative global position of this equivalence, e.g. this -> a
polarity = 0: neutral global position of this equivalence, e.g. this <-> a
polarity > 0: positive global position of this equivalence, e.g. a -> this- Returns:
- the result which we want to return to the parent-formula of this equivalence
-
transformExclusiveDisjunction
public Proposition transformExclusiveDisjunction(java.util.function.Consumer<Disjunction> consumer, Proposition left, Proposition right, int polarity)
Description copied from interface:Transform
This method is visited by theExclusiveDisjunctionAcceptanceConditions
of the acceptance condition on which we apply thisTransform
.- Specified by:
transformExclusiveDisjunction
in interfaceTransform<Disjunction,Proposition>
- Parameters:
consumer
- the consumer of the computed return valuesleft
- the left part of the xorright
- the right part of the xorpolarity
- polarity < 0: negative global position of this xor, e.g. this -> a
polarity = 0: neutral global position of this xor, e.g. this <-> a
polarity > 0: positive global position of this xor, e.g. a -> this- Returns:
- the result which we want to return to the parent-formula of this xor
-
transformNegation
public Proposition transformNegation(java.util.function.Consumer<Disjunction> consumer, Proposition sub, int polarity)
Description copied from interface:Transform
This method is visited by theNegationAcceptanceConditions
of the acceptance condition on which we apply thisTransform
.- Specified by:
transformNegation
in interfaceTransform<Disjunction,Proposition>
- Parameters:
consumer
- the consumer of the computed return valuessub
- the subformula of this negation, i.e. this = neg(sub)polarity
- polarity < 0: negative global position of this negation, e.g. this -> a
polarity = 0: neutral global position of this negation, e.g. this <-> a
polarity > 0: positive global position of this negation, e.g. a -> this- Returns:
- the result which we want to return to the parent-formula of this negation
-
transformArgument
public Proposition transformArgument(java.util.function.Consumer<Disjunction> consumer, Argument argument, int polarity)
Description copied from interface:Transform
This method is visited by theArguments
of the acceptance condition on which we apply thisTransform
.- Specified by:
transformArgument
in interfaceTransform<Disjunction,Proposition>
- Parameters:
consumer
- the consumer of the computed return valuesargument
- the argument which calls this methodpolarity
- polarity < 0: negative global position of this argument, e.g. this -> a
polarity = 0: neutral global position of this argument, e.g. this <-> a
polarity > 0: positive global position of this argument, e.g. a -> this- Returns:
- the result which we want to return to the parent-formula of this argument
-
transformContradiction
public Proposition transformContradiction(java.util.function.Consumer<Disjunction> consumer, int polarity)
Description copied from interface:Transform
This method is visited by theContradictionAcceptanceConditions
of the acceptance condition on which we apply thisTransform
.- Specified by:
transformContradiction
in interfaceTransform<Disjunction,Proposition>
- Parameters:
consumer
- the consumer of the computed return valuespolarity
- polarity < 0: negative global position of this contradiction, e.g. this -> a
polarity = 0: neutral global position of this contradiction, e.g. this <-> a
polarity > 0: positive global position of this contradiction, e.g. a -> this- Returns:
- the result which we want to return to the parent-formula of this contradiction
-
transformTautology
public Proposition transformTautology(java.util.function.Consumer<Disjunction> consumer, int polarity)
Description copied from interface:Transform
This method is visited by theTautologyAcceptanceConditions
of the acceptance condition on which we apply thisTransform
.- Specified by:
transformTautology
in interfaceTransform<Disjunction,Proposition>
- Parameters:
consumer
- the consumer of the computed return valuespolarity
- polarity < 0: negative global position of this tautology, e.g. this -> a
polarity = 0: neutral global position of this tautology, e.g. this <-> a
polarity > 0: positive global position of this tautology, e.g. a -> this- Returns:
- the result which we want to return to the parent-formula of this tautology
-
-