% 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
% 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