Ordering of OptimizationVariables in an OptimizationProblem

When I use the problem-based optimization framework to create an OptimizationProblem, e.g.,
r=optimvar('r',5,'LowerBound',0,'UpperBound',1);
B= optimvar('B', 3);
prob=optimproblem('Constraints', sum(r)<=1,'Objective', sum(r)+sum(B));
the ordering of the variables in prob appears to be alphabetical,
prob.Variables
ans = struct with fields:
B: [3×1 optim.problemdef.OptimizationVariable] r: [5×1 optim.problemdef.OptimizationVariable]
However, I would prefer the ordering to be r first, then B. I thought I might be able to use orderfields() to change it, but no luck:
prob.Variables=orderfields(prob.Variables,{'r','B'})
OptimizationProblem property 'Variables' is read-only.
Is there a supported way of doing this?
The reason I want to do this is so that when I use,
s=prob2struct(prob);
the sub-matrix partitions of s.lb, s.ub, s.Aeq, etc... corresponding to r and B will have an ordering that I can know and control in advance. I'm assuming this ordering is dictated by the ordering of the fields in prob.Variables.

3 件のコメント

Bjorn Gustavsson
Bjorn Gustavsson 2021 年 5 月 25 日
Is it worth the hassle to use this modern/automatic "problem-based framework"? I've always shied away from this type of automatic parsing just because of not knowing/not being sure about how these things are handled. What are the benefits you see/expect?
Matt J
Matt J 2021 年 5 月 25 日
編集済み: Matt J 2021 年 5 月 25 日
IMO, it is at minimum often a convenient tool for setting up linear constraints. It spares you the mental gymnastics of having to figure out the matrix form of the constraints, especially when the constraints may involve multi-dimensional sums. Also, when the original mathematical formulation of the problem involves multiple unknown arrays like r and B, it spares you the effort of having to concatenate them into a single unknown vector.
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 5 月 26 日
So, I might be better off if I learn a new trick...

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSystems of Nonlinear Equations についてさらに検索

製品

リリース

R2020a

質問済み:

2021 年 5 月 24 日

コメント済み:

2021 年 5 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by