How to automatically constrain some of the unknown values in an optimization problem?

1 回表示 (過去 30 日間)
Rikke
Rikke 2019 年 3 月 20 日
コメント済み: Rikke 2019 年 3 月 20 日
I have an optimization problem with several unknown values (x) which is a part of an array:
A=[0 0 x(1) x(2) 0 0 0 x(3) x(4) x(5) 0 0 0 x(6) 0 0 x(7) x(8)];
The x-values are to be optimized but each x-'group', which is separated by the zeros, are to be equal to each other. ex.: x(1)=x(2) and x(3)=x(4)=x(5) and so on. x(6) is not to be equal to another x because it is not in a 'group' with other x's, therfore x(6) will not be constrained.
I am supposed to write this constraint as ceq(x)=[..] in a constraint function.
Is there any automatic coding that can constrain these x-values in the way i explained?

採用された回答

Torsten
Torsten 2019 年 3 月 20 日
If you know in advance which elements of the x-vector are grouped together, you can simply use Aeq and beq to define the equality constraints. No need to use the nonlinear constraints option in ceq.
  2 件のコメント
Rikke
Rikke 2019 年 3 月 20 日
Thanks for your respond! I know which one is grouped together, but it will be time consuming because I actually have an array of 1740 elements with 55 of them as the unknown x-values. And I want the optimization model to work with any kind of array not only the one I have for the moment.
Matt J
Matt J 2019 年 3 月 20 日
編集済み: Matt J 2019 年 3 月 20 日
@Rikke,
How are the groupings of the 55 unknowns specified as input? Do you have some sort of binary map?

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

その他の回答 (1 件)

Matt J
Matt J 2019 年 3 月 20 日
編集済み: Matt J 2019 年 3 月 20 日
I will assume you have some binary vector v which indicates the groupings of the variables, so for example this,
[0 0 x(1) x(2) 0 0 0 x(3) x(4) x(5) 0 0 0 x(6) 0 0 x(7) x(8)];
would be input as the vector
v=[0 0 1 1 0 0 0 1 1 1 0 0 0 1 0 0 1 1];
Then you can construct the linear equality constraint matrices Aeq, beq as follows
Aeq=diff(speye(numel(v)) ,1,1);
discard=(v(1:end-1)==0)|(diff(v)~=0);
Aeq(discard,:)=[];
Aeq(:,~v)=[];
beq=zeros(size(Aeq,1),1);
  2 件のコメント
Matt J
Matt J 2019 年 3 月 20 日
For the 8-variable example that you posted, this should result in
>> full(Aeq), full(beq).'
ans =
-1 1 0 0 0 0 0 0
0 0 -1 1 0 0 0 0
0 0 0 -1 1 0 0 0
0 0 0 0 0 0 -1 1
ans =
0 0 0 0
indicating that the first two unknowns will be equal, the next 3 unknowns will be equal and the final two unknowns will be equal.
Rikke
Rikke 2019 年 3 月 20 日
Thank you so much Matt J, it worked!

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

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by