将MATLAB与AMPL结合使用 [英] Using MATLAB with AMPL
问题描述
我收集了一些用AMPL和GAMS编写的优化问题.而且我在Matlab中有一个算法.如何在Matlab中使用算法解决这些问题? 我已经阅读了GAMS的GDXMRW接口,但据我了解,该接口只能在Matlab& GAMS?因此,有必要在GAMS中执行梯度,导数等的所有计算,然后将这些结果提供给Matlab吗? 也许有人知道该如何连接?
(免责声明:我为MathWorks工作.)
我迟到了3年,但是对于其他阅读本书的人来说,您可以使用 https://ampl.com/api/1.2.2/matlab/quick-start.html ).对于问题中的非线性函数,您可以要求任何点的目标值,梯度和粗麻布计算.线性和二次函数作为MATLAB数组和矩阵存储在下面的amplprob字段中.
典型用途是
>> 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);
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?
(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);
这篇关于将MATLAB与AMPL结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!