Matlab能否调用Lingo?
哪位高手知道,怎么使用Matlab调用Lingo编的程序?
使用Lingo的API 我把API传上来,你可以看到安装后里面有很多其他语言调用的API,还有一些帮助文档可以参考 在最新的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 = ;
% 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 = ;
csScript = ;
% 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');
应该能把,我觉得。。。。
我运行程序,但是有错误
页:
[1]