问题
I have a collection of optimization problems written in AMPL and GAMS. And I have an algorithm in Matlab. How can I solve these problems with algorithm in Matlab? I've read about GDXMRW interface for GAMS, but as I understood it can only exchange data between Matlab & GAMS? So will it be necessary to perform all calculations of gradients, derivatives etc. in GAMS and then to give these results to Matlab? Maybe someone knows how to connect this?
回答1:
(Disclaimer: I work for MathWorks.)
I am 3 years late but for anyone else that read this, you can use https://www.mathworks.com/matlabcentral/fileexchange/64634-ampl-interface-to-matlab. For AMPL problems, I think this is exactly what you are looking for.
It gives you an interface to AMPL problems (stored either in nl-files or objects of AMPL-API https://ampl.com/api/1.2.2/matlab/quick-start.html). For nonlinear functions in your problem, you can ask for objective value, gradient and hessian computations for any point. Linear and quadratic functions are stored in fields of amplprob below as MATLAB arrays and matrices.
A typical use is
>> amplprob = amplread('my_problem.nl')
>> % objective value of the first nonlinear objective function
>> f = nonlinobjective(amplprob,x,1)
>> % value, gradient and hessian of the first nonlinear objective function
>> [f,J,H] = nonlinobjective(amplprob,x,1)
>> % value and gradient of the second nonlinear constraint at x
>> [g, G] = nonlinconstr(amplprob,x,2);
回答2:
You can connect AMPL to MATLAB using amplfunc.mex
and spamfunc.mex
described in Hooking Your Solver to AMPL, page 23. These mex files are available for download from http://www.ampl.com/DOWNLOADS/solvers/examples/. Gradient can be computed automatically using the amplfunc
function provided by the amplfunc.mex
.
There is also an AMPL interface to MATLAB developed by TOMLAB.
来源:https://stackoverflow.com/questions/26296567/using-matlab-with-ampl