Search in sources :

Example 1 with BoolTableByteArray

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

the class TestReorderInputs method testDeleteVar.

public void testDeleteVar() throws Exception {
    TruthTable t = new TruthTable(3).addResult();
    BoolTableByteArray col = (BoolTableByteArray) t.getResult(0);
    for (int i = 0; i < t.getRows(); i++) col.set(i, i + 1);
    ReorderInputs reorderInputs = new ReorderInputs(t);
    reorderInputs.getItems().delete(2);
    TruthTable newTable = reorderInputs.reorder();
    assertEquals(2, newTable.getVars().size());
    assertEquals(1, newTable.getResultCount());
    ContextFiller cf = new ContextFiller(newTable.getVars());
    cf.set(t.getVars().get(2), false);
    for (int i = 0; i < newTable.getRows(); i++) {
        cf.setContextTo(i);
        assertEquals(newTable.getByContext(0, cf), t.getByContext(0, cf));
    }
}
Also used : BoolTableByteArray(de.neemann.digital.analyse.quinemc.BoolTableByteArray) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller) TruthTable(de.neemann.digital.analyse.TruthTable)

Example 2 with BoolTableByteArray

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

the class TestReorderInputs method testReorder.

public void testReorder() throws Exception {
    TruthTable t = new TruthTable(5).addResult();
    BoolTableByteArray col = (BoolTableByteArray) t.getResult(0);
    for (int i = 0; i < t.getRows(); i++) col.set(i, i + 1);
    ReorderInputs reorderInputs = new ReorderInputs(t);
    reorderInputs.getItems().swap(1, 2);
    TruthTable newTable = reorderInputs.reorder();
    ContextFiller cf = new ContextFiller(t.getVars());
    for (int i = 0; i < t.getRows(); i++) {
        cf.setContextTo(i);
        assertEquals(newTable.getByContext(0, cf), t.getByContext(0, cf));
    }
}
Also used : BoolTableByteArray(de.neemann.digital.analyse.quinemc.BoolTableByteArray) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller) TruthTable(de.neemann.digital.analyse.TruthTable)

Example 3 with BoolTableByteArray

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

the class TestReorderOutputs method testDeleteResult.

public void testDeleteResult() throws Exception {
    TruthTable t = new TruthTable(3).addResult().addResult();
    BoolTableByteArray col = (BoolTableByteArray) t.getResult(0);
    for (int i = 0; i < t.getRows(); i++) col.set(i, i + 1);
    ReorderOutputs reorderOutputs = new ReorderOutputs(t);
    reorderOutputs.getItems().delete(1);
    TruthTable newTable = reorderOutputs.reorder();
    assertEquals(3, newTable.getVars().size());
    assertEquals(1, newTable.getResultCount());
}
Also used : BoolTableByteArray(de.neemann.digital.analyse.quinemc.BoolTableByteArray) TruthTable(de.neemann.digital.analyse.TruthTable)

Example 4 with BoolTableByteArray

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

the class ModelAnalyser method simpleFiller.

private void simpleFiller(TruthTable tt) throws NodeException, AnalyseException {
    if (inputs.size() > MAX_INPUTS_ALLOWED)
        throw new AnalyseException(Lang.get("err_toManyInputs_max_N0_is_N1", MAX_INPUTS_ALLOWED, inputs.size()));
    BitSetter bitsetter = new BitSetter(inputs.size()) {

        @Override
        public void setBit(int row, int bit, boolean value) {
            inputs.get(bit).getValue().setBool(value);
        }
    };
    int rows = 1 << inputs.size();
    ArrayList<BoolTableByteArray> data = new ArrayList<>();
    for (Signal s : outputs) {
        BoolTableByteArray e = new BoolTableByteArray(rows);
        data.add(e);
        tt.addResult(s.getName(), e);
    }
    model.init();
    for (int row = 0; row < rows; row++) {
        bitsetter.fill(row);
        model.doStep();
        for (int i = 0; i < outputs.size(); i++) {
            data.get(i).set(row, outputs.get(i).getValue().getBool());
        }
    }
}
Also used : BoolTableByteArray(de.neemann.digital.analyse.quinemc.BoolTableByteArray) BitSetter(de.neemann.digital.analyse.expression.BitSetter) ArrayList(java.util.ArrayList)

Example 5 with BoolTableByteArray

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

the class BoolTableExpandedTest method testCombined.

public void testCombined() {
    ArrayList<Signal> in1 = new Signals("b", "c").list();
    ArrayList<Signal> in2 = new Signals("a", "b", "c", "d").list();
    List<Variable> vars = new Vars("a", "b", "c", "d").list();
    BoolTableExpanded bt = new BoolTableExpanded(new BoolTableByteArray(new byte[] { 1, 1, 0, 0 }), in1, in2);
    TableReducer tr = new TableReducer(vars, bt);
    assertTrue(tr.canReduce());
    List<Variable> v = tr.getVars();
    assertEquals(1, v.size());
    assertEquals("b", v.get(0).getIdentifier());
    BoolTable t1 = tr.getTable();
    assertEquals(ThreeStateValue.one, t1.get(0));
    assertEquals(ThreeStateValue.zero, t1.get(1));
}
Also used : Signal(de.neemann.digital.core.Signal) Variable(de.neemann.digital.analyse.expression.Variable) BoolTableByteArray(de.neemann.digital.analyse.quinemc.BoolTableByteArray) BoolTable(de.neemann.digital.analyse.quinemc.BoolTable) TableReducer(de.neemann.digital.analyse.quinemc.TableReducer)

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