use of kodkod.engine.Evaluator in project org.alloytools.alloy by AlloyTools.
the class IntConstraints method print.
/**
* Prints the solution to the screen.
*/
private final void print(Solution sol, Options options) {
System.out.println(sol.stats());
final Evaluator eval = new Evaluator(sol.instance(), options);
final long mask = -1L >>> 32;
for (int i = 0; i < 1000; i++) {
long min = (low + 10 * i) & mask, max = (min + 10) & mask;
long result = eval.evaluate(var[i].sum()) & mask;
System.out.println(min + " <= [var_" + (i + 1) + "=" + result + "] <= " + max);
}
}
use of kodkod.engine.Evaluator in project org.alloytools.alloy by AlloyTools.
the class Viktor method display.
private final void display(Instance instance, Options options) {
final Evaluator eval = new Evaluator(instance, options);
for (int i = 0; i < 2; i++) {
System.out.print(" | ");
System.out.print(instance.tuples(x[i]).indexView().min());
System.out.println(" |");
}
for (int i = 0; i < rows; i++) {
System.out.print("| ");
for (int j = 0; j < cols; j++) {
System.out.print(instance.tuples(a[i][j]).isEmpty() ? 0 : 1);
System.out.print(" ");
}
System.out.print(i == 1 ? "| * | " : "| | ");
System.out.print(instance.tuples(x[i + 2]).indexView().min());
System.out.print(i == 1 ? " | = | " : " | | ");
System.out.print(eval.evaluate(b[i]));
System.out.println(" |");
}
for (int i = 5; i < 8; i++) {
System.out.print(" | ");
System.out.print(instance.tuples(x[i]).indexView().min());
System.out.println(" |");
}
// for(int i = 0; i < 3; i++)
// System.out.println(b[i]);
//
// for(int i = 0; i < rows; i++) {
// for(int j = 0 ; j < 8; j++) {
// IntExpression e0 = x[j].sum();
// IntExpression e1 = a[i][j].some().thenElse(e0,
// IntConstant.constant(0));
// System.out.println(e0 + " : " + eval.evaluate(e0));
// System.out.println(e1 + " : " + eval.evaluate(e1));
// }
// }
}
use of kodkod.engine.Evaluator in project org.alloytools.alloy by AlloyTools.
the class KK method main.
public static void main(String[] args) throws Exception {
Relation x6 = Relation.unary("R");
int[] ints = new int[] { 0, 1, 2 };
List<Object> atomlist = new LinkedList<Object>();
atomlist.add("R$0");
atomlist.add("R$1");
atomlist.add("R$2");
for (int i : ints) atomlist.add(i);
Universe universe = new Universe(atomlist);
TupleFactory factory = universe.factory();
Bounds bounds = new Bounds(universe);
TupleSet x6_upper = factory.noneOf(1);
x6_upper.add(factory.tuple("R$0"));
x6_upper.add(factory.tuple("R$1"));
x6_upper.add(factory.tuple("R$2"));
bounds.bound(x6, x6_upper);
for (int i : ints) {
bounds.boundExactly(i, factory.setOf(i));
}
Formula x11 = x6.some();
IntExpression x5 = x6.count();
Formula x9 = x11.implies(x5.gt(IntConstant.constant(0)));
Formula x7 = x9.not();
Solver solver = new Solver();
solver.options().setSolver(SATFactory.DefaultSAT4J);
solver.options().setBitwidth(2);
// solver.options().setFlatten(false);
solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
solver.options().setSymmetryBreaking(20);
solver.options().setSkolemDepth(0);
System.out.println("Solving...");
System.out.println(PrettyPrinter.print(x7, 0));
System.out.println(bounds);
Solution sol = solver.solve(x7, bounds);
System.out.println(sol.toString());
Instance inst = sol.instance();
Evaluator ev = new Evaluator(inst);
System.out.println(ev.evaluate(x6.some()));
System.out.println(ev.evaluate(x5));
System.out.println(ev.evaluate(x5.gt(IntConstant.constant(0))));
System.out.println(ev.evaluate(x6.some().implies(x5.gt(IntConstant.constant(0))).not()));
System.out.println(ev.evaluate(x7));
}
use of kodkod.engine.Evaluator in project org.alloytools.alloy by AlloyTools.
the class BugTests method testEmina_01232006.
public final void testEmina_01232006() {
final List<String> atoms = new ArrayList<String>(5);
for (int i = 0; i < 5; i++) atoms.add("a" + i);
final Universe u = new Universe(atoms);
final TupleFactory tf = u.factory();
final Relation r1 = Relation.unary("r1"), r2 = Relation.binary("r2"), r3 = Relation.ternary("r3");
final Bounds b = new Bounds(u);
final TupleSet r2Bound = tf.noneOf(2);
for (int i = 0; i < 4; i++) r2Bound.add(tf.tuple(atoms.get(i), atoms.get(i)));
r2Bound.add(tf.tuple("a4", "a1"));
r2Bound.add(tf.tuple("a4", "a2"));
b.bound(r2, r2Bound);
b.bound(r1, tf.setOf("a0", "a3"), tf.setOf("a0", "a3", "a4"));
b.bound(r3, tf.setOf(tf.tuple("a0", "a0", "a0"), tf.tuple("a3", "a3", "a3")));
final Formula f = r1.product(r2).in(r3);
final Instance instance = solver.solve(f, b).instance();
assertTrue((new Evaluator(instance)).evaluate(f));
// System.out.println(instance);
// System.out.println((new Evaluator(instance)).evaluate(f ));
}
use of kodkod.engine.Evaluator in project org.alloytools.alloy by AlloyTools.
the class BugTests method testFelix_01032007.
public final void testFelix_01032007() {
List<String> atomlist = Arrays.asList("-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "0", "1", "2", "3", "4", "5", "6", "7");
Universe universe = new Universe(atomlist);
TupleFactory factory = universe.factory();
Bounds bounds = new Bounds(universe);
bounds.boundExactly(-8, factory.range(factory.tuple("-8"), factory.tuple("-8")));
bounds.boundExactly(-7, factory.range(factory.tuple("-7"), factory.tuple("-7")));
bounds.boundExactly(-6, factory.range(factory.tuple("-6"), factory.tuple("-6")));
bounds.boundExactly(-5, factory.range(factory.tuple("-5"), factory.tuple("-5")));
bounds.boundExactly(-4, factory.range(factory.tuple("-4"), factory.tuple("-4")));
bounds.boundExactly(-3, factory.range(factory.tuple("-3"), factory.tuple("-3")));
bounds.boundExactly(-2, factory.range(factory.tuple("-2"), factory.tuple("-2")));
bounds.boundExactly(-1, factory.range(factory.tuple("-1"), factory.tuple("-1")));
bounds.boundExactly(0, factory.range(factory.tuple("0"), factory.tuple("0")));
bounds.boundExactly(1, factory.range(factory.tuple("1"), factory.tuple("1")));
bounds.boundExactly(2, factory.range(factory.tuple("2"), factory.tuple("2")));
bounds.boundExactly(3, factory.range(factory.tuple("3"), factory.tuple("3")));
bounds.boundExactly(4, factory.range(factory.tuple("4"), factory.tuple("4")));
bounds.boundExactly(5, factory.range(factory.tuple("5"), factory.tuple("5")));
bounds.boundExactly(6, factory.range(factory.tuple("6"), factory.tuple("6")));
bounds.boundExactly(7, factory.range(factory.tuple("7"), factory.tuple("7")));
Expression set = IntConstant.constant(8).toExpression();
Solver solver = new Solver();
solver.options().setSolver(SATFactory.DefaultSAT4J);
solver.options().setBitwidth(4);
solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
Solution sol = solver.solve(set.some(), bounds);
assertNotNull("expected SATISFIABLE but was " + sol.outcome(), sol.instance());
Evaluator eval = new Evaluator(sol.instance(), solver.options());
TupleSet ts = eval.evaluate(set);
assertFalse(ts.size() == 0);
}
Aggregations