Ordering of OptimizationVariables in an OptimizationProblem
Afficher commentaires plus anciens
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
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'})
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 commentaires
Bjorn Gustavsson
le 25 Mai 2021
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?
Bjorn Gustavsson
le 26 Mai 2021
So, I might be better off if I learn a new trick...
Réponses (0)
Catégories
En savoir plus sur Systems of Nonlinear Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!