I am working on formulating an optimization problem where I have a 2-D matrix A.
A= [0 f1 0 f2]
[f3 f3 0 0]
.........
And I have another 2-D matrix B that I should fill. B has the same size of A. I need b_ij (element of B) to be zero if a_ij=0 (element of A) and I need b_ij to be greater than zero and less than or equal to a_ij if a_ij is not zero.
How can I represent this in my formulation? I have added this constraint/condition:
b_ij<=a_ij
But this does not satisfy the condition that states that b_ij is not equal zero when a_ij is not equal zero. Any help?
If all elements are positive, keep the smallest element of each matrix by doing an element by element comparison :
B2 = min(A,B)
Alternatively, create a logical matrix indicating if a condition is answered and multiply element by element with the matrix B
, only elements who satisfy the condition remain, others are set to zero:
B = B.*(A~=0)
Then keep elements of B
that are smaller or equal to elements of A
, and replace them by the value of A
otherwise.
B = B.*(B<=A) + A.*(B>A) )
This option lets you generalize your constraint.
You indicate needing elements of b_ij to be greater than zero if elements of a_ij are greater than zero. An option is to use the function max
to ensure that all elements of B
are positive.
B = max(1e-2,B); % exact value is yours to set.
This step is up to you and depend on your problem.
You want to implement the implication
a = 0 => b = 0
a <> 0 => 0 < b <= a
If a
is (constant) data this is trivial. If a
is a variable then things are not so easy.
You implemented part of the implications as
b <= a
This implies a
is non-negative: a>=0
. It also implies b
is non-negative. The remaining implication a>0 => b>0
can now be implemented as
a <= δ * 1000
b >= δ / 1000
δ in {0,1}
Many MIP solvers support indicator constraints. That would allow you to say:
δ = 0 -> a = 0
δ = 1 -> b >= 0.001
δ in {0,1}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.