# HG changeset patch # User Alpar Juttner # Date 1336206164 -7200 # Node ID 8d281761dea448411e2f138095495a641e1d3fae # Parent b873350e62589b27ff179b81242404ed21828bfb Fix buggy reinitialization in _solver_bits::VarIndex::clear() (#441) - In addition, rows.clear() and cols.clear() are moved up to LpBase::clear() diff -r b873350e6258 -r 8d281761dea4 lemon/bits/solver_bits.h --- a/lemon/bits/solver_bits.h Thu Jan 19 15:25:06 2012 +0100 +++ b/lemon/bits/solver_bits.h Sat May 05 10:22:44 2012 +0200 @@ -44,6 +44,7 @@ void clear() { first_item = -1; + last_item = -1; first_free_item = -1; items.clear(); cross.clear(); diff -r b873350e6258 -r 8d281761dea4 lemon/cbc.cc --- a/lemon/cbc.cc Thu Jan 19 15:25:06 2012 +0100 +++ b/lemon/cbc.cc Sat May 05 10:22:44 2012 +0200 @@ -423,8 +423,6 @@ } _prob = new CoinModel(); - rows.clear(); - cols.clear(); } void CbcMip::_messageLevel(MessageLevel level) { diff -r b873350e6258 -r 8d281761dea4 lemon/clp.cc --- a/lemon/clp.cc Thu Jan 19 15:25:06 2012 +0100 +++ b/lemon/clp.cc Sat May 05 10:22:44 2012 +0200 @@ -424,8 +424,6 @@ void ClpLp::_clear() { delete _prob; _prob = new ClpSimplex(); - rows.clear(); - cols.clear(); _col_names_ref.clear(); _clear_temporals(); } diff -r b873350e6258 -r 8d281761dea4 lemon/cplex.cc --- a/lemon/cplex.cc Thu Jan 19 15:25:06 2012 +0100 +++ b/lemon/cplex.cc Sat May 05 10:22:44 2012 +0200 @@ -437,8 +437,6 @@ CPXfreeprob(cplexEnv(),&_prob); int status; _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem"); - rows.clear(); - cols.clear(); } void CplexBase::_messageLevel(MessageLevel level) { diff -r b873350e6258 -r 8d281761dea4 lemon/glpk.cc --- a/lemon/glpk.cc Thu Jan 19 15:25:06 2012 +0100 +++ b/lemon/glpk.cc Sat May 05 10:22:44 2012 +0200 @@ -520,8 +520,6 @@ void GlpkBase::_clear() { glp_erase_prob(lp); - rows.clear(); - cols.clear(); } void GlpkBase::freeEnv() { diff -r b873350e6258 -r 8d281761dea4 lemon/lp_base.h --- a/lemon/lp_base.h Thu Jan 19 15:25:06 2012 +0100 +++ b/lemon/lp_base.h Sat May 05 10:22:44 2012 +0200 @@ -1542,7 +1542,7 @@ void min() { _setSense(MIN); } ///Clears the problem - void clear() { _clear(); } + void clear() { _clear(); rows.clear(); cols.clear(); } /// Sets the message level of the solver void messageLevel(MessageLevel level) { _messageLevel(level); } diff -r b873350e6258 -r 8d281761dea4 test/lp_test.cc --- a/test/lp_test.cc Thu Jan 19 15:25:06 2012 +0100 +++ b/test/lp_test.cc Sat May 05 10:22:44 2012 +0200 @@ -41,11 +41,38 @@ using namespace lemon; +int countCols(LpBase & lp) { + int count=0; + for (LpBase::ColIt c(lp); c!=INVALID; ++c) ++count; + return count; +} + +int countRows(LpBase & lp) { + int count=0; + for (LpBase::RowIt r(lp); r!=INVALID; ++r) ++count; + return count; +} + + void lpTest(LpSolver& lp) { typedef LpSolver LP; + // Test LpBase::clear() + check(countRows(lp)==0, "Wrong number of rows"); + check(countCols(lp)==0, "Wrong number of cols"); + lp.addCol(); lp.addRow(); lp.addRow(); + check(countRows(lp)==2, "Wrong number of rows"); + check(countCols(lp)==1, "Wrong number of cols"); + lp.clear(); + check(countRows(lp)==0, "Wrong number of rows"); + check(countCols(lp)==0, "Wrong number of cols"); + lp.addCol(); lp.addCol(); lp.addCol(); lp.addRow(); + check(countRows(lp)==1, "Wrong number of rows"); + check(countCols(lp)==3, "Wrong number of cols"); + lp.clear(); + std::vector x(10); // for(int i=0;i<10;i++) x.push_back(lp.addCol()); lp.addColSet(x);