mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-29 16:01:19 -04:00
checks the result after minimization
This commit is contained in:
parent
0f9a633d30
commit
d4685e29f7
@ -0,0 +1,72 @@
|
|||||||
|
package de.neemann.digital.gui.components.table;
|
||||||
|
|
||||||
|
import de.neemann.digital.analyse.expression.ContextFiller;
|
||||||
|
import de.neemann.digital.analyse.expression.Expression;
|
||||||
|
import de.neemann.digital.analyse.expression.ExpressionException;
|
||||||
|
import de.neemann.digital.analyse.expression.Variable;
|
||||||
|
import de.neemann.digital.analyse.expression.format.FormatterException;
|
||||||
|
import de.neemann.digital.analyse.quinemc.BoolTable;
|
||||||
|
import de.neemann.digital.analyse.quinemc.ThreeStateValue;
|
||||||
|
import de.neemann.digital.lang.Lang;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the created results
|
||||||
|
* Created by hneemann on 15.03.17.
|
||||||
|
*/
|
||||||
|
public class CheckResultListener implements ExpressionListener {
|
||||||
|
private final ExpressionListener listener;
|
||||||
|
private final List<Variable> variables;
|
||||||
|
private final BoolTable boolTable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param listener the listener to delegate the results to
|
||||||
|
* @param variables the variables used
|
||||||
|
* @param boolTable the booltable to check
|
||||||
|
* @throws ExpressionException ExpressionException
|
||||||
|
*/
|
||||||
|
public CheckResultListener(ExpressionListener listener, List<Variable> variables, BoolTable boolTable) throws ExpressionException {
|
||||||
|
this.listener = listener;
|
||||||
|
this.variables = variables;
|
||||||
|
this.boolTable = boolTable;
|
||||||
|
|
||||||
|
int n = 1 << variables.size();
|
||||||
|
if (n != boolTable.size())
|
||||||
|
throw new ExpressionException(Lang.get("err_exact_N0_valuesNecessaryNot_N1", n, boolTable.size()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@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)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void check(ThreeStateValue threeStateValue, boolean calculate) throws ExpressionException {
|
||||||
|
switch (threeStateValue) {
|
||||||
|
case dontCare:
|
||||||
|
return;
|
||||||
|
case one:
|
||||||
|
if (!calculate)
|
||||||
|
throw new ExpressionException("internal minimization error: found false, expected true");
|
||||||
|
break;
|
||||||
|
case zero:
|
||||||
|
if (calculate)
|
||||||
|
throw new ExpressionException("internal minimization error: found true, expected false");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws FormatterException, ExpressionException {
|
||||||
|
listener.close();
|
||||||
|
}
|
||||||
|
}
|
@ -88,6 +88,9 @@ public class ExpressionCreator {
|
|||||||
if (!Main.enableExperimental() && localVars.size() > MAX_INPUTS_ALLOWED)
|
if (!Main.enableExperimental() && localVars.size() > MAX_INPUTS_ALLOWED)
|
||||||
throw new AnalyseException(Lang.get("err_toManyInputsIn_N0_max_N1_is_N2", resultName, MAX_INPUTS_ALLOWED, localVars.size()));
|
throw new AnalyseException(Lang.get("err_toManyInputsIn_N0_max_N1_is_N2", resultName, MAX_INPUTS_ALLOWED, localVars.size()));
|
||||||
|
|
||||||
|
|
||||||
|
listener = new CheckResultListener(listener, localVars, boolTable);
|
||||||
|
|
||||||
getMinimizer(localVars.size()).minimize(localVars, boolTable, resultName, listener);
|
getMinimizer(localVars.size()).minimize(localVars, boolTable, resultName, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user