- 在线时间
- 53 小时
- 最后登录
- 2017-4-13
- 注册时间
- 2012-12-23
- 听众数
- 8
- 收听数
- 0
- 能力
- 0 分
- 体力
- 547 点
- 威望
- 0 点
- 阅读权限
- 30
- 积分
- 209
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 88
- 主题
- 8
- 精华
- 0
- 分享
- 0
- 好友
- 7
升级   54.5% TA的每日心情 | 开心 2017-4-13 08:50 |
---|
签到天数: 66 天 [LV.6]常住居民II
- 自我介绍
- 要有科研学习的精神
|
在最新的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');
|
|