COIN-OR::LEMON - Graph Library

Changeset 1349:f8ec64f78b5f in lemon


Ignore:
Timestamp:
05/07/15 11:42:19 (9 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Parents:
1346:f95b18d99843 (diff), 1347:0900cfe4a84d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Phase:
public
Message:

Merge bugfix #473

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lemon/cplex.cc

    r1336 r1349  
    3838  }
    3939
     40  void CplexEnv::incCnt()
     41  {
     42    _cnt_lock->lock();
     43    ++(*_cnt);
     44    _cnt_lock->unlock();
     45  }
     46
     47  void CplexEnv::decCnt()
     48  {
     49    _cnt_lock->lock();
     50    --(*_cnt);
     51    if (*_cnt == 0) {
     52      delete _cnt;
     53      _cnt_lock->unlock();
     54      delete _cnt_lock;
     55      CPXcloseCPLEX(&_env);
     56    }
     57    else _cnt_lock->unlock();
     58  }
     59 
    4060  CplexEnv::CplexEnv() {
    4161    int status;
     62    _env = CPXopenCPLEX(&status);
     63    if (_env == 0)
     64      throw LicenseError(status);
    4265    _cnt = new int;
    4366    (*_cnt) = 1;
    44     _env = CPXopenCPLEX(&status);
    45     if (_env == 0) {
    46       delete _cnt;
    47       _cnt = 0;
    48       throw LicenseError(status);
    49     }
     67    _cnt_lock = new bits::Lock;
    5068  }
    5169
     
    5371    _env = other._env;
    5472    _cnt = other._cnt;
    55     ++(*_cnt);
     73    _cnt_lock = other._cnt_lock;
     74    incCnt();
    5675  }
    5776
    5877  CplexEnv& CplexEnv::operator=(const CplexEnv& other) {
     78    decCnt();
    5979    _env = other._env;
    6080    _cnt = other._cnt;
    61     ++(*_cnt);
     81    _cnt_lock = other._cnt_lock;
     82    incCnt();
    6283    return *this;
    6384  }
    6485
    6586  CplexEnv::~CplexEnv() {
    66     --(*_cnt);
    67     if (*_cnt == 0) {
    68       delete _cnt;
    69       CPXcloseCPLEX(&_env);
    70     }
     87    decCnt();
    7188  }
    7289
  • lemon/cplex.cc

    r1347 r1349  
    105105    int status;
    106106    _prob = CPXcloneprob(cplexEnv(), cplex._prob, &status);
    107     rows = cplex.rows;
    108     cols = cplex.cols;
     107    _rows = cplex._rows;
     108    _cols = cplex._cols;
    109109    messageLevel(MESSAGE_NOTHING);
    110110  }
     
    133133                         ExprIterator e, Value ub) {
    134134    int i = CPXgetnumrows(cplexEnv(), _prob);
     135
     136    int rmatbeg = 0;
     137   
     138    std::vector<int> indices;
     139    std::vector<Value> values;
     140
     141    for(ExprIterator it=b; it!=e; ++it) {
     142      indices.push_back(it->first);
     143      values.push_back(it->second);
     144    }
     145
    135146    if (lb == -INF) {
    136147      const char s = 'L';
    137       CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0);
     148      CPXaddrows(cplexEnv(), _prob, 0, 1, values.size(), &ub, &s,
     149                 &rmatbeg, &indices.front(), &values.front(), 0, 0);
    138150    } else if (ub == INF) {
    139151      const char s = 'G';
    140       CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
     152      CPXaddrows(cplexEnv(), _prob, 0, 1, values.size(), &lb, &s,
     153                 &rmatbeg, &indices.front(), &values.front(), 0, 0);
    141154    } else if (lb == ub){
    142155      const char s = 'E';
    143       CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
     156      CPXaddrows(cplexEnv(), _prob, 0, 1, values.size(), &lb, &s,
     157                 &rmatbeg, &indices.front(), &values.front(), 0, 0);
    144158    } else {
    145159      const char s = 'R';
    146160      double len = ub - lb;
    147       CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, &len, 0);
    148     }
    149 
    150     std::vector<int> indices;
    151     std::vector<int> rowlist;
    152     std::vector<Value> values;
    153 
    154     for(ExprIterator it=b; it!=e; ++it) {
    155       indices.push_back(it->first);
    156       values.push_back(it->second);
    157       rowlist.push_back(i);
    158     }
    159 
    160     CPXchgcoeflist(cplexEnv(), _prob, values.size(),
    161                    &rowlist.front(), &indices.front(), &values.front());
    162 
     161      CPXaddrows(cplexEnv(), _prob, 0, 1, values.size(), &ub, &s,
     162                 &rmatbeg, &indices.front(), &values.front(), 0, 0);
     163      CPXchgrngval(cplexEnv(), _prob, 1, &i, &len);
     164    }
     165   
    163166    return i;
    164167  }
     
    173176
    174177  void CplexBase::_eraseColId(int i) {
    175     cols.eraseIndex(i);
    176     cols.shiftIndices(i);
     178    _cols.eraseIndex(i);
     179    _cols.shiftIndices(i);
    177180  }
    178181  void CplexBase::_eraseRowId(int i) {
    179     rows.eraseIndex(i);
    180     rows.shiftIndices(i);
     182    _rows.eraseIndex(i);
     183    _rows.shiftIndices(i);
    181184  }
    182185
Note: See TracChangeset for help on using the changeset viewer.