Home How to add a constraint to my optimization?
Reply: 2

How to add a constraint to my optimization?

Jhon Kami
Jhon Kami Published in 2017-12-07 09:42:07Z

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:


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?

Laure Reply to 2017-12-07 11:08:11Z

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.

Erwin Kalvelagen
Erwin Kalvelagen Reply to 2017-12-07 12:05:22Z

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}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.351671 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO