Convert result of an optimisation problem back to original variables

1 次查看(过去 30 天)
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.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Problem-Based Optimization Setup 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by