COIN-OR::LEMON - Graph Library

Changeset 1143:4fb22cfa5759 in lemon-0.x


Ignore:
Timestamp:
02/08/05 18:47:19 (15 years ago)
Author:
marci
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1542
Message:

The pair of setSomeThing function is getSomeThing.

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

Legend:

Unmodified
Added
Removed
  • src/work/marci/lp/lp_solver_base.h

    r1113 r1143  
    172172
    173173  /*! \e
     174    \todo kellenene uj iterable structure bele, mert ez nem az igazi
    174175    \todo A[x,y]-t cserel. Jobboldal, baloldal csere.
    175176    \todo LEKERDEZESEK!!!
     
    202203    IterablePartition<int> col_iter_map;
    203204    /// \e
     205    std::vector<RowIt> int_row_map;
     206    /// \e
     207    std::vector<ColIt> int_col_map;
     208    /// \e
    204209    const int VALID_CLASS;
    205210    /// \e
     
    298303                               const std::vector<std::pair<int, _Value> >& coeffs) = 0;
    299304    /// \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;
    300308    virtual void _setColCoeffs(int i,
    301309                               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;
    302314  public:
    303315    /// \e
     
    374386        col_it=col_iter_map.push_back(i, VALID_CLASS);
    375387      }
     388      int_col_map.push_back(col_it);
    376389      return col_it;
    377390    }
     
    387400        row_it=row_iter_map.push_back(i, VALID_CLASS);
    388401      }
     402      int_row_map.push_back(row_it);
    389403      return row_it;
    390404    }
     
    401415        if (col_iter_map[it]>cols[1]) --col_iter_map[it];
    402416      }
     417      int_col_map.erase(int_col_map.begin()+cols[1]);
    403418    }
    404419    /// \e
     
    414429        if (row_iter_map[it]>rows[1]) --row_iter_map[it];
    415430      }
     431      int_row_map.erase(int_row_map.begin()+rows[1]);
    416432    }
    417433    /// \e
     
    510526    }
    511527    /// \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
    512538    void setColCoeffs(ColIt col_it, const DualExpression& expr) {
    513539      std::vector<std::pair<int, _Value> > col_coeffs;
     
    520546    }
    521547    /// \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
    522559    void setObjCoeffs(const Expression& expr) {
    523560      for(typename Expression::Data::const_iterator i=expr.data.begin();
     
    525562        setObjCoef((*i).first, (*i).second);
    526563      }
     564    }
     565    /// \e
     566    /// This routine modifies \c expr by only adding to it.
     567    void getObjCoeffs(Expression& expr) {
     568      /// FIXME not yet implemented
    527569    }
    528570    //@}
     
    548590    LPGLPK() : Parent(),
    549591                        lp(lpx_create_prob()) {
     592      int_row_map.push_back(RowIt());
     593      int_col_map.push_back(ColIt());
    550594      lpx_set_int_parm(lp, LPX_K_DUAL, 1);
    551595    }
     
    593637        indices[length]=it->first;
    594638        doubles[length]=it->second;
    595 //      std::cout << "  " << indices[length] << " "
    596 //                << doubles[length] << std::endl;
    597       }
    598 //      std::cout << i << " " << length << std::endl;
     639      }
    599640      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      }
    600654      delete [] indices;
    601655      delete [] doubles;
     
    615669      }
    616670      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      }
    617684      delete [] indices;
    618685      delete [] doubles;
  • src/work/marci/lp/max_flow_expression.cc

    r1111 r1143  
    33#include <fstream>
    44
     5#include <lemon/graph_utils.h>
    56#include <lemon/smart_graph.h>
    67#include <lemon/list_graph.h>
     
    4950  typedef LPSolver::RowIt RowIt;
    5051  typedef Graph::EdgeMap<ColIt> EdgeIndexMap;
     52  typedef Graph::NodeMap<RowIt> NodeIndexMap;
    5153  EdgeIndexMap edge_index_map(g);
     54  NodeIndexMap node_index_map(g);
    5255  PrimalMap<Edge, EdgeIndexMap> flow(lp, edge_index_map);
    5356
     
    7679    if ((n!=s) && (n!=t)) {
    7780      RowIt row_it=lp.addRow();
     81      node_index_map.set(n, row_it);
    7882      lp.setRowCoeffs(row_it, expr);
    7983      lp.setRowLowerBound(row_it, 0.0);
    8084      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//       }
    8191    }
    8292  }
    8393  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//   }
    84106  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;
    85118}
Note: See TracChangeset for help on using the changeset viewer.