diff -r 41caee260bd4 -r 43a3d06e0ee0 src/work/athos/lp_old/magic_square.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/athos/lp_old/magic_square.cc Wed Mar 23 09:49:41 2005 +0000 @@ -0,0 +1,99 @@ +// -*- c++ -*- +#include +#include + +#include +#include + +using std::cout; +using std::endl; +using namespace lemon; + +/* + On an 1537Mhz PC, the run times with + glpk are the following. + for n=3,4, some secondes + for n=5, 25 hours + */ + +int main(int, char **) { + const int n=3; + const double row_sum=(1.0+n*n)*n/2; + Timer ts; + ts.reset(); + typedef LpGlpk LPSolver; + typedef LPSolver::Col Col; + LPSolver lp; + typedef std::map, Col> Coords; + Coords x; + // we create a new variable for each entry + // of the magic square + for (int i=1; i<=n; ++i) { + for (int j=1; j<=n; ++j) { + Col col=lp.addCol(); + x[std::make_pair(i,j)]=col; + lp.setColLowerBound(col, 1.0); + lp.setColUpperBound(col, double(n*n)); + } + } + LPSolver::Expression expr3, expr4; + for (int i=1; i<=n; ++i) { + LPSolver::Expression expr1, expr2; + for (int j=1; j<=n; ++j) { + 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: "<