COIN-OR::LEMON - Graph Library

Changeset 1243:41caee260bd4 in lemon-0.x for src/work/athos


Ignore:
Timestamp:
03/22/05 17:49:30 (20 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...

Location:
src/work/athos/lp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/work/athos/lp/lp_solver_glpk.h

    r1241 r1243  
    165165    }
    166166    void _setCoeff(int col, int row, double value) {
    167       /// FIXME not yet implemented
     167      ///FIXME Of course this is not efficient at all, but GLPK knows not more.
     168      int change_this;
     169      bool get_set_row;
     170      //The only thing we can do is optimize on whether working with a row
     171      //or a coloumn
     172      int row_num = rowNum();
     173      int col_num = colNum();
     174      if (col_num<row_num){
     175        //There are more rows than coloumns
     176        get_set_row=true;
     177        int mem_length=1+row_num;
     178        int* indices = new int[mem_length];
     179        double* doubles = new double[mem_length];
     180        int length=lpx_get_mat_col(lp, i, indices, doubles);
     181      }else{
     182        get_set_row=false;
     183        int mem_length=1+col_num;
     184        int* indices = new int[mem_length];
     185        double* doubles = new double[mem_length];
     186        int length=lpx_get_mat_row(lp, i, indices, doubles);
     187      }
     188      //Itten     
     189int* indices = new int[mem_length];
     190      double* doubles = new double[mem_length];
     191      int length=lpx_get_mat_col(lp, i, indices, doubles);
     192 
     193      delete [] indices;
     194      delete [] doubles;
     195
    168196    }
    169197    double _getCoeff(int col, int row) {
  • 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.