|
| 1 | +package org.variantsync.diffdetective.variation.tree.view.relevance.spec; |
| 2 | + |
| 3 | +import org.prop4j.Node; |
| 4 | +import org.prop4j.NodeWriter; |
| 5 | +import org.variantsync.diffdetective.analysis.logic.SAT; |
| 6 | +import org.variantsync.diffdetective.util.fide.FixTrueFalse; |
| 7 | +import org.variantsync.diffdetective.util.fide.FixTrueFalse.Formula; |
| 8 | +import org.variantsync.diffdetective.variation.tree.VariationNode; |
| 9 | +import org.variantsync.diffdetective.variation.tree.view.relevance.Relevance; |
| 10 | + |
| 11 | +/** |
| 12 | + * This class serves as a specification for {@link org.variantsync.diffdetective.variation.tree.view.relevance.Configure}. |
| 13 | + * Both classes must act semantically equivalent as a {@link Relevance} predicate. |
| 14 | + * Whereas Configure is an implementation optimized to avoid SAT calls where necessary, the implementation in ConfigureSpec |
| 15 | + * is kept simple by design to remain verifiable. |
| 16 | + * ConfigureSpec tests a partial configuration against a variation tree or diff by checking each node individually. |
| 17 | + * To this end ConfigureSpec uses the default, naive implementations of {@link Relevance} instead of providing |
| 18 | + * optimized implementations for tree traversal as Configure does. |
| 19 | + * |
| 20 | + * This class is not intended for production use and rather is supposed to be used in tests. |
| 21 | + * |
| 22 | + * @author Paul Bittner |
| 23 | + */ |
| 24 | +public record ConfigureSpec(Formula config) implements Relevance { |
| 25 | + public static boolean test(Formula formula, VariationNode<?, ?> v) { |
| 26 | + return SAT.isSatisfiable( |
| 27 | + Formula.and( |
| 28 | + formula, |
| 29 | + FixTrueFalse.EliminateTrueAndFalse(v.getPresenceCondition()) |
| 30 | + ) |
| 31 | + ); |
| 32 | + } |
| 33 | + |
| 34 | + public ConfigureSpec(final Node configuration) { |
| 35 | + this(FixTrueFalse.EliminateTrueAndFalse(configuration)); |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public boolean test(VariationNode<?, ?> t) { |
| 40 | + return test(config, t); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public String getFunctionName() { |
| 45 | + return "configure_spec"; |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public String parametersToString() { |
| 50 | + return config.get().toString(NodeWriter.logicalSymbols); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public String toString() { |
| 55 | + return Relevance.toString(this); |
| 56 | + } |
| 57 | +} |
0 commit comments