use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class Dijkstra method bounds.
/**
* Returns the bounds corresponding to the given scopes.
*
* @return bounds
*/
public Bounds bounds(int states, int processes, int mutexes) {
final List<String> atoms = new ArrayList<String>(states + processes + mutexes);
for (int i = 0; i < states; i++) {
atoms.add("State" + i);
}
for (int i = 0; i < processes; i++) {
atoms.add("Process" + i);
}
for (int i = 0; i < mutexes; i++) {
atoms.add("Mutex" + i);
}
final Universe u = new Universe(atoms);
final TupleFactory f = u.factory();
final Bounds b = new Bounds(u);
final TupleSet sb = f.range(f.tuple("State0"), f.tuple("State" + (states - 1)));
final TupleSet pb = f.range(f.tuple("Process0"), f.tuple("Process" + (processes - 1)));
final TupleSet mb = f.range(f.tuple("Mutex0"), f.tuple("Mutex" + (mutexes - 1)));
b.bound(State, sb);
b.bound(holds, sb.product(pb).product(mb));
b.bound(waits, sb.product(pb).product(mb));
b.bound(sfirst, sb);
b.bound(slast, sb);
b.bound(sord, sb.product(sb));
b.bound(Process, pb);
b.bound(Mutex, mb);
b.bound(mfirst, mb);
b.bound(mlast, mb);
b.bound(mord, mb.product(mb));
return b;
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class NUM374 method bounds.
/**
* Returns the bounds for the given scope.
*
* @return bounds for the given scope
*/
public final Bounds bounds(int n) {
assert n > 0;
final List<String> atoms = new ArrayList<String>(n);
for (int i = 0; i < n; i++) atoms.add("a" + i);
final Universe u = new Universe(atoms);
final Bounds b = new Bounds(u);
final TupleFactory f = u.factory();
final TupleSet all3 = f.allOf(3);
b.bound(sum, all3);
b.bound(product, all3);
b.bound(exponent, all3);
b.bound(n1, f.allOf(1));
return b;
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class Quasigroups7 method bounds.
/**
* Returns the partial bounds the problem (axioms 1, 4, 9-11).
*
* @return the partial bounds for the problem
*/
public Bounds bounds() {
final List<String> atoms = new ArrayList<String>(14);
for (int i = 0; i < 7; i++) atoms.add("e1" + i);
for (int i = 0; i < 7; i++) atoms.add("e2" + i);
final Universe u = new Universe(atoms);
final Bounds b = new Bounds(u);
final TupleFactory f = u.factory();
b.boundExactly(s1, f.range(f.tuple("e10"), f.tuple("e16")));
b.boundExactly(s2, f.range(f.tuple("e20"), f.tuple("e26")));
// axioms 9, 10, 11
for (int i = 0; i < 7; i++) {
b.boundExactly(e1[i], f.setOf("e1" + i));
b.boundExactly(e2[i], f.setOf("e2" + i));
}
// axom 1
final TupleSet op1h = f.area(f.tuple("e10", "e10", "e10"), f.tuple("e16", "e16", "e16"));
// axiom 4
final TupleSet op2h = f.area(f.tuple("e20", "e20", "e20"), f.tuple("e26", "e26", "e26"));
b.bound(op1, op1h);
b.bound(op2, op2h);
return b;
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class TOP020 method bounds.
/**
* Returns bounds for the given scope.
*
* @return bounds for the given scope.
*/
public final Bounds bounds(int n) {
assert n > 0;
final List<String> atoms = new ArrayList<String>(n);
for (int i = 0; i < n; i++) atoms.add("a" + i);
final Universe u = new Universe(atoms);
final Bounds b = new Bounds(u);
final TupleFactory f = u.factory();
b.bound(hausdorff, f.allOf(1));
b.bound(member, f.allOf(2));
b.bound(open, f.allOf(2));
b.bound(disjoint, f.allOf(2));
b.bound(closed, f.allOf(2));
b.bound(coerce, f.allOf(2));
b.bound(diagonal, f.allOf(2));
b.bound(product, f.allOf(3));
b.bound(tsproduct, f.allOf(3));
b.bound(ordered, f.allOf(3));
return b;
}
use of kodkod.instance.TupleFactory 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));
}
Aggregations