Complete revision:
I have all 4 machines that can run in positive and negative directions which results in 2 outputs: $ P_1 = \begin{cases} -390 \le P_1 \le -300 & \text{for neg mode}\\ 0 & \text{for off mode}\\ 190 \le P_1 \le 380 & \text{for pos mode} \end{cases}$
These must match exactly the "Setpoint" while minimizing the efficiency. The efficiency for each machine is given by the equation: $ \frac{0.03}{190}x+0.937-0.2 \cdot i\\ \text{for i in the range number of machine} $ So far I tried formulating like this using 3 variables for each mode, but I still can't reformulate to constraint the output.
# Define the problem as a minimization problem, for each setpoint
for P_co in P_cos:
prob = LpProblem("HydroOptimization", LpMaximize)
# Define decision variables
P = [LpVariable(f"P{i}", P_min_p, P_max_t, cat="Continuous") for i in range(N)]
X = [LpVariable(f"X{i}{j}", cat ="Binary") for i in range(N) for j in ["p","t","z"]]
print(X)
Eff = LpVariable(f"Eff", lowBound=0, upBound= 1, cat='Continuous')
for i in range(N):
prob += X[3*i] + X[3*i+1] + X[3*i+2] == 1, f"Pump Turbine Zero condition{i}"
Less_eq = LpConstraint(e = P[i],
sense=LpConstraintLE,
rhs = P_max_p if X[3*i] == 1 else 0)
Great_eq = LpConstraint(e =P[i],
sense=LpConstraintGE,
rhs = P_min_t if X[3*i+1] == 1 else 0)
Great_eq = LpConstraint(e =P[i],
sense=LpConstraintEQ,
rhs = 0 if X[3*i+2] == 1 else 0)
prob.addConstraint(name = f"less_eq{i}", constraint=X[3*i]<=P[i]<=)
prob.addConstraint(name = f"Great_eq{i}", constraint=Great_eq)
prob.addConstraint(name = f"Prod{i}", constraint= LpAffineExpression(P[i], X[3*i]) + LpAffineExpression(P[i], X[3*i+1]) + X[3*i+2]*0 == P[i])
print(prob)
prob += lpSum(P) == P_co, "Setpoint"
# Define objective function
for i in range(N):
Eff += (-0.0000012*(P[i]-390)**2+1)*(P[i])
Eff = Eff/4*P_co
prob += Eff
print(prob)
# Solve the problem
status = prob.solve()
# Print the solution status
print("Solution status:", LpStatus[status])
# Print the decision variable values
print("P values:", [P[i].value() for i in range(N)])
print("Efficiency:",Eff.value())
Also later I would like to implement the start up and shutdown cost of each machine