Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert isinstance(expr, Expr)
expr *= sqrt(x)
assert isinstance(expr, GenExpr)
expr = x + y
assert isinstance(expr, Expr)
expr **= 1.5
assert isinstance(expr, GenExpr)
expr = x + y
assert isinstance(expr, Expr)
assert isinstance(expr + exp(x), GenExpr)
assert isinstance(expr - exp(x), GenExpr)
assert isinstance(expr/x, GenExpr)
assert isinstance(expr * x**1.2, GenExpr)
assert isinstance(sqrt(expr), GenExpr)
assert isinstance(abs(expr), GenExpr)
assert isinstance(log(expr), GenExpr)
assert isinstance(exp(expr), GenExpr)
with pytest.raises(ZeroDivisionError):
expr /= 0.0
expr += exp(z)
assert isinstance(expr, GenExpr)
expr = x + y
assert isinstance(expr, Expr)
expr -= exp(z)
assert isinstance(expr, GenExpr)
expr = x + y
assert isinstance(expr, Expr)
expr /= x
assert isinstance(expr, GenExpr)
expr = x + y
assert isinstance(expr, Expr)
expr *= sqrt(x)
assert isinstance(expr, GenExpr)
expr = x + y
assert isinstance(expr, Expr)
expr **= 1.5
assert isinstance(expr, GenExpr)
expr = x + y
assert isinstance(expr, Expr)
assert isinstance(expr + exp(x), GenExpr)
assert isinstance(expr - exp(x), GenExpr)
assert isinstance(expr/x, GenExpr)
assert isinstance(expr * x**1.2, GenExpr)
assert isinstance(sqrt(expr), GenExpr)
assert isinstance(abs(expr), GenExpr)
assert isinstance(log(expr), GenExpr)
assert isinstance(genexpr, GenExpr)
genexpr += exp(x)
assert isinstance(genexpr, GenExpr)
genexpr -= exp(x)
assert isinstance(genexpr, GenExpr)
genexpr /= log(x + 1)
assert isinstance(genexpr, GenExpr)
genexpr *= (x + y)**1.2
assert isinstance(genexpr, GenExpr)
genexpr /= exp(2)
assert isinstance(genexpr, GenExpr)
genexpr /= x + y
assert isinstance(genexpr, GenExpr)
genexpr = x**1.5 + y
assert isinstance(genexpr, GenExpr)
assert isinstance(sqrt(x) + genexpr, GenExpr)
assert isinstance(exp(x) + genexpr, GenExpr)
assert isinstance(1/x + genexpr, GenExpr)
assert isinstance(1/x**1.5 - genexpr, GenExpr)
assert isinstance(y/x - exp(genexpr), GenExpr)
# sqrt(2) is not a constant expression and
# we can only power to constant expressions!
with pytest.raises(NotImplementedError):
genexpr **= sqrt(2)
(5.791380, 1.214782),
(8.304504, 8.196392),
(9.812677, 5.284600),
(9.445761, 9.541600)]
m = Model()
a = m.addVar('a', lb=None)
b = m.addVar('b', ub=None)
r = m.addVar('r')
# minimize radius
m.setObjective(r, 'minimize')
for i,p in enumerate(points):
# NOTE: SCIP will not identify this as SOC constraints!
m.addCons( sqrt((a - p[0])**2 + (b - p[1])**2) <= r, name = 'point_%d'%i)
m.optimize()
bestsol = m.getBestSol()
assert abs(m.getSolVal(bestsol, r) - 5.2543) < 1.0e-3
assert abs(m.getSolVal(bestsol, a) - 6.1242) < 1.0e-3
assert abs(m.getSolVal(bestsol, b) - 5.4702) < 1.0e-3
def test_equation(model):
m, x, y, z = model
equat = 2*x**1.2 - 3*sqrt(y) == 1
assert isinstance(equat, ExprCons)
assert equat._lhs == equat._rhs
assert equat._lhs == 1.0
equat = exp(x+2*y) == 1 + x**1.2
assert isinstance(equat, ExprCons)
assert isinstance(equat.expr, GenExpr)
assert equat._lhs == equat._rhs
assert equat._lhs == 0.0
equat = x == 1 + x**1.2
assert isinstance(equat, ExprCons)
assert isinstance(equat.expr, GenExpr)
assert equat._lhs == equat._rhs
assert equat._lhs == 0.0
assert isinstance(genexpr, GenExpr)
genexpr /= exp(2)
assert isinstance(genexpr, GenExpr)
genexpr /= x + y
assert isinstance(genexpr, GenExpr)
genexpr = x**1.5 + y
assert isinstance(genexpr, GenExpr)
assert isinstance(sqrt(x) + genexpr, GenExpr)
assert isinstance(exp(x) + genexpr, GenExpr)
assert isinstance(1/x + genexpr, GenExpr)
assert isinstance(1/x**1.5 - genexpr, GenExpr)
assert isinstance(y/x - exp(genexpr), GenExpr)
# sqrt(2) is not a constant expression and
# we can only power to constant expressions!
with pytest.raises(NotImplementedError):
genexpr **= sqrt(2)