use of de.neemann.digital.analyse.quinemc.QuineMcCluskey in project Digital by hneemann.
the class MinimizerQuineMcCluskey method minimize.
@Override
public void minimize(List<Variable> vars, BoolTable boolTable, String resultName, ExpressionListener listener) throws ExpressionException, FormatterException {
QuineMcCluskey qmc = createQuineMcCluskey(vars).fillTableWith(boolTable);
PrimeSelector ps = new PrimeSelectorDefault();
Expression e = qmc.simplify(ps).getExpression();
if (ps.getAllSolutions() != null) {
for (ArrayList<TableRow> i : ps.getAllSolutions()) {
listener.resultFound(resultName, QuineMcCluskey.addAnd(null, i, vars));
}
} else {
listener.resultFound(resultName, e);
}
}
use of de.neemann.digital.analyse.quinemc.QuineMcCluskey in project Digital by hneemann.
the class KarnaughMapTest method testIndex.
/**
* Creates bool tables with one "one".
* Calculates the KV map.
* Tests if the covered cell belongs to the single "one" in the table!
*/
public void testIndex() throws IOException, ParseException, KarnaughException, ExpressionException {
for (int vars = 2; vars <= 4; vars++) {
int rows = 1 << vars;
for (int row = 0; row < rows; row++) {
// create bool table
BoolTableBoolArray t = new BoolTableBoolArray(rows);
// put one one to the tabel
t.set(row, true);
Expression exp = new QuineMcCluskey(Variable.vars(vars)).fillTableWith(t).simplify(new PrimeSelectorDefault()).getExpression();
// create the KV covers
KarnaughMap c = new KarnaughMap(Variable.vars(vars), exp);
// there is only on cover
assertEquals(1, c.size());
KarnaughMap.Cover cover = c.iterator().next();
// the size of the cover is one cell
assertEquals(1, cover.getSize());
KarnaughMap.Pos pos = cover.getPos();
// the row in the truth table is the row containing the one.
assertEquals(row, c.getCell(pos.getRow(), pos.getCol()).getBoolTableRow());
}
}
}
use of de.neemann.digital.analyse.quinemc.QuineMcCluskey 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)));
}
}
}
}
}
Aggregations