[Lemon-commits] [lemon_svn] athos: r1670 - in hugo/trunk/src/work: athos/lp marci/lp

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


Author: athos
Date: Tue Mar 22 17:49:30 2005
New Revision: 1670

Modified:
   hugo/trunk/src/work/athos/lp/lp_solver_glpk.h
   hugo/trunk/src/work/athos/lp/magic_square.cc
   hugo/trunk/src/work/marci/lp/makefile

Log:
Ami félig van kész, ma már félig marad...

Modified: hugo/trunk/src/work/athos/lp/lp_solver_glpk.h
==============================================================================
--- hugo/trunk/src/work/athos/lp/lp_solver_glpk.h	(original)
+++ hugo/trunk/src/work/athos/lp/lp_solver_glpk.h	Tue Mar 22 17:49:30 2005
@@ -164,7 +164,35 @@
       lpx_del_rows(lp, 1, rows);
     }
     void _setCoeff(int col, int row, double value) {
-      /// FIXME not yet implemented
+      ///FIXME Of course this is not efficient at all, but GLPK knows not more.
+      int change_this;
+      bool get_set_row;
+      //The only thing we can do is optimize on whether working with a row 
+      //or a coloumn
+      int row_num = rowNum();
+      int col_num = colNum();
+      if (col_num<row_num){
+	//There are more rows than coloumns
+	get_set_row=true;
+	int mem_length=1+row_num;
+	int* indices = new int[mem_length];
+	double* doubles = new double[mem_length];
+	int length=lpx_get_mat_col(lp, i, indices, doubles);
+      }else{
+	get_set_row=false;
+	int mem_length=1+col_num;
+	int* indices = new int[mem_length];
+	double* doubles = new double[mem_length];
+	int length=lpx_get_mat_row(lp, i, indices, doubles);
+      }
+      //Itten      
+int* indices = new int[mem_length];
+      double* doubles = new double[mem_length];
+      int length=lpx_get_mat_col(lp, i, indices, doubles);
+ 
+      delete [] indices;
+      delete [] doubles;
+
     }
     double _getCoeff(int col, int row) {
       /// FIXME not yet implemented

Modified: hugo/trunk/src/work/athos/lp/magic_square.cc
==============================================================================
--- hugo/trunk/src/work/athos/lp/magic_square.cc	(original)
+++ hugo/trunk/src/work/athos/lp/magic_square.cc	Tue Mar 22 17:49:30 2005
@@ -17,7 +17,7 @@
  */
 
 int main(int, char **) {
-  const int n=4;
+  const int n=3;
   const double row_sum=(1.0+n*n)*n/2;
   Timer ts;
   ts.reset();
@@ -43,12 +43,18 @@
       expr1+=x[std::make_pair(i, j)];
       expr2+=x[std::make_pair(j, i)];
     }
+
     // sum of rows and columns
     lp.addRow(expr1==row_sum);
     lp.addRow(expr2==row_sum);
+      cout <<"Expr1: "<<expr1<<endl;
+      cout <<"Expr2: "<<expr2<<endl;
+
     expr3+=x[std::make_pair(i, i)];
     expr4+=x[std::make_pair(i, (n+1)-i)];
   }
+  cout <<"Expr3: "<<expr3<<endl;
+  cout <<"Expr4: "<<expr4<<endl;
   // sum of the diagonal entries
   lp.addRow(expr3==row_sum);
   lp.addRow(expr4==row_sum);
@@ -60,31 +66,34 @@
 	   << endl;
     }
   }
-  // we make new binary variables for each pair of 
-  // entries of the square to achieve that 
-  // the values of different entries are different
-  lp.setMIP();
-  for (Coords::const_iterator it=x.begin(); it!=x.end(); ++it) {
-    Coords::const_iterator jt=it; ++jt;
-    for(; jt!=x.end(); ++jt) {
-      Col col1=(*it).second;
-      Col col2=(*jt).second;
-      Col col=lp.addCol();
-      lp.setColLowerBound(col, 0.0);
-      lp.setColUpperBound(col, 1.0);
-      lp.addRow(double(-n*n+1.0)<=1.0*col2-1.0*col1-double(n*n)*col<=-1.0);
-      lp.setColInt(col);
-    }
-  }
-  cout << "elapsed time: " << ts << endl;
-  lp.solveSimplex();
-  // let's solve the integer problem
-  lp.solveBandB();
-  cout << "elapsed time: " << ts << endl;
-  for (int i=1; i<=n; ++i) {
-    for (int j=1; j<=n; ++j) { 
-      cout << "x("<<i<<","<<j<<")="<<lp.getMIPPrimal(x[std::make_pair(i,j)]) 
-	   << endl;
-    }
-  }
+
+
+
+//   // we make new binary variables for each pair of 
+//   // entries of the square to achieve that 
+//   // the values of different entries are different
+//   lp.setMIP();
+//   for (Coords::const_iterator it=x.begin(); it!=x.end(); ++it) {
+//     Coords::const_iterator jt=it; ++jt;
+//     for(; jt!=x.end(); ++jt) {
+//       Col col1=(*it).second;
+//       Col col2=(*jt).second;
+//       Col col=lp.addCol();
+//       lp.setColLowerBound(col, 0.0);
+//       lp.setColUpperBound(col, 1.0);
+//       lp.addRow(double(-n*n+1.0)<=1.0*col2-1.0*col1-double(n*n)*col<=-1.0);
+//       lp.setColInt(col);
+//     }
+//   }
+//   cout << "elapsed time: " << ts << endl;
+//   lp.solveSimplex();
+//   // let's solve the integer problem
+//   lp.solveBandB();
+//   cout << "elapsed time: " << ts << endl;
+//   for (int i=1; i<=n; ++i) {
+//     for (int j=1; j<=n; ++j) { 
+//       cout << "x("<<i<<","<<j<<")="<<lp.getMIPPrimal(x[std::make_pair(i,j)]) 
+// 	   << endl;
+//     }
+//   }
 }

Modified: hugo/trunk/src/work/marci/lp/makefile
==============================================================================
--- hugo/trunk/src/work/marci/lp/makefile	(original)
+++ hugo/trunk/src/work/marci/lp/makefile	Tue Mar 22 17:49:30 2005
@@ -5,7 +5,7 @@
 CXXFLAGS = -g -O2 -W -Wall $(INCLUDEDIRS) -ansi -pedantic
 LDFLAGS  =  -lglpk#-lcplex -lm -lpthread -lilocplex -L/usr/local/cplex/cplex75/lib/i86_linux2_glibc2.2_gcc3.0/static_mt# -L$(GLPKROOT)/lib
 
-BINARIES = magic_square max_flow_expression expression_test max_flow_by_lp# sample sample2 sample11 sample15
+BINARIES = magic_square max_flow_expression #expression_test max_flow_by_lp# sample sample2 sample11 sample15
 
 #include ../makefile
 



More information about the Lemon-commits mailing list