简体   繁体   English

如何为我的优化添加约束?

[英]How to add a constraint to my optimization?

I am working on formulating an optimization problem where I have a 2-D matrix A. 我正在制定一个具有二维矩阵A的优化问题。

           A= [0 f1 0 f2]
              [f3 f3 0 0]
              .........

And I have another 2-D matrix B that I should fill. 我还有另一个二维矩阵B应该填写。 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. B具有与A相同的大小。如果a_ij = 0(A的元素),则我需要b_ij(B的元素)为零;如果a_ij不为零,则我需要b_ij大于零且小于或等于a_ij。

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. 但这不满足以下条件:当a_ij不等于零时,b_ij不等于零。 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 = 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元素小于或等于A元素,否则将其替换为A的值。

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. 如果a_ij的元素大于零,则指示需要b_ij的元素大于零。 An option is to use the function max to ensure that all elements of B are positive. 一种选择是使用函数max来确保B所有元素均为正。

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. 如果a是(恒定)数据,那么这是微不足道的。 If a is a variable then things are not so easy. 如果a是变量,那么事情就不那么容易了。

You implemented part of the implications as 您实现了部分含义为

b <= a

This implies a is non-negative: a>=0 . 这意味着a为非负数: a>=0 It also implies b is non-negative. 这也意味着b为非负数。 The remaining implication a>0 => b>0 can now be implemented as 剩下的含义a>0 => b>0现在可以实现为

a <= δ * 1000
b >= δ / 1000
δ in {0,1}

Many MIP solvers support indicator constraints. 许多MIP求解器支持指标约束。 That would allow you to say: 那可以让你说:

δ = 0 -> a = 0
δ = 1 -> b >= 0.001 
δ in {0,1}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM