Search in sources :

Example 1 with ExpressionListenerStore

use of de.neemann.digital.gui.components.table.ExpressionListenerStore in project Digital by hneemann.

the class QuineMcCluskeyExamTest method testMultipleSolutions.

public void testMultipleSolutions() throws ExpressionException, FormatterException {
    ExpressionListenerStore results = new ExpressionListenerStore(null);
    new MinimizerQuineMcCluskeyExam().minimize(Variable.vars(4), new BoolTableByteArray(new byte[] { 2, 0, 0, 0, 1, 2, 0, 0, 1, 1, 2, 0, 1, 1, 1, 2 }), "Y", results);
    assertEquals(4, results.getResults().size());
    int compl = -1;
    for (ExpressionListenerStore.Result r : results.getResults()) {
        assertEquals("Y", r.getName());
        int c = r.getExpression().traverse(new ComplexityVisitor()).getComplexity();
        if (compl < 0)
            compl = c;
        assertEquals(compl, c);
    }
}
Also used : ComplexityVisitor(de.neemann.digital.analyse.expression.ComplexityVisitor) MinimizerQuineMcCluskeyExam(de.neemann.digital.analyse.MinimizerQuineMcCluskeyExam) ExpressionListenerStore(de.neemann.digital.gui.components.table.ExpressionListenerStore)

Example 2 with ExpressionListenerStore

use of de.neemann.digital.gui.components.table.ExpressionListenerStore in project Digital by hneemann.

the class MinimizerRegressionTest method performTestCalculation.

/**
 * Generates a expression from the table and then checks if
 * the expression reproduces the given table.
 * Does not test if the expression is minimal.
 *
 * @param n   the number of variables
 * @param tab the truth table
 * @throws ExpressionException
 */
private static void performTestCalculation(int n, byte[] tab, MinimizerInterface minimizer) throws ExpressionException, FormatterException {
    ArrayList<Variable> v = vars(n);
    final ExpressionListenerStore listener = new ExpressionListenerStore(null);
    minimizer.minimize(v, new BoolTableByteArray(tab), "Y", listener);
    Expression e = listener.getFirst();
    assertNotNull(e);
    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 : Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller) ExpressionListenerStore(de.neemann.digital.gui.components.table.ExpressionListenerStore)

Example 3 with ExpressionListenerStore

use of de.neemann.digital.gui.components.table.ExpressionListenerStore in project Digital by hneemann.

the class QuineMcCluskeyExamTest method testMinimal.

public void testMinimal() throws ExpressionException, FormatterException {
    ExpressionListenerStore results = new ExpressionListenerStore(null);
    new MinimizerQuineMcCluskeyExam().minimize(Variable.vars(4), new BoolTableByteArray(new byte[] { 1, 2, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1 }), "Y", results);
    assertEquals(1, results.getResults().size());
}
Also used : MinimizerQuineMcCluskeyExam(de.neemann.digital.analyse.MinimizerQuineMcCluskeyExam) ExpressionListenerStore(de.neemann.digital.gui.components.table.ExpressionListenerStore)

Example 4 with ExpressionListenerStore

use of de.neemann.digital.gui.components.table.ExpressionListenerStore in project Digital by hneemann.

the class CircuitBuilderTest method testBus.

public void testBus() throws Exception {
    final ToBreakRunner runner = new ToBreakRunner("dig/circuitBuilder/busTest.dig", false);
    // create truth table incl. ModelAnalyzerInfo
    TruthTable tt = new ModelAnalyser(runner.getModel()).analyse();
    assertEquals(8, tt.getVars().size());
    assertEquals(8, tt.getResultCount());
    // create expressions based on truth table
    ExpressionListenerStore expr = new ExpressionListenerStore(null);
    new ExpressionCreator(tt).create(expr);
    // build a new circuit
    CircuitBuilder circuitBuilder = new CircuitBuilder(runner.getLibrary().getShapeFactory(), false, tt.getVars()).setModelAnalyzerInfo(tt.getModelAnalyzerInfo());
    new BuilderExpressionCreator(circuitBuilder).create(expr);
    Circuit circuit = circuitBuilder.createCircuit();
    // check
    List<VisualElement> in = circuit.findElements(v -> v.equalsDescription(In.DESCRIPTION));
    assertEquals(2, in.size());
    checkPin(in.get(0), "A", "1,2,3,4");
    checkPin(in.get(1), "B", "5,6,7,8");
    List<VisualElement> out = circuit.findElements(v -> v.equalsDescription(Out.DESCRIPTION));
    assertEquals(2, out.size());
    checkPin(out.get(0), "S", "9,10,11,12");
    checkPin(out.get(1), "U", "13,14,15,16");
}
Also used : ModelAnalyser(de.neemann.digital.analyse.ModelAnalyser) TruthTable(de.neemann.digital.analyse.TruthTable) ToBreakRunner(de.neemann.digital.integration.ToBreakRunner) Circuit(de.neemann.digital.draw.elements.Circuit) VisualElement(de.neemann.digital.draw.elements.VisualElement) BuilderExpressionCreator(de.neemann.digital.gui.components.table.BuilderExpressionCreator) ExpressionListenerStore(de.neemann.digital.gui.components.table.ExpressionListenerStore) ExpressionCreator(de.neemann.digital.gui.components.table.ExpressionCreator) BuilderExpressionCreator(de.neemann.digital.gui.components.table.BuilderExpressionCreator)

Aggregations

ExpressionListenerStore (de.neemann.digital.gui.components.table.ExpressionListenerStore)4 MinimizerQuineMcCluskeyExam (de.neemann.digital.analyse.MinimizerQuineMcCluskeyExam)2 ModelAnalyser (de.neemann.digital.analyse.ModelAnalyser)1 TruthTable (de.neemann.digital.analyse.TruthTable)1 ComplexityVisitor (de.neemann.digital.analyse.expression.ComplexityVisitor)1 ContextFiller (de.neemann.digital.analyse.expression.ContextFiller)1 Expression (de.neemann.digital.analyse.expression.Expression)1 Variable (de.neemann.digital.analyse.expression.Variable)1 Circuit (de.neemann.digital.draw.elements.Circuit)1 VisualElement (de.neemann.digital.draw.elements.VisualElement)1 BuilderExpressionCreator (de.neemann.digital.gui.components.table.BuilderExpressionCreator)1 ExpressionCreator (de.neemann.digital.gui.components.table.ExpressionCreator)1 ToBreakRunner (de.neemann.digital.integration.ToBreakRunner)1