[Lemon-commits] [lemon_svn] marci: r1542 - hugo/trunk/src/work/marci/lp

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:46:07 CET 2006


Author: marci
Date: Tue Feb  8 18:47:19 2005
New Revision: 1542

Modified:
   hugo/trunk/src/work/marci/lp/lp_solver_base.h
   hugo/trunk/src/work/marci/lp/max_flow_expression.cc

Log:
The pair of setSomeThing function is getSomeThing.


Modified: hugo/trunk/src/work/marci/lp/lp_solver_base.h
==============================================================================
--- hugo/trunk/src/work/marci/lp/lp_solver_base.h	(original)
+++ hugo/trunk/src/work/marci/lp/lp_solver_base.h	Tue Feb  8 18:47:19 2005
@@ -171,6 +171,7 @@
 
 
   /*! \e
+    \todo kellenene uj iterable structure bele, mert ez nem az igazi
     \todo A[x,y]-t cserel. Jobboldal, baloldal csere.
     \todo LEKERDEZESEK!!!
     \todo DOKSI!!!! Doxygen group!!!
@@ -201,6 +202,10 @@
     /// \e
     IterablePartition<int> col_iter_map;
     /// \e
+    std::vector<RowIt> int_row_map;
+    /// \e
+    std::vector<ColIt> int_col_map;
+    /// \e
     const int VALID_CLASS;
     /// \e
     const int INVALID_CLASS;
@@ -297,8 +302,15 @@
     virtual void _setRowCoeffs(int i, 
 			       const std::vector<std::pair<int, _Value> >& coeffs) = 0;
     /// \e
+    /// This routine modifies \c coeffs only by the \c push_back method.
+    virtual void _getRowCoeffs(int i, 
+			       std::vector<std::pair<int, _Value> >& coeffs) = 0;
     virtual void _setColCoeffs(int i, 
 			       const std::vector<std::pair<int, _Value> >& coeffs) = 0;
+    /// \e
+    /// This routine modifies \c coeffs only by the \c push_back method.
+    virtual void _getColCoeffs(int i, 
+			       std::vector<std::pair<int, _Value> >& coeffs) = 0;
   public:
     /// \e
     enum Bound { FREE, LOWER, UPPER, DOUBLE, FIXED };
@@ -373,6 +385,7 @@
       } else { //a cucc vegere kell inzertalni mert nincs szabad hely
 	col_it=col_iter_map.push_back(i, VALID_CLASS);
       }
+      int_col_map.push_back(col_it);
       return col_it;
     }
     /// \e
@@ -386,6 +399,7 @@
       } else { //a cucc vegere kell inzertalni mert nincs szabad hely
 	row_it=row_iter_map.push_back(i, VALID_CLASS);
       }
+      int_row_map.push_back(row_it);
       return row_it;
     }
     /// \e
@@ -400,6 +414,7 @@
 	   col_iter_map.valid(it); col_iter_map.next(it)) {
 	if (col_iter_map[it]>cols[1]) --col_iter_map[it];
       }
+      int_col_map.erase(int_col_map.begin()+cols[1]);
     }
     /// \e
     void eraseRow(const RowIt& row_it) {
@@ -413,6 +428,7 @@
 	   row_iter_map.valid(it); row_iter_map.next(it)) {
 	if (row_iter_map[it]>rows[1]) --row_iter_map[it];
       }
+      int_row_map.erase(int_row_map.begin()+rows[1]);
     }
     /// \e
     template <typename Begin, typename End>
@@ -509,6 +525,16 @@
       _setRowCoeffs(row_iter_map[row_it], row_coeffs);
     }
     /// \e
+    /// This routine modifies \c expr by only adding to it.
+    void getRowCoeffs(RowIt row_it, Expression& expr) {
+      std::vector<std::pair<int, _Value> > row_coeffs;
+      _getRowCoeffs(row_iter_map[row_it], row_coeffs);
+      for(typename std::vector<std::pair<int, _Value> >::const_iterator 
+ 	    i=row_coeffs.begin(); i!=row_coeffs.end(); ++i) {
+ 	expr+= (*i).second*int_col_map[(*i).first];
+      }
+    }
+    /// \e
     void setColCoeffs(ColIt col_it, const DualExpression& expr) {
       std::vector<std::pair<int, _Value> > col_coeffs;
       for(typename DualExpression::Data::const_iterator i=expr.data.begin(); 
@@ -519,12 +545,28 @@
       _setColCoeffs(col_iter_map[col_it], col_coeffs);
     }
     /// \e
+    /// This routine modifies \c expr by only adding to it.
+    void getColCoeffs(ColIt col_it, DualExpression& expr) {
+      std::vector<std::pair<int, _Value> > col_coeffs;
+      _getColCoeffs(col_iter_map[col_it], col_coeffs);
+      for(typename std::vector<std::pair<int, _Value> >::const_iterator 
+ 	    i=col_coeffs.begin(); i!=col_coeffs.end(); ++i) {
+ 	expr+= (*i).second*int_row_map[(*i).first];
+      }
+    }
+    /// \e
+    /// \bug ez igy nem jo
     void setObjCoeffs(const Expression& expr) {
       for(typename Expression::Data::const_iterator i=expr.data.begin(); 
 	  i!=expr.data.end(); ++i) {
 	setObjCoef((*i).first, (*i).second);
       }
     }
+    /// \e
+    /// This routine modifies \c expr by only adding to it.
+    void getObjCoeffs(Expression& expr) {
+      /// FIXME not yet implemented
+    }
     //@}
   };
   
@@ -547,6 +589,8 @@
     /// \e
     LPGLPK() : Parent(), 
 			lp(lpx_create_prob()) {
+      int_row_map.push_back(RowIt());
+      int_col_map.push_back(ColIt());
       lpx_set_int_parm(lp, LPX_K_DUAL, 1);
     }
     /// \e
@@ -592,15 +636,25 @@
 	++length;
 	indices[length]=it->first;
 	doubles[length]=it->second;
-// 	std::cout << "  " << indices[length] << " " 
-// 		  << doubles[length] << std::endl;
       }
-//      std::cout << i << " " << length << std::endl;
       lpx_set_mat_row(lp, i, length, indices, doubles);
       delete [] indices;
       delete [] doubles;
     }
     /// \e
+    virtual void _getRowCoeffs(int i, 
+			       std::vector<std::pair<int, double> >& coeffs) {
+      int mem_length=1+colNum();
+      int* indices = new int[mem_length];
+      double* doubles = new double[mem_length];
+      int length=lpx_get_mat_row(lp, i, indices, doubles);
+      for (int i=1; i<=length; ++i) {
+	coeffs.push_back(std::make_pair(indices[i], doubles[i]));
+      }
+      delete [] indices;
+      delete [] doubles;
+    }
+    /// \e
     virtual void _setColCoeffs(int i, 
 			       const std::vector<std::pair<int, double> >& coeffs) {
       int mem_length=1+rowNum();
@@ -618,6 +672,19 @@
       delete [] doubles;
     }
     /// \e
+    virtual void _getColCoeffs(int i, 
+			       std::vector<std::pair<int, double> >& coeffs) {
+      int mem_length=1+rowNum();
+      int* indices = new int[mem_length];
+      double* doubles = new double[mem_length];
+      int length=lpx_get_mat_col(lp, i, indices, doubles);
+      for (int i=1; i<=length; ++i) {
+	coeffs.push_back(std::make_pair(indices[i], doubles[i]));
+      }
+      delete [] indices;
+      delete [] doubles;
+    }
+    /// \e
     virtual void _eraseCol(int i) {
       int cols[2];
       cols[1]=i;

Modified: hugo/trunk/src/work/marci/lp/max_flow_expression.cc
==============================================================================
--- hugo/trunk/src/work/marci/lp/max_flow_expression.cc	(original)
+++ hugo/trunk/src/work/marci/lp/max_flow_expression.cc	Tue Feb  8 18:47:19 2005
@@ -2,6 +2,7 @@
 #include <iostream>
 #include <fstream>
 
+#include <lemon/graph_utils.h>
 #include <lemon/smart_graph.h>
 #include <lemon/list_graph.h>
 #include <lemon/dimacs.h>
@@ -48,7 +49,9 @@
   typedef LPSolver::ColIt ColIt;
   typedef LPSolver::RowIt RowIt;
   typedef Graph::EdgeMap<ColIt> EdgeIndexMap;
+  typedef Graph::NodeMap<RowIt> NodeIndexMap;
   EdgeIndexMap edge_index_map(g);
+  NodeIndexMap node_index_map(g);
   PrimalMap<Edge, EdgeIndexMap> flow(lp, edge_index_map);
 
   // nonnegativity of flow and capacity function
@@ -75,11 +78,41 @@
     // flow conservation constraints
     if ((n!=s) && (n!=t)) {
       RowIt row_it=lp.addRow();
+      node_index_map.set(n, row_it);
       lp.setRowCoeffs(row_it, expr);
       lp.setRowLowerBound(row_it, 0.0);
       lp.setRowUpperBound(row_it, 0.0);
+//       cout << expr << endl;
+//       {
+// 	LPSolver::Expression expr;
+// 	lp.getRowCoeffs(node_index_map[n], expr);	
+// 	cout << expr << endl;
+//       }
     }
   }
   lp.solveSimplex();
+//   cout << "num of nodes: " << countNodes(g) << endl;
+//   cout << "num of edges: " << countEdges(g) << endl;
+//   cout << "num of rows: " << lp.rowNum() << endl;
+//   cout << "num of rows: " << lp.int_row_map.size() << endl;
+//   for (int i=0; i<lp.int_row_map.size(); ++i) {
+//     cout << lp.int_row_map[i] << " " << endl;
+//   }
+//   cout << "num of columns: " << lp.colNum() << endl;
+//   cout << "num of columns: " << lp.int_col_map.size() << endl;
+//   for (int i=0; i<lp.int_col_map.size(); ++i) {
+//     cout << lp.int_col_map[i] << " " << endl;
+//   }
   cout << "elapsed time: " << ts << endl;
+//   Graph::NodeIt n(g);
+//   ++n;
+//   for(Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) {
+//     cout << edge_index_map[e] << endl;
+//   }
+//   for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) {
+//     cout << edge_index_map[e] << endl;
+//   }
+//   LPSolver::DualExpression expr;
+//   lp.getRowCoeffs(node_index_map[n], expr);
+//   cout << expr << endl;
 }



More information about the Lemon-commits mailing list