How to use the mip.entities.LinExpr function in mip

To help you get started, we’ve selected a few mip 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 coin-or / python-mip / mip / entities.py View on Github external
def __rsub__(
        self, other: Union["mip.Var", LinExpr, numbers.Real]
    ) -> Union["mip.Var", LinExpr]:
        if isinstance(other, Var):
            return LinExpr([self, other], [-1, 1])
        elif isinstance(other, LinExpr):
            return other.__sub__(self)
        elif isinstance(other, numbers.Real):
            return LinExpr([self], [-1], other)
        else:
            raise TypeError("type {} not supported".format(type(other)))
github coin-or / python-mip / mip / entities.py View on Github external
def __add__(
        self, other: Union["mip.Var", LinExpr, numbers.Real]
    ) -> Union["mip.Var", LinExpr]:
        if isinstance(other, Var):
            return LinExpr([self, other], [1, 1])
        if isinstance(other, LinExpr):
            return other.__add__(self)
        if isinstance(other, numbers.Real):
            if fabs(other) < mip.EPS:
                return self
            return LinExpr([self], [1], other)

        raise TypeError("type {} not supported".format(type(other)))
github coin-or / python-mip / mip / entities.py View on Github external
def copy(self) -> "mip.LinExpr":
        copy = LinExpr()
        copy.__const = self.__const
        copy.__expr = self.__expr.copy()
        copy.__sense = self.__sense
        return copy
github coin-or / python-mip / mip / entities.py View on Github external
def __rsub__(
        self, other: Union["mip.Var", LinExpr, numbers.Real]
    ) -> Union["mip.Var", LinExpr]:
        if isinstance(other, Var):
            return LinExpr([self, other], [-1, 1])
        elif isinstance(other, LinExpr):
            return other.__sub__(self)
        elif isinstance(other, numbers.Real):
            return LinExpr([self], [-1], other)
        else:
            raise TypeError("type {} not supported".format(type(other)))
github coin-or / python-mip / mip / entities.py View on Github external
def __ge__(self, other: Union["mip.Var", LinExpr, numbers.Real]) -> LinExpr:
        if isinstance(other, Var):
            return LinExpr([self, other], [1, -1], sense=">")
        elif isinstance(other, LinExpr):
            return other <= self
        elif isinstance(other, numbers.Real):
            if other != 0:
                return LinExpr([self], [1], -1 * other, sense=">")
            return LinExpr([self], [1], sense=">")
        else:
            raise TypeError("type {} not supported".format(type(other)))
github coin-or / python-mip / mip / entities.py View on Github external
def __sub__(
        self, other: Union["mip.Var", LinExpr, numbers.Real]
    ) -> Union["mip.Var", LinExpr]:
        if isinstance(other, Var):
            return LinExpr([self, other], [1, -1])
        elif isinstance(other, LinExpr):
            return (-other).__add__(self)
        elif isinstance(other, numbers.Real):
            if fabs(other) < mip.EPS:
                return self
            return LinExpr([self], [1], -other)
        else:
            raise TypeError("type {} not supported".format(type(other)))