谁知道怎么用matlab调用lingo

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了谁知道怎么用matlab调用lingo相关的知识,希望对你有一定的参考价值。

我现在有一程序用matlab编写,是0-1整数规划问题,5000个变量,5000个约束条件,用matlab根本无法运行出来,但是用lingo又无法写出来约束条件,太麻烦,哪位大哥,如果您会这方面的话,给小弟支个招,感激不尽!财富不多,谢谢

我现在也在学习matlab调用lingo,现在只是安装了API,然后在matlab上做了随matlab启动,简单的按照API上的测试了下,可以用,算了几个自带的例子,有的还运行不出来。但具体的参数设置还在学习。API的英文手册看起来有点费力,手册里面的例子大小写有时候不分,用起来起来也不方便复制到matlab中。

每次启动matlab时,workspace会加载API,然后输入命令窗输入mxlindo,有提示。

楼主先去www.lindo.com官网下载API吧,共同学习 

参考技术A 这么大规模的0-1规划恐怕用lingo也不一定能解出来 不知道你说的无法写约束是什么意思 不过你不要对lingo抱太大希望 规模太大恐怕你最好换其它思路 参考技术B 在MATLAB安装目录下新建一个名为works的文件夹,将Staff.m和STAFFPTR.lng文件放在这个文件目录下,然后把Lingd15.h和Lingd15.lib放在LINGO安装目录下,
1. STAFFPTR.lng
MODEL:
SETS:
DAYS / MON TUE WED THU FRI SAT SUN/:
NEEDS, START, ONDUTY;
ENDSETS

[OBJECTIVE] MIN = @SUM( DAYS( I): START( I));

@FOR( DAYS( TODAY):

! Calculate number on duty;
ONDUTY( TODAY) =
@SUM( DAYS( D)| D #LE# 5:
START( @WRAP( TODAY - D + 1, @SIZE( DAYS))));

! Enforce staffing requirement;
ONDUTY( TODAY) >= NEEDS( TODAY);

@GIN( START);
);

DATA:
NEEDS = @POINTER( 1);
@POINTER( 2) = START;
@POINTER( 3) = ONDUTY;
@POINTER( 4) = OBJECTIVE;
@POINTER( 5) = @STATUS();
ENDDATA
END

2. Staff.m
clear; clc;

% 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

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

% Free Lingo environment
calllib('Lingd15', 'LSdeleteEnvLng', pLingo);

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

ECN的创建BAPI谁知道呢?

我在外部传入一个ECN更改单号,在CC01中通过这个更改单创建ECN更改单号,然后要用这个创建的更改单在CS02中更改BOM.谁知道如何在CC01中通过BAPI来创建ECN号呢?BDC应该也是可以做的,但是我要做成RFC的函数共外部调用.这样的需求用BAPI做是不是更好呢?谁知道这样的BAPI啊?

参考技术A CCAP_ALT_DATE_CREATECCAP_ECN_CREATECCAP_ECN_HEADER_CREATECCAP_ECR_CREATEFYI 参考技术B TKS 我用BDC实现了,有空的时候再研究研究BAPI

以上是关于谁知道怎么用matlab调用lingo的主要内容,如果未能解决你的问题,请参考以下文章

如何在lingo中快速输入一个矩阵

谁知道mat文件怎么打开 详细

谁知道利用逆变换法(反变换法),用matlab编程正态分布随机变量随机数?

如果用lingo软件可以进行求解,那么用MATLAB可以实现吗

如何将lingo中的程序在matlab中运行

unity3D 调用外部alpha,控制透明度谁知道怎么做