use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class Translator method inlinePredicates.
/**
* Returns an annotated formula f such that f.node is equivalent to
* annotated.node with its <tt>simplified</tt> predicates replaced with their
* corresponding Formulas and the remaining predicates replaced with equivalent
* constraints. The annotated formula f will contain transitive source
* information for each of the subformulas of f.node. Specifically, let t be a
* subformula of f.node, and s be a descdendent of annotated.node from which t
* was derived. Then, f.source[t] = annotated.source[s].
* </p>
*
* @requires simplified.keySet() in
* annotated.predicates()[RelationPredicate.NAME]
* @requires no disj p, p': simplified.keySet() | simplified.get(p) =
* simplifed.get(p') // this must hold in order to maintain the
* invariant that each subformula of the returned formula has exactly
* one source
* @requires for each p in simplified.keySet(), the formulas "p and
* [[this.bounds]]" and "simplified.get(p) and [[this.bounds]]" are
* equisatisfiable
* @return an annotated formula f such that f.node is equivalent to
* annotated.node with its <tt>simplified</tt> predicates replaced with
* their corresponding Formulas and the remaining predicates replaced
* with equivalent constraints.
*/
private AnnotatedNode<Formula> inlinePredicates(final AnnotatedNode<Formula> annotated, final Map<RelationPredicate, Formula> simplified) {
final Map<Node, Node> sources = new IdentityHashMap<Node, Node>();
final AbstractReplacer inliner = new AbstractReplacer(annotated.sharedNodes()) {
private RelationPredicate source = null;
@Override
protected <N extends Node> N cache(N node, N replacement) {
if (replacement instanceof Formula) {
if (source == null) {
final Node nsource = annotated.sourceOf(node);
if (replacement != nsource)
sources.put(replacement, nsource);
} else {
sources.put(replacement, source);
}
}
return super.cache(node, replacement);
}
@Override
public Formula visit(RelationPredicate pred) {
Formula ret = lookup(pred);
if (ret != null)
return ret;
source = pred;
if (simplified.containsKey(pred)) {
ret = simplified.get(pred).accept(this);
} else {
ret = pred.toConstraints().accept(this);
}
source = null;
return cache(pred, ret);
}
};
return annotate(annotated.node().accept(inliner), sources);
}
use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class HOL2ProcTranslator method translate.
public static HOLTranslation translate(AnnotatedNode<Formula> annotated, Bounds bounds, Options options) {
HOL2ProcTranslator tr = new HOL2ProcTranslator(annotated.sharedNodes());
Formula converted = annotated.node().accept(tr.withHistory());
if (tr.conversions.size() == 0) {
return new HOLTranslationOld.FOL(annotated, bounds, options);
} else {
return new HOLTranslationOld.Some4All(annotated, converted, tr.conversions, bounds, options);
}
}
use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class Handshake method main.
/**
* Usage: java examples.Handshake [# persons, must be >= 2]
*/
public static void main(String[] args) {
if (args.length < 1)
usage();
final Handshake model = new Handshake();
final Solver solver = new Solver();
try {
final int persons = Integer.parseInt(args[0]);
if (persons < 2)
usage();
solver.options().setBitwidth(6);
// solver.options().setSolver(SATFactory.ZChaff);
solver.options().setSolver(SATFactory.MiniSat);
solver.options().setSymmetryBreaking(0);
solver.options().setBitwidth(32 - Integer.numberOfLeadingZeros(persons));
solver.options().setReporter(new ConsoleReporter());
final Bounds b = model.bounds(persons);
// .and(model.Person.count().eq(IntConstant.constant(persons)));
final Formula f = model.runPuzzle();
Solution sol = solver.solve(f, b);
System.out.println(sol);
} catch (NumberFormatException nfe) {
usage();
}
}
use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class Handshake method declarations.
/**
* Returns the declarations
*
* @return
*
* <pre>
* sig Person {spouse: Person, shaken: set Person}
* one sig Jocelyn, Hilary extends Person {}
* </pre>
*/
public Formula declarations() {
final Formula f0 = spouse.function(Person, Person);
final Formula f1 = shaken.in(Person.product(Person));
final Formula f2 = Hilary.one().and(Jocelyn.one());
return f0.and(f1).and(f2);
}
use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class Lists method main.
/**
* Usage: java examples.Lists [scope]
*/
public static void main(String[] args) {
if (args.length < 1)
usage();
try {
final int n = Integer.parseInt(args[0]);
final Lists model = new Lists();
final Bounds b = model.bounds(n);
final Solver solver = new Solver();
solver.options().setSolver(SATFactory.MiniSat);
// solver.options().setFlatten(false);
// solver.options().setSkolemize(false);
Formula f = model.runShow();
System.out.println("running show");
Solution s = solver.solve(f, b);
System.out.println(s);
f = model.checkEmpties();
System.out.println("checking empties");
s = solver.solve(f, b);
System.out.println(s);
f = model.checkReflexive();
System.out.println("checking reflexive");
s = solver.solve(f, b);
System.out.println(s);
f = model.checkSymmetric();
System.out.println("checking symmetric");
s = solver.solve(f, b);
System.out.println(s);
} catch (NumberFormatException nfe) {
usage();
} catch (HigherOrderDeclException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnboundLeafException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations