QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 1907|回复: 3
打印 上一主题 下一主题

高手帮忙解决Matlab调用Lingo出错问题

[复制链接]
字体大小: 正常 放大
beifang        

8

主题

8

听众

209

积分

升级  54.5%

  • TA的每日心情
    开心
    2017-4-13 08:50
  • 签到天数: 66 天

    [LV.6]常住居民II

    自我介绍
    要有科研学习的精神
    跳转到指定楼层
    1#
    发表于 2014-11-5 09:28 |只看该作者 |倒序浏览
    |招呼Ta 关注Ta
    在最新的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');



    zan
    转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信

    15

    主题

    12

    听众

    91

    积分

    升级  90.53%

  • TA的每日心情
    慵懒
    2016-2-14 18:58
  • 签到天数: 27 天

    [LV.4]偶尔看看III

    邮箱绑定达人

    群组高等数学串讲

    群组2014第三期英语写作

    群组2015年美赛冲刺

    群组2015美赛备战交流群组

    群组2016美赛交流群组

    回复

    使用道具 举报

    15

    主题

    12

    听众

    91

    积分

    升级  90.53%

  • TA的每日心情
    慵懒
    2016-2-14 18:58
  • 签到天数: 27 天

    [LV.4]偶尔看看III

    邮箱绑定达人

    群组高等数学串讲

    群组2014第三期英语写作

    群组2015年美赛冲刺

    群组2015美赛备战交流群组

    群组2016美赛交流群组

    回复

    使用道具 举报

    21

    主题

    97

    听众

    3110

    积分

  • TA的每日心情
    奋斗
    2014-3-2 00:26
  • 签到天数: 243 天

    [LV.8]以坛为家I

       MATLAB本身可以调用LINGO,只是由于一些技术原因,64位的MATLAB不能调用64位的LINGO,32位的可以,可不要人云亦云,说什么什么不能调用,实则支持非常多的语言调用。
    有什么好说的
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 注册地址

    qq
    收缩
    • 电话咨询

    • 04714969085
    fastpost

    关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

    手机版|Archiver| |繁體中文 手机客户端  

    蒙公网安备 15010502000194号

    Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

    GMT+8, 2024-6-15 23:19 , Processed in 0.612838 second(s), 67 queries .

    回顶部