Changeset 1243:41caee260bd4 in lemon0.x for src/work/athos/lp/magic_square.cc
 Timestamp:
 03/22/05 17:49:30 (19 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@1670
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/work/athos/lp/magic_square.cc
r1241 r1243 18 18 19 19 int main(int, char **) { 20 const int n= 4;20 const int n=3; 21 21 const double row_sum=(1.0+n*n)*n/2; 22 22 Timer ts; … … 44 44 expr2+=x[std::make_pair(j, i)]; 45 45 } 46 46 47 // sum of rows and columns 47 48 lp.addRow(expr1==row_sum); 48 49 lp.addRow(expr2==row_sum); 50 cout <<"Expr1: "<<expr1<<endl; 51 cout <<"Expr2: "<<expr2<<endl; 52 49 53 expr3+=x[std::make_pair(i, i)]; 50 54 expr4+=x[std::make_pair(i, (n+1)i)]; 51 55 } 56 cout <<"Expr3: "<<expr3<<endl; 57 cout <<"Expr4: "<<expr4<<endl; 52 58 // sum of the diagonal entries 53 59 lp.addRow(expr3==row_sum); … … 61 67 } 62 68 } 63 // we make new binary variables for each pair of 64 // entries of the square to achieve that 65 // the values of different entries are different 66 lp.setMIP(); 67 for (Coords::const_iterator it=x.begin(); it!=x.end(); ++it) { 68 Coords::const_iterator jt=it; ++jt; 69 for(; jt!=x.end(); ++jt) { 70 Col col1=(*it).second; 71 Col col2=(*jt).second; 72 Col col=lp.addCol(); 73 lp.setColLowerBound(col, 0.0); 74 lp.setColUpperBound(col, 1.0); 75 lp.addRow(double(n*n+1.0)<=1.0*col21.0*col1double(n*n)*col<=1.0); 76 lp.setColInt(col); 77 } 78 } 79 cout << "elapsed time: " << ts << endl; 80 lp.solveSimplex(); 81 // let's solve the integer problem 82 lp.solveBandB(); 83 cout << "elapsed time: " << ts << endl; 84 for (int i=1; i<=n; ++i) { 85 for (int j=1; j<=n; ++j) { 86 cout << "x("<<i<<","<<j<<")="<<lp.getMIPPrimal(x[std::make_pair(i,j)]) 87 << endl; 88 } 89 } 69 70 71 72 // // we make new binary variables for each pair of 73 // // entries of the square to achieve that 74 // // the values of different entries are different 75 // lp.setMIP(); 76 // for (Coords::const_iterator it=x.begin(); it!=x.end(); ++it) { 77 // Coords::const_iterator jt=it; ++jt; 78 // for(; jt!=x.end(); ++jt) { 79 // Col col1=(*it).second; 80 // Col col2=(*jt).second; 81 // Col col=lp.addCol(); 82 // lp.setColLowerBound(col, 0.0); 83 // lp.setColUpperBound(col, 1.0); 84 // lp.addRow(double(n*n+1.0)<=1.0*col21.0*col1double(n*n)*col<=1.0); 85 // lp.setColInt(col); 86 // } 87 // } 88 // cout << "elapsed time: " << ts << endl; 89 // lp.solveSimplex(); 90 // // let's solve the integer problem 91 // lp.solveBandB(); 92 // cout << "elapsed time: " << ts << endl; 93 // for (int i=1; i<=n; ++i) { 94 // for (int j=1; j<=n; ++j) { 95 // cout << "x("<<i<<","<<j<<")="<<lp.getMIPPrimal(x[std::make_pair(i,j)]) 96 // << endl; 97 // } 98 // } 90 99 }
Note: See TracChangeset
for help on using the changeset viewer.