Search in sources :

Example 36 with Bounds

use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.

the class IncrementalOverflowEnumTest method solveAll.

@Override
protected Iterator<Solution> solveAll(final Formula formula) {
    final IncrementalSolver solver = IncrementalSolver.solver(options);
    return new Iterator<Solution>() {

        Solution sol;

        @Override
        public boolean hasNext() {
            return sol == null || sol.sat();
        }

        @Override
        public Solution next() {
            if (sol == null) {
                sol = solver.solve(formula, bounds);
            } else {
                Evaluator ev = new Evaluator(sol.instance());
                int a = evalInt(ev, op1);
                int b = evalInt(ev, op2);
                int r = evalInt(ev, ret);
                Formula f = op1.eq(IntConstant.constant(a).toExpression()).and(op2.eq(IntConstant.constant(b).toExpression())).and(ret.eq(IntConstant.constant(r).toExpression())).not();
                sol = solver.solve(f, new Bounds(factory.universe()));
            }
            return sol;
        }

        @Override
        public void remove() {
            throw new RuntimeException("Not supported");
        }
    };
}
Also used : Formula(kodkod.ast.Formula) Bounds(kodkod.instance.Bounds) Iterator(java.util.Iterator) Evaluator(kodkod.engine.Evaluator) IncrementalSolver(kodkod.engine.IncrementalSolver) Solution(kodkod.engine.Solution)

Example 37 with Bounds

use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.

the class IntTest method testBitsetCast.

public void testBitsetCast() {
    final int width = 4, msb = width - 1;
    solver.options().setBitwidth(width);
    final List<Integer> atoms = new ArrayList<Integer>(width);
    for (int i = 0; i < msb; i++) {
        atoms.add(Integer.valueOf(1 << i));
    }
    atoms.add(Integer.valueOf(-1 << msb));
    final Bounds b = new Bounds(new Universe(atoms));
    final TupleFactory f = b.universe().factory();
    for (Integer i : atoms) {
        b.boundExactly(i, f.setOf(i));
    }
    b.bound(r1, f.allOf(1));
    for (int i = -1 << msb, max = 1 << msb; i < max; i++) {
        Formula test = r1.sum().toBitset().eq(IntConstant.constant(i).toBitset());
        Solution sol = solver.solve(test, b);
        Instance inst = sol.instance();
        assertNotNull(inst);
        Evaluator eval = new Evaluator(inst, solver.options());
        assertEquals(i, eval.evaluate(r1.sum()));
    }
}
Also used : Formula(kodkod.ast.Formula) Instance(kodkod.instance.Instance) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Evaluator(kodkod.engine.Evaluator) Solution(kodkod.engine.Solution)

Example 38 with Bounds

use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.

the class IntTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    bounds = new Bounds(factory.universe());
    solver.options().setSolver(SATFactory.MiniSat);
}
Also used : Bounds(kodkod.instance.Bounds)

Example 39 with Bounds

use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.

the class BugTests method testFelix_05152007_2.

public final void testFelix_05152007_2() {
    Relation x5 = Relation.nary("A", 1);
    List<String> atomlist = Arrays.asList("A0", "A1", "A2");
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);
    TupleSet x5_upper = factory.noneOf(1);
    x5_upper.add(factory.tuple("A2"));
    x5_upper.add(factory.tuple("A1"));
    x5_upper.add(factory.tuple("A0"));
    bounds.bound(x5, x5_upper);
    Formula x7 = x5.eq(x5).not();
    Solver solver = new Solver();
    solver.options().setLogTranslation(1);
    solver.options().setSolver(SATFactory.MiniSatProver);
    solver.options().setBitwidth(4);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
    Solution sol = solver.solve(x7, bounds);
    Set<Formula> core = Nodes.minRoots(x7, sol.proof().highLevelCore().values());
    assertEquals(1, core.size());
    assertTrue(core.contains(x7));
}
Also used : TupleSet(kodkod.instance.TupleSet) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Solution(kodkod.engine.Solution)

Example 40 with Bounds

use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.

the class BugTests method testFelix_11192007.

public final void testFelix_11192007() {
    List<String> atomlist = Arrays.asList("A", "B", "C");
    Universe universe = new Universe(atomlist);
    Bounds bounds = new Bounds(universe);
    Solver solver = new Solver();
    solver.options().setLogTranslation(2);
    solver.options().setSolver(SATFactory.MiniSatProver);
    solver.options().setBitwidth(4);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
    solver.options().setSymmetryBreaking(20);
    solver.options().setSkolemDepth(0);
    Solution sol = solver.solve(Formula.TRUE, bounds);
    assertNotNull(sol.instance());
}
Also used : Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) Universe(kodkod.instance.Universe) Solution(kodkod.engine.Solution)

Aggregations

Bounds (kodkod.instance.Bounds)140 Formula (kodkod.ast.Formula)83 Universe (kodkod.instance.Universe)79 TupleFactory (kodkod.instance.TupleFactory)76 Solution (kodkod.engine.Solution)75 Solver (kodkod.engine.Solver)67 TupleSet (kodkod.instance.TupleSet)55 Relation (kodkod.ast.Relation)49 ArrayList (java.util.ArrayList)45 Expression (kodkod.ast.Expression)21 Variable (kodkod.ast.Variable)21 IntExpression (kodkod.ast.IntExpression)20 Instance (kodkod.instance.Instance)12 Decls (kodkod.ast.Decls)11 Evaluator (kodkod.engine.Evaluator)8 HigherOrderDeclException (kodkod.engine.fol2sat.HigherOrderDeclException)7 UnboundLeafException (kodkod.engine.fol2sat.UnboundLeafException)7 ConsoleReporter (kodkod.engine.config.ConsoleReporter)6 Tuple (kodkod.instance.Tuple)6 LinkedHashSet (java.util.LinkedHashSet)5