Search in sources :

Example 1 with State

use of de.bmoth.modelchecker.State in project bmoth by hhu-stups.

the class StateTest method testStateEquals3.

@Test
public void testStateEquals3() throws Exception {
    HashMap<String, Expr> map = new HashMap<>();
    map.put("x", z3Context.mkInt(11));
    State state = new State(map);
    assertEquals(state, state);
    assertNotEquals(state, new Object());
}
Also used : Expr(com.microsoft.z3.Expr) HashMap(java.util.HashMap) State(de.bmoth.modelchecker.State) Test(org.junit.Test)

Example 2 with State

use of de.bmoth.modelchecker.State in project bmoth by hhu-stups.

the class BoundedModelChecker method doModelCheck.

@Override
protected ModelCheckingResult doModelCheck() {
    for (int k = 0; k < maxSteps; k++) {
        // get a clean solver
        solver.reset();
        // INIT(V0)
        solver.add(init());
        // CONJUNCTION i from 1 to k T(Vi-1, Vi)
        for (int i = 1; i <= k; i++) {
            solver.add(transition(i - 1, i));
        }
        // not INV(Vk)
        solver.add(getContext().mkNot(invariant(k)));
        // CONJUNCTION i from 1 to k, j from i + 1 to k (Vi != Vj)
        solver.add(distinctVectors(k));
        Status check = solver.check();
        if (check == Status.SATISFIABLE) {
            // counter example found!
            State counterExample = getStateFromModel(solver.getModel(), k);
            return ModelCheckingResult.createCounterExampleFound(k, counterExample, null);
        }
    }
    // no counter example found after maxStep steps
    return ModelCheckingResult.createExceededMaxSteps(maxSteps);
}
Also used : Status(com.microsoft.z3.Status) State(de.bmoth.modelchecker.State)

Example 3 with State

use of de.bmoth.modelchecker.State in project bmoth by hhu-stups.

the class KInductionModelChecker method doModelCheck.

@Override
protected ModelCheckingResult doModelCheck() {
    for (int k = 0; k < maxSteps; k++) {
        // get a clean baseSolver
        baseSolver.reset();
        // INIT(V0)
        baseSolver.add(init());
        // CONJUNCTION i from 1 to k T(Vi-1, Vi)
        for (int i = 1; i <= k; i++) {
            baseSolver.add(transition(i - 1, i));
        }
        // not INV(Vk)
        baseSolver.add(getContext().mkNot(invariant(k)));
        Status check = baseSolver.check();
        if (check == Status.SATISFIABLE) {
            // counter example found!
            State counterExample = getStateFromModel(baseSolver.getModel(), k);
            return createCounterExampleFound(k, counterExample, null);
        } else {
            stepSolver.reset();
            stepSolver.add();
            // CONJUNCTION i from 1 to k, j from i + 1 to k (Vi != Vj)
            stepSolver.add(distinctVectors(k));
            for (int i = 0; i <= k; i++) {
                stepSolver.add(transition(i - 1, i));
            }
            for (int i = 0; i <= k; i++) {
                stepSolver.add(invariant(i));
            }
            stepSolver.add(getContext().mkNot(invariant(k + 1)));
            Status checkStep = stepSolver.check();
            if (checkStep == Status.UNSATISFIABLE)
                // TODO think about state space root!
                return createVerified(k, null);
        }
    }
    // no counter example found after maxStep steps
    return createExceededMaxSteps(maxSteps);
}
Also used : Status(com.microsoft.z3.Status) State(de.bmoth.modelchecker.State)

Example 4 with State

use of de.bmoth.modelchecker.State in project bmoth by hhu-stups.

the class StateTest method testGetStateConstraint.

@Test
public void testGetStateConstraint() {
    HashMap<String, Expr> map1 = new HashMap<>();
    map1.put("x", z3Context.mkInt(11));
    map1.put("y", z3Context.mkInt(12));
    State state1 = new State(map1);
    State state2 = new State(new HashMap<>());
    assertEquals("(and (= x 11) (= y 12))", state1.getStateConstraint(z3Context).toString());
    assertNull(state2.getStateConstraint(z3Context));
}
Also used : Expr(com.microsoft.z3.Expr) HashMap(java.util.HashMap) State(de.bmoth.modelchecker.State) Test(org.junit.Test)

Example 5 with State

use of de.bmoth.modelchecker.State in project bmoth by hhu-stups.

the class StateTest method testToString.

@Test
public void testToString() throws Exception {
    HashMap<String, Expr> map = new HashMap<>();
    map.put("z", z3Context.mkInt(13));
    map.put("x", z3Context.mkInt(11));
    map.put("y", z3Context.mkInt(12));
    map.put("a", z3Context.mkInt(-200));
    State state = new State(map);
    assertEquals("{a=-200, x=11, y=12, z=13}", state.toString());
}
Also used : Expr(com.microsoft.z3.Expr) HashMap(java.util.HashMap) State(de.bmoth.modelchecker.State) Test(org.junit.Test)

Aggregations

State (de.bmoth.modelchecker.State)8 Expr (com.microsoft.z3.Expr)6 HashMap (java.util.HashMap)6 Test (org.junit.Test)6 Status (com.microsoft.z3.Status)2