Index: lemon/lp_glpk.cc
===================================================================
--- lemon/lp_glpk.cc	(revision 2253)
+++ lemon/lp_glpk.cc	(revision 2312)
@@ -117,22 +117,34 @@
   }
   
-  void LpGlpk::_setRowCoeffs(int i, 
-			     int length,
-			     const int   * indices, 
-			     const Value   * values )
-  {
-    lpx_set_mat_row(lp, i, length,
-		    const_cast<int * >(indices) ,
-		    const_cast<Value * >(values));
-  }
-  
-  void LpGlpk::_setColCoeffs(int i, 
-			     int length,
-			     const int   * indices, 
-			     const Value   * values)
-  {
-    lpx_set_mat_col(lp, i, length,
-		    const_cast<int * >(indices),
-		    const_cast<Value * >(values));
+  void LpGlpk::_setRowCoeffs(int i, LpRowIterator b, LpRowIterator e) 
+  {
+    std::vector<int> indices;
+    std::vector<Value> values;
+
+    indices.push_back(0);
+    values.push_back(0);
+
+    for(LpRowIterator it=b; it!=e; ++it) {
+      indices.push_back(it->first);
+      values.push_back(it->second);
+    }
+
+    lpx_set_mat_row(lp, i, values.size() - 1, &indices[0], &values[0]);
+  }
+  
+  void LpGlpk::_setColCoeffs(int i, LpColIterator b, LpColIterator e) {
+
+    std::vector<int> indices;
+    std::vector<Value> values;
+
+    indices.push_back(0);
+    values.push_back(0);
+
+    for(LpColIterator it=b; it!=e; ++it) {
+      indices.push_back(it->first);
+      values.push_back(it->second);
+    }
+    
+    lpx_set_mat_col(lp, i, values.size() - 1, &indices[0], &values[0]);
   }
 
@@ -140,35 +152,59 @@
   void LpGlpk::_setCoeff(int row, int col, Value value) 
   {
-    ///FIXME Of course this is not efficient at all, but GLPK knows not more.
-    // First approach: get one row, apply changes and set it again
-    //(one idea to improve this: maybe it is better to do this with 1 coloumn)
+
+    if (lpx_get_num_cols(lp) < lpx_get_num_rows(lp)) {
+
+      int length=lpx_get_mat_row(lp, row, 0, 0);
+      
+      std::vector<int> indices(length + 2);
+      std::vector<Value> values(length + 2);
+      
+      lpx_get_mat_row(lp, row, &indices[0], &values[0]);
+      
+      //The following code does not suppose that the elements of the
+      //array indices are sorted
+      bool found=false;
+      for (int i = 1; i <= length; ++i) {
+        if (indices[i]==col){
+          found=true;
+          values[i]=value;
+          break;
+        }
+      }
+      if (!found){
+        ++length;
+        indices[length]=col;
+        values[length]=value;
+      }
     
-    int mem_length=2+lpx_get_num_cols(lp);
-    int* indices = new int[mem_length];
-    Value* values = new Value[mem_length];
+      lpx_set_mat_row(lp, row, length, &indices[0], &values[0]);
+
+    } else {
+
+      int length=lpx_get_mat_col(lp, col, 0, 0);
+      
+      std::vector<int> indices(length + 2);
+      std::vector<Value> values(length + 2);
+      
+      lpx_get_mat_col(lp, col, &indices[0], &values[0]);
+      
+      //The following code does not suppose that the elements of the
+      //array indices are sorted
+      bool found=false;
+      for (int i = 1; i <= length; ++i) {
+        if (indices[i]==col){
+          found=true;
+          values[i]=value;
+          break;
+        }
+      }
+      if (!found){
+        ++length;
+        indices[length]=row;
+        values[length]=value;
+      }
     
-
-    int length=lpx_get_mat_row(lp, row, indices, values);
-
-    //The following code does not suppose that the elements of the array indices are sorted
-    int i=1;
-    bool found=false;
-    while (i <= length && !found){
-      if (indices[i]==col){
-	found = true;
-	values[i]=value;
-      }
-      ++i;
-    }
-    if (!found){
-      ++length;
-      indices[length]=col;
-      values[length]=value;
-    }
-    
-    lpx_set_mat_row(lp, row, length, indices, values);
-    delete [] indices;
-    delete [] values;
-    
+      lpx_set_mat_col(lp, col, length, &indices[0], &values[0]);
+    }
   }
 
