diff --git a/python/cuopt/cuopt/linear_programming/problem.py b/python/cuopt/cuopt/linear_programming/problem.py index baf971619..80cb83ee6 100644 --- a/python/cuopt/cuopt/linear_programming/problem.py +++ b/python/cuopt/cuopt/linear_programming/problem.py @@ -195,6 +195,12 @@ def getVariableName(self): """ return self.VariableName + def __neg__(self): + return LinearExpression([self], [-1.0], 0.0) + + def __pos__(self): + return self + def __add__(self, other): match other: case int() | float(): @@ -204,6 +210,8 @@ def __add__(self, other): return LinearExpression([self, other], [1.0, 1.0], 0.0) case LinearExpression(): return other + self + case QuadraticExpression(): + return other + self case _: raise ValueError( "Cannot add type %s to variable" % type(other).__name__ @@ -221,6 +229,8 @@ def __sub__(self, other): case LinearExpression(): # self - other -> other * -1.0 + self return other * -1.0 + self + case QuadraticExpression(): + return other * -1.0 + self case _: raise ValueError( "Cannot subtract type %s from variable"