首页 > 代码库 > vc++和LINGO编程

vc++和LINGO编程

 1 #include<iostream>
 2 #include "Lingd11.h"
 3 #pragma comment(lib,"Lingd11.lib")
 4 using namespace std;
 5 
 6 
 7 int main()
 8 {
 9     char cScript[50];
10     memset(cScript,0,50*sizeof(char));
11 
12     pLSenvLINGO pLINGO;
13     pLINGO = LScreateEnvLng();
14     if(!pLINGO)
15     {
16         cout<<"Can‘t create LINGO environment!"<<endl;
17     }
18     double dStatus = 1;
19     int nError = 1;
20 
21     nError = LSopenLogFileLng(pLINGO,"Result.log");
22     if(nError)
23     {
24         cout<<"Fail open Log!"<<endl;
25     }
26     double res[6];
27     memset(res,0,6*sizeof(double));
28     double f_num[6] = {60,70,60,50,20,30};
29     int nPointersNow ;
30     //@POINTER(1)
31     nError = LSsetPointerLng(pLINGO,f_num,&nPointersNow);
32     if(nError)
33     {
34         cout<<"Fail transfer memory1!"<<endl;
35     }
36     //@POINTER(2)
37     nError = LSsetPointerLng(pLINGO,res,&nPointersNow);
38     if(nError)
39     {
40         cout<<"Fail transfer memory!2"<<endl;
41     }
42     //@POINTER(2)
43     nError = LSsetPointerLng(pLINGO,&dStatus,&nPointersNow);
44     if(nError)
45     {
46         cout<<"Fail transfer memory!3"<<endl;
47     }
48     //LINGO运行脚本
49     strcpy( cScript, "SET ECHOIN 1 \n TAKE SOLVE.LNG \n GO \n QUIT \n");
50     nError = LSexecuteScriptLng(pLINGO,cScript);
51     if(nError)
52     {
53         cout<<"Fail run LINGO!"<<endl;
54     }
55     LScloseLogFileLng(pLINGO);
56     if(nError || dStatus != LS_STATUS_GLOBAL_LNG)
57     {
58         cout<<"Unable to solve!"<<endl;
59     }
60     LSdeleteEnvLng(pLINGO);
61     double result = 0;
62     for(int i = 0;i < 6;i++)
63     {
64         result += res[i];
65     }
66     cout<<"result: "<<result<<endl;
67 
68     system("pause");
69     return 0;
70 }

 

MODEL:
SETS:
ID/1..6/;
NO(ID):x,num;
ENDSETS
!求解目标;
min=num(3)* x(1)+x(2)+x(3)+x(4)+x(5)+x(6);
!约束条件;
x(6)+x(1)>=num(1);
x(1)+x(2)>=num(2);
x(2)+x(3)>=num(3);
x(3)+x(4)>=num(4);
x(4)+x(5)>=num(5);
x(5)+x(6)>=num(6);
x(1)>=num(1);
DATA:
!把VC中的数据m_Num1,…,m_Num6传递到Lingo中的变量num1,…,num6;
num=@POINTER(1);
!把Lingo计算的结果和状态分别传到VC中的变量res,dStatus;
@POINTER(2)=x;
@POINTER(3)=@STATUS();
ENDDATA
END 

 

lingo与高级语言连接(以C++)为例

http://blog.csdn.net/ds1231h/article/details/52383707

lingo与VC混合编程

http://wenku.baidu.com/link?url=4uPZs0tb8qZZMBZXskuJ7Y-PqyMXwlwtetxpILVCbBNadDHmmHrmDwr49OFa8JbgVN2lgUmk7BUVlyJRhII8g490dGTP1lJvz-7civWkmme

lingo和高级语言混合编程 

http://blog.chinaunix.net/uid-29764914-id-4459488.html

vc++和LINGO编程