lemon/lp_soplex.cc
changeset 2366 bfbdded3763a
parent 2364 3a5e67bd42d2
child 2368 6b2e8b734ae7
equal deleted inserted replaced
2:053f8c567490 3:44b93eb26297
    88     dual_value[i] = dual_value.back();
    88     dual_value[i] = dual_value.back();
    89     dual_value.pop_back();
    89     dual_value.pop_back();
    90     solved = false;
    90     solved = false;
    91   }
    91   }
    92   
    92   
    93   void LpSoplex::_getColName(int col, std::string &name) {
    93   void LpSoplex::_getColName(int col, std::string &name) const {
    94     name = colNames[col]; 
    94     name = colNames[col]; 
    95   }
    95   }
    96   
    96   
    97   void LpSoplex::_setColName(int col, const std::string &name) {
    97   void LpSoplex::_setColName(int col, const std::string &name) {
       
    98     invColNames.erase(colNames[col]);
    98     colNames[col] = name; 
    99     colNames[col] = name; 
       
   100     if (!name.empty()) {
       
   101       invColNames.insert(std::make_pair(name, col));
       
   102     }
       
   103   }
       
   104 
       
   105   int LpSoplex::_colByName(const std::string& name) const {
       
   106     std::map<std::string, int>::const_iterator it =
       
   107       invColNames.find(name);
       
   108     if (it != invColNames.end()) {
       
   109       return it->second;
       
   110     } else {
       
   111       return -1;
       
   112     }
    99   }
   113   }
   100   
   114   
   101 
   115 
   102   void LpSoplex::_setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e) {
   116   void LpSoplex::_setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e) {
   103     for (int j = 0; j < soplex->nCols(); ++j) {
   117     for (int j = 0; j < soplex->nCols(); ++j) {
   107       soplex->changeElement(i, it->first, it->second);
   121       soplex->changeElement(i, it->first, it->second);
   108     }
   122     }
   109     solved = false;
   123     solved = false;
   110   }
   124   }
   111 
   125 
   112   void LpSoplex::_getRowCoeffs(int i, RowIterator b) {
   126   void LpSoplex::_getRowCoeffs(int i, RowIterator b) const {
   113     const soplex::SVector& vec = soplex->rowVector(i);
   127     const soplex::SVector& vec = soplex->rowVector(i);
   114     for (int k = 0; k < vec.size(); ++k) {
   128     for (int k = 0; k < vec.size(); ++k) {
   115       *b = std::make_pair(vec.index(k), vec.value(k));
   129       *b = std::make_pair(vec.index(k), vec.value(k));
   116       ++b;
   130       ++b;
   117     }
   131     }
   125       soplex->changeElement(it->first, j, it->second);
   139       soplex->changeElement(it->first, j, it->second);
   126     }
   140     }
   127     solved = false;
   141     solved = false;
   128   }
   142   }
   129 
   143 
   130   void LpSoplex::_getColCoeffs(int i, ColIterator b) {
   144   void LpSoplex::_getColCoeffs(int i, ColIterator b) const {
   131     const soplex::SVector& vec = soplex->colVector(i);
   145     const soplex::SVector& vec = soplex->colVector(i);
   132     for (int k = 0; k < vec.size(); ++k) {
   146     for (int k = 0; k < vec.size(); ++k) {
   133       *b = std::make_pair(vec.index(k), vec.value(k));
   147       *b = std::make_pair(vec.index(k), vec.value(k));
   134       ++b;
   148       ++b;
   135     }
   149     }
   138   void LpSoplex::_setCoeff(int i, int j, Value value) {
   152   void LpSoplex::_setCoeff(int i, int j, Value value) {
   139     soplex->changeElement(i, j, value);
   153     soplex->changeElement(i, j, value);
   140     solved = false;
   154     solved = false;
   141   }
   155   }
   142 
   156 
   143   LpSoplex::Value LpSoplex::_getCoeff(int i, int j) {
   157   LpSoplex::Value LpSoplex::_getCoeff(int i, int j) const {
   144     return soplex->rowVector(i)[j];
   158     return soplex->rowVector(i)[j];
   145   }
   159   }
   146 
   160 
   147   void LpSoplex::_setColLowerBound(int i, Value value) {
   161   void LpSoplex::_setColLowerBound(int i, Value value) {
   148     soplex->changeLower(i, value != -INF ? value : -soplex::infinity); 
   162     soplex->changeLower(i, value != -INF ? value : -soplex::infinity); 
   149     solved = false;
   163     solved = false;
   150   }
   164   }
   151   
   165   
   152   LpSoplex::Value LpSoplex::_getColLowerBound(int i) {
   166   LpSoplex::Value LpSoplex::_getColLowerBound(int i) const {
   153     double value = soplex->lower(i);
   167     double value = soplex->lower(i);
   154     return value != -soplex::infinity ? value : -INF;
   168     return value != -soplex::infinity ? value : -INF;
   155   }
   169   }
   156 
   170 
   157   void LpSoplex::_setColUpperBound(int i, Value value) {
   171   void LpSoplex::_setColUpperBound(int i, Value value) {
   158     soplex->changeUpper(i, value != INF ? value : soplex::infinity); 
   172     soplex->changeUpper(i, value != INF ? value : soplex::infinity); 
   159     solved = false;
   173     solved = false;
   160   }
   174   }
   161 
   175 
   162   LpSoplex::Value LpSoplex::_getColUpperBound(int i) {
   176   LpSoplex::Value LpSoplex::_getColUpperBound(int i) const {
   163     double value = soplex->upper(i);
   177     double value = soplex->upper(i);
   164     return value != soplex::infinity ? value : INF;
   178     return value != soplex::infinity ? value : INF;
   165   }
   179   }
   166 
   180 
   167   void LpSoplex::_setRowBounds(int i, Value lb, Value ub) {
   181   void LpSoplex::_setRowBounds(int i, Value lb, Value ub) {
   168     soplex->changeRange(i, lb != -INF ? lb : -soplex::infinity,
   182     soplex->changeRange(i, lb != -INF ? lb : -soplex::infinity,
   169                         ub != INF ? ub : soplex::infinity);
   183                         ub != INF ? ub : soplex::infinity);
   170     solved = false;
   184     solved = false;
   171   }
   185   }
   172   void LpSoplex::_getRowBounds(int i, Value &lower, Value &upper) {
   186   void LpSoplex::_getRowBounds(int i, Value &lower, Value &upper) const {
   173     lower = soplex->lhs(i);
   187     lower = soplex->lhs(i);
   174     if (lower == -soplex::infinity) lower = -INF;
   188     if (lower == -soplex::infinity) lower = -INF;
   175     upper = soplex->rhs(i);
   189     upper = soplex->rhs(i);
   176     if (upper == -soplex::infinity) upper = INF;
   190     if (upper == -soplex::infinity) upper = INF;
   177   }
   191   }
   179   void LpSoplex::_setObjCoeff(int i, Value obj_coef) {
   193   void LpSoplex::_setObjCoeff(int i, Value obj_coef) {
   180     soplex->changeObj(i, obj_coef);
   194     soplex->changeObj(i, obj_coef);
   181     solved = false;
   195     solved = false;
   182   }
   196   }
   183 
   197 
   184   LpSoplex::Value LpSoplex::_getObjCoeff(int i) {
   198   LpSoplex::Value LpSoplex::_getObjCoeff(int i) const {
   185     return soplex->obj(i);
   199     return soplex->obj(i);
   186   }
   200   }
   187 
   201 
   188   void LpSoplex::_clearObj() {
   202   void LpSoplex::_clearObj() {
   189     for (int i = 0; i < soplex->nCols(); ++i) {
   203     for (int i = 0; i < soplex->nCols(); ++i) {
   210     default:
   224     default:
   211       return UNSOLVED;
   225       return UNSOLVED;
   212     }
   226     }
   213   }
   227   }
   214 
   228 
   215   LpSoplex::Value LpSoplex::_getPrimal(int i) {
   229   LpSoplex::Value LpSoplex::_getPrimal(int i) const {
   216     return primal_value[i];
   230     return primal_value[i];
   217   }
   231   }
   218 
   232 
   219   LpSoplex::Value LpSoplex::_getDual(int i) {
   233   LpSoplex::Value LpSoplex::_getDual(int i) const {
   220     return dual_value[i];
   234     return dual_value[i];
   221   }
   235   }
   222   
   236   
   223   LpSoplex::Value LpSoplex::_getPrimalValue() {
   237   LpSoplex::Value LpSoplex::_getPrimalValue() const {
   224     return soplex->objValue();
   238     return soplex->objValue();
   225   }
   239   }
   226 
   240 
   227   bool LpSoplex::_isBasicCol(int i) {
   241   bool LpSoplex::_isBasicCol(int i) const {
   228     return soplex->getBasisColStatus(i) == soplex::SPxSolver::BASIC;
   242     return soplex->getBasisColStatus(i) == soplex::SPxSolver::BASIC;
   229   }  
   243   }  
   230 
   244 
   231   LpSoplex::SolutionStatus LpSoplex::_getPrimalStatus() {
   245   LpSoplex::SolutionStatus LpSoplex::_getPrimalStatus() const {
   232     if (!solved) return UNDEFINED;
   246     if (!solved) return UNDEFINED;
   233     switch (soplex->status()) {
   247     switch (soplex->status()) {
   234     case soplex::SPxSolver::OPTIMAL:
   248     case soplex::SPxSolver::OPTIMAL:
   235       return OPTIMAL;
   249       return OPTIMAL;
   236     case soplex::SPxSolver::UNBOUNDED:
   250     case soplex::SPxSolver::UNBOUNDED:
   240     default:
   254     default:
   241       return UNDEFINED;
   255       return UNDEFINED;
   242     }
   256     }
   243   }
   257   }
   244 
   258 
   245   LpSoplex::SolutionStatus LpSoplex::_getDualStatus() {
   259   LpSoplex::SolutionStatus LpSoplex::_getDualStatus() const {
   246     if (!solved) return UNDEFINED;
   260     if (!solved) return UNDEFINED;
   247     switch (soplex->status()) {
   261     switch (soplex->status()) {
   248     case soplex::SPxSolver::OPTIMAL:
   262     case soplex::SPxSolver::OPTIMAL:
   249       return OPTIMAL;
   263       return OPTIMAL;
   250     case soplex::SPxSolver::UNBOUNDED:
   264     case soplex::SPxSolver::UNBOUNDED:
   252     default:
   266     default:
   253       return UNDEFINED;
   267       return UNDEFINED;
   254     }
   268     }
   255   }
   269   }
   256 
   270 
   257   LpSoplex::ProblemTypes LpSoplex::_getProblemType() {
   271   LpSoplex::ProblemTypes LpSoplex::_getProblemType() const {
   258     if (!solved) return UNKNOWN;
   272     if (!solved) return UNKNOWN;
   259     switch (soplex->status()) {
   273     switch (soplex->status()) {
   260     case soplex::SPxSolver::OPTIMAL:
   274     case soplex::SPxSolver::OPTIMAL:
   261       return PRIMAL_DUAL_FEASIBLE;
   275       return PRIMAL_DUAL_FEASIBLE;
   262     case soplex::SPxSolver::UNBOUNDED:
   276     case soplex::SPxSolver::UNBOUNDED:
   272   }
   286   }
   273   void LpSoplex::_setMin() {
   287   void LpSoplex::_setMin() {
   274     soplex->changeSense(soplex::SPxSolver::MINIMIZE);
   288     soplex->changeSense(soplex::SPxSolver::MINIMIZE);
   275     solved = false;
   289     solved = false;
   276   }
   290   }
   277   bool LpSoplex::_isMax() {
   291   bool LpSoplex::_isMax() const {
   278     return soplex->spxSense() == soplex::SPxSolver::MAXIMIZE;
   292     return soplex->spxSense() == soplex::SPxSolver::MAXIMIZE;
   279   }
   293   }
   280 
   294 
   281   
   295   
   282 } //namespace lemon
   296 } //namespace lemon