Not ready, but I commit it for simplicity.
authorathos
Thu, 09 Jun 2005 09:49:48 +0000
changeset 14587a483c1d38b5
parent 1457 be025fc1b13d
child 1459 2ee881cf30a8
Not ready, but I commit it for simplicity.
lemon/lp_base.h
lemon/lp_cplex.cc
lemon/lp_glpk.cc
     1.1 --- a/lemon/lp_base.h	Thu Jun 09 09:47:51 2005 +0000
     1.2 +++ b/lemon/lp_base.h	Thu Jun 09 09:49:48 2005 +0000
     1.3 @@ -108,11 +108,13 @@
     1.4  
     1.5    public:
     1.6  
     1.7 -    ///\e
     1.8 +    ///Possible outcomes of an LP solving procedure
     1.9      enum SolveExitStatus {
    1.10 -      ///\e
    1.11 +      ///This means that the problem has been successfully solved: either
    1.12 +      ///an optimal solution has been found or infeasibility/unboundedness
    1.13 +      ///has been proved.
    1.14        SOLVED = 0,
    1.15 -      ///\e
    1.16 +      ///Any other case (including the case when some user specified limit has been exceeded)
    1.17        UNSOLVED = 1
    1.18      };
    1.19        
    1.20 @@ -915,7 +917,11 @@
    1.21  
    1.22      ///@{
    1.23  
    1.24 -    ///\e
    1.25 +    ///\e Solve the LP problem at hand
    1.26 +    ///
    1.27 +    ///\return The result of the optimization procedure. Possible values and their meanings can be found in the documentation of \ref SolveExitStatus.
    1.28 +    ///
    1.29 +    ///\todo Which method is used to solve the problem
    1.30      SolveExitStatus solve() { return _solve(); }
    1.31      
    1.32      ///@}
    1.33 @@ -924,7 +930,7 @@
    1.34  
    1.35      ///@{
    1.36  
    1.37 -    ///\e
    1.38 +    ///\e 
    1.39      SolutionStatus primalStatus() {
    1.40        return _getPrimalStatus();
    1.41      }
     2.1 --- a/lemon/lp_cplex.cc	Thu Jun 09 09:47:51 2005 +0000
     2.2 +++ b/lemon/lp_cplex.cc	Thu Jun 09 09:49:48 2005 +0000
     2.3 @@ -25,7 +25,6 @@
     2.4      //    env = CPXopenCPLEXdevelop(&status);     
     2.5      env = CPXopenCPLEX(&status);     
     2.6      lp = CPXcreateprob(env, &status, "LP problem");
     2.7 -    //CPXmsg (cpxresults, "Hello-bello\n");
     2.8    }
     2.9    
    2.10    LpCplex::~LpCplex() {
    2.11 @@ -230,93 +229,123 @@
    2.12      }
    2.13      
    2.14    }
    2.15 -
    2.16 +  // The routine returns zero unless an error occurred during the
    2.17 +  // optimization. Examples of errors include exhausting available
    2.18 +  // memory (CPXERR_NO_MEMORY) or encountering invalid data in the
    2.19 +  // CPLEX problem object (CPXERR_NO_PROBLEM). Exceeding a
    2.20 +  // user-specified CPLEX limit, or proving the model infeasible or
    2.21 +  // unbounded, are not considered errors. Note that a zero return
    2.22 +  // value does not necessarily mean that a solution exists. Use query
    2.23 +  // routines CPXsolninfo, CPXgetstat, and CPXsolution to obtain
    2.24 +  // further information about the status of the optimization.
    2.25    LpCplex::SolveExitStatus LpCplex::_solve()
    2.26    {
    2.27 -    
    2.28 +    //CPX_PARAM_LPMETHOD 
    2.29      status = CPXlpopt (env, lp);
    2.30      if (status == 0){
    2.31 -      return SOLVED;
    2.32 +      //We want to exclude some cases
    2.33 +      switch (CPXgetstat (env, lp)){
    2.34 +      case CPX_OBJ_LIM:
    2.35 +      case CPX_IT_LIM_FEAS:
    2.36 +      case CPX_IT_LIM_INFEAS:               
    2.37 +      case CPX_TIME_LIM_FEAS:
    2.38 +      case CPX_TIME_LIM_INFEAS:
    2.39 +	return UNSOLVED;
    2.40 +      default:
    2.41 +	return SOLVED; 
    2.42 +      }
    2.43      }
    2.44      else{
    2.45        return UNSOLVED;
    2.46      }
    2.47 -//     int i=  lpx_simplex(lp);
    2.48 -//     switch (i) {
    2.49 -//     case LPX_E_OK: 
    2.50 -//       return SOLVED;
    2.51 -//       break;
    2.52 -//     default:
    2.53 -//       return UNSOLVED;
    2.54 -//     }
    2.55    }
    2.56  
    2.57 -  LpCplex::SolutionStatus LpCplex::_getPrimalStatus()
    2.58 -  {
    2.59 -//7.5-os cplex statusai
    2.60 -// #define CPX_OPTIMAL                      1
    2.61 -// #define CPX_INFEASIBLE                   2
    2.62 -// #define CPX_UNBOUNDED                    3
    2.63 -// #define CPX_OBJ_LIM                      4
    2.64 -// #define CPX_IT_LIM_FEAS                  5
    2.65 -// #define CPX_IT_LIM_INFEAS                6
    2.66 -// #define CPX_TIME_LIM_FEAS                7
    2.67 -// #define CPX_TIME_LIM_INFEAS              8
    2.68 -// #define CPX_NUM_BEST_FEAS                9
    2.69 -// #define CPX_NUM_BEST_INFEAS             10
    2.70 -// #define CPX_OPTIMAL_INFEAS              11
    2.71 -// #define CPX_ABORT_FEAS                  12
    2.72 -// #define CPX_ABORT_INFEAS                13
    2.73 -// #define CPX_ABORT_DUAL_INFEAS           14
    2.74 -// #define CPX_ABORT_PRIM_INFEAS           15
    2.75 -// #define CPX_ABORT_PRIM_DUAL_INFEAS      16
    2.76 -// #define CPX_ABORT_PRIM_DUAL_FEAS        17
    2.77 -// #define CPX_ABORT_CROSSOVER             18
    2.78 -// #define CPX_INForUNBD                   19
    2.79 -// #define CPX_PIVOT                       20
    2.80  
    2.81 +//7.5-os cplex statusai (Vigyazat: a 9.0-asei masok!)
    2.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.
    2.83 +
    2.84 +// For Simplex, Barrier  
    2.85 +// 1  	CPX_OPTIMAL  
    2.86 +// 	 Optimal solution found  
    2.87 +// 2  	CPX_INFEASIBLE  
    2.88 +// 	 Problem infeasible  
    2.89 +// 3    CPX_UNBOUNDED  
    2.90 +// 	 Problem unbounded  
    2.91 +// 4  	CPX_OBJ_LIM  
    2.92 +// 	 Objective limit exceeded in Phase II  
    2.93 +// 5  	CPX_IT_LIM_FEAS  
    2.94 +// 	 Iteration limit exceeded in Phase II  
    2.95 +// 6  	CPX_IT_LIM_INFEAS  
    2.96 +// 	 Iteration limit exceeded in Phase I  
    2.97 +// 7  	CPX_TIME_LIM_FEAS  
    2.98 +// 	 Time limit exceeded in Phase II  
    2.99 +// 8  	CPX_TIME_LIM_INFEAS  
   2.100 +// 	 Time limit exceeded in Phase I  
   2.101 +// 9  	CPX_NUM_BEST_FEAS  
   2.102 +// 	 Problem non-optimal, singularities in Phase II  
   2.103 +// 10 	CPX_NUM_BEST_INFEAS  
   2.104 +// 	 Problem non-optimal, singularities in Phase I  
   2.105 +// 11 	CPX_OPTIMAL_INFEAS  
   2.106 +// 	 Optimal solution found, unscaled infeasibilities  
   2.107 +// 12 	CPX_ABORT_FEAS  
   2.108 +// 	 Aborted in Phase II  
   2.109 +// 13 	CPX_ABORT_INFEAS  
   2.110 +// 	 Aborted in Phase I  
   2.111 +// 14  	CPX_ABORT_DUAL_INFEAS  
   2.112 +// 	 Aborted in barrier, dual infeasible  
   2.113 +// 15  	CPX_ABORT_PRIM_INFEAS  
   2.114 +// 	 Aborted in barrier, primal infeasible  
   2.115 +// 16  	CPX_ABORT_PRIM_DUAL_INFEAS  
   2.116 +// 	 Aborted in barrier, primal and dual infeasible  
   2.117 +// 17  	CPX_ABORT_PRIM_DUAL_FEAS  
   2.118 +// 	 Aborted in barrier, primal and dual feasible  
   2.119 +// 18  	CPX_ABORT_CROSSOVER  
   2.120 +// 	 Aborted in crossover  
   2.121 +// 19  	CPX_INForUNBD  
   2.122 +// 	 Infeasible or unbounded  
   2.123 +// 20   CPX_PIVOT
   2.124 +//       User pivot used
   2.125 +//
   2.126  //     Ezeket hova tegyem:
   2.127  // ??case CPX_ABORT_DUAL_INFEAS           
   2.128  // ??case CPX_ABORT_CROSSOVER             
   2.129  // ??case CPX_INForUNBD                   
   2.130  // ??case CPX_PIVOT                       
   2.131  
   2.132 +  LpCplex::SolutionStatus LpCplex::_getPrimalStatus()
   2.133 +  {
   2.134      int stat = CPXgetstat (env, lp);
   2.135      switch (stat) {
   2.136      case 0:
   2.137        return UNDEFINED; //Undefined
   2.138 -      break;      
   2.139      case CPX_OPTIMAL://Optimal
   2.140        return OPTIMAL;
   2.141 -      break;
   2.142      case CPX_UNBOUNDED://Unbounded
   2.143        return INFINITE;
   2.144 -      break;
   2.145      case CPX_INFEASIBLE://Infeasible 
   2.146 -    case CPX_IT_LIM_INFEAS:
   2.147 -    case CPX_TIME_LIM_INFEAS:
   2.148 -    case CPX_NUM_BEST_INFEAS:             
   2.149 -    case CPX_OPTIMAL_INFEAS:              
   2.150 -    case CPX_ABORT_INFEAS:                
   2.151 -    case CPX_ABORT_PRIM_INFEAS:           
   2.152 -    case CPX_ABORT_PRIM_DUAL_INFEAS:      
   2.153 + //    case CPX_IT_LIM_INFEAS:
   2.154 +//     case CPX_TIME_LIM_INFEAS:
   2.155 +//     case CPX_NUM_BEST_INFEAS:             
   2.156 +//     case CPX_OPTIMAL_INFEAS:              
   2.157 +//     case CPX_ABORT_INFEAS:                
   2.158 +//     case CPX_ABORT_PRIM_INFEAS:           
   2.159 +//     case CPX_ABORT_PRIM_DUAL_INFEAS:      
   2.160        return INFEASIBLE;
   2.161 -      break;
   2.162 -    case CPX_OBJ_LIM:                    
   2.163 -    case CPX_IT_LIM_FEAS:             
   2.164 -    case CPX_TIME_LIM_FEAS:                
   2.165 -    case CPX_NUM_BEST_FEAS:                
   2.166 -    case CPX_ABORT_FEAS:                  
   2.167 -    case CPX_ABORT_PRIM_DUAL_FEAS:        
   2.168 -      return FEASIBLE;
   2.169 -      break;
   2.170 +//     case CPX_OBJ_LIM:                    
   2.171 +//     case CPX_IT_LIM_FEAS:             
   2.172 +//     case CPX_TIME_LIM_FEAS:                
   2.173 +//     case CPX_NUM_BEST_FEAS:                
   2.174 +//     case CPX_ABORT_FEAS:                  
   2.175 +//     case CPX_ABORT_PRIM_DUAL_FEAS:        
   2.176 +//       return FEASIBLE;
   2.177      default:
   2.178        return UNDEFINED; //Everything else comes here
   2.179        //FIXME error
   2.180      }
   2.181  
   2.182 +  }
   2.183  
   2.184 -    //Nem tudom, hanyas cplex verzio statusai
   2.185 +//9.0-as cplex verzio statusai
   2.186  // CPX_STAT_ABORT_DUAL_OBJ_LIM
   2.187  // CPX_STAT_ABORT_IT_LIM
   2.188  // CPX_STAT_ABORT_OBJ_LIM
   2.189 @@ -333,26 +362,20 @@
   2.190  // CPX_STAT_OPTIMAL_RELAXED
   2.191  // CPX_STAT_UNBOUNDED
   2.192  
   2.193 -//     int stat = CPXgetstat (env, lp);
   2.194 -//     switch (stat) {
   2.195 -//     case CPX_STAT_OPTIMAL://Optimal
   2.196 -//       return OPTIMAL;
   2.197 -//       break;
   2.198 -//     case CPX_STAT_INFEASIBLE://Infeasible 
   2.199 -//       return INFEASIBLE;
   2.200 -//       break;
   2.201 -//     case CPX_STAT_UNBOUNDED://Unbounded
   2.202 -//       return INFINITE;
   2.203 -//       break;
   2.204 -//     case CPX_STAT_NUM_BEST://Feasible
   2.205 -//       return FEASIBLE;
   2.206 -//       break;
   2.207 -//     default:
   2.208 -//       return UNDEFINED; //Everything else comes here
   2.209 -//       //FIXME error
   2.210 -//     }
   2.211 -
   2.212 -  }
   2.213 +  LpCplex::SolutionStatus LpCplex::_getDualStatus()
   2.214 +  {
   2.215 +    int stat = CPXgetstat (env, lp);
   2.216 +    switch (stat) {
   2.217 +    case 0:
   2.218 +      return UNDEFINED; //Undefined
   2.219 +    case CPX_OPTIMAL://Optimal
   2.220 +      return OPTIMAL;
   2.221 +    case CPX_UNBOUNDED:
   2.222 +     return INFEASIBLE;
   2.223 +    default:
   2.224 +      return UNDEFINED; //Everything else comes here
   2.225 +      //FIXME error
   2.226 +    }
   2.227  
   2.228    LpCplex::Value LpCplex::_getPrimal(int i)
   2.229    {
     3.1 --- a/lemon/lp_glpk.cc	Thu Jun 09 09:47:51 2005 +0000
     3.2 +++ b/lemon/lp_glpk.cc	Thu Jun 09 09:49:48 2005 +0000
     3.3 @@ -396,11 +396,10 @@
     3.4  
     3.5    LpGlpk::SolveExitStatus LpGlpk::_solve()
     3.6    {
     3.7 -    int i=  lpx_simplex(lp);
     3.8 +    int i =  lpx_simplex(lp);
     3.9      switch (i) {
    3.10      case LPX_E_OK: 
    3.11        return SOLVED;
    3.12 -      break;
    3.13      default:
    3.14        return UNSOLVED;
    3.15      }
    3.16 @@ -423,6 +422,54 @@
    3.17      switch (stat) {
    3.18      case LPX_UNDEF://Undefined (no solve has been run yet)
    3.19        return UNDEFINED;
    3.20 +    case LPX_NOFEAS://There is no feasible solution (primal, I guess)
    3.21 +    case LPX_INFEAS://Infeasible 
    3.22 +      return INFEASIBLE;
    3.23 +    case LPX_UNBND://Unbounded
    3.24 +      return INFINITE;
    3.25 +    case LPX_FEAS://Feasible
    3.26 +      return FEASIBLE;
    3.27 +    case LPX_OPT://Feasible
    3.28 +      return OPTIMAL;
    3.29 +    default:
    3.30 +      return UNDEFINED; //to avoid gcc warning
    3.31 +      //FIXME error
    3.32 +    }
    3.33 +  }
    3.34 +
    3.35 +  LpGlpk::SolutionStatus LpGlpk::_getDualStatus()
    3.36 +  {
    3.37 +    int stat=  lpx_get_dual_stat(lp);
    3.38 +    switch (stat) {
    3.39 +    case LPX_D_UNDEF://Undefined (no solve has been run yet)
    3.40 +      return UNDEFINED;
    3.41 +    case LPX_D_NOFEAS://There is no feasible solution (primal, I guess)
    3.42 +    case LPX_D_INFEAS://Infeasible 
    3.43 +      return INFEASIBLE;
    3.44 +    case LPX_FEAS://Feasible    
    3.45 +      int stat2=  lpx_get_prim_stat(lp);
    3.46 +      switch (stat2){
    3.47 +      case LPX_P_NOFEAS:
    3.48 +	return INFINITE;
    3.49 +      case LPX_OPT:
    3.50 +	return OPTIMAL;
    3.51 +      default:
    3.52 +	return FEASIBLE;
    3.53 +      }
    3.54 +    default:
    3.55 +      return UNDEFINED; //to avoid gcc warning
    3.56 +      //FIXME error
    3.57 +    }
    3.58 +  }
    3.59 +
    3.60 +  LpGlpk::ProblemTypes LpGlpk::_problemType()
    3.61 +  {
    3.62 +    int stat=  lpx_get_status(lp);
    3.63 +    int statp=  lpx_get_prim_stat(lp);
    3.64 +    int statd=  lpx_get_dual_stat(lp);
    3.65 +    switch (stat) {
    3.66 +    case LPX_UNDEF://Undefined (no solve has been run yet)
    3.67 +      return UNDEFINED;
    3.68        break;
    3.69      case LPX_NOFEAS://There is no feasible solution (primal, I guess)
    3.70      case LPX_INFEAS://Infeasible 
    3.71 @@ -443,7 +490,6 @@
    3.72      }
    3.73    }
    3.74  
    3.75 -
    3.76    void LpGlpk::_setMax()
    3.77    {
    3.78      lpx_set_obj_dir(lp, LPX_MAX);