Ami f?lig van k?sz, ma m?r f?lig marad...
1.1 --- a/src/work/athos/lp/lp_solver_glpk.h Tue Mar 22 16:00:00 2005 +0000
1.2 +++ b/src/work/athos/lp/lp_solver_glpk.h Tue Mar 22 16:49:30 2005 +0000
1.3 @@ -164,7 +164,35 @@
1.4 lpx_del_rows(lp, 1, rows);
1.5 }
1.6 void _setCoeff(int col, int row, double value) {
1.7 - /// FIXME not yet implemented
1.8 + ///FIXME Of course this is not efficient at all, but GLPK knows not more.
1.9 + int change_this;
1.10 + bool get_set_row;
1.11 + //The only thing we can do is optimize on whether working with a row
1.12 + //or a coloumn
1.13 + int row_num = rowNum();
1.14 + int col_num = colNum();
1.15 + if (col_num<row_num){
1.16 + //There are more rows than coloumns
1.17 + get_set_row=true;
1.18 + int mem_length=1+row_num;
1.19 + int* indices = new int[mem_length];
1.20 + double* doubles = new double[mem_length];
1.21 + int length=lpx_get_mat_col(lp, i, indices, doubles);
1.22 + }else{
1.23 + get_set_row=false;
1.24 + int mem_length=1+col_num;
1.25 + int* indices = new int[mem_length];
1.26 + double* doubles = new double[mem_length];
1.27 + int length=lpx_get_mat_row(lp, i, indices, doubles);
1.28 + }
1.29 + //Itten
1.30 +int* indices = new int[mem_length];
1.31 + double* doubles = new double[mem_length];
1.32 + int length=lpx_get_mat_col(lp, i, indices, doubles);
1.33 +
1.34 + delete [] indices;
1.35 + delete [] doubles;
1.36 +
1.37 }
1.38 double _getCoeff(int col, int row) {
1.39 /// FIXME not yet implemented
2.1 --- a/src/work/athos/lp/magic_square.cc Tue Mar 22 16:00:00 2005 +0000
2.2 +++ b/src/work/athos/lp/magic_square.cc Tue Mar 22 16:49:30 2005 +0000
2.3 @@ -17,7 +17,7 @@
2.4 */
2.5
2.6 int main(int, char **) {
2.7 - const int n=4;
2.8 + const int n=3;
2.9 const double row_sum=(1.0+n*n)*n/2;
2.10 Timer ts;
2.11 ts.reset();
2.12 @@ -43,12 +43,18 @@
2.13 expr1+=x[std::make_pair(i, j)];
2.14 expr2+=x[std::make_pair(j, i)];
2.15 }
2.16 +
2.17 // sum of rows and columns
2.18 lp.addRow(expr1==row_sum);
2.19 lp.addRow(expr2==row_sum);
2.20 + cout <<"Expr1: "<<expr1<<endl;
2.21 + cout <<"Expr2: "<<expr2<<endl;
2.22 +
2.23 expr3+=x[std::make_pair(i, i)];
2.24 expr4+=x[std::make_pair(i, (n+1)-i)];
2.25 }
2.26 + cout <<"Expr3: "<<expr3<<endl;
2.27 + cout <<"Expr4: "<<expr4<<endl;
2.28 // sum of the diagonal entries
2.29 lp.addRow(expr3==row_sum);
2.30 lp.addRow(expr4==row_sum);
2.31 @@ -60,31 +66,34 @@
2.32 << endl;
2.33 }
2.34 }
2.35 - // we make new binary variables for each pair of
2.36 - // entries of the square to achieve that
2.37 - // the values of different entries are different
2.38 - lp.setMIP();
2.39 - for (Coords::const_iterator it=x.begin(); it!=x.end(); ++it) {
2.40 - Coords::const_iterator jt=it; ++jt;
2.41 - for(; jt!=x.end(); ++jt) {
2.42 - Col col1=(*it).second;
2.43 - Col col2=(*jt).second;
2.44 - Col col=lp.addCol();
2.45 - lp.setColLowerBound(col, 0.0);
2.46 - lp.setColUpperBound(col, 1.0);
2.47 - lp.addRow(double(-n*n+1.0)<=1.0*col2-1.0*col1-double(n*n)*col<=-1.0);
2.48 - lp.setColInt(col);
2.49 - }
2.50 - }
2.51 - cout << "elapsed time: " << ts << endl;
2.52 - lp.solveSimplex();
2.53 - // let's solve the integer problem
2.54 - lp.solveBandB();
2.55 - cout << "elapsed time: " << ts << endl;
2.56 - for (int i=1; i<=n; ++i) {
2.57 - for (int j=1; j<=n; ++j) {
2.58 - cout << "x("<<i<<","<<j<<")="<<lp.getMIPPrimal(x[std::make_pair(i,j)])
2.59 - << endl;
2.60 - }
2.61 - }
2.62 +
2.63 +
2.64 +
2.65 +// // we make new binary variables for each pair of
2.66 +// // entries of the square to achieve that
2.67 +// // the values of different entries are different
2.68 +// lp.setMIP();
2.69 +// for (Coords::const_iterator it=x.begin(); it!=x.end(); ++it) {
2.70 +// Coords::const_iterator jt=it; ++jt;
2.71 +// for(; jt!=x.end(); ++jt) {
2.72 +// Col col1=(*it).second;
2.73 +// Col col2=(*jt).second;
2.74 +// Col col=lp.addCol();
2.75 +// lp.setColLowerBound(col, 0.0);
2.76 +// lp.setColUpperBound(col, 1.0);
2.77 +// lp.addRow(double(-n*n+1.0)<=1.0*col2-1.0*col1-double(n*n)*col<=-1.0);
2.78 +// lp.setColInt(col);
2.79 +// }
2.80 +// }
2.81 +// cout << "elapsed time: " << ts << endl;
2.82 +// lp.solveSimplex();
2.83 +// // let's solve the integer problem
2.84 +// lp.solveBandB();
2.85 +// cout << "elapsed time: " << ts << endl;
2.86 +// for (int i=1; i<=n; ++i) {
2.87 +// for (int j=1; j<=n; ++j) {
2.88 +// cout << "x("<<i<<","<<j<<")="<<lp.getMIPPrimal(x[std::make_pair(i,j)])
2.89 +// << endl;
2.90 +// }
2.91 +// }
2.92 }
3.1 --- a/src/work/marci/lp/makefile Tue Mar 22 16:00:00 2005 +0000
3.2 +++ b/src/work/marci/lp/makefile Tue Mar 22 16:49:30 2005 +0000
3.3 @@ -5,7 +5,7 @@
3.4 CXXFLAGS = -g -O2 -W -Wall $(INCLUDEDIRS) -ansi -pedantic
3.5 LDFLAGS = -lglpk#-lcplex -lm -lpthread -lilocplex -L/usr/local/cplex/cplex75/lib/i86_linux2_glibc2.2_gcc3.0/static_mt# -L$(GLPKROOT)/lib
3.6
3.7 -BINARIES = magic_square max_flow_expression expression_test max_flow_by_lp# sample sample2 sample11 sample15
3.8 +BINARIES = magic_square max_flow_expression #expression_test max_flow_by_lp# sample sample2 sample11 sample15
3.9
3.10 #include ../makefile
3.11