% By default, Lingo API is in the d:\LINGO15 folder
addpath('D:\\LINGO15');
% Load the Lingo API
loadlibrary('Lingd15', 'Lingd15.h');
if ~libisloaded('Lingd15')
error('Cannot load LINGO library');
end
% Print out LINGO library functions
libfunctions('Lingd15', '-full');
% Create the Lingo environment
pLingo = calllib('Lingd15', 'LScreateEnvLng');
if ~( exist('pLingo', 'var') && isa(pLingo, 'lib.pointer') )
error('Cannot create LINGO environment object');
end
% Open a Lingo log file
nError = calllib('Lingd15', 'LSopenLogFileLng', pLingo, 'D:\\LINGO15\\testLingoLib15.log');
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG')
error('Cannot open LINGO log file');
end
% Pass memory transfer pointers to LINGO
nError = calllib('Lingd15', 'LSsetPointerLng', pLingo, dNeedsPtr, nPointerNowPtr);
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG')
error('Cannot assign pointer');
end
nError = calllib('Lingd15', 'LSsetPointerLng', pLingo, dStartPtr, nPointerNowPtr);
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG')
error('Cannot assign pointer');
end
nError = calllib('Lingd15', 'LSsetPointerLng', pLingo, dOnDutyPtr, nPointerNowPtr);
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG')
error('Cannot assign pointer');
end
nError = calllib('Lingd15', 'LSsetPointerLng', pLingo, dTotalPtr, nPointerNowPtr);
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG')
error('Cannot assign pointer');
end
nError = calllib('Lingd15', '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('Lingd15', 'LSexecuteScriptLng', pLingo, sprintf(csScript));
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG')
error('Cannot execute script');
end
% Close log file
calllib('Lingd15', '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
3. 注意,MATLAB当前目录为先前创建的works文件夹,运行看结果:
MATLAB显示的:
Warning: The data type 'FcnPtr' used by function LSsetCallbackErrorLng does not exist.
> In loadlibrary (line 431)
In Staff (line 7)
Warning: The data type 'FcnPtr' used by function LSsetCallbackSolverLng does not exist.
> In loadlibrary (line 431)
In Staff (line 7)
Start : 0 4 1 0 0 0 2
Needs : 1 4 3 7 2 5 3
On Duty: 2 6 7 7 5 5 3
出错
loadlibrary>getLoadlibraryCompilerConfiguration
(line 497)
compilerConfiguration=compilerConfiguration(1);
%unix machines return c and cpp
compilers here