Quick substitution of all multi-objective optimization results (gamultiobj) into optimization expressions

18 views (last 30 days)
I'm using problem-based optimization formulation for the first time (it's great!) and I've been struggling a bit with how to interact seamlessly with the results. My optimization is multi-objective and the setup has the following characteristics:
  • Using problem-based optimization formulation, I'm defining many variables using optimvar (e.g., rho, D, W)
  • From there I'm defining objective and constraint functions as OptimizationExpression objects, e.g. V=pi*(D/2)^2*W, M=rho*V (simplified but still relevant to my actual problem)
  • In my case, minimizing volume V is one of the objectives, but M is a part of another objective as well as some constraints, so I would like to quickly evaluate the OptimizationExpression M over the optimization results (Pareto front) returned within sol and use it in some post-processing plots.
After much experimentation, I did find that I can substitute a particular result by index into an existing OptimizationExpression object using the following syntax:
ii=10; % Index of solution I'm interested in
solStruct=struct(sol(ii));
Mval=evaluate(M,solStruct.Values);
Obviously I can build a loop over ii to get an array Mval, but is there a way to do it more elegantly? (And am I using the intended method to evaluate a single solution from the optimization?)

Answers (1)

Matt J
Matt J about 9 hours ago
Edited: Matt J 1 minute ago
Obviously I can build a loop over ii to get an array Mval, but is there a way to do it more elegantly?
Doesn't seem it like it. If "more elegantly" means doing it in one line of code, you can make your own mfile function to hide the loop, or you can use arrayfun,
Mval=arrayfun( @(s) evaluate(M,struct(s).Values) ,sol);

Community Treasure Hunt

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

Start Hunting!