Search in sources :

Example 16 with ContextFiller

use of de.neemann.digital.analyse.expression.ContextFiller in project Digital by hneemann.

the class ReorderInputs method reorder.

/**
 * Creates a new table matching the actual state of the items
 *
 * @return the new table
 * @throws ExpressionException ExpressionException
 */
public TruthTable reorder() throws ExpressionException {
    ArrayList<Variable> newVars = new ArrayList<>();
    ArrayList<Variable> deletedVars = new ArrayList<>();
    deletedVars.addAll(table.getVars());
    for (String name : names) {
        Variable found = null;
        for (Variable v : deletedVars) if (v.getIdentifier().equals(name)) {
            found = v;
            break;
        }
        if (found != null) {
            newVars.add(found);
            deletedVars.remove(found);
        }
    }
    if (newVars.size() < 2)
        throw new ExpressionException(Lang.get("err_tableBecomesToSmall"));
    TruthTable newTable = new TruthTable(newVars);
    for (int j = 0; j < table.getResultCount(); j++) newTable.addResult(table.getResultName(j));
    ContextFiller fc = new ContextFiller(newTable.getVars());
    for (Variable v : deletedVars) fc.set(v, false);
    for (int row = 0; row < newTable.getRows(); row++) {
        fc.setContextTo(row);
        for (int t = 0; t < newTable.getResultCount(); t++) newTable.setByContext(t, fc, table.getByContext(t, fc));
    }
    return newTable;
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller) TruthTable(de.neemann.digital.analyse.TruthTable) ArrayList(java.util.ArrayList) ExpressionException(de.neemann.digital.analyse.expression.ExpressionException)

Example 17 with ContextFiller

use of de.neemann.digital.analyse.expression.ContextFiller in project Digital by hneemann.

the class CheckResultListener method resultFound.

@Override
public void resultFound(String name, Expression expression) throws FormatterException, ExpressionException {
    listener.resultFound(name, expression);
    ContextFiller cf = new ContextFiller(variables);
    for (int i = 0; i < boolTable.size(); i++) check(boolTable.get(i), expression.calculate(cf.setContextTo(i)));
}
Also used : ContextFiller(de.neemann.digital.analyse.expression.ContextFiller)

Aggregations

ContextFiller (de.neemann.digital.analyse.expression.ContextFiller)17 Expression (de.neemann.digital.analyse.expression.Expression)10 Variable (de.neemann.digital.analyse.expression.Variable)10 ArrayList (java.util.ArrayList)6 BoolTableByteArray (de.neemann.digital.analyse.quinemc.BoolTableByteArray)4 TruthTable (de.neemann.digital.analyse.TruthTable)3 FormatToExpression (de.neemann.digital.analyse.expression.format.FormatToExpression)2 ExpressionException (de.neemann.digital.analyse.expression.ExpressionException)1 QuineMcCluskey (de.neemann.digital.analyse.quinemc.QuineMcCluskey)1 TableRow (de.neemann.digital.analyse.quinemc.TableRow)1 ThreeStateValue (de.neemann.digital.analyse.quinemc.ThreeStateValue)1 PrimeSelectorDefault (de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault)1 ExpressionListenerStore (de.neemann.digital.gui.components.table.ExpressionListenerStore)1