Ejemplo n.º 1
0
 def test_make(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     x = PyLinexpr1(e)
     x.set_coeff(PyVar('x0'), PyDoubleScalarCoeff(3))
     x.set_coeff(PyVar('z'), PyDoubleScalarCoeff(-9))
     x.set_cst(PyDoubleScalarCoeff(8))
     c = PyTcons1.make(PyTexpr1(x), ConsTyp.AP_CONS_SUPEQ)
     self.assertEqual(str(c), '8.0 + 3.0 · x0 - 9.0 · z >= 0')
Ejemplo n.º 2
0
 def test_is_unsat(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     x = PyLinexpr1(e)
     x.set_coeff(PyVar('x0'), PyDoubleScalarCoeff(3))
     x.set_coeff(PyVar('z'), PyDoubleScalarCoeff(-9))
     x.set_cst(PyDoubleScalarCoeff(8))
     c = PyLincons1(ConsTyp.AP_CONS_SUPEQ, x)
     self.assertFalse(c.is_unsat())
     self.assertTrue(PyLincons1.unsat(e).is_unsat())
     self.assertTrue(PyLincons1(ConsTyp.AP_CONS_DISEQ, PyLinexpr1(e)).is_unsat())
Ejemplo n.º 3
0
 def test_init(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     x = PyLinexpr1(e)
     x.set_coeff(PyVar('x0'), PyDoubleScalarCoeff(3))
     x.set_coeff(PyVar('z'), PyDoubleScalarCoeff(-9))
     x.set_cst(PyDoubleScalarCoeff(8))
     c = PyLincons1(ConsTyp.AP_CONS_SUPEQ, x)
     self.assertEqual(str(c), '3.0·x0 - 9.0·z + 8.0 >= 0')
     self.assertEqual(str(PyLincons1.unsat(e)), '-1.0 >= 0')
     self.assertEqual(str(PyLincons1(ConsTyp.AP_CONS_DISEQ, PyLinexpr1(e))), '0.0 != 0')
Ejemplo n.º 4
0
 def test_init(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     x = PyLinexpr1(e)
     x0 = PyLinexpr1(e, 0)
     self.assertEqual(str(PyTexpr1(x)), '0.0')
     self.assertEqual(str(PyTexpr1(x0)), '0.0 + 0.0 · x0 + 0.0 · y + 0.0 · z')
     x.set_coeff(PyVar('x0'), PyDoubleScalarCoeff(-1))
     x.set_coeff(PyVar('z'), PyDoubleScalarCoeff(-9))
     x.set_cst(PyDoubleScalarCoeff(8))
     self.assertEqual(str(PyTexpr1(x)), '8.0 - 1.0 · x0 - 9.0 · z')
Ejemplo n.º 5
0
 def test_deepcopy(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     x = PyLinexpr1(e)
     x.set_coeff(PyVar('x0'), PyDoubleScalarCoeff(3))
     x.set_coeff(PyVar('z'), PyDoubleScalarCoeff(-9))
     x.set_cst(PyDoubleScalarCoeff(8))
     c0 = PyTcons1.make(PyTexpr1(x), ConsTyp.AP_CONS_SUPEQ)
     c1 = deepcopy(c0)
     c2 = c0
     self.assertNotEqual(id(c0), id(c1))
     self.assertEqual(id(c0), id(c2))
Ejemplo n.º 6
0
 def test_init(self):
     e = PyEnvironment([PyVar('x'), PyVar('y')], [PyVar('z')])
     x1 = PyLinexpr1(e)
     x1.set_coeff(PyVar('x'), PyDoubleScalarCoeff(3))
     x1.set_coeff(PyVar('z'), PyDoubleScalarCoeff(-9))
     x1.set_cst(PyDoubleScalarCoeff(8))
     c1 = PyLincons1(ConsTyp.AP_CONS_SUPEQ, x1)
     x2 = PyLinexpr1(e)
     x2.set_coeff(PyVar('x'), PyDoubleScalarCoeff(1))
     c2 = PyLincons1(ConsTyp.AP_CONS_SUP, x2)
     a = PyLincons1Array([c1, c2])
     self.assertEqual(str(a), '3.0·x - 9.0·z + 8.0 >= 0 ∧ 1.0·x + 0.0 > 0')
Ejemplo n.º 7
0
 def test_is_real(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     x0 = PyLinexpr1(e)
     x0.set_coeff(PyVar('x0'), PyDoubleScalarCoeff(3))
     self.assertFalse(x0.is_real())
     x1 = PyLinexpr1(e)
     x1.set_coeff(PyVar('x0'), PyDoubleScalarCoeff(3))
     x1.set_coeff(PyVar('z'), PyDoubleScalarCoeff(-9))
     self.assertFalse(x1.is_real())
     x2 = PyLinexpr1(e)
     x2.set_coeff(PyVar('z'), PyDoubleScalarCoeff(-9))
     self.assertTrue(x2.is_real())
Ejemplo n.º 8
0
 def test_is_quasilinear(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     x0 = PyLinexpr1(e)
     x0.set_coeff(PyVar('x0'), PyDoubleScalarCoeff(3))
     x0.set_cst(PyDoubleScalarCoeff(-9))
     self.assertTrue(x0.is_quasilinear())
     x1 = PyLinexpr1(e)
     x1.set_coeff(PyVar('x0'), PyDoubleIntervalCoeff(3, 3))
     x1.set_cst(PyDoubleIntervalCoeff(-9, 9))
     self.assertFalse(x1.is_quasilinear())
     x2 = PyLinexpr1(e)
     x2.set_coeff(PyVar('x0'), PyDoubleScalarCoeff(3))
     x2.set_cst(PyDoubleIntervalCoeff(-9, 9))
     self.assertTrue(x2.is_quasilinear())
Ejemplo n.º 9
0
 def test_get(self):
     e = PyEnvironment([PyVar('x'), PyVar('y')], [PyVar('z')])
     x1 = PyLinexpr1(e)
     x1.set_coeff(PyVar('x'), PyDoubleScalarCoeff(3))
     x1.set_coeff(PyVar('z'), PyDoubleScalarCoeff(-9))
     x1.set_cst(PyDoubleScalarCoeff(8))
     c1 = PyLincons1(ConsTyp.AP_CONS_SUPEQ, x1)
     x2 = PyLinexpr1(e)
     x2.set_coeff(PyVar('x'), PyDoubleScalarCoeff(1))
     c2 = PyLincons1(ConsTyp.AP_CONS_SUP, x2)
     a = PyLincons1Array([c1, c2])
     c = a.get(1)
     self.assertNotEqual(str(c), str(c1))
     self.assertEqual(str(c), str(c2))
Ejemplo n.º 10
0
 def get_cst(self):
     cst = self.lincons1.lincons0.linexpr0.contents.cst
     if cst.discr == CoeffDiscr.AP_COEFF_INTERVAL:
         if cst.val.interval.contents.inf.contents.discr == ScalarDiscr.AP_SCALAR_MPQ:
             result = PyMPQIntervalCoeff()
         elif cst.val.interval.contents.inf.contents.discr == ScalarDiscr.AP_SCALAR_MPFR:
             result = PyMPFRIntervalCoeff(0, 0)
         else:  # cst.val.interval.contents.inf.contents.discr == ScalarDiscr.AP_SCALAR_DOUBLE
             result = PyDoubleIntervalCoeff()
     else:  # CoeffDiscr.AP_COEFF_SCALAR
         if cst.val.scalar.contents.discr == ScalarDiscr.AP_SCALAR_MPQ:
             result = PyMPQScalarCoeff()
         elif cst.val.scalar.contents.discr == ScalarDiscr.AP_SCALAR_MPFR:
             result = PyMPFRScalarCoeff(0)
         else:  # cst.val.scalar.contents.discr == ScalarDiscr.AP_SCALAR_DOUBLE
             result = PyDoubleScalarCoeff()
     libapron.ap_coeff_set(result.coeff, self.lincons1.lincons0.linexpr0.contents.cst)
     return result
Ejemplo n.º 11
0
 def get_coeff(self, var: PyVar):
     coeff = libapron.ap_linexpr1_coeffref(self, var._as_parameter_)
     if coeff.contents.discr == CoeffDiscr.AP_COEFF_INTERVAL:
         discr = coeff.contents.val.interval.contents.inf.contents.discr
         if discr == ScalarDiscr.AP_SCALAR_MPQ:
             result = PyMPQIntervalCoeff()
         elif discr == ScalarDiscr.AP_SCALAR_MPFR:
             result = PyMPFRIntervalCoeff(0, 0)
         else:  # discr == ScalarDiscr.AP_SCALAR_DOUBLE
             result = PyDoubleIntervalCoeff()
     else:  # CoeffDiscr.AP_COEFF_SCALAR
         if coeff.contents.val.scalar.contents.discr == ScalarDiscr.AP_SCALAR_MPQ:
             result = PyMPQScalarCoeff()
         elif coeff.contents.val.scalar.contents.discr == ScalarDiscr.AP_SCALAR_MPFR:
             result = PyMPFRScalarCoeff(0)
         else:  # coeff.contents.val.scalar.contents.discr == ScalarDiscr.AP_SCALAR_DOUBLE
             result = PyDoubleScalarCoeff()
     libapron.ap_linexpr1_get_coeff(result, self, var._as_parameter_)
     return result
Ejemplo n.º 12
0
 def get_cst(self):
     cst = deepcopy(self.linexpr1.linexpr0.contents.cst)
     if cst.discr == CoeffDiscr.AP_COEFF_INTERVAL:
         if cst.val.interval.contents.inf.contents.discr == ScalarDiscr.AP_SCALAR_MPQ:
             result = PyMPQIntervalCoeff(cst)
         elif cst.val.interval.contents.inf.contents.discr == ScalarDiscr.AP_SCALAR_MPFR:
             result = PyMPFRIntervalCoeff(cst)
         else:
             assert cst.val.interval.contents.inf.contents.discr == ScalarDiscr.AP_SCALAR_DOUBLE
             result = PyDoubleIntervalCoeff(cst)
     else:
         assert cst.discr == CoeffDiscr.AP_COEFF_SCALAR
         if cst.val.scalar.contents.discr == ScalarDiscr.AP_SCALAR_MPQ:
             result = PyMPQScalarCoeff(cst)
         elif cst.val.scalar.contents.discr == ScalarDiscr.AP_SCALAR_MPFR:
             result = PyMPFRScalarCoeff(cst)
         else:
             assert cst.val.scalar.contents.discr == ScalarDiscr.AP_SCALAR_DOUBLE
             result = PyDoubleScalarCoeff(cst)
     return result
Ejemplo n.º 13
0
 def test_init(self):
     self.assertEqual(str(PyDoubleScalarCoeff()), '0.0')
Ejemplo n.º 14
0
 def test_get_coeff(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     self.assertEqual(
         PyLinexpr1(e).get_coeff(PyVar('x0')), PyDoubleScalarCoeff(0.0))
     self.assertNotEqual(
         PyLinexpr1(e).get_coeff(PyVar('x0')), PyDoubleScalarCoeff(-3))
Ejemplo n.º 15
0
 def test_set_cst(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     x = PyLinexpr1(e)
     x.set_cst(PyDoubleScalarCoeff(9))
     self.assertEqual(str(x), '9.0')
Ejemplo n.º 16
0
 def test_get_coeff(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     x = PyLinexpr1(e)
     c = PyLincons1(ConsTyp.AP_CONS_SUPEQ, x)
     self.assertEqual(c.get_coeff(PyVar('x0')), PyDoubleScalarCoeff(0.0))
     self.assertNotEqual(c.get_coeff(PyVar('x0')), PyDoubleScalarCoeff(-3))
Ejemplo n.º 17
0
 def unsat(cls, environment: PyEnvironment):
     x = PyTexpr1.cst(environment, PyDoubleScalarCoeff(-1.0))
     return cls.make(x, ConsTyp.AP_CONS_SUPEQ)
Ejemplo n.º 18
0
 def unsat(cls, environment: PyEnvironment):
     x = PyLinexpr1(environment)
     x.set_cst(PyDoubleScalarCoeff(-1.0))
     lincons = cls(ConsTyp.AP_CONS_SUPEQ, x)
     return lincons
Ejemplo n.º 19
0
 def test_neg(self):
     self.assertEqual(-PyDoubleScalarCoeff(-0.5), PyDoubleScalarCoeff(0.5))
     self.assertEqual(-PyDoubleScalarCoeff(0), PyDoubleScalarCoeff(0))
     self.assertEqual(-PyDoubleScalarCoeff(0.5), PyDoubleScalarCoeff(-0.5))
Ejemplo n.º 20
0
 def test_cmp(self):
     self.assertTrue(PyDoubleScalarCoeff(-0.5) < PyDoubleScalarCoeff())
     self.assertFalse(PyDoubleScalarCoeff() < PyDoubleScalarCoeff(-0.5))
     self.assertTrue(PyDoubleScalarCoeff() == PyDoubleScalarCoeff(0))
     self.assertFalse(PyDoubleScalarCoeff() == PyDoubleScalarCoeff(-0.5))
     self.assertTrue(PyDoubleScalarCoeff() > PyDoubleScalarCoeff(-0.5))
     self.assertFalse(PyDoubleScalarCoeff(-0.5) > PyDoubleScalarCoeff())
Ejemplo n.º 21
0
 def test_deepcopy(self):
     c0 = PyDoubleScalarCoeff()
     c1 = deepcopy(c0)
     c2 = c0
     self.assertNotEqual(id(c0), id(c1))
     self.assertEqual(id(c0), id(c2))
Ejemplo n.º 22
0
 def test_set_coeff(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     x = PyLinexpr1(e)
     c = PyLincons1(ConsTyp.AP_CONS_SUPEQ, x)
     c.set_coeff(PyVar('z'), PyDoubleScalarCoeff(-9))
     self.assertEqual(str(c), '-9.0·z + 0.0 >= 0')