@@ -1701,6 +1701,15 @@ def __ge__(self, other: Union[float, int, highs_var, highs_linear_expression]):
17011701 else :
17021702 return highs_linear_expression (self ).__ge__ (other )
17031703
1704+ # self / scalar
1705+ def __truediv__ (self , other : Union [float , int , highs_linear_expression ]):
1706+ expr = highs_linear_expression (self )
1707+ expr /= other
1708+ return expr
1709+
1710+ # scalar / self
1711+ def __rtruediv__ (self , other : Union [float , int , highs_linear_expression ]):
1712+ raise Exception ("Only division of a linear expression by a scalar is allowed." )
17041713
17051714# highs constraint
17061715class highs_cons (object ):
@@ -2243,6 +2252,32 @@ def __isub__(self, other: Union[float, int, highs_var, highs_linear_expression])
22432252
22442253 self .constant = (self .constant or 0.0 ) - float (other )
22452254 return self
2255+
2256+ # expr / scalar
2257+ def __truediv__ (self , other : Union [float , int , highs_linear_expression ]):
2258+ copy = highs_linear_expression (self )
2259+ copy /= other
2260+ return copy
2261+
2262+ # expr /= scalar
2263+ def __itruediv__ (self , other : Union [float , int , highs_linear_expression ]):
2264+ if isinstance (other , (float , int )):
2265+ divisor = float (other )
2266+
2267+ elif isinstance (other , highs_linear_expression ) and other .idxs == [] and other .constant is not None :
2268+ divisor = float (other .constant )
2269+
2270+ else :
2271+ raise Exception ("Only division by a scalar is allowed." )
2272+
2273+ if divisor == 0 :
2274+ raise ZeroDivisionError ("division by zero" )
2275+
2276+ return self .__imul__ (1.0 / divisor )
2277+
2278+ # scalar / expr
2279+ def __rtruediv__ (self , other : Union [float , int , highs_var , highs_linear_expression ]):
2280+ raise Exception ("Only division of a linear expression by a scalar is allowed." )
22462281
22472282 def __imul__ (self , other : Union [float , int , highs_var , highs_linear_expression ]):
22482283 if isinstance (other , (float , int )):
0 commit comments