lemon/lp_cplex.cc
changeset 2388 c6d537888fe5
parent 2364 3a5e67bd42d2
child 2391 14a343be7a5a
equal deleted inserted replaced
21:9940554549da 22:1fd44b8ecb1f
    82   
    82   
    83   void LpCplex::_eraseRow(int i) {
    83   void LpCplex::_eraseRow(int i) {
    84     CPXdelrows(env, lp, i, i);
    84     CPXdelrows(env, lp, i, i);
    85   }
    85   }
    86   
    86   
    87   void LpCplex::_getColName(int col, std::string &name)
    87   void LpCplex::_getColName(int col, std::string &name) const
    88   {
    88   {
    89     ///\bug Untested
    89     ///\bug Untested
    90     int storespace;
    90     int storespace;
    91     CPXgetcolname(env, lp, 0, 0, 0, &storespace, col, col);
    91     CPXgetcolname(env, lp, 0, 0, 0, &storespace, col, col);
    92 
    92 
   105     char *names[1];
   105     char *names[1];
   106     names[0] = const_cast<char*>(name.c_str());
   106     names[0] = const_cast<char*>(name.c_str());
   107     ///\bug return code unchecked for error
   107     ///\bug return code unchecked for error
   108     CPXchgcolname(env, lp, 1, &col, names);    
   108     CPXchgcolname(env, lp, 1, &col, names);    
   109   }
   109   }
       
   110 
       
   111   int LpCplex::_colByName(const std::string& name) const
       
   112   {
       
   113     int index;
       
   114     if (CPXgetcolindex(env, lp, 
       
   115                        const_cast<char*>(name.c_str()), &index) == 0) {
       
   116       return index;
       
   117     }
       
   118     return -1; 
       
   119   }
   110   
   120   
   111   ///\warning Data at index 0 is ignored in the arrays.
   121   ///\warning Data at index 0 is ignored in the arrays.
   112   void LpCplex::_setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e)
   122   void LpCplex::_setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e)
   113   {
   123   {
   114     std::vector<int> indices;
   124     std::vector<int> indices;
   123 
   133 
   124     status = CPXchgcoeflist(env, lp, values.size(), 
   134     status = CPXchgcoeflist(env, lp, values.size(), 
   125 			    &rowlist[0], &indices[0], &values[0]); 
   135 			    &rowlist[0], &indices[0], &values[0]); 
   126   }
   136   }
   127 
   137 
   128   void LpSoplex::_getRowCoeffs(int i, RowIterator b) {
   138   void LpSoplex::_getRowCoeffs(int i, RowIterator b) const {
   129     /// \todo implement
   139     /// \todo implement
   130   }
   140   }
   131   
   141   
   132   void LpCplex::_setColCoeffs(int i, ConstColIterator b, ConstColIterator e)
   142   void LpCplex::_setColCoeffs(int i, ConstColIterator b, ConstColIterator e)
   133   {
   143   {
   143 
   153 
   144     status = CPXchgcoeflist(env, lp, values.size(), 
   154     status = CPXchgcoeflist(env, lp, values.size(), 
   145 			    &indices[0], &collist[0], &values[0]); 
   155 			    &indices[0], &collist[0], &values[0]); 
   146   }
   156   }
   147 
   157 
   148   void LpSoplex::_getColCoeffs(int i, ColIterator b) {
   158   void LpSoplex::_getColCoeffs(int i, ColIterator b) const {
   149     /// \todo implement
   159     /// \todo implement
   150   }
   160   }
   151   
   161   
   152   void LpCplex::_setCoeff(int row, int col, Value value) 
   162   void LpCplex::_setCoeff(int row, int col, Value value) 
   153   {
   163   {
   154     CPXchgcoef(env, lp, row, col, value);
   164     CPXchgcoef(env, lp, row, col, value);
   155   }
   165   }
   156 
   166 
   157   LpCplex::Value LpCplex::_getCoeff(int row, int col) 
   167   LpCplex::Value LpCplex::_getCoeff(int row, int col) const
   158   {
   168   {
   159     LpCplex::Value value;
   169     LpCplex::Value value;
   160     CPXgetcoef(env, lp, row, col, &value);
   170     CPXgetcoef(env, lp, row, col, &value);
   161     return value;
   171     return value;
   162   }
   172   }
   171     bd[0]=value;
   181     bd[0]=value;
   172     status = CPXchgbds(env, lp, 1, indices, lu, bd);
   182     status = CPXchgbds(env, lp, 1, indices, lu, bd);
   173  
   183  
   174   }
   184   }
   175 
   185 
   176   LpCplex::Value LpCplex::_getColLowerBound(int i)
   186   LpCplex::Value LpCplex::_getColLowerBound(int i) const
   177   {
   187   {
   178     LpCplex::Value x;
   188     LpCplex::Value x;
   179     CPXgetlb (env, lp, &x, i, i);
   189     CPXgetlb (env, lp, &x, i, i);
   180     return x;
   190     return x;
   181   }
   191   }
   189     Value bd[1];
   199     Value bd[1];
   190     bd[0]=value;
   200     bd[0]=value;
   191     status = CPXchgbds(env, lp, 1, indices, lu, bd);
   201     status = CPXchgbds(env, lp, 1, indices, lu, bd);
   192   }
   202   }
   193 
   203 
   194   LpCplex::Value LpCplex::_getColUpperBound(int i)
   204   LpCplex::Value LpCplex::_getColUpperBound(int i) const
   195   {
   205   {
   196     LpCplex::Value x;
   206     LpCplex::Value x;
   197     CPXgetub (env, lp, &x, i, i);
   207     CPXgetub (env, lp, &x, i, i);
   198     return x;
   208     return x;
   199   }
   209   }
   268 // //     }
   278 // //     }
   269 
   279 
   270 // //     status = CPXchgcoef(env, lp, i, -2, value_rng);
   280 // //     status = CPXchgcoef(env, lp, i, -2, value_rng);
   271 //   }
   281 //   }
   272   
   282   
   273   void LpCplex::_getRowBounds(int i, Value &lb, Value &ub)
   283   void LpCplex::_getRowBounds(int i, Value &lb, Value &ub) const
   274   {
   284   {
   275     char sense;
   285     char sense;
   276     CPXgetsense(env, lp, &sense,i,i);
   286     CPXgetsense(env, lp, &sense,i,i);
   277     lb=-INF;
   287     lb=-INF;
   278     ub=INF;
   288     ub=INF;
   300   void LpCplex::_setObjCoeff(int i, Value obj_coef)
   310   void LpCplex::_setObjCoeff(int i, Value obj_coef)
   301   {
   311   {
   302     CPXchgcoef(env, lp, -1, i, obj_coef);
   312     CPXchgcoef(env, lp, -1, i, obj_coef);
   303   }
   313   }
   304 
   314 
   305   LpCplex::Value LpCplex::_getObjCoeff(int i)
   315   LpCplex::Value LpCplex::_getObjCoeff(int i) const
   306   {
   316   {
   307     Value x;
   317     Value x;
   308     CPXgetcoef(env, lp, -1, i, &x);
   318     CPXgetcoef(env, lp, -1, i, &x);
   309     return x;
   319     return x;
   310   }
   320   }
   365       return UNSOLVED;
   375       return UNSOLVED;
   366     }
   376     }
   367 #endif
   377 #endif
   368   }
   378   }
   369 
   379 
   370   LpCplex::Value LpCplex::_getPrimal(int i)
   380   LpCplex::Value LpCplex::_getPrimal(int i) const
   371   {
   381   {
   372     Value x;
   382     Value x;
   373     CPXgetx(env, lp, &x, i, i);
   383     CPXgetx(env, lp, &x, i, i);
   374     return x;
   384     return x;
   375   }
   385   }
   376 
   386 
   377   LpCplex::Value LpCplex::_getDual(int i)
   387   LpCplex::Value LpCplex::_getDual(int i) const
   378   {
   388   {
   379     Value y;
   389     Value y;
   380     CPXgetpi(env, lp, &y, i, i);
   390     CPXgetpi(env, lp, &y, i, i);
   381     return y;
   391     return y;
   382   }
   392   }
   383   
   393   
   384   LpCplex::Value LpCplex::_getPrimalValue()
   394   LpCplex::Value LpCplex::_getPrimalValue() const
   385   {
   395   {
   386     Value objval;
   396     Value objval;
   387     //method = CPXgetmethod (env, lp);
   397     //method = CPXgetmethod (env, lp);
   388     //printf("CPXgetprobtype %d \n",CPXgetprobtype(env,lp));
   398     //printf("CPXgetprobtype %d \n",CPXgetprobtype(env,lp));
   389     status = CPXgetobjval(env, lp, &objval);
   399     status = CPXgetobjval(env, lp, &objval);
   390     //printf("Objective value: %g \n",objval);
   400     //printf("Objective value: %g \n",objval);
   391     return objval;
   401     return objval;
   392   }
   402   }
   393   bool LpCplex::_isBasicCol(int i) {
   403   bool LpCplex::_isBasicCol(int i) const
       
   404   {
   394     int cstat[CPXgetnumcols(env, lp)];
   405     int cstat[CPXgetnumcols(env, lp)];
   395     CPXgetbase(env, lp, cstat, NULL);
   406     CPXgetbase(env, lp, cstat, NULL);
   396     return (cstat[i]==CPX_BASIC);
   407     return (cstat[i]==CPX_BASIC);
   397   }  
   408   }  
   398 
   409 
   456 // 3 Network Simplex 
   467 // 3 Network Simplex 
   457 // 4 Standard Barrier 
   468 // 4 Standard Barrier 
   458 // Default: 0 
   469 // Default: 0 
   459 // Description: Method for linear optimization. 
   470 // Description: Method for linear optimization. 
   460 // Determines which algorithm is used when CPXlpopt() (or "optimize" in the Interactive Optimizer) is called. Currently the behavior of the "Automatic" setting is that CPLEX simply invokes the dual simplex method, but this capability may be expanded in the future so that CPLEX chooses the method based on problem characteristics 
   471 // Determines which algorithm is used when CPXlpopt() (or "optimize" in the Interactive Optimizer) is called. Currently the behavior of the "Automatic" setting is that CPLEX simply invokes the dual simplex method, but this capability may be expanded in the future so that CPLEX chooses the method based on problem characteristics 
   461   //Hulye cplex
       
   462   void statusSwitch(CPXENVptr env,int& stat){
   472   void statusSwitch(CPXENVptr env,int& stat){
   463 #if CPX_VERSION < 900
   473 #if CPX_VERSION < 900
   464     int lpmethod;
   474     int lpmethod;
   465     CPXgetintparam (env,CPX_PARAM_LPMETHOD,&lpmethod);
   475     CPXgetintparam (env,CPX_PARAM_LPMETHOD,&lpmethod);
   466     if (lpmethod==2){
   476     if (lpmethod==2){
   473       }
   483       }
   474     }
   484     }
   475 #endif
   485 #endif
   476   }
   486   }
   477 
   487 
   478   LpCplex::SolutionStatus LpCplex::_getPrimalStatus()
   488   LpCplex::SolutionStatus LpCplex::_getPrimalStatus() const
   479   {
   489   {
   480     //Unboundedness not treated well: the following is from cplex 9.0 doc
   490     //Unboundedness not treated well: the following is from cplex 9.0 doc
   481     // About Unboundedness
   491     // About Unboundedness
   482 
   492 
   483     // The treatment of models that are unbounded involves a few
   493     // The treatment of models that are unbounded involves a few
   556 // CPX_STAT_OPTIMAL_FACE_UNBOUNDED
   566 // CPX_STAT_OPTIMAL_FACE_UNBOUNDED
   557 // CPX_STAT_OPTIMAL_INFEAS
   567 // CPX_STAT_OPTIMAL_INFEAS
   558 // CPX_STAT_OPTIMAL_RELAXED
   568 // CPX_STAT_OPTIMAL_RELAXED
   559 // CPX_STAT_UNBOUNDED
   569 // CPX_STAT_UNBOUNDED
   560 
   570 
   561   LpCplex::SolutionStatus LpCplex::_getDualStatus()
   571   LpCplex::SolutionStatus LpCplex::_getDualStatus() const
   562   {
   572   {
   563     int stat = CPXgetstat(env, lp);
   573     int stat = CPXgetstat(env, lp);
   564 #if CPX_VERSION >= 800
   574 #if CPX_VERSION >= 800
   565     switch (stat)
   575     switch (stat)
   566     {
   576     {
   585       //FIXME error
   595       //FIXME error
   586     }
   596     }
   587 #endif
   597 #endif
   588   }
   598   }
   589 
   599 
   590   LpCplex::ProblemTypes LpCplex::_getProblemType()
   600   LpCplex::ProblemTypes LpCplex::_getProblemType() const
   591   {
   601   {
   592     int stat = CPXgetstat(env, lp);
   602     int stat = CPXgetstat(env, lp);
   593 #if CPX_VERSION >= 800
   603 #if CPX_VERSION >= 800
   594     switch (stat)
   604     switch (stat)
   595     {
   605     {
   625   void LpCplex::_setMin()
   635   void LpCplex::_setMin()
   626   {
   636   {
   627     CPXchgobjsen(env, lp, CPX_MIN);
   637     CPXchgobjsen(env, lp, CPX_MIN);
   628    }
   638    }
   629 
   639 
   630   bool LpCplex::_isMax()
   640   bool LpCplex::_isMax() const
   631   {
   641   {
   632     if (CPXgetobjsen(env, lp)==CPX_MAX)
   642     if (CPXgetobjsen(env, lp)==CPX_MAX)
   633       return true;
   643       return true;
   634     else
   644     else
   635       return false;
   645       return false;