src/lemon/lp_cplex.cc
changeset 1405 3626c7f10f14
parent 1381 998e8def9676
child 1407 7152559e3d08
equal deleted inserted replaced
0:e920226fe141 1:03b335ffe8ab
    12  * This software is provided "AS IS" with no warranty of any kind,
    12  * This software is provided "AS IS" with no warranty of any kind,
    13  * express or implied, and with no claim as to its suitability for any
    13  * express or implied, and with no claim as to its suitability for any
    14  * purpose.
    14  * purpose.
    15  *
    15  *
    16  */
    16  */
    17 
    17 #include <iostream>
    18 #include"lp_cplex.h"
    18 #include<lemon/lp_cplex.h>
    19 
    19 
    20 ///\file
    20 ///\file
    21 ///\brief Implementation of the LEMON-CPLEX lp solver interface.
    21 ///\brief Implementation of the LEMON-CPLEX lp solver interface.
    22 namespace lemon {
    22 namespace lemon {
    23   
    23   
    63 // 	  goto Terminate;
    63 // 	  goto Terminate;
    64 // 	}
    64 // 	}
    65       
    65       
    66   }
    66   }
    67   
    67   
    68   LpSolverBase &LpCplex::_newLp() {return *(LpSolverBase*)0;}
    68   LpSolverBase &LpCplex::_newLp() 
    69   LpSolverBase &LpCplex::_copyLp() {return *(LpSolverBase*)0;}
    69   {
       
    70     return *(LpSolverBase*)0;
       
    71   }
       
    72   LpSolverBase &LpCplex::_copyLp() {
       
    73     return *(LpSolverBase*)0;
       
    74     //Ez lesz majd CPXcloneprob (env, lp, &status);
       
    75   }
    70 
    76 
    71   int LpCplex::_addCol()
    77   int LpCplex::_addCol()
    72   {
    78   {
    73     int i = CPXgetnumcols (env, lp);
    79     int i = CPXgetnumcols (env, lp);
    74     Value lb[1],ub[1];
    80     Value lb[1],ub[1];
   153   {
   159   {
   154     //Bad parameter
   160     //Bad parameter
   155     if (lb==INF || ub==-INF) {
   161     if (lb==INF || ub==-INF) {
   156       //FIXME error
   162       //FIXME error
   157     }
   163     }
   158 
   164     
   159     int cnt=1;
   165     int cnt=1;
   160     int indices[1];
   166     int indices[1];
   161     indices[0]=i;
   167     indices[0]=i;
   162     char sense[1];
   168     char sense[1];
   163 
   169 
   164     if (lb==-INF){
   170     if (lb==-INF){
   165       sense[0]='L';
   171       sense[0]='L';
   166       CPXchgsense (env, lp, cnt, indices, sense);
   172       CPXchgsense (env, lp, cnt, indices, sense);
   167       CPXchgcoef (env, lp, i, -1, ub);
   173       CPXchgcoef (env, lp, i, -1, ub);
       
   174       
   168     }
   175     }
   169     else{
   176     else{
   170       if (ub==INF){
   177       if (ub==INF){
   171 	sense[0]='G';
   178 	sense[0]='G';
   172 	CPXchgsense (env, lp, cnt, indices, sense);
   179 	CPXchgsense (env, lp, cnt, indices, sense);
   186 	}
   193 	}
   187       }
   194       }
   188     }
   195     }
   189   }
   196   }
   190 
   197 
   191   void LpCplex::_setRowLowerBound(int i, Value value)
   198 //   void LpCplex::_setRowLowerBound(int i, Value value)
   192   {
   199 //   {
   193     //Not implemented, obsolete
   200 //     //Not implemented, obsolete
   194   }
   201 //   }
   195   
   202   
   196   void LpCplex::_setRowUpperBound(int i, Value value)
   203 //   void LpCplex::_setRowUpperBound(int i, Value value)
   197   {
   204 //   {
   198     //Not implemented, obsolete
   205 //     //Not implemented, obsolete
   199 //     //TODO Ezt kell meg megirni
   206 // //     //TODO Ezt kell meg megirni
   200 //     //type of the problem
   207 // //     //type of the problem
   201 //     char sense[1];
   208 // //     char sense[1];
   202 //     status = CPXgetsense (env, lp, sense, i, i);
   209 // //     status = CPXgetsense (env, lp, sense, i, i);
   203 //     Value rhs[1];
   210 // //     Value rhs[1];
   204 //     status = CPXgetrhs (env, lp, rhs, i, i);
   211 // //     status = CPXgetrhs (env, lp, rhs, i, i);
   205 
   212 
   206 //     switch (sense[0]) {
   213 // //     switch (sense[0]) {
   207 //     case 'L'://<= constraint
   214 // //     case 'L'://<= constraint
   208 //       break;
   215 // //       break;
   209 //     case 'E'://= constraint
   216 // //     case 'E'://= constraint
   210 //       break;
   217 // //       break;
   211 //     case 'G'://>= constraint
   218 // //     case 'G'://>= constraint
   212 //       break;
   219 // //       break;
   213 //     case 'R'://ranged constraint
   220 // //     case 'R'://ranged constraint
   214 //       break;
   221 // //       break;
   215 //     default: ;
   222 // //     default: ;
   216 //       //FIXME error
   223 // //       //FIXME error
   217 //     }
   224 // //     }
   218 
   225 
   219 //     status = CPXchgcoef (env, lp, i, -2, value_rng);
   226 // //     status = CPXchgcoef (env, lp, i, -2, value_rng);
   220   }
   227 //   }
   221   
   228   
   222   void LpCplex::_setObjCoeff(int i, Value obj_coef)
   229   void LpCplex::_setObjCoeff(int i, Value obj_coef)
   223   {
   230   {
   224     CPXchgcoef (env, lp, -1, i, obj_coef);
   231     CPXchgcoef (env, lp, -1, i, obj_coef);
   225   }
   232   }
   252 //     }
   259 //     }
   253   }
   260   }
   254 
   261 
   255   LpCplex::SolutionStatus LpCplex::_getPrimalStatus()
   262   LpCplex::SolutionStatus LpCplex::_getPrimalStatus()
   256   {
   263   {
       
   264 // CPX_STAT_ABORT_DUAL_OBJ_LIM
       
   265 // CPX_STAT_ABORT_IT_LIM
       
   266 // CPX_STAT_ABORT_OBJ_LIM
       
   267 // CPX_STAT_ABORT_PRIM_OBJ_LIM
       
   268 // CPX_STAT_ABORT_TIME_LIM
       
   269 // CPX_STAT_ABORT_USER
       
   270 // CPX_STAT_FEASIBLE_RELAXED
       
   271 // CPX_STAT_INFEASIBLE
       
   272 // CPX_STAT_INForUNBD
       
   273 // CPX_STAT_NUM_BEST
       
   274 // CPX_STAT_OPTIMAL
       
   275 // CPX_STAT_OPTIMAL_FACE_UNBOUNDED
       
   276 // CPX_STAT_OPTIMAL_INFEAS
       
   277 // CPX_STAT_OPTIMAL_RELAXED
       
   278 // CPX_STAT_UNBOUNDED
       
   279 
   257     //Unimplemented
   280     //Unimplemented
   258     return OPTIMAL;
   281     int stat = CPXgetstat (env, lp);
   259 //     int stat=  lpx_get_status(lp);
   282     switch (stat) {
   260 //     switch (stat) {
   283     case CPX_STAT_OPTIMAL://Optimal
   261 //     case LPX_UNDEF://Undefined (no solve has been run yet)
   284       return OPTIMAL;
   262 //       return UNDEFINED;
   285       break;
   263 //       break;
   286     case CPX_STAT_INFEASIBLE://Infeasible 
   264 //     case LPX_NOFEAS://There is no feasible solution (primal, I guess)
   287       return INFEASIBLE;
   265 //     case LPX_INFEAS://Infeasible 
   288       break;
   266 //       return INFEASIBLE;
   289     case CPX_STAT_UNBOUNDED://Unbounded
   267 //       break;
   290       return INFINITE;
   268 //     case LPX_UNBND://Unbounded
   291       break;
   269 //       return INFINITE;
   292     case CPX_STAT_NUM_BEST://Feasible
   270 //       break;
   293       return FEASIBLE;
   271 //     case LPX_FEAS://Feasible
   294       break;
   272 //       return FEASIBLE;
   295     default:
   273 //       break;
   296       return UNDEFINED; //Everything else comes here
   274 //     case LPX_OPT://Feasible
   297       //FIXME error
   275 //       return OPTIMAL;
   298     }
   276 //       break;
       
   277 //     default:
       
   278 //       return UNDEFINED; //to avoid gcc warning
       
   279 //       //FIXME error
       
   280 //     }
       
   281   }
   299   }
   282 
   300 
   283   LpCplex::Value LpCplex::_getPrimal(int i)
   301   LpCplex::Value LpCplex::_getPrimal(int i)
   284   {
   302   {
   285     Value x;
   303     Value x;
   287     return x;
   305     return x;
   288   }
   306   }
   289   
   307   
   290   LpCplex::Value LpCplex::_getPrimalValue()
   308   LpCplex::Value LpCplex::_getPrimalValue()
   291   {
   309   {
   292     //Unimplemented
   310     Value objval;
   293     return 0;
   311     //method = CPXgetmethod (env, lp);
       
   312     status = CPXgetobjval (env, lp, &objval);
       
   313     return objval;
   294   }
   314   }
   295   
   315   
   296  
   316  
   297 
   317 
   298 
   318