How to change optimization variable

How to take the number of zero elements of an optimization variable as part of the constraint condition?I want to take the number of non-zero solutions of the optimization variable x as part of the constraint.

 採用された回答

Matt J
Matt J 2021 年 9 月 11 日
編集済み: Matt J 2021 年 9 月 11 日

1 投票

You cannot do that in a continuous optimization problem, although in sparse optimization, it is common to approximate the number of non-zeros as norm(x,1).
If it's a binary linear programming that you're solving, the number of non-zeros is simply the linear function sum(x). If it's a more general integer linear program where 0<=x(i)<=M, you can introduce extra binary variables z with the constraint that x/M<=z<=x, and the number of non-zeros will then be sum(z).

3 件のコメント

培国 原
培国 原 2021 年 9 月 11 日
"Constraints must be an OptimizationConstraint or a struct containing OptimizationConstraints."
I always have this problem when I calculate. How can I solve it?
培国 原
培国 原 2021 年 9 月 11 日
Thank you very much for your advice, which is very useful!
Matt J
Matt J 2021 年 9 月 11 日
You're welcome, but if you consider your question answered, please click Accept.

サインインしてコメントする。

その他の回答 (0 件)

質問済み:

2021 年 9 月 11 日

コメント済み:

2021 年 9 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by