Search in sources :

Example 11 with BoolTableByteArray

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

Example 12 with BoolTableByteArray

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

the class ModelAnalyser method dependantFiller.

private void dependantFiller(TruthTable tt, DependencyAnalyser da) throws NodeException, AnalyseException {
    model.init();
    for (Signal out : outputs) {
        ArrayList<Signal> ins = reorder(da.getInputs(out), inputs);
        if (ins.size() > MAX_INPUTS_ALLOWED)
            throw new AnalyseException(Lang.get("err_toManyInputs_max_N0_is_N1", MAX_INPUTS_ALLOWED, ins.size()));
        int rows = 1 << ins.size();
        BoolTableByteArray e = new BoolTableByteArray(rows);
        BitSetter bitsetter = new BitSetter(ins.size()) {

            @Override
            public void setBit(int row, int bit, boolean value) {
                ins.get(bit).getValue().setBool(value);
            }
        };
        for (int row = 0; row < rows; row++) {
            bitsetter.fill(row);
            model.doStep();
            e.set(row, out.getValue().getBool());
        }
        tt.addResult(out.getName(), new BoolTableExpanded(e, ins, inputs));
    }
}
Also used : BoolTableByteArray(de.neemann.digital.analyse.quinemc.BoolTableByteArray) BitSetter(de.neemann.digital.analyse.expression.BitSetter)

Aggregations

BoolTableByteArray (de.neemann.digital.analyse.quinemc.BoolTableByteArray)12 Variable (de.neemann.digital.analyse.expression.Variable)6 TruthTable (de.neemann.digital.analyse.TruthTable)4 ContextFiller (de.neemann.digital.analyse.expression.ContextFiller)4 BitSetter (de.neemann.digital.analyse.expression.BitSetter)2 BoolTable (de.neemann.digital.analyse.quinemc.BoolTable)2 Signal (de.neemann.digital.core.Signal)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 Expression (de.neemann.digital.analyse.expression.Expression)1 QuineMcCluskey (de.neemann.digital.analyse.quinemc.QuineMcCluskey)1 TableReducer (de.neemann.digital.analyse.quinemc.TableReducer)1 TableRow (de.neemann.digital.analyse.quinemc.TableRow)1