COIN-OR::LEMON - Graph Library

Ignore:
Timestamp:
03/22/05 17:49:30 (15 years ago)
Author:
athos
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1670
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/work/athos/lp/magic_square.cc

    r1241 r1243  
    1818
    1919int main(int, char **) {
    20   const int n=4;
     20  const int n=3;
    2121  const double row_sum=(1.0+n*n)*n/2;
    2222  Timer ts;
     
    4444      expr2+=x[std::make_pair(j, i)];
    4545    }
     46
    4647    // sum of rows and columns
    4748    lp.addRow(expr1==row_sum);
    4849    lp.addRow(expr2==row_sum);
     50      cout <<"Expr1: "<<expr1<<endl;
     51      cout <<"Expr2: "<<expr2<<endl;
     52
    4953    expr3+=x[std::make_pair(i, i)];
    5054    expr4+=x[std::make_pair(i, (n+1)-i)];
    5155  }
     56  cout <<"Expr3: "<<expr3<<endl;
     57  cout <<"Expr4: "<<expr4<<endl;
    5258  // sum of the diagonal entries
    5359  lp.addRow(expr3==row_sum);
     
    6167    }
    6268  }
    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*col2-1.0*col1-double(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*col2-1.0*col1-double(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//   }
    9099}
Note: See TracChangeset for help on using the changeset viewer.