Search in sources :

Example 1 with PrimeSelectorDefault

use of de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault in project Digital by hneemann.

the class MinimizerQuineMcCluskey method minimize.

@Override
public void minimize(List<Variable> vars, BoolTable boolTable, String resultName, ExpressionListener listener) throws ExpressionException, FormatterException {
    QuineMcCluskey qmc = createQuineMcCluskey(vars).fillTableWith(boolTable);
    PrimeSelector ps = new PrimeSelectorDefault();
    Expression e = qmc.simplify(ps).getExpression();
    if (ps.getAllSolutions() != null) {
        for (ArrayList<TableRow> i : ps.getAllSolutions()) {
            listener.resultFound(resultName, QuineMcCluskey.addAnd(null, i, vars));
        }
    } else {
        listener.resultFound(resultName, e);
    }
}
Also used : QuineMcCluskey(de.neemann.digital.analyse.quinemc.QuineMcCluskey) PrimeSelectorDefault(de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault) Expression(de.neemann.digital.analyse.expression.Expression) TableRow(de.neemann.digital.analyse.quinemc.TableRow) PrimeSelector(de.neemann.digital.analyse.quinemc.primeselector.PrimeSelector)

Example 2 with PrimeSelectorDefault

use of de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault in project Digital by hneemann.

the class QuineMcCluskeyTest method testMultipleResults.

public void testMultipleResults() throws ExpressionException {
    QuineMcCluskeyExam t = new QuineMcCluskeyExam(Variable.vars("A", "B", "C"));
    t.fillTableWith(new BoolTableByteArray(new byte[] { 0, 1, 1, 0, 0, 1, 1, 1 }));
    PrimeSelectorDefault ps = new PrimeSelectorDefault();
    t.simplify(ps);
    assertEquals(2, ps.getAllSolutions().size());
}
Also used : PrimeSelectorDefault(de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault)

Example 3 with PrimeSelectorDefault

use of de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault in project Digital by hneemann.

the class QuineMcCluskeyRegressionTest method testRegression3.

public void testRegression3() throws Exception {
    Variable a = new Variable("A");
    Variable b = new Variable("B");
    Variable c = new Variable("C");
    Variable d = new Variable("D");
    ArrayList<Variable> vars = new ArrayList<>();
    vars.add(a);
    vars.add(b);
    vars.add(c);
    vars.add(d);
    QuineMcCluskey t = new QuineMcCluskey(vars);
    Expression ex = or(a, c);
    t.fillTableWith(new BoolTableExpression(ex, new ContextFiller(vars)));
    // System.out.println("--");
    while (!t.isFinished()) {
        // System.out.println(FormatToExpression.FORMATTER_JAVA.format(t.getExpression()));
        t.simplifyStep();
    }
    t.simplifyPrimes(new PrimeSelectorDefault());
    assertEquals("A || C", FormatToExpression.FORMATTER_JAVA.format(t.getExpression()));
// System.out.println("--");
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) PrimeSelectorDefault(de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault) FormatToExpression(de.neemann.digital.analyse.expression.format.FormatToExpression) Expression(de.neemann.digital.analyse.expression.Expression) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller) ArrayList(java.util.ArrayList)

Example 4 with PrimeSelectorDefault

use of de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault in project Digital by hneemann.

the class KarnaughMapTest method testIndex.

/**
 * Creates bool tables with one "one".
 * Calculates the KV map.
 * Tests if the covered cell belongs to the single "one" in the table!
 */
public void testIndex() throws IOException, ParseException, KarnaughException, ExpressionException {
    for (int vars = 2; vars <= 4; vars++) {
        int rows = 1 << vars;
        for (int row = 0; row < rows; row++) {
            // create bool table
            BoolTableBoolArray t = new BoolTableBoolArray(rows);
            // put one one to the tabel
            t.set(row, true);
            Expression exp = new QuineMcCluskey(Variable.vars(vars)).fillTableWith(t).simplify(new PrimeSelectorDefault()).getExpression();
            // create the KV covers
            KarnaughMap c = new KarnaughMap(Variable.vars(vars), exp);
            // there is only on cover
            assertEquals(1, c.size());
            KarnaughMap.Cover cover = c.iterator().next();
            // the size of the cover is one cell
            assertEquals(1, cover.getSize());
            KarnaughMap.Pos pos = cover.getPos();
            // the row in the truth table is the row containing the one.
            assertEquals(row, c.getCell(pos.getRow(), pos.getCol()).getBoolTableRow());
        }
    }
}
Also used : QuineMcCluskey(de.neemann.digital.analyse.quinemc.QuineMcCluskey) PrimeSelectorDefault(de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault) Expression(de.neemann.digital.analyse.expression.Expression) BoolTableBoolArray(de.neemann.digital.analyse.quinemc.BoolTableBoolArray)

Example 5 with PrimeSelectorDefault

use of de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault in project Digital by hneemann.

the class QuineMcCluskeyTest method testSimplify.

public void testSimplify() throws ExpressionException, FormatterException {
    // Vorlesung
    Variable a = new Variable("A");
    Variable b = new Variable("B");
    Variable c = new Variable("C");
    Variable d = new Variable("D");
    Expression e = or(and(a, c, d), and(not(c), not(d)), and(not(b), c));
    QuineMcCluskey t = new QuineMcCluskey(e);
    t.simplifyStep();
    assertFalse(t.isFinished());
    assertEquals("-000,1,5\n" + "-100,4,8\n" + "-010,2,6\n" + "-011,3,7\n" + "0-00,1,4\n" + "1-00,5,8\n" + "1-11,7,9\n" + "00-0,1,2\n" + "10-0,5,6\n" + "001-,2,3\n" + "101-,6,7\n", t.toString());
    t.simplifyStep();
    assertFalse(t.isFinished());
    /*
        assertEquals(
                "--00,1,4,5,8\n" +
                        "--00,1,4,5,8\n" +
                        "-0-0,1,2,5,6\n" +
                "-0-0,1,2,5,6\n" +
                "-01-,2,3,6,7\n" +
                "-01-,2,3,6,7\n", t.toString());

        ArrayList<TableRow> primes = t.getPrimes();
        assertEquals(1, primes.size());
        assertEquals("1-11,7,9", primes.get(0).toString());

        t = t.removeDuplicates();*/
    assertFalse(t.isFinished());
    assertEquals("--00,1,4,5,8\n" + "-0-0,1,2,5,6\n" + "-01-,2,3,6,7\n", t.toString());
    t.simplifyStep();
    assertTrue(t.isFinished());
    assertEquals("", t.toString());
    ArrayList<TableRow> primes = t.getPrimes();
    assertEquals(4, primes.size());
    assertEquals("1-11,7,9", primes.get(0).toString());
    assertEquals("-0-0,1,2,5,6", primes.get(2).toString());
    assertEquals("--00,1,4,5,8", primes.get(1).toString());
    assertEquals("-01-,2,3,6,7", primes.get(3).toString());
    Expression exp = t.getExpression();
    assertEquals("(A && C && D) || (!B && !D) || (!B && C) || (!C && !D)", FormatToExpression.FORMATTER_JAVA.format(exp));
    t.simplifyPrimes(new PrimeSelectorDefault());
    exp = t.getExpression();
    assertEquals("(A && C && D) || (!B && C) || (!C && !D)", FormatToExpression.FORMATTER_JAVA.format(exp));
}
Also used : PrimeSelectorDefault(de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault) FormatToExpression(de.neemann.digital.analyse.expression.format.FormatToExpression)

Aggregations

PrimeSelectorDefault (de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault)5 Expression (de.neemann.digital.analyse.expression.Expression)3 FormatToExpression (de.neemann.digital.analyse.expression.format.FormatToExpression)2 QuineMcCluskey (de.neemann.digital.analyse.quinemc.QuineMcCluskey)2 ContextFiller (de.neemann.digital.analyse.expression.ContextFiller)1 Variable (de.neemann.digital.analyse.expression.Variable)1 BoolTableBoolArray (de.neemann.digital.analyse.quinemc.BoolTableBoolArray)1 TableRow (de.neemann.digital.analyse.quinemc.TableRow)1 PrimeSelector (de.neemann.digital.analyse.quinemc.primeselector.PrimeSelector)1 ArrayList (java.util.ArrayList)1