Using Matlab as a solver in LS-OPT

5 views (last 30 days)
Adwait
Adwait on 15 May 2015
Answered: Adwait on 27 Jun 2015
Hi,
I am trying to optimize a function in Matlab using LS-OPT, a design optimization tool. I am trying to implement this problem as a test case using Matlab instead of perl as the solver: http://www.lsoptsupport.com/examples-4.0/optimization-example
Eventually, I will replace the Matlab script with another script that runs a finite element model that takes about 15 minutes to run (one iteration).
I am having trouble integrating Matlab as the user-defined solver in LS-OPT. I am able to parameterize the Matlab script and get the script to terminate normally and compute the response f normally, but I'm not able to get the response back into LS-OPT to move to the next iteration. So LS-OPT thinks there is an error termination.
Any ideas on how to do get the response back to LS-OPT? Any help on integrating with LS-OPT would be appreciated.
PS: LS-OPT has a robust global optimization algorithm that uses response surface methodology for functions with long runtimes, so I chose this over Matlab's optimization commands.

Accepted Answer

Adwait
Adwait on 27 Jun 2015
As Ben mentioned above, the user defined solver must output 'N o r m a l' to the standard output (Windows command line, not Matlab command window) after a successful run for Matlab to proceed to the next iteration. This can be done by running a dummy batch file that runs the Matlab script and then outputs to standard output (echo N o r m a l). Alternatively, the system command can be used in Matlab to execute echo N o r m a l on the Windows command line.

More Answers (2)

Ben
Ben on 18 Jun 2015
Sorry for getting back to you this late, I was on a business trip.
It is most likely that LS-OPT is not continuing to the next iteration because the stage where your matlab script was running did not terminate properly. Remember that once your script is executed you need to terminate it with either 'N o r m a l' or 'E r r o r', else LS-OPT will not continue to the next stage.
You can include such a response in MATLAB in the following way:
if exist('output', 'file')
disp('N o r m a l');
else
disp('E r r o r');
end
where output.txt is any file which includes your response.
I hope this helpes you solve your problem!
Kind regards
Ben
  1 Comment
Adwait
Adwait on 27 Jun 2015
Thanks for your response. I was able to solve the problem.
Initially, I tried disp('N o r m a l') as you suggested. However, this outputs to the Matlab command window. LS-OPT looks for 'N o r m a l' in standard output, which is the Windows command line. I got around this by running a batch file in the command field of LS-OPT that then runs the Matlab script and prints 'N o r m a l' to the command line using the echo command:
matlab -nodesktop -nosplash -wait -r UVA_LX_opt_mbp_new
echo N o r m a l
An easier way to do this would be to use the system command in Matlab, but I haven't tested this with LS-OPT.

Sign in to comment.


Ben
Ben on 18 May 2015
Edited: Ben on 18 May 2015
Often this problem is related to wrong referencing of the output file. I recommend checking the response command. If this does not help, I recommend contacting your local dynamore support.
Good Luck and kind regards
Ben
Edit: At the moment I am working on a similar problem. I will update this thread if I can provide further information that will help you...

Categories

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

Products

Community Treasure Hunt

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

Start Hunting!