In Python, I'm using the PuLP library to maximize values of side_1 and side_2. They have a constraint: The values of side_1 and side_2 must be equal and opposite to each other. I would like to set a minimum absolute value of side_1 and side_2. If that minimum absolute value cannot be reached, I'd like for the value to be 0 for both side_1 and side_2.
Below, the code will give me a value of -2 for side_1 and 2 for side_2. side_1 value must equal side_2 value:
model = p.pulp.LpProblem('linear_programming', p.LpMaximize)
solver = p.getSolver('PULP_CBC_CMD')
side_1 = p.LpVariable('side_1',lowBound=-3,upBound=0,cat='integer')
side_2 = p.LpVariable('side_2',lowBound=0,upBound=2,cat='integer')
sum_obj = side_2 - side_1
model+=sum_obj
sum_cons = side_2 + side_1 == 0
model += sum_cons
results = model.solve(solver=solver)
print(f'Model Resuts: {p.LpStatus[results]}')
I'd like to set an absolute minimum_threshold that the values can be, or set the result values to 0 for side_1 and side_2. In this case, if I set a threshold of 3, it would return 0 because side_2 has a upBound of 2
I've tried to add a constraint:
minimum_threshold = 3
constraint = side_2 * (minimum_threshold - side_2) >= 0
model += constraint
This would work, but PuLP does not allow multiplications of vars unless one side is a constant.
Are there any ways around this, or a different library that can handle the multiplication I tried above?