use of kodkod.engine.Solution in project org.alloytools.alloy by AlloyTools.
the class MGT066 method main.
/**
* Usage: java examples.tptp.MGT066 [univ size]
*/
public static void main(String[] args) {
if (args.length < 1)
usage();
try {
final int n = Integer.parseInt(args[0]);
if (n < 1)
usage();
final MGT066 model = new MGT066();
final Solver solver = new Solver();
solver.options().setSolver(SATFactory.MiniSat);
solver.options().setSymmetryBreaking(n * n);
final Formula f = model.axioms();
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.Solution in project org.alloytools.alloy by AlloyTools.
the class TOP020 method main.
/**
* Usage: java examples.tptp.TOP020 [univ size]
*/
public static void main(String[] args) {
if (args.length < 1)
usage();
try {
final int n = Integer.parseInt(args[0]);
if (n < 1)
usage();
final TOP020 model = new TOP020();
final Solver solver = new Solver();
solver.options().setSolver(SATFactory.MiniSat);
final Formula f = model.checkChallenge_AMR_1_4_4();
final Bounds b = model.bounds(n);
// System.out.println(f);
// System.out.println(b);
final Solution sol = solver.solve(f, b);
System.out.println(sol);
} catch (NumberFormatException nfe) {
usage();
}
}
use of kodkod.engine.Solution in project org.alloytools.alloy by AlloyTools.
the class BookExamples method trial.
/**
* This tries a particular solution against the formula.
*/
private static Solution trial(A4Reporter rep, TupleFactory fac, Solver solver, Iterable<Sig> sigs, Formula f, A4Solution frame, Object[] t) {
try {
frame.kr2typeCLEAR();
Bounds b = null;
TupleSet ts = null;
for (int i = 1; i < t.length; i++) {
Object x = t[i];
if (x == null)
return null;
if (x instanceof String && ((String) x).length() > 0) {
// This
// means
// it's
// a
// unary
// Tuple
// containing
// the
// given
// atom
Tuple xx = fac.tuple((String) x);
if (ts == null)
ts = fac.noneOf(1);
ts.add(xx);
continue;
}
if (x instanceof Tuple) {
// This means it's a Tuple
Tuple xx = (Tuple) x;
if (ts == null)
ts = fac.noneOf(xx.arity());
ts.add(xx);
continue;
}
if (x instanceof String) {
// The empty string means the sig
// name follows here
i++;
if (i >= t.length - 1 || !(t[i] instanceof String) || !(t[i + 1] instanceof String))
return null;
String sigName = (String) (t[i]);
i++;
String fieldName = (String) (t[i]);
Sig first = hasSig(sigs, sigName);
if (first == null)
return null;
Expression expr = null;
if (fieldName.length() == 0) {
expr = frame.a2k(first);
} else {
for (Field field : first.getFields()) if (field.label.equals(fieldName)) {
expr = frame.a2k(field);
while (expr instanceof BinaryExpression) expr = ((BinaryExpression) expr).right();
break;
}
}
if (!(expr instanceof Relation))
return null;
if (b == null)
// We delay the expansive
b = frame.getBounds();
// really find a possible match
if (ts == null)
ts = fac.noneOf(expr.arity());
if (!ts.containsAll(b.lowerBound((Relation) expr)))
// Sanity check
return null;
if (!b.upperBound((Relation) expr).containsAll(ts))
// Sanity check
return null;
b.boundExactly((Relation) expr, ts);
ts = null;
continue;
}
}
SATFactory sat = solver.options().solver();
Solution sol;
try {
solver.options().setSolver(SATFactory.DefaultSAT4J);
sol = solver.solve(f, b);
} finally {
solver.options().setSolver(sat);
}
if (sol == null || (sol.outcome() != SATISFIABLE && sol.outcome() != TRIVIALLY_SATISFIABLE))
return null;
if (rep != null)
rep.debug("Comment: " + t[0] + "\n");
return sol;
} catch (Throwable ex) {
return null;
}
}
use of kodkod.engine.Solution 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.engine.Solution 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