lemon/lp_cplex.cc
changeset 1458 7a483c1d38b5
parent 1436 e0beb94d08bf
child 1460 7c58aabb9eea
equal deleted inserted replaced
1:420117566428 2:b867f31caee3
    23   LpCplex::LpCplex() : LpSolverBase() {
    23   LpCplex::LpCplex() : LpSolverBase() {
    24 
    24 
    25     //    env = CPXopenCPLEXdevelop(&status);     
    25     //    env = CPXopenCPLEXdevelop(&status);     
    26     env = CPXopenCPLEX(&status);     
    26     env = CPXopenCPLEX(&status);     
    27     lp = CPXcreateprob(env, &status, "LP problem");
    27     lp = CPXcreateprob(env, &status, "LP problem");
    28     //CPXmsg (cpxresults, "Hello-bello\n");
       
    29   }
    28   }
    30   
    29   
    31   LpCplex::~LpCplex() {
    30   LpCplex::~LpCplex() {
    32     CPXfreeprob(env,&lp); 
    31     CPXfreeprob(env,&lp); 
    33     CPXcloseCPLEX(&env); 
    32     CPXcloseCPLEX(&env); 
   228     for (int i=0;i< CPXgetnumcols (env, lp);++i){
   227     for (int i=0;i< CPXgetnumcols (env, lp);++i){
   229       CPXchgcoef (env, lp, -1, i, 0);
   228       CPXchgcoef (env, lp, -1, i, 0);
   230     }
   229     }
   231     
   230     
   232   }
   231   }
   233 
   232   // The routine returns zero unless an error occurred during the
       
   233   // optimization. Examples of errors include exhausting available
       
   234   // memory (CPXERR_NO_MEMORY) or encountering invalid data in the
       
   235   // CPLEX problem object (CPXERR_NO_PROBLEM). Exceeding a
       
   236   // user-specified CPLEX limit, or proving the model infeasible or
       
   237   // unbounded, are not considered errors. Note that a zero return
       
   238   // value does not necessarily mean that a solution exists. Use query
       
   239   // routines CPXsolninfo, CPXgetstat, and CPXsolution to obtain
       
   240   // further information about the status of the optimization.
   234   LpCplex::SolveExitStatus LpCplex::_solve()
   241   LpCplex::SolveExitStatus LpCplex::_solve()
   235   {
   242   {
   236     
   243     //CPX_PARAM_LPMETHOD 
   237     status = CPXlpopt (env, lp);
   244     status = CPXlpopt (env, lp);
   238     if (status == 0){
   245     if (status == 0){
   239       return SOLVED;
   246       //We want to exclude some cases
       
   247       switch (CPXgetstat (env, lp)){
       
   248       case CPX_OBJ_LIM:
       
   249       case CPX_IT_LIM_FEAS:
       
   250       case CPX_IT_LIM_INFEAS:               
       
   251       case CPX_TIME_LIM_FEAS:
       
   252       case CPX_TIME_LIM_INFEAS:
       
   253 	return UNSOLVED;
       
   254       default:
       
   255 	return SOLVED; 
       
   256       }
   240     }
   257     }
   241     else{
   258     else{
   242       return UNSOLVED;
   259       return UNSOLVED;
   243     }
   260     }
   244 //     int i=  lpx_simplex(lp);
   261   }
   245 //     switch (i) {
   262 
   246 //     case LPX_E_OK: 
   263 
   247 //       return SOLVED;
   264 //7.5-os cplex statusai (Vigyazat: a 9.0-asei masok!)
   248 //       break;
   265 // This table lists the statuses, returned by the CPXgetstat() routine, for solutions to LP problems or mixed integer problems. If no solution exists, the return value is zero.
   249 //     default:
   266 
   250 //       return UNSOLVED;
   267 // For Simplex, Barrier  
   251 //     }
   268 // 1  	CPX_OPTIMAL  
   252   }
   269 // 	 Optimal solution found  
   253 
   270 // 2  	CPX_INFEASIBLE  
   254   LpCplex::SolutionStatus LpCplex::_getPrimalStatus()
   271 // 	 Problem infeasible  
   255   {
   272 // 3    CPX_UNBOUNDED  
   256 //7.5-os cplex statusai
   273 // 	 Problem unbounded  
   257 // #define CPX_OPTIMAL                      1
   274 // 4  	CPX_OBJ_LIM  
   258 // #define CPX_INFEASIBLE                   2
   275 // 	 Objective limit exceeded in Phase II  
   259 // #define CPX_UNBOUNDED                    3
   276 // 5  	CPX_IT_LIM_FEAS  
   260 // #define CPX_OBJ_LIM                      4
   277 // 	 Iteration limit exceeded in Phase II  
   261 // #define CPX_IT_LIM_FEAS                  5
   278 // 6  	CPX_IT_LIM_INFEAS  
   262 // #define CPX_IT_LIM_INFEAS                6
   279 // 	 Iteration limit exceeded in Phase I  
   263 // #define CPX_TIME_LIM_FEAS                7
   280 // 7  	CPX_TIME_LIM_FEAS  
   264 // #define CPX_TIME_LIM_INFEAS              8
   281 // 	 Time limit exceeded in Phase II  
   265 // #define CPX_NUM_BEST_FEAS                9
   282 // 8  	CPX_TIME_LIM_INFEAS  
   266 // #define CPX_NUM_BEST_INFEAS             10
   283 // 	 Time limit exceeded in Phase I  
   267 // #define CPX_OPTIMAL_INFEAS              11
   284 // 9  	CPX_NUM_BEST_FEAS  
   268 // #define CPX_ABORT_FEAS                  12
   285 // 	 Problem non-optimal, singularities in Phase II  
   269 // #define CPX_ABORT_INFEAS                13
   286 // 10 	CPX_NUM_BEST_INFEAS  
   270 // #define CPX_ABORT_DUAL_INFEAS           14
   287 // 	 Problem non-optimal, singularities in Phase I  
   271 // #define CPX_ABORT_PRIM_INFEAS           15
   288 // 11 	CPX_OPTIMAL_INFEAS  
   272 // #define CPX_ABORT_PRIM_DUAL_INFEAS      16
   289 // 	 Optimal solution found, unscaled infeasibilities  
   273 // #define CPX_ABORT_PRIM_DUAL_FEAS        17
   290 // 12 	CPX_ABORT_FEAS  
   274 // #define CPX_ABORT_CROSSOVER             18
   291 // 	 Aborted in Phase II  
   275 // #define CPX_INForUNBD                   19
   292 // 13 	CPX_ABORT_INFEAS  
   276 // #define CPX_PIVOT                       20
   293 // 	 Aborted in Phase I  
   277 
   294 // 14  	CPX_ABORT_DUAL_INFEAS  
       
   295 // 	 Aborted in barrier, dual infeasible  
       
   296 // 15  	CPX_ABORT_PRIM_INFEAS  
       
   297 // 	 Aborted in barrier, primal infeasible  
       
   298 // 16  	CPX_ABORT_PRIM_DUAL_INFEAS  
       
   299 // 	 Aborted in barrier, primal and dual infeasible  
       
   300 // 17  	CPX_ABORT_PRIM_DUAL_FEAS  
       
   301 // 	 Aborted in barrier, primal and dual feasible  
       
   302 // 18  	CPX_ABORT_CROSSOVER  
       
   303 // 	 Aborted in crossover  
       
   304 // 19  	CPX_INForUNBD  
       
   305 // 	 Infeasible or unbounded  
       
   306 // 20   CPX_PIVOT
       
   307 //       User pivot used
       
   308 //
   278 //     Ezeket hova tegyem:
   309 //     Ezeket hova tegyem:
   279 // ??case CPX_ABORT_DUAL_INFEAS           
   310 // ??case CPX_ABORT_DUAL_INFEAS           
   280 // ??case CPX_ABORT_CROSSOVER             
   311 // ??case CPX_ABORT_CROSSOVER             
   281 // ??case CPX_INForUNBD                   
   312 // ??case CPX_INForUNBD                   
   282 // ??case CPX_PIVOT                       
   313 // ??case CPX_PIVOT                       
   283 
   314 
       
   315   LpCplex::SolutionStatus LpCplex::_getPrimalStatus()
       
   316   {
   284     int stat = CPXgetstat (env, lp);
   317     int stat = CPXgetstat (env, lp);
   285     switch (stat) {
   318     switch (stat) {
   286     case 0:
   319     case 0:
   287       return UNDEFINED; //Undefined
   320       return UNDEFINED; //Undefined
   288       break;      
       
   289     case CPX_OPTIMAL://Optimal
   321     case CPX_OPTIMAL://Optimal
   290       return OPTIMAL;
   322       return OPTIMAL;
   291       break;
       
   292     case CPX_UNBOUNDED://Unbounded
   323     case CPX_UNBOUNDED://Unbounded
   293       return INFINITE;
   324       return INFINITE;
   294       break;
       
   295     case CPX_INFEASIBLE://Infeasible 
   325     case CPX_INFEASIBLE://Infeasible 
   296     case CPX_IT_LIM_INFEAS:
   326  //    case CPX_IT_LIM_INFEAS:
   297     case CPX_TIME_LIM_INFEAS:
   327 //     case CPX_TIME_LIM_INFEAS:
   298     case CPX_NUM_BEST_INFEAS:             
   328 //     case CPX_NUM_BEST_INFEAS:             
   299     case CPX_OPTIMAL_INFEAS:              
   329 //     case CPX_OPTIMAL_INFEAS:              
   300     case CPX_ABORT_INFEAS:                
   330 //     case CPX_ABORT_INFEAS:                
   301     case CPX_ABORT_PRIM_INFEAS:           
   331 //     case CPX_ABORT_PRIM_INFEAS:           
   302     case CPX_ABORT_PRIM_DUAL_INFEAS:      
   332 //     case CPX_ABORT_PRIM_DUAL_INFEAS:      
   303       return INFEASIBLE;
   333       return INFEASIBLE;
   304       break;
   334 //     case CPX_OBJ_LIM:                    
   305     case CPX_OBJ_LIM:                    
   335 //     case CPX_IT_LIM_FEAS:             
   306     case CPX_IT_LIM_FEAS:             
   336 //     case CPX_TIME_LIM_FEAS:                
   307     case CPX_TIME_LIM_FEAS:                
   337 //     case CPX_NUM_BEST_FEAS:                
   308     case CPX_NUM_BEST_FEAS:                
   338 //     case CPX_ABORT_FEAS:                  
   309     case CPX_ABORT_FEAS:                  
   339 //     case CPX_ABORT_PRIM_DUAL_FEAS:        
   310     case CPX_ABORT_PRIM_DUAL_FEAS:        
   340 //       return FEASIBLE;
   311       return FEASIBLE;
       
   312       break;
       
   313     default:
   341     default:
   314       return UNDEFINED; //Everything else comes here
   342       return UNDEFINED; //Everything else comes here
   315       //FIXME error
   343       //FIXME error
   316     }
   344     }
   317 
   345 
   318 
   346   }
   319     //Nem tudom, hanyas cplex verzio statusai
   347 
       
   348 //9.0-as cplex verzio statusai
   320 // CPX_STAT_ABORT_DUAL_OBJ_LIM
   349 // CPX_STAT_ABORT_DUAL_OBJ_LIM
   321 // CPX_STAT_ABORT_IT_LIM
   350 // CPX_STAT_ABORT_IT_LIM
   322 // CPX_STAT_ABORT_OBJ_LIM
   351 // CPX_STAT_ABORT_OBJ_LIM
   323 // CPX_STAT_ABORT_PRIM_OBJ_LIM
   352 // CPX_STAT_ABORT_PRIM_OBJ_LIM
   324 // CPX_STAT_ABORT_TIME_LIM
   353 // CPX_STAT_ABORT_TIME_LIM
   331 // CPX_STAT_OPTIMAL_FACE_UNBOUNDED
   360 // CPX_STAT_OPTIMAL_FACE_UNBOUNDED
   332 // CPX_STAT_OPTIMAL_INFEAS
   361 // CPX_STAT_OPTIMAL_INFEAS
   333 // CPX_STAT_OPTIMAL_RELAXED
   362 // CPX_STAT_OPTIMAL_RELAXED
   334 // CPX_STAT_UNBOUNDED
   363 // CPX_STAT_UNBOUNDED
   335 
   364 
   336 //     int stat = CPXgetstat (env, lp);
   365   LpCplex::SolutionStatus LpCplex::_getDualStatus()
   337 //     switch (stat) {
   366   {
   338 //     case CPX_STAT_OPTIMAL://Optimal
   367     int stat = CPXgetstat (env, lp);
   339 //       return OPTIMAL;
   368     switch (stat) {
   340 //       break;
   369     case 0:
   341 //     case CPX_STAT_INFEASIBLE://Infeasible 
   370       return UNDEFINED; //Undefined
   342 //       return INFEASIBLE;
   371     case CPX_OPTIMAL://Optimal
   343 //       break;
   372       return OPTIMAL;
   344 //     case CPX_STAT_UNBOUNDED://Unbounded
   373     case CPX_UNBOUNDED:
   345 //       return INFINITE;
   374      return INFEASIBLE;
   346 //       break;
   375     default:
   347 //     case CPX_STAT_NUM_BEST://Feasible
   376       return UNDEFINED; //Everything else comes here
   348 //       return FEASIBLE;
   377       //FIXME error
   349 //       break;
   378     }
   350 //     default:
       
   351 //       return UNDEFINED; //Everything else comes here
       
   352 //       //FIXME error
       
   353 //     }
       
   354 
       
   355   }
       
   356 
   379 
   357   LpCplex::Value LpCplex::_getPrimal(int i)
   380   LpCplex::Value LpCplex::_getPrimal(int i)
   358   {
   381   {
   359     Value x;
   382     Value x;
   360     CPXgetx (env, lp, &x, i, i);
   383     CPXgetx (env, lp, &x, i, i);