Decision Optimization

Expand all | Collapse all

Cplex 20.1 crash

  • 1.  Cplex 20.1 crash

    Posted 16 days ago
    Edited by K Braeu_ 16 days ago

    Hello

    I am trying to port old code to CPLEX 20.1

    The declarations for setting up the problem in the old code are as follows:


    #define MAXIMIZE -1
    
    #define MAXN 30000 /* maximum No of variables */
    #define MAXM 40000 /* maximum No of constraints */
    #define MAXMN 80000 /* maximum No of nonzeros */
    
    int NRows ;
    int NCols ;
    
    double objx [MAXN-1] ;
    double rhsx [MAXM-1] ;
    double matval [MAXMN-1] ;
    double bdl [MAXN-1] ;
    double bdu [MAXN-1] ;
    int matbeg [MAXN-1] ;
    int matcnt [MAXN-1] ;
    int matind [MAXMN-1] ;
    char senx [MAXM-1] ;
    

    I tried to port to CPLEX 20.1 by doing the following (I am using the 64 bit version)


    CPXCENVptr env = NULL;
    CPXLPptr lp = NULL;
    
    /* Initialize environment */
    env = CPXXopenCPLEX (&status) ;
    
    lp = CPXXcreateprob(env, &status, "problem");
    
    // declare new variables conforming to CPLEX 20.1 and populate with the elements of the old ones. Can I do it this way?
    CPXDIM xNCols = (CPXDIM) NCols ;
    CPXDIM xNRows = (CPXDIM) NRows ;
    
    CPXNNZ const* xmatbeg = (CPXNNZ const*) matbeg ;
    CPXDIM const* xmatcnt = (CPXDIM const*) matcnt ;
    CPXDIM const * xmatind1 = (CPXDIM const *) matind1 ;
    
    double const* xobjx = (double const*) objx ;
    double const* xrhsx = (double const*) rhsx ;
    char const* xsenx = (char const*) senx ;
    double const* xmatval = (double const*) matval ;
    double const* xbdl = (double const*) bdl ;
    double const* xbdu = (double const*) bdu ;
    
    
    //for (i=0; i<NCols;i++) printf ("xobjx[%d] = %f objx[%d] = %f \n", i, xobjx[i], i, objx[i]) ;  the arrays are populated with the correct values
    //for (i=0; i<NRows;i++) printf ("xrhsx[%d] = %f rhsx[%d] = %f \n", i, xrhsx[i], i, rhsx[i]) ;
    
    // set up the lp
    status = CPXXcopylp (env, lp, xNCols, xNRows, MAXIMIZE, xobjx, xrhsx, xsenx, xmatbeg, xmatcnt, xmatind1, xmatval, xbdl, xbdu, NULL);
    
    // optimize
    status = CPXXlpopt (env, lp);
    
    // close
    status = CPXXcloseCPLEX (&env) ;
    


    The code compiles but the executable crashes when calling CPXXcopylp
    Segmentation fault (core dumped)

    Also CPXXcloseCPLEX(&env) ist not stated correctly. The argument of the function should not be &env.

    Can someone help?




  • 2.  RE: Cplex 20.1 crash

    Posted 15 days ago
    Why don't you directly declare the correct input structures? It should just work: when you move from CPX to CPXX, you move from 32 to 64 bits declarations, so get "the same structures but bigger": instead of int, you will get __int64, which will be able to store your previous running data that is 32 bits.

    You cannot just cast your old declarations into the new expected ones: for example, CPXNNZ const* xmatbeg = (CPXNNZ const*) matbeg ; is wrong IMO.
    CPXNNZ are __int64 or long long, depending on the platform, and your previous input one is an int.

    ------------------------------
    Vincent Beraudier
    ------------------------------



  • 3.  RE: Cplex 20.1 crash

    Posted 15 days ago
    
       CPXENVptr env = NULL ;
       CPXLPptr  lp  = NULL ; 
    
    
       ...
    
       /* Initialize the CPLEX environment */
       env = CPXXopenCPLEX (&status);
    
       lp = CPXXcreateprob(env, &status, "batch"); 
    
    
    /* transform the original arrays that describe the problem to CPLEX 20.1 compatible ones */ 
     
      CPXDIM xNCols  = (CPXDIM) NCols  ; 
      CPXDIM xNRows  = (CPXDIM) NRows  ;
      CPXNNZ xNNZ    = (CPXNNZ) NNZeros    ;
    
      CPXNNZ *xmatbeg  = calloc(xNCols,sizeof(CPXNNZ *));
      CPXDIM *xmatcnt  = calloc(xNCols,sizeof(CPXDIM *)); 
      CPXDIM *xmatind1 = calloc(xNNZ,  sizeof(CPXDIM *));
    
      double *xobjx = calloc(xNCols,sizeof(double *));
      double *xrhsx   = calloc(xNRows,sizeof(double *));  
      double *xmatval = calloc(xNNZ,sizeof(double *));
      double *xbdl    = calloc(xNCols,sizeof(double *));
      double *xbdu    = calloc(xNCols,sizeof(double *));
      char   *xsenx   = calloc(xNRows,sizeof(char   *)) ;
    
    /* copy the data into the new defined arrays  */             
    for (int i=0; i<xNCols;i++) xbdl[i]  = (double const) bdl[i]   ;
    for (int i=0; i<xNCols;i++) xbdu[i]  = (double const) bdu[i]   ;
    for (int i=0; i<xNCols;i++) xobjx[i] = (double const) objx[i]  ;
    
    for (int i=0; i<xNRows;i++) xrhsx[i] = (double const) rhsx[i]  ;
    for (int i=0; i<xNRows;i++) xsenx[i] = senx[i]  ;
    
    for (int i=0; i<xNCols;i++)   xmatbeg[i]  = (CPXNNZ const) matbeg[i]  ;
    for (int i=0; i<xNCols;i++)   xmatcnt[i]  = (CPXDIM const) matcnt[i]  ;
    for (int i=0; i<xNNZ;i++)     xmatind1[i] = (CPXDIM const) matind1[i] ;
    for (int i=0; i<xNNZ;i++)     xmatval[i]  = (double const) matval[i]  ;
    
    /*
    for (i=0; i<NCols;i++)  printf ("xobjx[%d] = %f objx[%d] = %f \n", i, xobjx[i], i, objx[i]) ;
    for (i=0; i<NRows;i++)  printf ("xrhsx[%d] = %f rhsx[%d] = %f \n", i, xrhsx[i], i, rhsx[i]) ;
    for (int i=0; i<NRows;i++)  printf ("xsenx[%d] = %c \n", i, xsenx[i]) ;
    */
    
       /* populate cplex with the problem data as required by Cplex 20.1  */ 
       status = CPXXcopylp (env, lp, xNCols, xNRows, MAXIMIZE, xobjx, xrhsx, xsenx, xmatbeg, xmatcnt, xmatind1, xmatval, xbdl,xbdu, NULL);
    
    ...
    
          status = CPXXcloseCPLEX (&env);
    
    
    
    


    I had a look in the 64bit examples provided by IBM and managed to get the application running.  The code looks now as listed above.

    CPXXcopylp() doesn't accept the "old" arrays. The application crashes in CPXXcopylp by the cause of segmentation fault.




    ------------------------------
    K Braeu_
    ------------------------------