use of org.logicng.transformations.dnf.DNFFactorization in project VERDICT by ge-high-assurance.
the class CutSetGenerator method generate.
/**
* Perform cut set generation for the given attack-defense tree.
*
* @param adtree
* @return
*/
public static ADTree generate(ADTree adtree) {
FormulaFactory factory = new FormulaFactory();
Cache cache = new Cache();
Formula formula = adtree.toLogicNg(factory, cache);
long startTime = System.currentTimeMillis();
// this is terribly inefficient for any non-trivial system
// and it has not yet been observed to terminate
// Formula minimal = QuineMcCluskeyAlgorithm.compute(formula);
// this should be inefficient too, but it finishes trivially for trees already in DNF form
// not yet tested on non-DNF trees because we don't have a model that produces one
Formula minimal = (new DNFFactorization()).apply(formula, false);
// for comparing approaches
System.out.println("converted to DNF in " + (System.currentTimeMillis() - startTime) + " ms");
return extract(minimal, cache);
}
use of org.logicng.transformations.dnf.DNFFactorization in project LogicNG by logic-ng.
the class FormulaFactoryWithoutContradictionCheckTest method testNormalforms.
@Test
public void testNormalforms() {
assertThat(this.tautology.nnf()).isEqualTo(this.tautology);
assertThat(this.contradiction.nnf()).isEqualTo(this.contradiction);
assertThat(this.tautology.cnf()).isEqualTo(this.tautology);
assertThat(this.contradiction.cnf()).isEqualTo(this.contradiction);
assertThat(this.tautology.transform(new DNFFactorization())).isEqualTo(this.tautology);
assertThat(this.contradiction.transform(new DNFFactorization())).isEqualTo(this.contradiction);
}
use of org.logicng.transformations.dnf.DNFFactorization in project ITSTools by lip6.
the class GalToLogicNG method simplify.
public void simplify(List<BooleanExpression> props) {
ExecutorService pool = Executors.newCachedThreadPool();
for (BooleanExpression be : props) {
// System.out.println("Before : "+ SerializationUtil.getText(be, true));
FutureTask<BooleanExpression> task = new FutureTask<>(() -> {
Formula ff = toFormula(be);
Formula fs = new DNFFactorization().apply(ff, false);
if (fs.numberOfNodes() >= 4 * ff.numberOfNodes() + 1) {
fs = ff;
}
BooleanExpression newbe = toGal(fs);
return newbe;
});
pool.execute(task);
try {
EcoreUtil.replace(be, task.get(500, TimeUnit.MILLISECONDS));
} catch (Exception e) {
task.cancel(true);
}
// QuineMcCluskeyAlgorithm.compute(ff);
// System.out.println("After LogicNG : "+ SerializationUtil.getText(newbe, true));
}
}
use of org.logicng.transformations.dnf.DNFFactorization in project symja_android_library by axkr.
the class BooleanFunctions method transformation.
/**
* Get the transformation from the ast options. Default is DNF.
*
* @param ast
* @param engine
* @return <code>null</code> if no or wrong method is defined as option
*/
private static FormulaTransformation transformation(final IAST ast, EvalEngine engine) {
int size = ast.argSize();
if (size > 1 && ast.get(size).isString()) {
IStringX lastArg = (IStringX) ast.get(size);
String method = lastArg.toString();
if (method.equals("DNF") || method.equals("SOP")) {
return new DNFFactorization();
} else if (method.equals("CNF") || method.equals("POS")) {
// don't use CNFFactorization, because of bad memory space complexity
return new BDDCNFTransformation();
}
// `1` currently not supported in `2`.
IOFunctions.printMessage(ast.topHead(), "unsupported", F.list(lastArg, S.Method), engine);
return null;
}
return new DNFFactorization();
}
Aggregations