将MATLAB与AMPL结合使用 [英] Using MATLAB with AMPL

查看:367
本文介绍了将MATLAB与AMPL结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收集了一些用AMPL和GAMS编写的优化问题.而且我在Matlab中有一个算法.如何在Matlab中使用算法解决这些问题? 我已经阅读了GAMS的GDXMRW接口,但据我了解,该接口只能在Matlab& GAMS?因此,有必要在GAMS中执行梯度,导数等的所有计算,然后将这些结果提供给Matlab吗? 也许有人知道该如何连接?

解决方案

(免责声明:我为MathWorks工作.)

我迟到了3年,但是对于其他阅读本书的人来说,您可以使用 解决方案

(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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆