Ejemplo n.º 1
0
    def test_logical(self):
        numpy_compare.assert_equal(sym.logical_not(x == 0), "!((x == 0))")

        # Test single-operand logical statements
        numpy_compare.assert_equal(sym.logical_and(x >= 1), "(x >= 1)")
        numpy_compare.assert_equal(sym.logical_or(x >= 1), "(x >= 1)")
        # Test binary operand logical statements
        numpy_compare.assert_equal(sym.logical_and(x >= 1, x <= 2),
                                   "((x >= 1) and (x <= 2))")
        numpy_compare.assert_equal(sym.logical_or(x <= 1, x >= 2),
                                   "((x >= 2) or (x <= 1))")
        # Test multiple operand logical statements
        numpy_compare.assert_equal(sym.logical_and(x >= 1, x <= 2, y == 2),
                                   "((y == 2) and (x >= 1) and (x <= 2))")
        numpy_compare.assert_equal(sym.logical_or(x >= 1, x <= 2, y == 2),
                                   "((y == 2) or (x >= 1) or (x <= 2))")
Ejemplo n.º 2
0
    def test_logical(self):
        self.assertEqual(str(sym.logical_not(x == 0)), "!((x == 0))")

        # Test single-operand logical statements
        self.assertEqual(str(sym.logical_and(x >= 1)), "(x >= 1)")
        self.assertEqual(str(sym.logical_or(x >= 1)), "(x >= 1)")
        # Test binary operand logical statements
        self.assertEqual(str(sym.logical_and(x >= 1, x <= 2)),
                         "((x >= 1) and (x <= 2))")
        self.assertEqual(str(sym.logical_or(x <= 1, x >= 2)),
                         "((x >= 2) or (x <= 1))")
        # Test multiple operand logical statements
        self.assertEqual(str(sym.logical_and(x >= 1, x <= 2, y == 2)),
                         "((y == 2) and (x >= 1) and (x <= 2))")
        self.assertEqual(str(sym.logical_or(x >= 1, x <= 2, y == 2)),
                         "((y == 2) or (x >= 1) or (x <= 2))")
Ejemplo n.º 3
0
 def test_dreal_satisfiability(self):
     x = Variable("x")
     f = logical_and(x > 1, x < 2)
     interval_box = EqualToDict(
         DrealSolver.CheckSatisfiability(f=f, delta=0.01))
     self.assertEqual(len(interval_box), 1)
     self.assertIsInstance(interval_box[x], DrealSolver.Interval)
Ejemplo n.º 4
0
    def test_logical(self):
        self.assertEqual(str(sym.logical_not(x == 0)),
                         "!((x == 0))")

        # Test single-operand logical statements
        self.assertEqual(str(sym.logical_and(x >= 1)), "(x >= 1)")
        self.assertEqual(str(sym.logical_or(x >= 1)), "(x >= 1)")
        # Test binary operand logical statements
        self.assertEqual(str(sym.logical_and(x >= 1, x <= 2)),
                         "((x >= 1) and (x <= 2))")
        self.assertEqual(str(sym.logical_or(x <= 1, x >= 2)),
                         "((x >= 2) or (x <= 1))")
        # Test multiple operand logical statements
        self.assertEqual(str(sym.logical_and(x >= 1, x <= 2, y == 2)),
                         "((y == 2) and (x >= 1) and (x <= 2))")
        self.assertEqual(str(sym.logical_or(x >= 1, x <= 2, y == 2)),
                         "((y == 2) or (x >= 1) or (x <= 2))")
Ejemplo n.º 5
0
 def test_minimize(self):
     x = Variable("x")
     delta = 0.01
     interval_box = EqualToDict(
         DrealSolver.Minimize(
             objective=x**2,
             constraint=logical_and(x >= 1, x <= 10),
             delta=delta,
             local_optimization=DrealSolver.LocalOptimization.kUse))
     self.assertEqual(len(interval_box), 1)
     self.assertIsInstance(interval_box[x], DrealSolver.Interval)
     print(interval_box[x].diam())
     self.assertAlmostEqual(interval_box[x].mid(), 1.0, delta=delta)
Ejemplo n.º 6
0
    def __init__(self):
        # Create a simple QP that uses all deduced linear constraint types,
        # along with a quadratic and linear cost.
        # The solution should be [1, 1].
        prog = mp.MathematicalProgram()
        x = prog.NewContinuousVariables(2, "x")
        self.prog = prog
        self.x = x
        self.constraints = [
            # Bounding box
            prog.AddLinearConstraint(x[0] >= 1),
            # Bounding box
            prog.AddLinearConstraint(sym.logical_and(x[1] >= 1, x[1] <= 2.)),
            # Linear inequality
            prog.AddLinearConstraint(3 * x[0] - x[1] <= 2),
            # Linaer equality
            prog.AddLinearConstraint(x[0] + 2 * x[1] == 3)]

        # TODO(eric.cousineau): Add constant terms
        self.costs = [prog.AddLinearCost(x[0] + x[1]),
                      prog.AddQuadraticCost(0.5 * (x[0]**2 + x[1]**2))]
    def __init__(self):
        # Create a simple QP that uses all deduced linear constraint types,
        # along with a quadratic and linear cost.
        # The solution should be [1, 1].
        prog = mp.MathematicalProgram()
        x = prog.NewContinuousVariables(2, "x")
        self.prog = prog
        self.x = x
        self.constraints = [
            # Bounding box
            prog.AddLinearConstraint(x[0] >= 1),
            # Bounding box
            prog.AddLinearConstraint(sym.logical_and(x[1] >= 1, x[1] <= 2.)),
            # Linear inequality
            prog.AddLinearConstraint(3 * x[0] - x[1] <= 2),
            # Linear equality
            prog.AddLinearConstraint(x[0] + 2 * x[1] == 3)]

        # TODO(eric.cousineau): Add constant terms
        self.costs = [prog.AddLinearCost(x[0] + x[1]),
                      prog.AddQuadraticCost(0.5 * (x[0]**2 + x[1]**2))]