How to use the pyscipopt.scip.Term function in PySCIPOpt

To help you get started, we’ve selected a few PySCIPOpt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SCIP-Interfaces / PySCIPOpt / tests / test_linexpr.py View on Github external
def test_operations_quadratic(model):
    m, x, y, z = model
    expr = x*x
    assert isinstance(expr, Expr)
    assert expr[x] == 0.0
    assert expr[y] == 0.0
    assert expr[CONST] == 0.0
    assert expr[Term(x,x)] == 1.0

    expr = x*y
    assert isinstance(expr, Expr)
    assert expr[x] == 0.0
    assert expr[y] == 0.0
    assert expr[CONST] == 0.0
    assert expr[Term(x,y)] == 1.0

    expr = (x - 1)*(y + 1)
    assert isinstance(expr, Expr)
    assert expr[x] == 1.0
    assert expr[y] == -1.0
    assert expr[CONST] == -1.0
    assert expr[Term(x,y)] == 1.0
github SCIP-Interfaces / PySCIPOpt / tests / test_linexpr.py View on Github external
assert expr[CONST] == 0.0
    assert expr[Term(x,x)] == 1.0

    expr = x*y
    assert isinstance(expr, Expr)
    assert expr[x] == 0.0
    assert expr[y] == 0.0
    assert expr[CONST] == 0.0
    assert expr[Term(x,y)] == 1.0

    expr = (x - 1)*(y + 1)
    assert isinstance(expr, Expr)
    assert expr[x] == 1.0
    assert expr[y] == -1.0
    assert expr[CONST] == -1.0
    assert expr[Term(x,y)] == 1.0
github SCIP-Interfaces / PySCIPOpt / tests / test_expr.py View on Github external
import pytest

from pyscipopt import Model, sqrt, log, exp
from pyscipopt.scip import Expr, GenExpr, ExprCons, Term, quicksum

@pytest.fixture(scope="module")
def model():
    m = Model()
    x = m.addVar("x")
    y = m.addVar("y")
    z = m.addVar("z")
    return m, x, y, z

CONST = Term()

def test_upgrade(model):
    m, x, y, z = model
    expr = x + y
    assert isinstance(expr, Expr)
    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
github SCIP-Interfaces / PySCIPOpt / tests / test_linexpr.py View on Github external
def test_operations_poly(model):
    m, x, y, z = model
    expr = x*x*x + 2*y*y
    assert isinstance(expr, Expr)
    assert expr[x] == 0.0
    assert expr[y] == 0.0
    assert expr[CONST] == 0.0
    assert expr[Term(x,x,x)] == 1.0
    assert expr[Term(y,y)] == 2.0
    assert expr.terms == (x**3 + 2*y**2).terms
github SCIP-Interfaces / PySCIPOpt / tests / test_linexpr.py View on Github external
def test_operations_poly(model):
    m, x, y, z = model
    expr = x*x*x + 2*y*y
    assert isinstance(expr, Expr)
    assert expr[x] == 0.0
    assert expr[y] == 0.0
    assert expr[CONST] == 0.0
    assert expr[Term(x,x,x)] == 1.0
    assert expr[Term(y,y)] == 2.0
    assert expr.terms == (x**3 + 2*y**2).terms
github SCIP-Interfaces / PySCIPOpt / tests / test_linexpr.py View on Github external
def test_power_for_quadratic(model):
    m, x, y, z = model
    expr = x**2 + x + 1
    assert isinstance(expr, Expr)
    assert expr[Term(x,x)] == 1.0
    assert expr[x] == 1.0
    assert expr[CONST] == 1.0
    assert len(expr.terms) == 3

    assert (x**2).terms == (x*x).terms
    assert ((x + 3)**2).terms == (x**2 + 6*x + 9).terms
github SCIP-Interfaces / PySCIPOpt / tests / test_linexpr.py View on Github external
import pytest

from pyscipopt import Model
from pyscipopt.scip import Expr, ExprCons, Term, quicksum

@pytest.fixture(scope="module")
def model():
    m = Model()
    x = m.addVar("x")
    y = m.addVar("y")
    z = m.addVar("z")
    return m, x, y, z

CONST = Term()

def test_term(model):
    m, x, y, z = model
    assert x[x] == 1.0
    assert x[y] == 0.0

def test_operations_linear(model):
    m, x, y, z = model
    expr = x + y
    assert isinstance(expr, Expr)
    assert expr[x] == 1.0
    assert expr[y] == 1.0
    assert expr[z] == 0.0

    expr = -x
    assert isinstance(expr, Expr)