Exemplo n.º 1
0
    def test_env_default_arguments(self):
        """Test use global env"""
        x = FreshSymbol()
        d = {x: TRUE()}

        model = EagerModel(d)
        self.assertEqual(model.get_value(x), TRUE())
Exemplo n.º 2
0
    def test_env_default_arguments(self):
        """Test use global env"""
        x = FreshSymbol()
        d = {x: TRUE()}

        model = EagerModel(d)
        self.assertEqual(model.get_value(x), TRUE())
Exemplo n.º 3
0
    def test_construction(self):
        """Build an eager model out of a dictionary"""

        x, y = FreshSymbol(), FreshSymbol()

        d = {x: TRUE(), y: FALSE()}

        model = EagerModel(assignment=d)

        self.assertEqual(model.get_value(x), TRUE())
        self.assertEqual(model.get_value(y), FALSE())
        self.assertEqual(model.get_value(And(x, y)), FALSE())
Exemplo n.º 4
0
    def test_construction(self):
        """Build an eager model out of a dictionary"""

        x, y = FreshSymbol(), FreshSymbol()

        d = {x: TRUE(), y: FALSE()}

        model = EagerModel(assignment=d)

        self.assertEqual(model.get_value(x), TRUE())
        self.assertEqual(model.get_value(y), FALSE())
        self.assertEqual(model.get_value(And(x,y)), FALSE())
Exemplo n.º 5
0
 def get_model(self):
     assignment = {}
     for s in self.environment.formula_manager.get_all_symbols():
         if s.is_term():
             v = self.get_value(s)
             assignment[s] = v
     return EagerModel(assignment=assignment, environment=self.environment)
Exemplo n.º 6
0
 def get_model(self):
     assignment = {}
     for s in self.declared_vars[-1]:
         if s.is_term():
             v = self.get_value(s)
             assignment[s] = v
     return EagerModel(assignment=assignment, environment=self.environment)
Exemplo n.º 7
0
    def get_model(self):
        assignment = {}
        for var, vid in self._var_ids.items():
            v = picosat.picosat_deref(self.pico, vid)
            assert v != 0, "Error when translating variable."

            value = self.mgr.Bool(v == 1)
            assignment[var] = value

        return EagerModel(assignment=assignment, environment=self.environment)
Exemplo n.º 8
0
 def test_warp_solvermodel(self):
     x, y, z = [FreshSymbol() for _ in xrange(3)]
     with Solver(name='z3') as solver:
         solver.add_assertion(And(x, y, z))
         solver.solve()
         z3_model = solver.get_model()
         eager_model = EagerModel(z3_model)
         for var, value in eager_model:
             self.assertIn(var, [x, y, z])
             self.assertEqual(value, TRUE())
Exemplo n.º 9
0
    def get_model(self):
        assignment = {}
        for var, vid in iteritems(self._var_ids):
            v = picosat.picosat_deref(self.pico, vid)
            if v == 0:
                assert False

            value = self.mgr.Bool(v == 1)
            assignment[var] = value

        return EagerModel(assignment=assignment, environment=self.environment)
Exemplo n.º 10
0
 def get_model(self):
     assignment = {}
     # MG: This iteration is probelmatic, since it assumes that all
     # defined symbols have a type that is compatible with this
     # solver.  In this case, the problem occurs with Arrays and
     # Strings that are not supported.
     for s in self.environment.formula_manager.get_all_symbols():
         if s.is_term():
             if s.symbol_type().is_array_type(): continue
             v = self.get_value(s)
             assignment[s] = v
     return EagerModel(assignment=assignment, environment=self.environment)
Exemplo n.º 11
0
    def test_result_is_const(self):
        """The result of get_value is a constant"""

        x, y = FreshSymbol(), FreshSymbol()
        d = {x: TRUE()}

        model = EagerModel(assignment=d)
        with self.assertRaises(PysmtTypeError):
            model.get_value(And(x, y), model_completion=False)

        d2 = {x: TRUE(), y: x}
        model = EagerModel(assignment=d2)
        with self.assertRaises(PysmtTypeError):
            model.get_value(And(x, y))
Exemplo n.º 12
0
    def test_eager_model_iterator(self):
        x, y, z = [Symbol(s) for s in "xyz"]
        with Solver(logic=QF_BOOL) as s:
            s.add_assertion(And(x, y))
            assert s.solve()
            d = {}
            d[x] = s.get_value(x)
            d[y] = s.get_value(y)
        m = EagerModel(assignment=d)

        # The model does not talk about 'z'
        for (k, _) in m:
            self.assertFalse(k == z)
Exemplo n.º 13
0
Arquivo: msat.py Projeto: idkwim/pysmt
 def get_model(self):
     assignment = {}
     msat_iterator = mathsat.msat_create_model_iterator(self.msat_env)
     while mathsat.msat_model_iterator_has_next(msat_iterator):
         term, value = mathsat.msat_model_iterator_next(msat_iterator)
         pysmt_term = self.converter.back(term)
         pysmt_value = self.converter.back(value)
         if self.environment.stc.get_type(pysmt_term).is_real_type() and \
            pysmt_value.is_int_constant():
             pysmt_value = self.mgr.Real(pysmt_value.constant_value())
         assignment[pysmt_term] = pysmt_value
     mathsat.msat_destroy_model_iterator(msat_iterator)
     return EagerModel(assignment=assignment, environment=self.environment)
Exemplo n.º 14
0
    def get_model(self):
        from pysmt.solvers.eager import EagerModel

        if not self._ext_solver:
            raise ValueError("No SAT model")

        self._ctrl_pipe.send("get_model")
        # Contextualize the result within the calling process
        _normalize = self.environment.formula_manager.normalize
        model_list = self._ctrl_pipe.recv()
        model = {}
        for k, v in model_list:
            _k, _v = _normalize(k), _normalize(v)
            model[_k] = _v

        return EagerModel(model)
Exemplo n.º 15
0
    def test_result_is_const(self):
        """The result of get_value is a constant"""

        x, y = FreshSymbol(), FreshSymbol()
        d = {x:TRUE()}

        model = EagerModel(assignment=d)
        with self.assertRaises(TypeError):
            model.get_value(And(x,y), model_completion=False)

        d2 = {x:TRUE(), y:x}
        model = EagerModel(assignment=d2)
        with self.assertRaises(TypeError):
            model.get_value(And(x,y))
Exemplo n.º 16
0
    def get_model(self):
        # TODO: We could provide a more sophisticated Model class,
        # that would contain the current Bdd and a copy of the
        # DdManager. This would make it possible to apply other
        # operations on the model (e.g., enumeration) in a simple way.
        if self.latest_model is None:
            _, current_state = self.assertions_stack[-1]
            assert current_state is not None, "solve() should be called before get_model()"
            # Build ddArray of variables
            var_array = self.converter.get_all_vars_array()
            minterm_set = self.ddmanager.PickOneMinterm(
                current_state, var_array, len(var_array))
            minterm = next(
                repycudd.ForeachCubeIterator(self.ddmanager, minterm_set))
            assignment = {}
            for i, node in enumerate(var_array):
                value = self.mgr.Bool(minterm[i] == 1)
                key = self.converter.idx2var[node.NodeReadIndex()]
                assignment[key] = value

            self.latest_model = EagerModel(assignment=assignment,
                                           environment=self.environment)
        return self.latest_model
Exemplo n.º 17
0
 def get_model(self):
     assignment = {}
     for s, _ in self.converter.declared_vars.items():
         assignment[s] = self.get_value(s)
     return EagerModel(assignment=assignment, environment=self.environment)
Exemplo n.º 18
0
 def test_contains(self):
     x, y, z = [FreshSymbol() for _ in xrange(3)]
     d = {x: TRUE(), y: FALSE()}
     model = EagerModel(assignment=d)
     self.assertTrue(x in model)
     self.assertFalse(z in model)
Exemplo n.º 19
0
    def test_complete_model(self):
        """Given a partial assignment, we can make a total model."""
        x, y = FreshSymbol(), FreshSymbol()
        r = FreshSymbol(REAL)
        p = FreshSymbol(INT)
        d = {x: TRUE()}

        model = EagerModel(assignment=d)

        self.assertEqual(model.get_value(x), TRUE())
        self.assertEqual(model.get_value(Or(x, y)), TRUE())
        self.assertTrue(model.get_value(p).is_constant(INT))
        self.assertTrue(model.get_value(r).is_constant(REAL))

        self.assertEqual(model.get_value(x, model_completion=False), TRUE())
        with self.assertRaises(PysmtTypeError):
            model.get_value(And(x, y), model_completion=False)
        with self.assertRaises(PysmtTypeError):
            model.get_value(p, model_completion=False)
        with self.assertRaises(PysmtTypeError):
            model.get_value(r, model_completion=False)
Exemplo n.º 20
0
    def test_complete_model(self):
        """Given a partial assignment, we can make a total model."""
        x, y = FreshSymbol(), FreshSymbol()
        r = FreshSymbol(REAL)
        p = FreshSymbol(INT)
        d = {x:TRUE()}

        model = EagerModel(assignment=d)

        self.assertEqual(model.get_value(x), TRUE())
        self.assertEqual(model.get_value(Or(x,y)), TRUE())
        self.assertTrue(model.get_value(p).is_constant(INT))
        self.assertTrue(model.get_value(r).is_constant(REAL))

        self.assertEqual(model.get_value(x, model_completion=False), TRUE())
        with self.assertRaises(TypeError):
            model.get_value(And(x,y), model_completion=False)
        with self.assertRaises(TypeError):
            model.get_value(p, model_completion=False)
        with self.assertRaises(TypeError):
            model.get_value(r, model_completion=False)
Exemplo n.º 21
0
 def get_model(self):
     assignment = {}
     for s in self.converter.declared_vars:
         v = self.get_value(s)
         assignment[s] = v
     return EagerModel(assignment=assignment, environment=self.environment)