Faster CPLEX problem build-up #422
authorAlpar Juttner <alpar@cs.elte.hu>
Wed, 12 Nov 2014 14:11:20 +0100
changeset 13301ad592289f93
parent 1323 5de6a70446f6
child 1333 27d7d232fbcc
Faster CPLEX problem build-up #422
lemon/cplex.cc
     1.1 --- a/lemon/cplex.cc	Wed Jul 09 14:41:36 2014 +0200
     1.2 +++ b/lemon/cplex.cc	Wed Nov 12 14:11:20 2014 +0100
     1.3 @@ -115,34 +115,37 @@
     1.4    int CplexBase::_addRow(Value lb, ExprIterator b,
     1.5                           ExprIterator e, Value ub) {
     1.6      int i = CPXgetnumrows(cplexEnv(), _prob);
     1.7 -    if (lb == -INF) {
     1.8 -      const char s = 'L';
     1.9 -      CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0);
    1.10 -    } else if (ub == INF) {
    1.11 -      const char s = 'G';
    1.12 -      CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
    1.13 -    } else if (lb == ub){
    1.14 -      const char s = 'E';
    1.15 -      CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
    1.16 -    } else {
    1.17 -      const char s = 'R';
    1.18 -      double len = ub - lb;
    1.19 -      CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, &len, 0);
    1.20 -    }
    1.21  
    1.22 +    int rmatbeg = 0;
    1.23 +    
    1.24      std::vector<int> indices;
    1.25 -    std::vector<int> rowlist;
    1.26      std::vector<Value> values;
    1.27  
    1.28      for(ExprIterator it=b; it!=e; ++it) {
    1.29        indices.push_back(it->first);
    1.30        values.push_back(it->second);
    1.31 -      rowlist.push_back(i);
    1.32      }
    1.33  
    1.34 -    CPXchgcoeflist(cplexEnv(), _prob, values.size(),
    1.35 -                   &rowlist.front(), &indices.front(), &values.front());
    1.36 -
    1.37 +    if (lb == -INF) {
    1.38 +      const char s = 'L';
    1.39 +      CPXaddrows(cplexEnv(), _prob, 0, 1, values.size(), &ub, &s,
    1.40 +                 &rmatbeg, &indices.front(), &values.front(), 0, 0);
    1.41 +    } else if (ub == INF) {
    1.42 +      const char s = 'G';
    1.43 +      CPXaddrows(cplexEnv(), _prob, 0, 1, values.size(), &lb, &s,
    1.44 +                 &rmatbeg, &indices.front(), &values.front(), 0, 0);
    1.45 +    } else if (lb == ub){
    1.46 +      const char s = 'E';
    1.47 +      CPXaddrows(cplexEnv(), _prob, 0, 1, values.size(), &lb, &s,
    1.48 +                 &rmatbeg, &indices.front(), &values.front(), 0, 0);
    1.49 +    } else {
    1.50 +      const char s = 'R';
    1.51 +      double len = ub - lb;
    1.52 +      CPXaddrows(cplexEnv(), _prob, 0, 1, values.size(), &ub, &s,
    1.53 +                 &rmatbeg, &indices.front(), &values.front(), 0, 0);
    1.54 +      CPXchgrngval(cplexEnv(), _prob, 1, &i, &len);
    1.55 +    }
    1.56 +    
    1.57      return i;
    1.58    }
    1.59