use of kodkod.engine.bool.BooleanAccumulator in project org.alloytools.alloy by AlloyTools.
the class BooleanMatrixTest method testOverride.
public final void testOverride() {
assertTrue(equivalent(mT324.override(mT324), mT324));
assertTrue(equivalent(mT324.override(mF324), mT324));
assertTrue(equivalent(mF324.override(mT324), mT324));
assertTrue(equivalent(mF324.override(mF324), mF324));
final BooleanMatrix mF324c = mF324.clone(), mT324c = mT324.clone();
mF324.set(3, vars[3]);
mF324.set(17, vars[17]);
mF324.set(22, vars[22]);
assertTrue(equivalent(mF324.override(mF324c), mF324));
assertTrue(equivalent(mF324.override(mT324), mT324));
mF324c.set(9, vars[9]);
assertTrue(equivalent(mF324.override(mF324c), mF324.or(mF324c)));
mT324.set(0, BooleanConstant.FALSE);
assertTrue(equivalent(mF324.override(mT324), mT324));
assertTrue(equivalent(mT324.override(mT324c), mT324c));
assertTrue(equivalent(mT324c.override(mT324), mT324));
final BooleanMatrix mFoF = f.matrix(dim324);
mF324.set(10, vars[10]);
mF324c.set(3, vars[4]);
mF324c.set(20, vars[20]);
mF324c.set(19, vars[19]);
mFoF.set(3, f.or(vars[4], f.and(vars[3], f.not(vars[4]))));
mFoF.set(9, vars[9]);
mFoF.set(10, f.and(vars[10], f.not(vars[9])));
mFoF.set(17, f.and(vars[17], f.and(f.not(vars[19]), f.not(vars[20]))));
mFoF.set(22, f.and(vars[22], f.and(f.not(vars[19]), f.not(vars[20]))));
mFoF.set(20, vars[20]);
mFoF.set(19, vars[19]);
assertTrue(equivalent(mF324.override(mF324c), mFoF));
mT324.set(3, vars[4]);
mT324.set(11, vars[11]);
for (int i = 16; i < 24; i++) mT324.set(i, vars[i - 16]);
final BooleanMatrix mFoT = f.matrix(dim324);
for (int i = 0; i < 16; i++) mFoT.set(i, mT324.get(i));
final BooleanAccumulator g = BooleanAccumulator.treeGate(Operator.AND);
for (int i = 0; i < 8; i++) g.add(f.not(vars[i]));
final BooleanValue v3 = f.accumulate(g);
for (int i = 16; i < 24; i++) mFoT.set(i, f.or(f.and(v3, mF324.get(i)), mT324.get(i)));
assertTrue(equivalent(mF324.override(mT324), mFoT));
final BooleanMatrix mToF = f.matrix(dim324);
for (int i = 0; i < 8; i++) mToF.set(i, f.or(mF324.get(i), f.and(mT324.get(i), f.not(vars[3]))));
for (int i = 8; i < 16; i++) mToF.set(i, f.or(mF324.get(i), f.and(mT324.get(i), f.not(vars[10]))));
for (int i = 16; i < 24; i++) mToF.set(i, f.or(mF324.get(i), f.and(mT324.get(i), f.and(f.not(vars[17]), f.not(vars[22])))));
assertTrue(equivalent(mT324.override(mF324), mToF));
final BooleanMatrix mToT = f.matrix(dim324).not();
mT324c.set(11, vars[12]);
mT324c.set(12, vars[13]);
mT324c.set(18, vars[18]);
for (int i = 0; i < 16; i++) mToT.set(i, mT324.get(i));
for (int i = 16; i < 24; i++) mToT.set(i, f.or(mT324.get(i), f.and(mT324c.get(i), v3)));
assertTrue(equivalent(mT324c.override(mT324), mToT));
}
use of kodkod.engine.bool.BooleanAccumulator in project org.alloytools.alloy by AlloyTools.
the class Translator method toBoolean.
// private HOLTranslation toHOLTransl(AnnotatedNode<Formula> annotated,
// SymmetryBreaker breaker) {
// checkHOLOptions(options);
//
// // AnnotatedNode<Formula> fl = FormulaFlattener.flatten(optimized, true);
// //TODO: need this?
// //AnnotatedNode<Formula> nnf1 = NNFConverter.toNNF(optimized,
// options.reporter());
// AnnotatedNode<Formula> nnf = FullNegationPropagator.toNNF(annotated,
// options.reporter());
// //AnnotatedNode<Formula> pnf = PrenexNFConverter.toPNF(nnf);
// AnnotatedNode<Formula> skl = Skolemizer.skolemize(nnf, bounds, options);
//
// return HOL2ProcTranslator.translate(skl, bounds, options);
// }
/**
* Translates the given annotated formula to a circuit, conjoins the circuit
* with an SBP generated by the given symmetry breaker, and returns its
* {@linkplain Translation} to CNF. The SBP breaks any symmetries that could not
* be broken during the
* {@linkplain #optimizeFormulaAndBounds(AnnotatedNode, SymmetryBreaker) formula
* and bounds optimization} step.
*
* @requires SAT(annotated.node, this.bounds, this.options) iff
* SAT(this.originalFormula, this.originalBounds, this.options)
* @requires breaker.bounds = this.bounds
* @ensures this.options.logTranslation => some this.log'
* @ensures this.options.reporter().translatingToBoolean(annotated.node(),
* this.bounds)
* @ensures this.options.reporter().generatingSBP()
* @return the translation of annotated.node with respect to this.bounds
*/
private Translation toBoolean(AnnotatedNode<Formula> annotated, SymmetryBreaker breaker) {
options.reporter().translatingToBoolean(annotated.node(), bounds);
final LeafInterpreter interpreter = LeafInterpreter.exact(bounds, options, incremental);
final BooleanFactory factory = interpreter.factory();
if (logging) {
assert !incremental;
final TranslationLogger logger = options.logTranslation() == 1 ? new MemoryLogger(annotated, bounds) : new FileLogger(annotated, bounds);
BooleanAccumulator circuit = FOL2BoolTranslator.translate(annotated, interpreter, logger);
final TranslationLog log = logger.log();
if (circuit.isShortCircuited()) {
return trivial(circuit.op().shortCircuit(), log);
} else if (circuit.size() == 0) {
return trivial(circuit.op().identity(), log);
}
circuit.add(breaker.generateSBP(interpreter, options));
return toCNF((BooleanFormula) factory.accumulate(circuit), interpreter, log);
} else {
BooleanValue circuit = (BooleanValue) FOL2BoolTranslator.translate(annotated, interpreter);
if (circuit.op() == Operator.CONST) {
return trivial((BooleanConstant) circuit, null);
}
return toCNF((BooleanFormula) factory.and(circuit, breaker.generateSBP(interpreter, options)), interpreter, null);
}
}
Aggregations