Effacer les filtres
Effacer les filtres

Convert result of an optimisation problem back to original variables

1 vue (au cours des 30 derniers jours)
Andrew Haselgrove
Andrew Haselgrove le 30 Mai 2019
I have constructed an optimisation problem with the problem-based framework, but would like to apply a range of solvers, so use prob2struct to convert the problem to the solver-based framework. In the 'Algorithms' section, it describes that, for decision variables, this is is the same as calling vars = [x(:);y(:)] on the decision variables.
My question is, how can this best be reversed? I am currently using the following:
function sol = toProblemVars(x, prob)
vars = prob.Variables;
idx = prob.varindex();
fields = fieldnames(vars);
for i = 1:numel(fields)
vars.(fields{i}) = zeros(size(vars.(fields{i})));
vars.(fields{i})(:) = x(idx.(fields{i}));
end
end
I have been trying to use deal or cell arrays to accomplish this in a neater manner, but have been unsuccessful.

Réponses (0)

Catégories

En savoir plus sur Problem-Based Optimization Setup dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by