Search in sources :

Example 1 with QuineMcCluskey

use of de.neemann.digital.analyse.quinemc.QuineMcCluskey 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 QuineMcCluskey

use of de.neemann.digital.analyse.quinemc.QuineMcCluskey 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 3 with QuineMcCluskey

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

the class BruteForceGetAllTest method performTestCalculation.

/*
    public void testFull() throws ExpressionException, FormatterException {
        new FullVariantDontCareCreator(4) {
            @Override
            public void handleTable(int n, int[] tab) throws ExpressionException {
                performTestCalculation(n, tab);
            }
        }.create();
    } /**/
private static void performTestCalculation(int n, byte[] tab) throws ExpressionException {
    BruteForceGetAll ps = new BruteForceGetAll();
    ArrayList<Variable> v = vars(n);
    new QuineMcCluskey(v).fillTableWith(new BoolTableByteArray(tab)).simplify(ps);
    ArrayList<ArrayList<TableRow>> solutions = ps.getAllSolutions();
    if (solutions != null) {
        for (ArrayList<TableRow> sol : solutions) {
            Expression e = QuineMcCluskey.addAnd(null, sol, v);
            ContextFiller context = new ContextFiller(v);
            for (int i = 0; i < tab.length; i++) {
                if (tab[i] <= 1) {
                    assertEquals(tab[i] == 1, e.calculate(context.setContextTo(i)));
                }
            }
        }
    }
}
Also used : QuineMcCluskey(de.neemann.digital.analyse.quinemc.QuineMcCluskey) Variable(de.neemann.digital.analyse.expression.Variable) BoolTableByteArray(de.neemann.digital.analyse.quinemc.BoolTableByteArray) Expression(de.neemann.digital.analyse.expression.Expression) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller) TableRow(de.neemann.digital.analyse.quinemc.TableRow) ArrayList(java.util.ArrayList)

Aggregations

Expression (de.neemann.digital.analyse.expression.Expression)3 QuineMcCluskey (de.neemann.digital.analyse.quinemc.QuineMcCluskey)3 TableRow (de.neemann.digital.analyse.quinemc.TableRow)2 PrimeSelectorDefault (de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault)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 BoolTableByteArray (de.neemann.digital.analyse.quinemc.BoolTableByteArray)1 PrimeSelector (de.neemann.digital.analyse.quinemc.primeselector.PrimeSelector)1 ArrayList (java.util.ArrayList)1