use of kodkod.ast.Node in project org.alloytools.alloy by AlloyTools.
the class AnnotatedNode method relations.
/**
* Returns the set of all relations at the leaves of this annotated node.
*
* @return Relation & this.node.*components
*/
public final Set<Relation> relations() {
final Set<Relation> relations = new IdentityHashSet<Relation>();
final AbstractVoidVisitor visitor = new AbstractVoidVisitor() {
private final Set<Node> visited = new IdentityHashSet<Node>(sharedNodes.size());
@Override
protected boolean visited(Node n) {
return sharedNodes.contains(n) && !visited.add(n);
}
@Override
public void visit(Relation relation) {
relations.add(relation);
}
};
node.accept(visitor);
return relations;
}
use of kodkod.ast.Node in project org.alloytools.alloy by AlloyTools.
the class FormulaFlattener method visit.
/**
* {@inheritDoc}
*
* @see kodkod.ast.visitor.AbstractVoidVisitor#visit(kodkod.ast.QuantifiedFormula)
*/
@Override
public final void visit(QuantifiedFormula qf) {
if (visited(qf))
return;
if (breakupQuantifiers) {
final Quantifier quant = qf.quantifier();
if ((!negated && quant == ALL) || (negated && quant == SOME)) {
// may
// break
// down
// further
final Map<Formula, Node> oldConjuncts = conjuncts;
conjuncts = new LinkedHashMap<Formula, Node>();
qf.formula().accept(this);
if (conjuncts.size() > 1) {
// was broken down further
final Decls decls = qf.decls();
for (Map.Entry<Formula, Node> entry : conjuncts.entrySet()) {
oldConjuncts.put(entry.getKey().forAll(decls), entry.getValue());
}
conjuncts = oldConjuncts;
return;
} else {
// wasn't broken down further
conjuncts = oldConjuncts;
}
}
// won't break down further
}
addConjunct(qf);
}
use of kodkod.ast.Node in project org.alloytools.alloy by AlloyTools.
the class FullNegationPropagator method toNNF.
public static AnnotatedNode<Formula> toNNF(AnnotatedNode<Formula> annotated, Reporter reporter) {
if (reporter != null)
reporter.convertingToNNF();
final FullNegationPropagator flat = new FullNegationPropagator(annotated.sharedNodes());
annotated.node().accept(flat);
final List<Formula> roots = new ArrayList<Formula>(flat.annotations.size());
roots.addAll(flat.annotations.keySet());
for (Iterator<Map.Entry<Formula, Node>> itr = flat.annotations.entrySet().iterator(); itr.hasNext(); ) {
final Map.Entry<Formula, Node> entry = itr.next();
final Node source = annotated.sourceOf(entry.getValue());
if (entry.getKey() == source) {
itr.remove();
/* TODO: what is this for? */
} else {
entry.setValue(source);
}
}
return AnnotatedNode.annotate(Formula.and(flat.conjuncts), flat.annotations);
}
use of kodkod.ast.Node in project org.alloytools.alloy by AlloyTools.
the class ReductionAndProofTest method testGranularity.
public final void testGranularity() {
final Variable x = Variable.unary("x");
final Variable y = Variable.unary("y");
final Formula f0 = a.some();
final Formula f1 = b.some();
final Formula f2 = a.eq(b);
final Formula f3 = x.product(y).in(Expression.UNIV.product(Expression.UNIV));
final Formula f4 = x.eq(y);
final Formula f5 = f3.or(f4).forSome(y.oneOf(b));
final Formula f6 = f5.forAll(x.oneOf(a));
final Formula f7 = f2.or(f6).not();
final Formula f8 = b.intersection(Expression.UNIV).some();
final Formula f9 = Formula.and(f0, f1, f7, f8);
Set<Node> core = core(f9, 0);
assertEquals(2, core.size());
assertTrue(core.contains(f1));
assertTrue(core.contains(f7));
core = core(f9, 1);
assertEquals(2, core.size());
assertTrue(core.contains(f1));
assertTrue(core.contains(f6));
core = reduce(f9, 2);
assertEquals(2, core.size());
assertTrue(core.contains(f1));
assertTrue(core.contains(f5));
core = core(f9, 3);
assertEquals(2, core.size());
assertTrue(core.contains(f1));
assertTrue(core.contains(f3));
}
Aggregations