I have a problem, where I have to find the optimal cost of 3 given motor.
Motor 1 has a range of 100 - 300 Motor 2 has a range of 400 - 1000 Motor 3 has a range of 50 - 250
They have a target value of 600
Motor 1 price is 5000 Motor 2 price is 5500 Motor 3 price is 5250
The equation looks like this:
Cost = Motor1 * 5000 + Motor2 * 5500 + Motor3 * 5250.
And a very important part, NOT every motor needs to run.
I have a python code, that can calculate it, but I can give it to it that not every motors needs to be inclued. Here is the code:
from pulp import LpProblem, LpVariable, LpMinimize
def find_lowest_cost():
# Define the problem
problem = LpProblem("Motor Optimization", LpMinimize)
# Define the decision variables
x = LpVariable("Motor1", lowBound=100, cat='Integer') # Power of motor 1
y = LpVariable("Motor2", lowBound=0, cat='Integer') # Power of motor 2
z = LpVariable("Motor3", lowBound=50, cat='Integer') # Power of motor 3
# Define the objective function (cost)
problem += x * 5000 + y * 5500 + z * 5250
# Define the constraints
problem += x >= 100 # Motor 1 lower bound
problem += x <= 300 # Motor 1 upper bound
problem += y >= 350 # Motor 2 lower bound
problem += y <= 1000 # Motor 2 upper bound
problem += z >= 50 # Motor 3 lower bound
problem += z <= 250 # Motor 3 upper bound
problem += x + y + z == 500 # Total power constraint
# Solve the problem
problem.solve()
# Retrieve the optimal solution
lowest_cost = problem.objective.value()
best_combination = (x.value(), y.value(), z.value())
return lowest_cost, best_combination
cost, combination = find_lowest_cost()
print("Lowest cost:", cost)
print("Motor combination:", combination)
I tried to add 'or' to the "Define the Constraints' part, but it did not help
problem += x >= 100 or x ==0 # Motor 1 lower bound
problem += x <= 300 # Motor 1 upper bound
problem += y >= 350 or y == 0 # Motor 2 lower bound
problem += y <= 1000 # Motor 2 upper bound
problem += z >= 50 or z == 0 # Motor 3 lower bound
problem += z <= 250 # Motor 3 upper bound
problem += x + y + z == 500 # Total power constraint
So my Questions is, how to implement that 'OR' into my code.
Thank you in advance