Find the minimum positive value between two decisions variables in MILP Environment and big-M method

14 visualizzazioni (ultimi 30 giorni)
In a MILP I have two decision variables, for convenience called A and B of size (T,D).
I would like to calculate the positive minimum value between A and B in the consecutive 16 instants and allocate it in the new decision variable D, of size (T/16,D).
The minimum should be the smallest positive value in any row of A and B, or it can be 0 if all 16 consecutive values of A and/or B are zero.
A = optimvar('A', T,N, 'LowerBound', 0,'UpperBound', Pmax,'Type','continuous');
B = optimvar('B', T,N, 'LowerBound', 0,UpperBound', Pmax,'Type','continuous');
D = optimvar('D', T/16,N, 'LowerBound', 0,'UpperBound', Pmax,'Type','continuous');
A and B are constrained as :
chargecons = x + A <= Pmax * u_c;
dischargecons = y + B <= Pmax * u_d;
onlyConlyD = u_c + u_d <= 1;
where x and y are others decisions variables.
The goal would be to calculate :
for k = 1: T/16
t_start = 16*(k-1) + 1 : k*16 ;
for t = t_start
D(k,d) = min(A(t,d) , B(t,d));
end
end
but of course linearized the constraints, so my idea was :
for k = 1: T/16
t_start = 16*(k-1) + 1 : k*16 ;
for t = t_start
mincons1(t,d) = D(k,d) <= A(t,d) + M * (1-z1(t,d));
mincons2(t,d) = D(k,d) <= B(t,d) + M * (1-z2(t,d));
end
end
where z1 and z2 are binary variables.
But the problem is that since the objective function is profit maximisation where x,y and D are present but not A or B, the solver simply sets A = B = 0 and gives a maximum value to D.
The other problem I have is how to handle the case where for the same row both A and B are = 0, D is automatically set to zero, but this is not the case I would like. I just want to get the minimum positive value between A and B within the block.

Risposte (1)

Umar
Umar il 23 Ott 2024 alle 12:58

Hi @Edoardo Beduglio,

To achieve your objective of calculating the positive minimum value between (A) and (B) over 16 consecutive time steps while maintaining constraints, you need to adjust the way we handle the constraints involving the binary variables (z_1) and (z_2). You want to ensure that if either A(t,d) or (B(t,d) has a positive value, then (D(k,d) should reflect the smallest positive value. If both are zero, you want (D(k,d) to also be zero. Here is how you can reformulate your constraints:

   for k = 1: T/16
       t_start = 16*(k-1) + 1 : k*16 ;
       for t = t_start
           mincons1(t,d) = D(k,d) <= A(t,d) + M * (1 - z1(t,d));
           mincons2(t,d) = D(k,d) <= B(t,d) + M * (1 - z2(t,d));
           % Ensure D(k,d) is set to zero if both A and B are zero
           mincons3(t,d) = z1(t,d) + z2(t,d) >= 1; % At least one must be 
           positive
       end
   end

Here, (M) is a large constant. The constraint mincons3 ensures that at least one of the binary variables must be activated if both decision variables are non-zero. Now to make sure that when both values are zero, you correctly set (D(k,d), you can introduce another binary variable, say (z3(t,d)) which indicates whether both A(t,d) and B(t,d) are zero:

   z3(t,d) = (A(t,d)==0 & B(t,d)==0);

Then modify your constraints accordingly:

   D(k,d) <= M * (1 - z3(t,d)); % If both are zero, D must also be zero.

Since your objective function focuses on profit maximization involving (x), (y)and (D)you should ensure that while maximizing profit, it does not inadvertently drive your decision variables (A) and (B) to zero. Consider adding penalties or rewards in your objective function that account for maintaining non-zero values in either of those matrices. Here is a simplified version of how your loop might look:

for k = 1: T/16
  t_start = 16*(k-1)+1 : k*16;
  for t = t_start
      % Minimum constraints
      mincons1(t,d) = D(k,d) <= A(t,d) + M * (1 - z1(t,d));
      mincons2(t,d) = D(k,d) <= B(t,d) + M * (1 - z2(t,d));
        % Both A and B cannot be zero at the same time without affecting D
        mincons3(t,d) = z1(t,d) + z2(t,d) >= 1; 
    end
  end

When tuning parameters, make sure that the constant (M) is appropriately chosen; it should be large enough to not constrain feasible solutions but not excessively large as it may lead to numerical instability in optimization.

Depending on the solver you are using, you might need to experiment with different formulations or settings to achieve optimal performance without unintended consequences on variable values.

By carefully structuring your constraints and handling edge cases effectively, you can ensure that your MILP formulation accurately captures the desired behavior of your decision variables while still achieving your overall objective of profit maximization.

Hope this helps.

Categorie

Scopri di più su Linear Programming and Mixed-Integer Linear Programming in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by