数学建模社区-数学中国

标题: 高手帮忙解决Matlab调用Lingo出错问题 [打印本页]

作者: beifang    时间: 2014-11-5 09:28
标题: 高手帮忙解决Matlab调用Lingo出错问题
在最新的Lingo 15.0版本里已经有了Matlab调用Lingo的例子,但运行有错误。

clear; clc;

% By default, 64-bit Lingo API is in the C:\LINGO64_15 folder
addpath('C:\\LINGO64_15');

% Load the Lingo API
loadlibrary('Lingd64_15', 'Lingd15.h');
if ~libisloaded('Lingd64_15')
    error('Cannot load LINGO library');
end

% Print out LINGO library functions
libfunctions('Lingd64_15', '-full');

% Create the Lingo environment
pLingo = calllib('Lingd64_15', 'LScreateEnvLng');
if ~( exist('pLingo', 'var') && isa(pLingo, 'lib.pointer') )
    error('Cannot create LINGO environment object');
end

% Open a Lingo log file
nError = calllib('Lingd64_15', 'LSopenLogFileLng', pLingo, 'C:\\LINGO64_15\\testLingoLib15.log');
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG'), error('Cannot open LINGO log file'); end

% Staffing needs
dNeeds = [1 4 3 7 2 5 3];

% Pointers to memory transfer areas
dNeedsPtr = libpointer('doublePtr', dNeeds);
dStartPtr = libpointer('doublePtr', zeros(1, 7));
dOnDutyPtr = libpointer('doublePtr', zeros(1, 7));
dStatusPtr = libpointer('doublePtr', -1);
dTotalPtr = libpointer('doublePtr', 0);
nPointerNowPtr = libpointer('int32Ptr', 0);

% Pass memory transfer pointers to LINGO
nError = calllib('Lingd64_15', 'LSsetPointerLng', pLingo, dNeedsPtr, nPointerNowPtr);
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG'), error('Cannot assign pointer'); end
nError = calllib('Lingd64_15', 'LSsetPointerLng', pLingo, dStartPtr, nPointerNowPtr);
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG'), error('Cannot assign pointer'); end
nError = calllib('Lingd64_15', 'LSsetPointerLng', pLingo, dOnDutyPtr, nPointerNowPtr);
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG'), error('Cannot assign pointer'); end
nError = calllib('Lingd64_15', 'LSsetPointerLng', pLingo, dTotalPtr, nPointerNowPtr);
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG'), error('Cannot assign pointer'); end
nError = calllib('Lingd64_15', 'LSsetPointerLng', pLingo, dStatusPtr, nPointerNowPtr);
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG'), error('Cannot assign pointer'); end

% Set up the command script
csScript = 'SET ECHOIN 1 \n';
csScript = [csScript 'TAKE STAFFPTR.lng \n'];
csScript = [csScript 'GO \n'];
csScript = [csScript 'QUIT \n'];

% Run the script
nError = calllib('Lingd64_15', 'LSexecuteScriptLng', pLingo, sprintf(csScript));
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG'), error('Cannot execute script'); end

% Close log file
calllib('Lingd64_15', 'LScloseLogFileLng', pLingo);

% Optimal?
if get(dStatusPtr, 'value')
    error('Unable to solve!');
else
    % Display solution
    disp(['Start  : ' num2str(dStartPtr.value)]);
    disp(['Needs  : ' num2str(dNeedsPtr.value)]);
    disp(['On Duty: ' num2str(dOnDutyPtr.value)]);
end

% Free Lingo environment
calllib('Lingd64_15', 'LSdeleteEnvLng', pLingo);

但调用出现如下错误:
??? Error using ==> loadlibrary>lFullPath at 545
Could not find file Lingd15.h.

Error in ==> loadlibrary at 220
        header=lFullPath(header);

Error in ==> Staff at 7
loadlibrary('Lingd64_15', 'Lingd15.h');




作者: wangrui2014    时间: 2015-1-26 14:36
我听说,matlabbenshenbunengdiaoyonglingo

作者: wangrui2014    时间: 2015-1-26 14:36
我听说,matlab本身不能调用lingo

作者: wujianjack2    时间: 2015-1-27 09:35
   MATLAB本身可以调用LINGO,只是由于一些技术原因,64位的MATLAB不能调用64位的LINGO,32位的可以,可不要人云亦云,说什么什么不能调用,实则支持非常多的语言调用。





欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5