use of kodkod.engine.Solver in project org.alloytools.alloy by AlloyTools.
the class CeilingsAndFloors method main.
/**
* Usage: java examples.CeilingsAndFloors [# men] [# platforms]
*/
public static void main(String[] args) {
if (args.length < 2)
usage();
final CeilingsAndFloors model = new CeilingsAndFloors();
final Solver solver = new Solver();
solver.options().setSolver(SATFactory.MiniSat);
try {
final int m = Integer.parseInt(args[0]);
final int p = Integer.parseInt(args[1]);
final Formula show = model.checkBelowTooDoublePrime();
final Solution sol = solver.solve(show, model.bounds(m, p));
System.out.println(show);
System.out.println(sol);
} catch (NumberFormatException nfe) {
usage();
}
}
use of kodkod.engine.Solver in project org.alloytools.alloy by AlloyTools.
the class DiffEg method main.
/**
* Usage: java examples.DiffEq [scope]
*/
public static void main(String[] args) {
if (args.length < 1)
usage();
try {
final int n = Integer.parseInt(args[0]);
if (n < 1)
usage();
final DiffEg model = new DiffEg();
final Solver solver = new Solver();
final Formula f = model.runPol();
final Bounds b = model.bounds(n);
System.out.println(f);
final Solution sol = solver.solve(f, b);
System.out.println(sol);
} catch (NumberFormatException nfe) {
usage();
}
}
use of kodkod.engine.Solver in project org.alloytools.alloy by AlloyTools.
the class Hotel method main.
/**
* Usage: java examples.Hotel [scope]
*/
public static void main(String[] args) {
if (args.length < 1)
usage();
try {
final int n = Integer.parseInt(args[0]);
if (n < 1)
usage();
final Hotel model = new Hotel();
final Solver solver = new Solver();
solver.options().setSolver(SATFactory.MiniSatProver);
solver.options().setLogTranslation(1);
final Formula f = model.checkNoBadEntry();
final Bounds b = model.bounds(n);
// System.out.println(PrettyPrinter.print(f, 2, 100));
final Solution sol = solver.solve(f, b);
System.out.println(sol);
if (sol.instance() == null) {
final Proof proof = sol.proof();
System.out.println("top-level formulas: " + proof.log().roots().size());
System.out.println("initial core: " + proof.highLevelCore().size());
System.out.print("\nminimizing core ... ");
final long start = System.currentTimeMillis();
proof.minimize(new RCEStrategy(proof.log()));
final Set<Formula> core = Nodes.minRoots(f, proof.highLevelCore().values());
final long end = System.currentTimeMillis();
System.out.println("done (" + (end - start) + " ms).");
System.out.println("minimal core: " + core.size());
for (Formula u : core) {
System.out.println(PrettyPrinter.print(u, 2, 100));
}
checkMinimal(core, b);
} else {
System.out.println(sol);
}
} catch (NumberFormatException nfe) {
usage();
}
}
use of kodkod.engine.Solver in project org.alloytools.alloy by AlloyTools.
the class Hotel method checkMinimal.
private static void checkMinimal(Set<Formula> core, Bounds bounds) {
System.out.print("checking minimality ... ");
final long start = System.currentTimeMillis();
final Set<Formula> minCore = new LinkedHashSet<Formula>(core);
Solver solver = new Solver();
solver.options().setSolver(SATFactory.MiniSat);
for (Iterator<Formula> itr = minCore.iterator(); itr.hasNext(); ) {
Formula f = itr.next();
Formula noF = Formula.TRUE;
for (Formula f1 : minCore) {
if (f != f1)
noF = noF.and(f1);
}
if (solver.solve(noF, bounds).instance() == null) {
itr.remove();
}
}
final long end = System.currentTimeMillis();
if (minCore.size() == core.size()) {
System.out.println("minimal (" + (end - start) + " ms).");
} else {
System.out.println("not minimal (" + (end - start) + " ms). The minimal core has these " + minCore.size() + " formulas:");
for (Formula f : minCore) {
System.out.println(" " + f);
}
// Solution sol = problem.solver.solve(Formula.and(minCore),
// problem.bounds);
// System.out.println(sol);
// sol.proof().highLevelCore();
}
}
use of kodkod.engine.Solver in project org.alloytools.alloy by AlloyTools.
the class Pigeonhole method main.
/**
* Usage: java tests.Pigeonhole [# pigeons] [# holes]
*/
public static void main(String[] args) {
if (args.length < 2)
usage();
final Pigeonhole model = new Pigeonhole();
final Solver solver = new Solver();
try {
final int p = Integer.parseInt(args[0]);
final int h = Integer.parseInt(args[1]);
solver.options().setSolver(SATFactory.MiniSat);
solver.options().setSymmetryBreaking(p);
final Formula show = model.declarations().and(model.pigeonPerHole());
final Solution sol = solver.solve(show, model.bounds(p, h));
// System.out.println(show);
System.out.println(sol);
} catch (NumberFormatException nfe) {
usage();
}
}
Aggregations