Beispiel #1
0
    def test_casso1(self):
        solver = SimplexSolver()
        x = Variable('x')
        y = Variable('y')

        solver.add_constraint(Constraint(x, Constraint.LEQ, y))
        solver.add_constraint(Constraint(y, Constraint.EQ, x + 3))
        solver.add_constraint(Constraint(x, Constraint.EQ, 10, WEAK))
        solver.add_constraint(Constraint(y, Constraint.EQ, 10, WEAK))

        self.assertTrue(
            (approx_equal(x.value, 10) and approx_equal(y.value, 13))
            or (approx_equal(x.value, 7) and approx_equal(y.value, 10)))
    def test_casso1(self):
        solver = SimplexSolver()
        x = Variable('x')
        y = Variable('y')

        solver.add_constraint(Constraint(x, Constraint.LEQ, y))
        solver.add_constraint(Constraint(y, Constraint.EQ, x + 3))
        solver.add_constraint(Constraint(x, Constraint.EQ, 10, WEAK))
        solver.add_constraint(Constraint(y, Constraint.EQ, 10, WEAK))

        self.assertTrue(
            (approx_equal(x.value, 10) and approx_equal(y.value, 13)) or
            (approx_equal(x.value,  7) and approx_equal(y.value, 10))
        )
    def assertExpressionEqual(self, expr1, expr2):

        if not isinstance(expr1, Expression):
            return False

        if not isinstance(expr2, Expression):
            return False

        if not approx_equal(expr1.constant, expr2.constant):
            return False

        if len(expr1.terms) != len(expr2.terms):
            return False

        if any(expr2.terms.get(var) != value for var, value in expr1.terms.items()):
            return False

        return True
Beispiel #4
0
    def assertExpressionEqual(self, expr1, expr2):

        if not isinstance(expr1, Expression):
            return False

        if not isinstance(expr2, Expression):
            return False

        if not approx_equal(expr1.constant, expr2.constant):
            return False

        if len(expr1.terms) != len(expr2.terms):
            return False

        if any(
                expr2.terms.get(var) != value
                for var, value in expr1.terms.items()):
            return False

        return True