lemon/lp_cplex.cc
changeset 1458 7a483c1d38b5
parent 1436 e0beb94d08bf
child 1460 7c58aabb9eea
     1.1 --- a/lemon/lp_cplex.cc	Thu Jun 09 09:47:51 2005 +0000
     1.2 +++ b/lemon/lp_cplex.cc	Thu Jun 09 09:49:48 2005 +0000
     1.3 @@ -25,7 +25,6 @@
     1.4      //    env = CPXopenCPLEXdevelop(&status);     
     1.5      env = CPXopenCPLEX(&status);     
     1.6      lp = CPXcreateprob(env, &status, "LP problem");
     1.7 -    //CPXmsg (cpxresults, "Hello-bello\n");
     1.8    }
     1.9    
    1.10    LpCplex::~LpCplex() {
    1.11 @@ -230,93 +229,123 @@
    1.12      }
    1.13      
    1.14    }
    1.15 -
    1.16 +  // The routine returns zero unless an error occurred during the
    1.17 +  // optimization. Examples of errors include exhausting available
    1.18 +  // memory (CPXERR_NO_MEMORY) or encountering invalid data in the
    1.19 +  // CPLEX problem object (CPXERR_NO_PROBLEM). Exceeding a
    1.20 +  // user-specified CPLEX limit, or proving the model infeasible or
    1.21 +  // unbounded, are not considered errors. Note that a zero return
    1.22 +  // value does not necessarily mean that a solution exists. Use query
    1.23 +  // routines CPXsolninfo, CPXgetstat, and CPXsolution to obtain
    1.24 +  // further information about the status of the optimization.
    1.25    LpCplex::SolveExitStatus LpCplex::_solve()
    1.26    {
    1.27 -    
    1.28 +    //CPX_PARAM_LPMETHOD 
    1.29      status = CPXlpopt (env, lp);
    1.30      if (status == 0){
    1.31 -      return SOLVED;
    1.32 +      //We want to exclude some cases
    1.33 +      switch (CPXgetstat (env, lp)){
    1.34 +      case CPX_OBJ_LIM:
    1.35 +      case CPX_IT_LIM_FEAS:
    1.36 +      case CPX_IT_LIM_INFEAS:               
    1.37 +      case CPX_TIME_LIM_FEAS:
    1.38 +      case CPX_TIME_LIM_INFEAS:
    1.39 +	return UNSOLVED;
    1.40 +      default:
    1.41 +	return SOLVED; 
    1.42 +      }
    1.43      }
    1.44      else{
    1.45        return UNSOLVED;
    1.46      }
    1.47 -//     int i=  lpx_simplex(lp);
    1.48 -//     switch (i) {
    1.49 -//     case LPX_E_OK: 
    1.50 -//       return SOLVED;
    1.51 -//       break;
    1.52 -//     default:
    1.53 -//       return UNSOLVED;
    1.54 -//     }
    1.55    }
    1.56  
    1.57 -  LpCplex::SolutionStatus LpCplex::_getPrimalStatus()
    1.58 -  {
    1.59 -//7.5-os cplex statusai
    1.60 -// #define CPX_OPTIMAL                      1
    1.61 -// #define CPX_INFEASIBLE                   2
    1.62 -// #define CPX_UNBOUNDED                    3
    1.63 -// #define CPX_OBJ_LIM                      4
    1.64 -// #define CPX_IT_LIM_FEAS                  5
    1.65 -// #define CPX_IT_LIM_INFEAS                6
    1.66 -// #define CPX_TIME_LIM_FEAS                7
    1.67 -// #define CPX_TIME_LIM_INFEAS              8
    1.68 -// #define CPX_NUM_BEST_FEAS                9
    1.69 -// #define CPX_NUM_BEST_INFEAS             10
    1.70 -// #define CPX_OPTIMAL_INFEAS              11
    1.71 -// #define CPX_ABORT_FEAS                  12
    1.72 -// #define CPX_ABORT_INFEAS                13
    1.73 -// #define CPX_ABORT_DUAL_INFEAS           14
    1.74 -// #define CPX_ABORT_PRIM_INFEAS           15
    1.75 -// #define CPX_ABORT_PRIM_DUAL_INFEAS      16
    1.76 -// #define CPX_ABORT_PRIM_DUAL_FEAS        17
    1.77 -// #define CPX_ABORT_CROSSOVER             18
    1.78 -// #define CPX_INForUNBD                   19
    1.79 -// #define CPX_PIVOT                       20
    1.80  
    1.81 +//7.5-os cplex statusai (Vigyazat: a 9.0-asei masok!)
    1.82 +// 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.
    1.83 +
    1.84 +// For Simplex, Barrier  
    1.85 +// 1  	CPX_OPTIMAL  
    1.86 +// 	 Optimal solution found  
    1.87 +// 2  	CPX_INFEASIBLE  
    1.88 +// 	 Problem infeasible  
    1.89 +// 3    CPX_UNBOUNDED  
    1.90 +// 	 Problem unbounded  
    1.91 +// 4  	CPX_OBJ_LIM  
    1.92 +// 	 Objective limit exceeded in Phase II  
    1.93 +// 5  	CPX_IT_LIM_FEAS  
    1.94 +// 	 Iteration limit exceeded in Phase II  
    1.95 +// 6  	CPX_IT_LIM_INFEAS  
    1.96 +// 	 Iteration limit exceeded in Phase I  
    1.97 +// 7  	CPX_TIME_LIM_FEAS  
    1.98 +// 	 Time limit exceeded in Phase II  
    1.99 +// 8  	CPX_TIME_LIM_INFEAS  
   1.100 +// 	 Time limit exceeded in Phase I  
   1.101 +// 9  	CPX_NUM_BEST_FEAS  
   1.102 +// 	 Problem non-optimal, singularities in Phase II  
   1.103 +// 10 	CPX_NUM_BEST_INFEAS  
   1.104 +// 	 Problem non-optimal, singularities in Phase I  
   1.105 +// 11 	CPX_OPTIMAL_INFEAS  
   1.106 +// 	 Optimal solution found, unscaled infeasibilities  
   1.107 +// 12 	CPX_ABORT_FEAS  
   1.108 +// 	 Aborted in Phase II  
   1.109 +// 13 	CPX_ABORT_INFEAS  
   1.110 +// 	 Aborted in Phase I  
   1.111 +// 14  	CPX_ABORT_DUAL_INFEAS  
   1.112 +// 	 Aborted in barrier, dual infeasible  
   1.113 +// 15  	CPX_ABORT_PRIM_INFEAS  
   1.114 +// 	 Aborted in barrier, primal infeasible  
   1.115 +// 16  	CPX_ABORT_PRIM_DUAL_INFEAS  
   1.116 +// 	 Aborted in barrier, primal and dual infeasible  
   1.117 +// 17  	CPX_ABORT_PRIM_DUAL_FEAS  
   1.118 +// 	 Aborted in barrier, primal and dual feasible  
   1.119 +// 18  	CPX_ABORT_CROSSOVER  
   1.120 +// 	 Aborted in crossover  
   1.121 +// 19  	CPX_INForUNBD  
   1.122 +// 	 Infeasible or unbounded  
   1.123 +// 20   CPX_PIVOT
   1.124 +//       User pivot used
   1.125 +//
   1.126  //     Ezeket hova tegyem:
   1.127  // ??case CPX_ABORT_DUAL_INFEAS           
   1.128  // ??case CPX_ABORT_CROSSOVER             
   1.129  // ??case CPX_INForUNBD                   
   1.130  // ??case CPX_PIVOT                       
   1.131  
   1.132 +  LpCplex::SolutionStatus LpCplex::_getPrimalStatus()
   1.133 +  {
   1.134      int stat = CPXgetstat (env, lp);
   1.135      switch (stat) {
   1.136      case 0:
   1.137        return UNDEFINED; //Undefined
   1.138 -      break;      
   1.139      case CPX_OPTIMAL://Optimal
   1.140        return OPTIMAL;
   1.141 -      break;
   1.142      case CPX_UNBOUNDED://Unbounded
   1.143        return INFINITE;
   1.144 -      break;
   1.145      case CPX_INFEASIBLE://Infeasible 
   1.146 -    case CPX_IT_LIM_INFEAS:
   1.147 -    case CPX_TIME_LIM_INFEAS:
   1.148 -    case CPX_NUM_BEST_INFEAS:             
   1.149 -    case CPX_OPTIMAL_INFEAS:              
   1.150 -    case CPX_ABORT_INFEAS:                
   1.151 -    case CPX_ABORT_PRIM_INFEAS:           
   1.152 -    case CPX_ABORT_PRIM_DUAL_INFEAS:      
   1.153 + //    case CPX_IT_LIM_INFEAS:
   1.154 +//     case CPX_TIME_LIM_INFEAS:
   1.155 +//     case CPX_NUM_BEST_INFEAS:             
   1.156 +//     case CPX_OPTIMAL_INFEAS:              
   1.157 +//     case CPX_ABORT_INFEAS:                
   1.158 +//     case CPX_ABORT_PRIM_INFEAS:           
   1.159 +//     case CPX_ABORT_PRIM_DUAL_INFEAS:      
   1.160        return INFEASIBLE;
   1.161 -      break;
   1.162 -    case CPX_OBJ_LIM:                    
   1.163 -    case CPX_IT_LIM_FEAS:             
   1.164 -    case CPX_TIME_LIM_FEAS:                
   1.165 -    case CPX_NUM_BEST_FEAS:                
   1.166 -    case CPX_ABORT_FEAS:                  
   1.167 -    case CPX_ABORT_PRIM_DUAL_FEAS:        
   1.168 -      return FEASIBLE;
   1.169 -      break;
   1.170 +//     case CPX_OBJ_LIM:                    
   1.171 +//     case CPX_IT_LIM_FEAS:             
   1.172 +//     case CPX_TIME_LIM_FEAS:                
   1.173 +//     case CPX_NUM_BEST_FEAS:                
   1.174 +//     case CPX_ABORT_FEAS:                  
   1.175 +//     case CPX_ABORT_PRIM_DUAL_FEAS:        
   1.176 +//       return FEASIBLE;
   1.177      default:
   1.178        return UNDEFINED; //Everything else comes here
   1.179        //FIXME error
   1.180      }
   1.181  
   1.182 +  }
   1.183  
   1.184 -    //Nem tudom, hanyas cplex verzio statusai
   1.185 +//9.0-as cplex verzio statusai
   1.186  // CPX_STAT_ABORT_DUAL_OBJ_LIM
   1.187  // CPX_STAT_ABORT_IT_LIM
   1.188  // CPX_STAT_ABORT_OBJ_LIM
   1.189 @@ -333,26 +362,20 @@
   1.190  // CPX_STAT_OPTIMAL_RELAXED
   1.191  // CPX_STAT_UNBOUNDED
   1.192  
   1.193 -//     int stat = CPXgetstat (env, lp);
   1.194 -//     switch (stat) {
   1.195 -//     case CPX_STAT_OPTIMAL://Optimal
   1.196 -//       return OPTIMAL;
   1.197 -//       break;
   1.198 -//     case CPX_STAT_INFEASIBLE://Infeasible 
   1.199 -//       return INFEASIBLE;
   1.200 -//       break;
   1.201 -//     case CPX_STAT_UNBOUNDED://Unbounded
   1.202 -//       return INFINITE;
   1.203 -//       break;
   1.204 -//     case CPX_STAT_NUM_BEST://Feasible
   1.205 -//       return FEASIBLE;
   1.206 -//       break;
   1.207 -//     default:
   1.208 -//       return UNDEFINED; //Everything else comes here
   1.209 -//       //FIXME error
   1.210 -//     }
   1.211 -
   1.212 -  }
   1.213 +  LpCplex::SolutionStatus LpCplex::_getDualStatus()
   1.214 +  {
   1.215 +    int stat = CPXgetstat (env, lp);
   1.216 +    switch (stat) {
   1.217 +    case 0:
   1.218 +      return UNDEFINED; //Undefined
   1.219 +    case CPX_OPTIMAL://Optimal
   1.220 +      return OPTIMAL;
   1.221 +    case CPX_UNBOUNDED:
   1.222 +     return INFEASIBLE;
   1.223 +    default:
   1.224 +      return UNDEFINED; //Everything else comes here
   1.225 +      //FIXME error
   1.226 +    }
   1.227  
   1.228    LpCplex::Value LpCplex::_getPrimal(int i)
   1.229    {