Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)))
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)))
def copy(self) -> "mip.LinExpr":
copy = LinExpr()
copy.__const = self.__const
copy.__expr = self.__expr.copy()
copy.__sense = self.__sense
return copy
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)))
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)))
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)))