Topic
  • 8 replies
  • Latest Post - ‏2012-11-25T16:13:59Z by T_O
SystemAdmin
SystemAdmin
7929 Posts

Pinned topic CPLEX callable library returning strange optimal solutions

‏2012-11-25T08:57:22Z |
I am using CPLEX 12.3 on Windows XP to solve the attached LP. When I use the callable library, the optimal value is 0.162602, but the value returned by Interactive CPLEX is 1.0000, which is the right solution.
Is there any explanation to such a situation?

Thank you for any advice.

Amar
Updated on 2012-11-25T16:13:59Z at 2012-11-25T16:13:59Z by T_O
  • T_O
    T_O
    448 Posts

    Re: CPLEX callable library returning strange optimal solutions

    ‏2012-11-25T09:14:52Z  
    Could you provide your code?

    Best regards,
    Thomas
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: CPLEX callable library returning strange optimal solutions

    ‏2012-11-25T10:01:54Z  
    • T_O
    • ‏2012-11-25T09:14:52Z
    Could you provide your code?

    Best regards,
    Thomas
    This is the main body of my code. I deleted the data input section of the code and left only the key functions that use the callable library. I built the LP model inside CPLEX using CPXcopylp.
    
    
    
    int main (
    
    int argc, 
    
    char *argv[]) 
    { FILE *data = NULL;   
    
    int  status=0, m=0, a, i, j, itcnt=0, num, nbr_dmu, nbr_in, nbr_out, obj_sense, multi_index, k=0, nbr_nz, nbr_surplus; 
    
    double LPcpu, obj_LP, TOT_cpu, sum = 0;   CPXENVptr env = NULL; CPXLPptr  lp  = NULL;   
    // *****************************************************************************// 
    //**************** DEFINE CPLEX ENVIRONMENT FOR THE LP PROBLEM *****************// 
    // *****************************************************************************// status = Create_CPX_Env(&env, &lp); 
    
    if (status) 
    { fprintf(stderr, 
    "Failed to create the CPLEX environment.\n", status); system(
    "pause"); abort(); 
    } 
    // *****************************************************************************// 
    //******************* SET CPLEX PARAMETERS FOR THE LP PROBLEMS *****************// 
    // *****************************************************************************// status = Set_CPX_parameters(&env); 
    
    if (status) 
    { fprintf(stderr, 
    "Failed to set CPLEX parameters.\n", status); system(
    "pause"); abort(); 
    } 
    // *****************************************************************************// 
    // *****************         BUILD THE LP & COPY LP to CPX        **************// 
    // *****************************************************************************// status = Build_LP(&env, &lp, inst_ID, obj_value[inst_ID[0]-1]); 
    
    if (status) 
    { fprintf(stderr, 
    "Failed to read and copy the LP problem.\n", status); system(
    "pause"); abort(); 
    } 
    // *****************************************************************************// 
    // ****************** SOLVE THE LP PROBLEM & GET THE OPTIMUM ****************** // 
    // *****************************************************************************// status = CPXlpopt(env, lp); 
    
    if (status) 
    { fprintf(stderr, 
    "Failed to solve the LP problem.\n"); obj_LP = 9999999999; 
    
    goto Append; 
    }   status = CPXgetobjval(env, lp, &obj_LP);             
    //Get the optimum value 
    
    if (status) 
    { fprintf(stderr, 
    "Failed to get the objective value for the LP.\n"); system(
    "pause"); 
    }     printf(
    "Obj = %lf\n", obj_LP);   
    // *****************************************************************************// 
    // *****************************************************************************// 
    // *****************************************************************************//   
    
    if (lp != NULL) 
    { status = CPXcloseCPLEX(&env); 
    
    if (status) fprintf(stderr, 
    "CPXfreeprob failed, error code %d.\n", status); 
    }   
    
    if (env != NULL) 
    { status = CPXcloseCPLEX(&env); 
    
    if (status) 
    { 
    
    char errmsg[1024]; fprintf(stderr, 
    "Could not close CPLEX enviroment.\n"); CPXgeterrorstring (env, status, errmsg); fprintf (stderr, 
    "%s", errmsg); 
    } 
    } 
    }
    


    I hope this will help.

    Amar
  • T_O
    T_O
    448 Posts

    Re: CPLEX callable library returning strange optimal solutions

    ‏2012-11-25T10:12:59Z  
    This is the main body of my code. I deleted the data input section of the code and left only the key functions that use the callable library. I built the LP model inside CPLEX using CPXcopylp.
    <pre class="jive-pre"> int main ( int argc, char *argv[]) { FILE *data = NULL; int status=0, m=0, a, i, j, itcnt=0, num, nbr_dmu, nbr_in, nbr_out, obj_sense, multi_index, k=0, nbr_nz, nbr_surplus; double LPcpu, obj_LP, TOT_cpu, sum = 0; CPXENVptr env = NULL; CPXLPptr lp = NULL; // *****************************************************************************// //**************** DEFINE CPLEX ENVIRONMENT FOR THE LP PROBLEM *****************// // *****************************************************************************// status = Create_CPX_Env(&env, &lp); if (status) { fprintf(stderr, "Failed to create the CPLEX environment.\n", status); system( "pause"); abort(); } // *****************************************************************************// //******************* SET CPLEX PARAMETERS FOR THE LP PROBLEMS *****************// // *****************************************************************************// status = Set_CPX_parameters(&env); if (status) { fprintf(stderr, "Failed to set CPLEX parameters.\n", status); system( "pause"); abort(); } // *****************************************************************************// // ***************** BUILD THE LP & COPY LP to CPX **************// // *****************************************************************************// status = Build_LP(&env, &lp, inst_ID, obj_value[inst_ID[0]-1]); if (status) { fprintf(stderr, "Failed to read and copy the LP problem.\n", status); system( "pause"); abort(); } // *****************************************************************************// // ****************** SOLVE THE LP PROBLEM & GET THE OPTIMUM ****************** // // *****************************************************************************// status = CPXlpopt(env, lp); if (status) { fprintf(stderr, "Failed to solve the LP problem.\n"); obj_LP = 9999999999; goto Append; } status = CPXgetobjval(env, lp, &obj_LP); //Get the optimum value if (status) { fprintf(stderr, "Failed to get the objective value for the LP.\n"); system( "pause"); } printf( "Obj = %lf\n", obj_LP); // *****************************************************************************// // *****************************************************************************// // *****************************************************************************// if (lp != NULL) { status = CPXcloseCPLEX(&env); if (status) fprintf(stderr, "CPXfreeprob failed, error code %d.\n", status); } if (env != NULL) { status = CPXcloseCPLEX(&env); if (status) { char errmsg[1024]; fprintf(stderr, "Could not close CPLEX enviroment.\n"); CPXgeterrorstring (env, status, errmsg); fprintf (stderr, "%s", errmsg); } } } </pre>

    I hope this will help.

    Amar
    I don't think so.

    I think you should provide the code of Build_LP and some details about inst_ID and obj_value. Also, you should make clear how you created the .lp file. Furthermore, it might be usefull to create a sav-file instead of an lp-file.

    Best regards,
    Thomas
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: CPLEX callable library returning strange optimal solutions

    ‏2012-11-25T12:03:54Z  
    • T_O
    • ‏2012-11-25T10:12:59Z
    I don't think so.

    I think you should provide the code of Build_LP and some details about inst_ID and obj_value. Also, you should make clear how you created the .lp file. Furthermore, it might be usefull to create a sav-file instead of an lp-file.

    Best regards,
    Thomas
    I am attaching the SAV format file. I will attach the Building code next.

    Thank you for your help.

    Amar
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: CPLEX callable library returning strange optimal solutions

    ‏2012-11-25T12:11:47Z  
    I am attaching the SAV format file. I will attach the Building code next.

    Thank you for your help.

    Amar
    The building code is attached. The inst_ID vector contains the values num, nbr, nbr_in, nbr_out and obj_sense as indicated in the code. The obj_value is 1.

    Thanks again for your help.

    Amar
  • T_O
    T_O
    448 Posts

    Re: CPLEX callable library returning strange optimal solutions

    ‏2012-11-25T15:47:25Z  
    The building code is attached. The inst_ID vector contains the values num, nbr, nbr_in, nbr_out and obj_sense as indicated in the code. The obj_value is 1.

    Thanks again for your help.

    Amar
    First of all: I did not try to understand the whole code, but some things are strange:

    • I can obtain the correct objective value (1) from the LP-file. I cannot obtain it from the .sav file directly.
    • Running "optimize" on the .sav file two times provides two different results.
    • Exporting and reimporting an .mps file from the .sav file does not provide an objective function.
    • There is "constr26" and "constr28", but no constr27. Is this correct?

    So it might be, that there is something wrong in your data (memory problem? index mismatch?).

    Best regards,
    Thomas
  • SystemAdmin
    SystemAdmin
    7929 Posts

    Re: CPLEX callable library returning strange optimal solutions

    ‏2012-11-25T15:53:08Z  
    • T_O
    • ‏2012-11-25T15:47:25Z
    First of all: I did not try to understand the whole code, but some things are strange:

    • I can obtain the correct objective value (1) from the LP-file. I cannot obtain it from the .sav file directly.
    • Running "optimize" on the .sav file two times provides two different results.
    • Exporting and reimporting an .mps file from the .sav file does not provide an objective function.
    • There is "constr26" and "constr28", but no constr27. Is this correct?

    So it might be, that there is something wrong in your data (memory problem? index mismatch?).

    Best regards,
    Thomas
    Thank you Thomas. I will try to investigate the potential problems that you mentioned, hoping that this will solve the problem.

    All the best.

    Amar
  • T_O
    T_O
    448 Posts

    Re: CPLEX callable library returning strange optimal solutions

    ‏2012-11-25T16:13:59Z  
    Thank you Thomas. I will try to investigate the potential problems that you mentioned, hoping that this will solve the problem.

    All the best.

    Amar
    Ok. You might try:
    status = CPXsetintparam (env, CPX_PARAM_DATACHECK, CPX_ON);

    See also:
    http://www-01.ibm.com/support/docview.wss?uid=swg21400039

    Best regards,
    Thomas