Search in sources :

Example 66 with Solution

use of kodkod.engine.Solution in project org.alloytools.alloy by AlloyTools.

the class HOLSome4AllTest method testE1.

@Test
public void testE1() {
    // SAT: some s: ints | all ns: set Node | #ns > s
    Formula f = ns.count().gt(si).forAll(ns.setOf(Node)).forSome(s.oneOf(Expression.INTS));
    Solution sol = solve(f);
    assertEquals(true, sol.sat());
    assertEquals(-1, evalS(sol));
}
Also used : QuantifiedFormula(kodkod.ast.QuantifiedFormula) Formula(kodkod.ast.Formula) Solution(kodkod.engine.Solution) Test(org.junit.Test)

Example 67 with Solution

use of kodkod.engine.Solution in project org.alloytools.alloy by AlloyTools.

the class HOLSome4AllTest method testE2.

@Test
public void testE2() {
    // UNSAT: some s: ints | s > 0 && (all ns: set Node | #ns > s)
    Formula cnd = si.gt(I0);
    Formula f = cnd.and(ns.count().gt(si).forAll(ns.setOf(Node))).forSome(s.oneOf(Expression.INTS));
    Solution sol = solve(f);
    assertEquals(false, sol.sat());
}
Also used : QuantifiedFormula(kodkod.ast.QuantifiedFormula) Formula(kodkod.ast.Formula) Solution(kodkod.engine.Solution) Test(org.junit.Test)

Example 68 with Solution

use of kodkod.engine.Solution in project org.alloytools.alloy by AlloyTools.

the class ReductionAndProofTest method testProof.

public final void testProof() {
    Variable v0 = Variable.unary("v0"), v1 = Variable.unary("v1"), v2 = Variable.unary("v2");
    Formula f0 = v0.join(a2b).eq(v1.union(v2)).and(v1.eq(v2).not());
    Formula f1 = f0.forSome(v0.oneOf(a).and(v1.oneOf(b)).and(v2.oneOf(b)));
    Formula f2 = a2b.function(a, b);
    Formula f3 = f1.and(f2).and(total.totalOrder(ordered, first, last));
    Solution sol = null;
    solver.options().setLogTranslation(0);
    solver.options().setSolver(SATFactory.MiniSat);
    sol = solver.solve(f3, bounds);
    assertEquals(Solution.Outcome.UNSATISFIABLE, sol.outcome());
    assertNull(sol.proof());
    solver.options().setLogTranslation(1);
    sol = solver.solve(f3, bounds);
    assertNull(sol.proof());
    solver.options().setSolver(SATFactory.MiniSatProver);
    sol = solver.solve(f3, bounds);
    // System.out.println(f3 + ", " + bounds);
    sol.proof().minimize(new ECFPStrategy());
    final Set<Formula> top = Nodes.minRoots(f3, sol.proof().highLevelCore().values());
    assertEquals(2, top.size());
    assertTrue(top.contains(f1));
    assertTrue(top.contains(f2));
// for(Iterator<TranslationLog.Record> itr = sol.proof().core();
// itr.hasNext(); ) {
// System.out.println(itr.next());
// }
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) ECFPStrategy(kodkod.engine.ucore.ECFPStrategy) Solution(kodkod.engine.Solution)

Example 69 with Solution

use of kodkod.engine.Solution in project org.alloytools.alloy by AlloyTools.

the class ReductionAndProofTest method reduce.

private Set<Formula> reduce(Formula formula) {
    final Solution sol = solver.solve(formula, bounds);
    assertEquals(Solution.Outcome.TRIVIALLY_UNSATISFIABLE, sol.outcome());
    sol.proof().minimize(null);
    return Nodes.minRoots(formula, sol.proof().highLevelCore().values());
}
Also used : Solution(kodkod.engine.Solution)

Example 70 with Solution

use of kodkod.engine.Solution in project org.alloytools.alloy by AlloyTools.

the class ReductionAndProofTest method core.

private Set<Node> core(Formula formula, int granularity) {
    solver.options().setCoreGranularity(granularity);
    final Solution sol = solver.solve(formula, bounds);
    assertEquals(Solution.Outcome.UNSATISFIABLE, sol.outcome());
    sol.proof().minimize(new NCEStrategy(sol.proof().log()));
    return new IdentityHashSet<Node>(sol.proof().highLevelCore().values());
}
Also used : NCEStrategy(kodkod.engine.ucore.NCEStrategy) IdentityHashSet(kodkod.util.collections.IdentityHashSet) Solution(kodkod.engine.Solution)

Aggregations

Solution (kodkod.engine.Solution)153 Formula (kodkod.ast.Formula)101 Bounds (kodkod.instance.Bounds)75 Solver (kodkod.engine.Solver)72 Universe (kodkod.instance.Universe)32 Relation (kodkod.ast.Relation)30 TupleFactory (kodkod.instance.TupleFactory)30 TupleSet (kodkod.instance.TupleSet)25 Variable (kodkod.ast.Variable)24 IntExpression (kodkod.ast.IntExpression)19 Expression (kodkod.ast.Expression)17 Test (org.junit.Test)16 QuantifiedFormula (kodkod.ast.QuantifiedFormula)15 Decls (kodkod.ast.Decls)11 Evaluator (kodkod.engine.Evaluator)10 HigherOrderDeclException (kodkod.engine.fol2sat.HigherOrderDeclException)7 UnboundLeafException (kodkod.engine.fol2sat.UnboundLeafException)7 ConsoleReporter (kodkod.engine.config.ConsoleReporter)6 Instance (kodkod.instance.Instance)6 ArrayList (java.util.ArrayList)5