QQ登录

只需要一步,快速开始

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

【请问从vb向lingo导入数组】 应该怎么办?

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

1

主题

9

听众

2

积分

升级  40%

该用户从未签到

自我介绍
大家好!我是新人笛声隆隆

社区QQ达人

跳转到指定楼层
1#
发表于 2015-4-4 16:53 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
我在vb向Lingo导入的几个指针:
nError = LSsetPointerLng(pLINGO, RowN, nPointersNow)
nError = LSsetPointerLng(pLINGO, SigUp, nPointersNow)
nError = LSsetPointerLng(pLINGO, SigRightUp, nPointersNow)
nError = LSsetPointerLng(pLINGO, Stuff(), nPointersNow)

前3个都是一个数
最后一个Stuff() 是数组
用指针的时候vb说ByRef参数类型不符,Stuff()就报错

【请问从vb向lingo导入 数组 应该怎么办?】



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

21

主题

97

听众

3110

积分

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

    [LV.8]以坛为家I

       你可以查下手册看看函数原型,三个参数都是指针类型,比如VC下一个简单的例子。

    1. Simple.lng
    model:

    sets:
       computers /standard, turbo/: profit, limit, labor, produce;
    endsets

    data:
       ! profit on a computer;
       profit = @pointer( 1);

       ! limit on the number of computers that can be produced;
       limit = @pointer( 2);

       ! labor required for production of a computer;
       labor = @pointer( 3);
    enddata

       ! maximize total profit;
       [rObj] max = @sum ( computers(i) : profit(i) * produce(i));

       ! enforce production limit;
       @for (computers(i) : produce(i) <= limit(i));

       ! labor constraint;
       @sum (computers(i) : labor(i) * produce(i)) <= 160;


    data:
       @pointer(4) = rObj;
       @pointer(5) = @status();
       @pointer(6) = produce;
    enddata

    end

    2. Simple.c
    #include <stdlib.h>
    #include "Lingd15.h"

    /*

      This code calls the LINGO DLL to solve the simple linear program:

      MAX     100 STANDARD + 150 TURBO
      SUBJECT TO
      2]  STANDARD <=   100
      3]  TURBO <=   120
      4]  STANDARD + 2 TURBO <=   160
      END

    */
    /////////////////////////////////////////////////////////////////////////////

    int __stdcall MyCallback( void* pModel, int nReserved, void* pUserData)
    {

       // this callback function will be called periodically by the Lingo solver

       int* pnCallbacks = (int*) pUserData;
       ++*pnCallbacks;
       if ( !(*pnCallbacks % 10)) printf( "In Callback: %d\n", *pnCallbacks);
       return( 0);

    }

    /////////////////////////////////////////////////////////////////////////////

    int __stdcall MyErrorCallback( void* pModel, void* pUserData, int nErrorCode,
    char* pcErrorText)
    {
       // this callback function will be called whenever Lingo hits an error

       printf( "In Error Callback: Error %d:\n%s \n", nErrorCode, pcErrorText);
       return( 0);

    }

    /////////////////////////////////////////////////////////////////////////////

    int main()
    {

       char cScript[256];

       char cComputers[64] = "STANDARD\nTURBO\n";
       int nError=-1, nPointersNow;
       int nCallbacks = 0;
       double dObjective, dStatus=-1.;
       double dProfit[] = {100., 150.};
       double dLimit[] = {100., 120.};
       double dLabor[] = {1., 2.};
       double dProduce[ sizeof( dProfit) / sizeof( double)];

       // create the LINGO environment object
       pLSenvLINGO pLINGO;
       pLINGO = LScreateEnvLng();
       if ( !pLINGO)
       {
          printf( "Can''t create LINGO environment!\n");
          goto FinalExit;
       }

       // Pass LINGO a pointer to our callback function
       nCallbacks = 0;
       nError = LSsetCallbackSolverLng( pLINGO, &MyCallback, &nCallbacks);
       if ( nError) goto ErrorExit;

       // Pass LINGO a pointer to our callback function
       nCallbacks = 0;
       nError = LSsetCallbackErrorLng( pLINGO, &MyErrorCallback, NULL);
       if ( nError) goto ErrorExit;

         // Open LINGO's log file  
       nError = LSopenLogFileLng( pLINGO, "LINGO.log");
       if ( nError) goto ErrorExit;

       // Pass memory transfer pointers to LINGO

       // @POINTER(1)
       nError = LSsetPointerLng( pLINGO, dProfit, &nPointersNow);
       if ( nError) goto ErrorExit;

       // @POINTER(2)
       nError = LSsetPointerLng( pLINGO, dLimit, &nPointersNow);
       if ( nError) goto ErrorExit;

       // @POINTER(3)
       nError = LSsetPointerLng( pLINGO, dLabor, &nPointersNow);
       if ( nError) goto ErrorExit;

       // @POINTER(4)
       nError = LSsetPointerLng( pLINGO, &dObjective, &nPointersNow);
       if ( nError) goto ErrorExit;

       // @POINTER(5)
       nError = LSsetPointerLng( pLINGO, &dStatus, &nPointersNow);
       if ( nError) goto ErrorExit;

       // @POINTER(6)
       nError = LSsetPointerLng( pLINGO, dProduce, &nPointersNow);
       if ( nError) goto ErrorExit;

       // @POINTER(7)
       nError = LSsetPointerLng( pLINGO, cComputers, &nPointersNow);
       if ( nError) goto ErrorExit;


       // Here is the script we want LINGO to run
       strcpy( cScript, "SET ECHOIN 1 \n TAKE SIMPLE.LNG \n GO \n QUIT \n");

       // Run the script
       nError = LSexecuteScriptLng( pLINGO, cScript);
       if ( nError) goto ErrorExit;

       // Close the log file
       LScloseLogFileLng( pLINGO);

       // Any problems?
       if ( nError || dStatus != LS_STATUS_GLOBAL_LNG)
       {

          // Had a problem   
          printf( "Unable to solve!");

       } else {

          // Everything went OK ... print results
          printf( "\nStandards: %g \nTurbos: %g \nProfit: %g \n",
           dProduce[0], dProduce[1], dObjective);
       }

       goto NormalExit;

    ErrorExit:
       printf("LINGO Error Code: %d\n", nError);

    NormalExit:
       LSdeleteEnvLng( pLINGO);

    FinalExit: ;

    }

    3. Makefile
    all : simple.obj simple.exe

    simple.obj : simple.c
            cl -c simple.c

    simple.exe : Lingd64_15.lib simple.obj
            cl simple.obj Lingd64_15.lib -Fesimple.exe

    当然,把用到的头文件和lib文件放在当前目录下

    4. 编译运行,结果:
    :  TAKE SIMPLE.LNG
    : model:
    ? sets:
    ?    computers /standard, turbo/: profit, limit, labor, produce;
    ? endsets
    ? data:
    ?    ! profit on a computer;
    ?    profit = @pointer( 1);
    ?    ! limit on the number of computers that can be produced;
    ?    limit = @pointer( 2);
    ?    ! labor required for production of a computer;
    ?    labor = @pointer( 3);
    ? enddata
    ?    ! maximize total profit;
    ?    [rObj] max = @sum ( computers(i) : profit(i) * produce(i));
    ?    ! enforce production limit;
    ?    @for (computers(i) : produce(i) <= limit(i));
    ?    ! labor constraint;
    ?    @sum (computers(i) : labor(i) * produce(i)) <= 160;
    ? data:
    ?    @pointer(4) = rObj;
    ?    @pointer(5) = @status();
    ?    @pointer(6) = produce;
    ? enddata
    ? end
    :  GO
      Compiling model ...
      Structural analysis, pass 1 ...
      Scalarizing model ...
      Generating nonzero matrix ...
      Solving ...

      Global optimal solution found.
      Objective value:                         14500.0000000
      Infeasibilities:                         0.00000000000
      Total solver iterations:                             0
      Elapsed runtime seconds:                          0.00

      Running output operations ...

      Model Class:                                        LP

      Total variables:                      2
      Nonlinear variables:                  0
      Integer variables:                    0

      Total constraints:                    4
      Nonlinear constraints:                0

      Total nonzeros:                       6
      Nonlinear nonzeros:                   0



                                         Variable                Value             Reduced Cost
                                PROFIT( STANDARD)        100.000000000            0.00000000000
                                   PROFIT( TURBO)        150.000000000            0.00000000000
                                 LIMIT( STANDARD)        100.000000000            0.00000000000
                                    LIMIT( TURBO)        120.000000000            0.00000000000
                                 LABOR( STANDARD)        1.00000000000            0.00000000000
                                    LABOR( TURBO)        2.00000000000            0.00000000000
                               PRODUCE( STANDARD)        100.000000000            0.00000000000
                                  PRODUCE( TURBO)        30.0000000000            0.00000000000

                                              Row         Slack or Surplus           Dual Price
                                             ROBJ        14500.0000000            1.00000000000
                                                2        0.00000000000            25.0000000000
                                                3        90.0000000000            0.00000000000
                                                4        0.00000000000            75.0000000000

    :  QUIT


    OK, have a try.
    有什么好说的
    回复

    使用道具 举报

    21

    主题

    97

    听众

    3110

    积分

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

    [LV.8]以坛为家I

       你可以查下手册看看函数原型,三个参数都是指针类型,比如VC下一个简单的例子。

    1. Simple.lng
    model:

    sets:
       computers /standard, turbo/: profit, limit, labor, produce;
    endsets

    data:
       ! profit on a computer;
       profit = @pointer( 1);

       ! limit on the number of computers that can be produced;
       limit = @pointer( 2);

       ! labor required for production of a computer;
       labor = @pointer( 3);
    enddata

       ! maximize total profit;
       [rObj] max = @sum ( computers(i) : profit(i) * produce(i));

       ! enforce production limit;
       @for (computers(i) : produce(i) <= limit(i));

       ! labor constraint;
       @sum (computers(i) : labor(i) * produce(i)) <= 160;


    data:
       @pointer(4) = rObj;
       @pointer(5) = @status();
       @pointer(6) = produce;
    enddata

    end

    2. Simple.c
    #include <stdlib.h>
    #include "Lingd15.h"

    /*

      This code calls the LINGO DLL to solve the simple linear program:

      MAX     100 STANDARD + 150 TURBO
      SUBJECT TO
      2]  STANDARD <=   100
      3]  TURBO <=   120
      4]  STANDARD + 2 TURBO <=   160
      END

    */
    /////////////////////////////////////////////////////////////////////////////

    int __stdcall MyCallback( void* pModel, int nReserved, void* pUserData)
    {

       // this callback function will be called periodically by the Lingo solver

       int* pnCallbacks = (int*) pUserData;
       ++*pnCallbacks;
       if ( !(*pnCallbacks % 10)) printf( "In Callback: %d\n", *pnCallbacks);
       return( 0);

    }

    /////////////////////////////////////////////////////////////////////////////

    int __stdcall MyErrorCallback( void* pModel, void* pUserData, int nErrorCode,
    char* pcErrorText)
    {
       // this callback function will be called whenever Lingo hits an error

       printf( "In Error Callback: Error %d:\n%s \n", nErrorCode, pcErrorText);
       return( 0);

    }

    /////////////////////////////////////////////////////////////////////////////

    int main()
    {

       char cScript[256];

       char cComputers[64] = "STANDARD\nTURBO\n";
       int nError=-1, nPointersNow;
       int nCallbacks = 0;
       double dObjective, dStatus=-1.;
       double dProfit[] = {100., 150.};
       double dLimit[] = {100., 120.};
       double dLabor[] = {1., 2.};
       double dProduce[ sizeof( dProfit) / sizeof( double)];

       // create the LINGO environment object
       pLSenvLINGO pLINGO;
       pLINGO = LScreateEnvLng();
       if ( !pLINGO)
       {
          printf( "Can''t create LINGO environment!\n");
          goto FinalExit;
       }

       // Pass LINGO a pointer to our callback function
       nCallbacks = 0;
       nError = LSsetCallbackSolverLng( pLINGO, &MyCallback, &nCallbacks);
       if ( nError) goto ErrorExit;

       // Pass LINGO a pointer to our callback function
       nCallbacks = 0;
       nError = LSsetCallbackErrorLng( pLINGO, &MyErrorCallback, NULL);
       if ( nError) goto ErrorExit;

         // Open LINGO's log file  
       nError = LSopenLogFileLng( pLINGO, "LINGO.log");
       if ( nError) goto ErrorExit;

       // Pass memory transfer pointers to LINGO

       // @POINTER(1)
       nError = LSsetPointerLng( pLINGO, dProfit, &nPointersNow);
       if ( nError) goto ErrorExit;

       // @POINTER(2)
       nError = LSsetPointerLng( pLINGO, dLimit, &nPointersNow);
       if ( nError) goto ErrorExit;

       // @POINTER(3)
       nError = LSsetPointerLng( pLINGO, dLabor, &nPointersNow);
       if ( nError) goto ErrorExit;

       // @POINTER(4)
       nError = LSsetPointerLng( pLINGO, &dObjective, &nPointersNow);
       if ( nError) goto ErrorExit;

       // @POINTER(5)
       nError = LSsetPointerLng( pLINGO, &dStatus, &nPointersNow);
       if ( nError) goto ErrorExit;

       // @POINTER(6)
       nError = LSsetPointerLng( pLINGO, dProduce, &nPointersNow);
       if ( nError) goto ErrorExit;

       // @POINTER(7)
       nError = LSsetPointerLng( pLINGO, cComputers, &nPointersNow);
       if ( nError) goto ErrorExit;


       // Here is the script we want LINGO to run
       strcpy( cScript, "SET ECHOIN 1 \n TAKE SIMPLE.LNG \n GO \n QUIT \n");

       // Run the script
       nError = LSexecuteScriptLng( pLINGO, cScript);
       if ( nError) goto ErrorExit;

       // Close the log file
       LScloseLogFileLng( pLINGO);

       // Any problems?
       if ( nError || dStatus != LS_STATUS_GLOBAL_LNG)
       {

          // Had a problem   
          printf( "Unable to solve!");

       } else {

          // Everything went OK ... print results
          printf( "\nStandards: %g \nTurbos: %g \nProfit: %g \n",
           dProduce[0], dProduce[1], dObjective);
       }

       goto NormalExit;

    ErrorExit:
       printf("LINGO Error Code: %d\n", nError);

    NormalExit:
       LSdeleteEnvLng( pLINGO);

    FinalExit: ;

    }

    3. Makefile
    all : simple.obj simple.exe

    simple.obj : simple.c
            cl -c simple.c

    simple.exe : Lingd64_15.lib simple.obj
            cl simple.obj Lingd64_15.lib -Fesimple.exe

    当然,把用到的头文件和lib文件放在当前目录下

    4. 编译运行,结果:
    :  TAKE SIMPLE.LNG
    : model:
    ? sets:
    ?    computers /standard, turbo/: profit, limit, labor, produce;
    ? endsets
    ? data:
    ?    ! profit on a computer;
    ?    profit = @pointer( 1);
    ?    ! limit on the number of computers that can be produced;
    ?    limit = @pointer( 2);
    ?    ! labor required for production of a computer;
    ?    labor = @pointer( 3);
    ? enddata
    ?    ! maximize total profit;
    ?    [rObj] max = @sum ( computers(i) : profit(i) * produce(i));
    ?    ! enforce production limit;
    ?    @for (computers(i) : produce(i) <= limit(i));
    ?    ! labor constraint;
    ?    @sum (computers(i) : labor(i) * produce(i)) <= 160;
    ? data:
    ?    @pointer(4) = rObj;
    ?    @pointer(5) = @status();
    ?    @pointer(6) = produce;
    ? enddata
    ? end
    :  GO
      Compiling model ...
      Structural analysis, pass 1 ...
      Scalarizing model ...
      Generating nonzero matrix ...
      Solving ...

      Global optimal solution found.
      Objective value:                         14500.0000000
      Infeasibilities:                         0.00000000000
      Total solver iterations:                             0
      Elapsed runtime seconds:                          0.00

      Running output operations ...

      Model Class:                                        LP

      Total variables:                      2
      Nonlinear variables:                  0
      Integer variables:                    0

      Total constraints:                    4
      Nonlinear constraints:                0

      Total nonzeros:                       6
      Nonlinear nonzeros:                   0



                                         Variable                Value             Reduced Cost
                                PROFIT( STANDARD)        100.000000000            0.00000000000
                                   PROFIT( TURBO)        150.000000000            0.00000000000
                                 LIMIT( STANDARD)        100.000000000            0.00000000000
                                    LIMIT( TURBO)        120.000000000            0.00000000000
                                 LABOR( STANDARD)        1.00000000000            0.00000000000
                                    LABOR( TURBO)        2.00000000000            0.00000000000
                               PRODUCE( STANDARD)        100.000000000            0.00000000000
                                  PRODUCE( TURBO)        30.0000000000            0.00000000000

                                              Row         Slack or Surplus           Dual Price
                                             ROBJ        14500.0000000            1.00000000000
                                                2        0.00000000000            25.0000000000
                                                3        90.0000000000            0.00000000000
                                                4        0.00000000000            75.0000000000

    :  QUIT


    OK, have a try.
    有什么好说的
    回复

    使用道具 举报

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

    qq
    收缩
    • 电话咨询

    • 04714969085
    fastpost

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

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

    蒙公网安备 15010502000194号

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

    GMT+8, 2024-5-23 02:38 , Processed in 0.373473 second(s), 70 queries .

    回顶部