use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.
the class Lists method bounds.
/**
* Returns the bounds for the given scope.
*
* @return the bounds for the given scope.
*/
public final Bounds bounds(int scope) {
assert scope > 0;
final int n = scope * 2;
final List<String> atoms = new ArrayList<String>(n);
for (int i = 0; i < scope; i++) atoms.add("Thing" + i);
for (int i = 0; i < scope; i++) atoms.add("List" + i);
// private final Relation Thing, List, NonEmptyList, EmptyList;
// private final Relation car, cdr, equivTo, prefixes;
final Universe u = new Universe(atoms);
final TupleFactory f = u.factory();
final Bounds b = new Bounds(u);
final int max = scope - 1;
b.bound(Thing, f.range(f.tuple("Thing0"), f.tuple("Thing" + max)));
b.bound(List, f.range(f.tuple("List0"), f.tuple("List" + max)));
b.bound(EmptyList, b.upperBound(List));
b.bound(NonEmptyList, b.upperBound(List));
b.bound(car, b.upperBound(List).product(b.upperBound(Thing)));
b.bound(cdr, b.upperBound(List).product(b.upperBound(List)));
b.bound(equivTo, b.upperBound(cdr));
b.bound(prefixes, b.upperBound(cdr));
return b;
}
use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.
the class RingElection method bounds.
/**
* Returns a bounds object that scopes Process, Time, and their fields according
* to given values.
*
* @return bounds
*/
public Bounds bounds(int processes, int times) {
final List<String> atoms = new ArrayList<String>(processes + times);
for (int i = 0; i < processes; i++) {
atoms.add("Process" + i);
}
for (int i = 0; i < times; i++) {
atoms.add("Time" + i);
}
final Universe u = new Universe(atoms);
final TupleFactory f = u.factory();
final Bounds b = new Bounds(u);
final TupleSet pb = f.range(f.tuple("Process0"), f.tuple("Process" + (processes - 1)));
final TupleSet tb = f.range(f.tuple("Time0"), f.tuple("Time" + (times - 1)));
b.bound(Process, pb);
b.bound(succ, pb.product(pb));
b.bound(toSend, pb.product(pb).product(tb));
b.bound(elected, pb.product(tb));
b.bound(pord, pb.product(pb));
b.bound(pfirst, pb);
b.bound(plast, pb);
b.bound(Time, tb);
b.bound(tord, tb.product(tb));
b.bound(tfirst, tb);
b.bound(tlast, tb);
return b;
}
use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.
the class Trees method main.
/**
* Usage: java examples.Trees [# vertices]
*/
public static void main(String[] args) {
if (args.length < 1)
usage();
try {
final int n = Integer.parseInt(args[0]);
final Trees model = new Trees();
final Bounds b = model.bounds(n);
final Solver solver = new Solver();
solver.options().setSolver(SATFactory.MiniSat);
solver.options().setBitwidth(16);
// System.out.println(solver.solve(model.checkEquivOfTreeDefns(),
// b));
final Formula[] statements = new Formula[5];
statements[0] = model.statement1();
statements[1] = model.statement2();
statements[2] = model.statement3();
statements[3] = model.statement4();
statements[4] = model.statement5();
long time = 0;
for (int i = 0; i < 5; i++) {
Formula f = model.declsAndFacts().and(statements[i]).and(statements[(i + 1) % 5].not());
Solution s = solver.solve(f, b);
time += s.stats().translationTime() + s.stats().solvingTime();
System.out.println(s);
if (s.instance() != null) {
return;
}
}
System.out.println("valid: " + time + " ms");
} catch (NumberFormatException nfe) {
usage();
} catch (HigherOrderDeclException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnboundLeafException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.
the class Trees method bounds.
/**
* Returns the bounds for the Trees problem that uses the given number of
* vertices.
*
* @return bounds for the Trees problem that uses the given number of vertices
*/
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("v" + i);
final Universe u = new Universe(atoms);
final TupleFactory f = u.factory();
final Bounds b = new Bounds(u);
b.bound(V, f.allOf(1));
b.bound(E, f.allOf(2));
return b;
}
use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.
the class Bigconfig method main.
/**
* Usage: java tests.Bigconfig [# hq] [# sub] [# closure unwindings, 0 for true
* closure] [size of partial instance, 0 default]
*
* @throws InterruptedException
*/
public static void main(String[] args) {
if (args.length < 3)
usage();
final Bigconfig model = new Bigconfig(Integer.parseInt(args[2]));
final Solver solver = new Solver();
// solver.options().setSolver(SATFactory.ZChaffMincost);
solver.options().setSolver(SATFactory.MiniSat);
try {
final int hq = Integer.parseInt(args[0]);
final int sub = Integer.parseInt(args[1]);
final int partial = args.length > 3 ? Integer.parseInt(args[3]) : 0;
final Formula show = model.show();
if (partial > 0) {
Bounds bounds = model.bounds(hq, sub - partial, hq + sub);
Solution sol = solver.solve(show, bounds);
System.out.println("Solved for " + hq + " hq and " + (sub - partial) + " subs.");
System.out.println(sol.outcome());
System.out.println(sol.stats());
System.out.println("Solving again with a partial instance: " + hq + " hq and " + sub + " subs.");
bounds = model.bounds(hq, sub, bounds.universe());
bounds.bound(model.link, sol.instance().tuples(model.link), bounds.upperBound(model.link));
sol = solver.solve(show, bounds);
System.out.println(sol.outcome());
System.out.println(sol.stats());
} else {
solver.options().setReporter(new ConsoleReporter());
final Bounds bounds = model.bounds(hq, sub, hq + sub);
final Solution sol = solver.solve(show, bounds);
System.out.println(sol.outcome());
System.out.println(sol.stats());
}
} catch (NumberFormatException nfe) {
usage();
}
}
Aggregations