QQ登录

只需要一步,快速开始

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

跪求高手,Matlab调用Lingo出错问题

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

8

主题

8

听众

209

积分

升级  54.5%

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

    [LV.6]常住居民II

    自我介绍
    要有科研学习的精神
    跳转到指定楼层
    1#
    发表于 2014-11-5 09:59 |只看该作者 |倒序浏览
    |招呼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 微信微信

    21

    主题

    97

    听众

    3110

    积分

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

    [LV.8]以坛为家I

      注意两个问题:
      1. LINGO安装路径;
      2. MATLAB与LINGO的版本匹配,32位,64位要对应;

      
      
    回复

    使用道具 举报

    beifang        

    8

    主题

    8

    听众

    209

    积分

    升级  54.5%

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

    [LV.6]常住居民II

    自我介绍
    要有科研学习的精神
    回复

    使用道具 举报

    21

    主题

    97

    听众

    3110

    积分

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

    [LV.8]以坛为家I

       没有MATLAB,不方便验证,错误说明是找不到“Lingd64_15.h"这个文件,你看下这个文件位置在哪,然后把路径修正下应该就可以了。
    有什么好说的
    回复

    使用道具 举报

    21

    主题

    97

    听众

    3110

    积分

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

    [LV.8]以坛为家I

    回复

    使用道具 举报

    beifang        

    8

    主题

    8

    听众

    209

    积分

    升级  54.5%

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

    [LV.6]常住居民II

    自我介绍
    要有科研学习的精神
    回复

    使用道具 举报

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

    qq
    收缩
    • 电话咨询

    • 04714969085
    fastpost

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

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

    蒙公网安备 15010502000194号

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

    GMT+8, 2025-8-16 02:00 , Processed in 0.833554 second(s), 78 queries .

    回顶部