Objective and constraints having a common function - Problem based in Matlab 2016b

1 view (last 30 days)
Hi,
In my current optimization problem, both the objective and cosntraint functions are calculated following a time-consuming simulink run. In order to avoid having to run the simulation twice at each iteration (one to compute the objective, one to compute the constraint), I would like to apply the same method as described in https://fr.mathworks.com/help/optim/ug/objective-and-constraints-using-common-function.html.
However, my work only gives access to Matlab 2016b, and the functions used are not available yet : optimvar, fcn2optimexpr.
Is there a way to convert my function "compute_all" (which computes both the objective and the constraint) to an optimization expression, but in Matlab 2016b ?
Thank you for your help,
Thomas

Accepted Answer

Alan Weiss
Alan Weiss on 31 Jul 2020
Perhaps what you are looking for is in Objective and Nonlinear Constraints in the Same Function.
Alan Weiss
MATLAB mathematical toolbox documentation
  5 Comments
Alan Weiss
Alan Weiss on 31 Jul 2020
No, this is not the problem-based approach. However, I finally see what you are getting at. MultiStart runs the objective and constraint functions inside its call, and does not necessarily enable you to avoid the double evaluation. I think that you could write your objective and constraint functions using persistent variables to get the same functionality as the nested function trick. But that would take some work and testing.
I suggest that you simply write a loop calling fmincon repeatedly with different initial points, using the nested function trick to avoid double evaluation. Really, all MultiStart does is run such a loop. Well, it also gathers the results in a convenient form. You can duplicate that little nicety using an idea I described in Loren's blog.
The bottom line is, you might as well just use the nested function trick and fmincon because it is not so straightforward to get that functionality in MultiStart. Or write the equivalent computeall function using persistent variables, and then show us how you made it work.
Alan Weiss
MATLAB mathematical toolbox documentation
Thomas Gilormini
Thomas Gilormini on 4 Aug 2020
Okay, thanks a lot for your help ! I think I will follow your advice and simply run a loop using fmincon with different starting points, this seems more adapted to me.
Thank your for all the answers,
Thomas

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!