Filter löschen
Filter löschen

Convert result of an optimisation problem back to original variables

1 Ansicht (letzte 30 Tage)
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.

Antworten (0)

Kategorien

Mehr zu Problem-Based Optimization Setup finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by