Code to stop fmincon after running after an elapsed time
Show older comments
I am planning to use fmincon in a for loop to generate solutions to a stochastic optimization problem. The issue is that for some parameter values, fmincon will go on indefinitely and from what I've read, it gets stuck in some region of the space of objective variables. In these cases, I only intend for fmincon to stop and proceed with the next iteration.
How can I automate this?
I have read a couple of answers dating back to 2009 but I am unsure if there is a solution to this now. I could resolve the issue by doing it manually, i.e. ctrl+C to stop fmincon, but in a for loop how would that be implemented?
Answers (1)
You can use the OutputFcn option to implement any stopping criterion you wish. Write your Output Function to return a value of 1 when you are ready to stop.
I don't know if it is wise to use time as a criterion because you can't always be sure how long an iteration is meant to take. Better to stick with the MaxFunEvals and MaxIter options provided, in my opinion.
Categories
Find more on Choose a Solver in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!