Search in sources :

Example 1 with DNFFactorization

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);
}
Also used : Formula(org.logicng.formulas.Formula) FormulaFactory(org.logicng.formulas.FormulaFactory) DNFFactorization(org.logicng.transformations.dnf.DNFFactorization)

Example 2 with DNFFactorization

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);
}
Also used : DNFFactorization(org.logicng.transformations.dnf.DNFFactorization) Test(org.junit.jupiter.api.Test)

Example 3 with DNFFactorization

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));
    }
}
Also used : Formula(org.logicng.formulas.Formula) BooleanExpression(fr.lip6.move.gal.BooleanExpression) FutureTask(java.util.concurrent.FutureTask) ExecutorService(java.util.concurrent.ExecutorService) DNFFactorization(org.logicng.transformations.dnf.DNFFactorization)

Example 4 with DNFFactorization

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();
}
Also used : IStringX(org.matheclipse.core.interfaces.IStringX) DNFFactorization(org.logicng.transformations.dnf.DNFFactorization) BDDCNFTransformation(org.logicng.transformations.cnf.BDDCNFTransformation)

Aggregations

DNFFactorization (org.logicng.transformations.dnf.DNFFactorization)4 Formula (org.logicng.formulas.Formula)2 BooleanExpression (fr.lip6.move.gal.BooleanExpression)1 ExecutorService (java.util.concurrent.ExecutorService)1 FutureTask (java.util.concurrent.FutureTask)1 Test (org.junit.jupiter.api.Test)1 FormulaFactory (org.logicng.formulas.FormulaFactory)1 BDDCNFTransformation (org.logicng.transformations.cnf.BDDCNFTransformation)1 IStringX (org.matheclipse.core.interfaces.IStringX)1