Changeset 1143:4fb22cfa5759 in lemon0.x for src
 Timestamp:
 02/08/05 18:47:19 (15 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@1542
 Location:
 src/work/marci/lp
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

src/work/marci/lp/lp_solver_base.h
r1113 r1143 172 172 173 173 /*! \e 174 \todo kellenene uj iterable structure bele, mert ez nem az igazi 174 175 \todo A[x,y]t cserel. Jobboldal, baloldal csere. 175 176 \todo LEKERDEZESEK!!! … … 202 203 IterablePartition<int> col_iter_map; 203 204 /// \e 205 std::vector<RowIt> int_row_map; 206 /// \e 207 std::vector<ColIt> int_col_map; 208 /// \e 204 209 const int VALID_CLASS; 205 210 /// \e … … 298 303 const std::vector<std::pair<int, _Value> >& coeffs) = 0; 299 304 /// \e 305 /// This routine modifies \c coeffs only by the \c push_back method. 306 virtual void _getRowCoeffs(int i, 307 std::vector<std::pair<int, _Value> >& coeffs) = 0; 300 308 virtual void _setColCoeffs(int i, 301 309 const std::vector<std::pair<int, _Value> >& coeffs) = 0; 310 /// \e 311 /// This routine modifies \c coeffs only by the \c push_back method. 312 virtual void _getColCoeffs(int i, 313 std::vector<std::pair<int, _Value> >& coeffs) = 0; 302 314 public: 303 315 /// \e … … 374 386 col_it=col_iter_map.push_back(i, VALID_CLASS); 375 387 } 388 int_col_map.push_back(col_it); 376 389 return col_it; 377 390 } … … 387 400 row_it=row_iter_map.push_back(i, VALID_CLASS); 388 401 } 402 int_row_map.push_back(row_it); 389 403 return row_it; 390 404 } … … 401 415 if (col_iter_map[it]>cols[1]) col_iter_map[it]; 402 416 } 417 int_col_map.erase(int_col_map.begin()+cols[1]); 403 418 } 404 419 /// \e … … 414 429 if (row_iter_map[it]>rows[1]) row_iter_map[it]; 415 430 } 431 int_row_map.erase(int_row_map.begin()+rows[1]); 416 432 } 417 433 /// \e … … 510 526 } 511 527 /// \e 528 /// This routine modifies \c expr by only adding to it. 529 void getRowCoeffs(RowIt row_it, Expression& expr) { 530 std::vector<std::pair<int, _Value> > row_coeffs; 531 _getRowCoeffs(row_iter_map[row_it], row_coeffs); 532 for(typename std::vector<std::pair<int, _Value> >::const_iterator 533 i=row_coeffs.begin(); i!=row_coeffs.end(); ++i) { 534 expr+= (*i).second*int_col_map[(*i).first]; 535 } 536 } 537 /// \e 512 538 void setColCoeffs(ColIt col_it, const DualExpression& expr) { 513 539 std::vector<std::pair<int, _Value> > col_coeffs; … … 520 546 } 521 547 /// \e 548 /// This routine modifies \c expr by only adding to it. 549 void getColCoeffs(ColIt col_it, DualExpression& expr) { 550 std::vector<std::pair<int, _Value> > col_coeffs; 551 _getColCoeffs(col_iter_map[col_it], col_coeffs); 552 for(typename std::vector<std::pair<int, _Value> >::const_iterator 553 i=col_coeffs.begin(); i!=col_coeffs.end(); ++i) { 554 expr+= (*i).second*int_row_map[(*i).first]; 555 } 556 } 557 /// \e 558 /// \bug ez igy nem jo 522 559 void setObjCoeffs(const Expression& expr) { 523 560 for(typename Expression::Data::const_iterator i=expr.data.begin(); … … 525 562 setObjCoef((*i).first, (*i).second); 526 563 } 564 } 565 /// \e 566 /// This routine modifies \c expr by only adding to it. 567 void getObjCoeffs(Expression& expr) { 568 /// FIXME not yet implemented 527 569 } 528 570 //@} … … 548 590 LPGLPK() : Parent(), 549 591 lp(lpx_create_prob()) { 592 int_row_map.push_back(RowIt()); 593 int_col_map.push_back(ColIt()); 550 594 lpx_set_int_parm(lp, LPX_K_DUAL, 1); 551 595 } … … 593 637 indices[length]=it>first; 594 638 doubles[length]=it>second; 595 // std::cout << " " << indices[length] << " " 596 // << doubles[length] << std::endl; 597 } 598 // std::cout << i << " " << length << std::endl; 639 } 599 640 lpx_set_mat_row(lp, i, length, indices, doubles); 641 delete [] indices; 642 delete [] doubles; 643 } 644 /// \e 645 virtual void _getRowCoeffs(int i, 646 std::vector<std::pair<int, double> >& coeffs) { 647 int mem_length=1+colNum(); 648 int* indices = new int[mem_length]; 649 double* doubles = new double[mem_length]; 650 int length=lpx_get_mat_row(lp, i, indices, doubles); 651 for (int i=1; i<=length; ++i) { 652 coeffs.push_back(std::make_pair(indices[i], doubles[i])); 653 } 600 654 delete [] indices; 601 655 delete [] doubles; … … 615 669 } 616 670 lpx_set_mat_col(lp, i, length, indices, doubles); 671 delete [] indices; 672 delete [] doubles; 673 } 674 /// \e 675 virtual void _getColCoeffs(int i, 676 std::vector<std::pair<int, double> >& coeffs) { 677 int mem_length=1+rowNum(); 678 int* indices = new int[mem_length]; 679 double* doubles = new double[mem_length]; 680 int length=lpx_get_mat_col(lp, i, indices, doubles); 681 for (int i=1; i<=length; ++i) { 682 coeffs.push_back(std::make_pair(indices[i], doubles[i])); 683 } 617 684 delete [] indices; 618 685 delete [] doubles; 
src/work/marci/lp/max_flow_expression.cc
r1111 r1143 3 3 #include <fstream> 4 4 5 #include <lemon/graph_utils.h> 5 6 #include <lemon/smart_graph.h> 6 7 #include <lemon/list_graph.h> … … 49 50 typedef LPSolver::RowIt RowIt; 50 51 typedef Graph::EdgeMap<ColIt> EdgeIndexMap; 52 typedef Graph::NodeMap<RowIt> NodeIndexMap; 51 53 EdgeIndexMap edge_index_map(g); 54 NodeIndexMap node_index_map(g); 52 55 PrimalMap<Edge, EdgeIndexMap> flow(lp, edge_index_map); 53 56 … … 76 79 if ((n!=s) && (n!=t)) { 77 80 RowIt row_it=lp.addRow(); 81 node_index_map.set(n, row_it); 78 82 lp.setRowCoeffs(row_it, expr); 79 83 lp.setRowLowerBound(row_it, 0.0); 80 84 lp.setRowUpperBound(row_it, 0.0); 85 // cout << expr << endl; 86 // { 87 // LPSolver::Expression expr; 88 // lp.getRowCoeffs(node_index_map[n], expr); 89 // cout << expr << endl; 90 // } 81 91 } 82 92 } 83 93 lp.solveSimplex(); 94 // cout << "num of nodes: " << countNodes(g) << endl; 95 // cout << "num of edges: " << countEdges(g) << endl; 96 // cout << "num of rows: " << lp.rowNum() << endl; 97 // cout << "num of rows: " << lp.int_row_map.size() << endl; 98 // for (int i=0; i<lp.int_row_map.size(); ++i) { 99 // cout << lp.int_row_map[i] << " " << endl; 100 // } 101 // cout << "num of columns: " << lp.colNum() << endl; 102 // cout << "num of columns: " << lp.int_col_map.size() << endl; 103 // for (int i=0; i<lp.int_col_map.size(); ++i) { 104 // cout << lp.int_col_map[i] << " " << endl; 105 // } 84 106 cout << "elapsed time: " << ts << endl; 107 // Graph::NodeIt n(g); 108 // ++n; 109 // for(Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) { 110 // cout << edge_index_map[e] << endl; 111 // } 112 // for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) { 113 // cout << edge_index_map[e] << endl; 114 // } 115 // LPSolver::DualExpression expr; 116 // lp.getRowCoeffs(node_index_map[n], expr); 117 // cout << expr << endl; 85 118 }
Note: See TracChangeset
for help on using the changeset viewer.