COIN-OR::LEMON - Graph Library

Changeset 2605:852361980706 in lemon-0.x for lemon/lp_cplex.cc


Ignore:
Timestamp:
04/08/08 18:01:28 (16 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3488
Message:

Bug fixes in LP solvers

  • the copyLp is clarified
  • newLp and copyLp gives back pointers
  • cplex gives back empty string for variables without name
  • cplex row and column retrieval
  • added macro for soplex
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/lp_cplex.cc

    r2591 r2605  
    1818
    1919#include <iostream>
     20#include <vector>
    2021#include<lemon/lp_cplex.h>
    2122
     
    2425namespace lemon {
    2526 
    26   LpCplex::LpCplex() : LpSolverBase() {
     27  LpCplex::LpCplex() {
    2728    //    env = CPXopenCPLEXdevelop(&status);     
    2829    env = CPXopenCPLEX(&status);     
    2930    lp = CPXcreateprob(env, &status, "LP problem");
    3031  }
     32
     33  LpCplex::LpCplex(const LpCplex& cplex) : LpSolverBase() {
     34    env = CPXopenCPLEX(&status);     
     35    lp = CPXcloneprob(env, cplex.lp, &status);
     36    rows = cplex.rows;
     37    cols = cplex.cols;
     38  }
    3139 
    3240  LpCplex::~LpCplex() {
    33     CPXfreeprob(env,&lp); 
    34     CPXcloseCPLEX(&env); 
    35   }
    36  
    37   LpSolverBase &LpCplex::_newLp()
     41    CPXfreeprob(env,&lp);
     42    CPXcloseCPLEX(&env);
     43  }
     44 
     45  LpSolverBase* LpCplex::_newLp()
    3846  {
    3947    //The first approach opens a new environment
    40     LpCplex* newlp=new LpCplex();
    41     return *newlp;
    42   }
    43 
    44   LpSolverBase &LpCplex::_copyLp() {
    45     ///\bug FixID data is not copied!
    46     //The first approach opens a new environment
    47     LpCplex* newlp=new LpCplex();
    48     //The routine CPXcloneprob can be used to create a new CPLEX problem
    49     //object and copy all the problem data from an existing problem
    50     //object to it. Solution and starting information is not copied.
    51     newlp->lp = CPXcloneprob(env, lp, &status);
    52     return *newlp;
     48    return new LpCplex();
     49  }
     50
     51  LpSolverBase* LpCplex::_copyLp() {
     52    return new LpCplex(*this);
    5353  }
    5454
     
    5757    int i = CPXgetnumcols(env, lp);
    5858    Value lb[1],ub[1];
    59     lb[0]=-INF;//-CPX_INFBOUND;
    60     ub[0]=INF;//CPX_INFBOUND;
     59    lb[0]=-INF;
     60    ub[0]=INF;
    6161    status = CPXnewcols(env, lp, 1, NULL, lb, ub, NULL, NULL);
    6262    return i;
     
    9090    int storespace;
    9191    CPXgetcolname(env, lp, 0, 0, 0, &storespace, col, col);
    92 
     92    if (storespace == 0) {
     93      name.clear();
     94      return;
     95    }
     96   
    9397    storespace *= -1;
    9498    std::vector<char> buf(storespace);
     
    137141
    138142  void LpCplex::_getRowCoeffs(int i, RowIterator b) const {
     143    int tmp1, tmp2, tmp3, length;
     144    CPXgetrows(env, lp, &tmp1, &tmp2, 0, 0, 0, &length, i, i);
     145   
     146    length = -length;
     147    std::vector<int> indices(length);
     148    std::vector<double> values(length);
     149
     150    CPXgetrows(env, lp, &tmp1, &tmp2, &indices[0], &values[0],
     151               length, &tmp3, i, i);
     152   
     153    for (int i = 0; i < length; ++i) {
     154      *b = std::make_pair(indices[i], values[i]);
     155      ++b;
     156    }
     157   
    139158    /// \todo implement
    140159  }
     
    157176
    158177  void LpCplex::_getColCoeffs(int i, ColIterator b) const {
    159     /// \todo implement
     178
     179    int tmp1, tmp2, tmp3, length;
     180    CPXgetcols(env, lp, &tmp1, &tmp2, 0, 0, 0, &length, i, i);
     181   
     182    length = -length;
     183    std::vector<int> indices(length);
     184    std::vector<double> values(length);
     185
     186    CPXgetcols(env, lp, &tmp1, &tmp2, &indices[0], &values[0],
     187               length, &tmp3, i, i);
     188   
     189    for (int i = 0; i < length; ++i) {
     190      *b = std::make_pair(indices[i], values[i]);
     191      ++b;
     192    }
     193   
    160194  }
    161195 
     
    188222    LpCplex::Value x;
    189223    CPXgetlb (env, lp, &x, i, i);
     224    if (x <= -CPX_INFBOUND) x = -INF;
    190225    return x;
    191226  }
     
    206241    LpCplex::Value x;
    207242    CPXgetub (env, lp, &x, i, i);
     243    if (x >= CPX_INFBOUND) x = INF;
    208244    return x;
    209245  }
     
    470506// Description: Method for linear optimization.
    471507// 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
     508#if CPX_VERSION < 900
    472509  void statusSwitch(CPXENVptr env,int& stat){
    473 #if CPX_VERSION < 900
    474510    int lpmethod;
    475511    CPXgetintparam (env,CPX_PARAM_LPMETHOD,&lpmethod);
     
    483519      }
    484520    }
     521  }
     522#else
     523  void statusSwitch(CPXENVptr,int&){}
    485524#endif
    486   }
    487525
    488526  LpCplex::SolutionStatus LpCplex::_getPrimalStatus() const
Note: See TracChangeset for help on using the changeset viewer.