# HG changeset patch
# User Alpar Juttner <alpar@cs.elte.hu>
# Date 1336315931 -7200
# Node ID 4764031c082c6c2b13501867b9d65e665a939334
# Parent  be7dd3a8d6a3150c54c756cc2f50a2db0112196b# Parent  8d281761dea448411e2f138095495a641e1d3fae
Merge bugfix #441 to branch 1.2

diff -r be7dd3a8d6a3 -r 4764031c082c lemon/bits/solver_bits.h
--- a/lemon/bits/solver_bits.h	Fri Jan 20 19:20:02 2012 +0100
+++ b/lemon/bits/solver_bits.h	Sun May 06 16:52:11 2012 +0200
@@ -44,6 +44,7 @@
 
       void clear() {
         first_item = -1;
+        last_item = -1;
         first_free_item = -1;
         items.clear();
         cross.clear();
diff -r be7dd3a8d6a3 -r 4764031c082c lemon/cbc.cc
--- a/lemon/cbc.cc	Fri Jan 20 19:20:02 2012 +0100
+++ b/lemon/cbc.cc	Sun May 06 16:52:11 2012 +0200
@@ -435,8 +435,6 @@
     }
 
     _prob = new CoinModel();
-    rows.clear();
-    cols.clear();
   }
 
   void CbcMip::_messageLevel(MessageLevel level) {
diff -r be7dd3a8d6a3 -r 4764031c082c lemon/clp.cc
--- a/lemon/clp.cc	Fri Jan 20 19:20:02 2012 +0100
+++ b/lemon/clp.cc	Sun May 06 16:52:11 2012 +0200
@@ -437,8 +437,6 @@
   void ClpLp::_clear() {
     delete _prob;
     _prob = new ClpSimplex();
-    rows.clear();
-    cols.clear();
     _col_names_ref.clear();
     _clear_temporals();
   }
diff -r be7dd3a8d6a3 -r 4764031c082c lemon/cplex.cc
--- a/lemon/cplex.cc	Fri Jan 20 19:20:02 2012 +0100
+++ b/lemon/cplex.cc	Sun May 06 16:52:11 2012 +0200
@@ -470,8 +470,6 @@
     CPXfreeprob(cplexEnv(),&_prob);
     int status;
     _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
-    rows.clear();
-    cols.clear();
   }
 
   void CplexBase::_messageLevel(MessageLevel level) {
diff -r be7dd3a8d6a3 -r 4764031c082c lemon/glpk.cc
--- a/lemon/glpk.cc	Fri Jan 20 19:20:02 2012 +0100
+++ b/lemon/glpk.cc	Sun May 06 16:52:11 2012 +0200
@@ -556,8 +556,6 @@
 
   void GlpkBase::_clear() {
     glp_erase_prob(lp);
-    rows.clear();
-    cols.clear();
   }
 
   void GlpkBase::freeEnv() {
diff -r be7dd3a8d6a3 -r 4764031c082c lemon/lp_base.h
--- a/lemon/lp_base.h	Fri Jan 20 19:20:02 2012 +0100
+++ b/lemon/lp_base.h	Sun May 06 16:52:11 2012 +0200
@@ -1556,7 +1556,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 be7dd3a8d6a3 -r 4764031c082c test/lp_test.cc
--- a/test/lp_test.cc	Fri Jan 20 19:20:02 2012 +0100
+++ b/test/lp_test.cc	Sun May 06 16:52:11 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<LP::Col> x(10);
   //  for(int i=0;i<10;i++) x.push_back(lp.addCol());
   lp.addColSet(x);