COIN-OR::LEMON - Graph Library

Changeset 352:4b89077ab715 in lemon-0.x


Ignore:
Timestamp:
04/17/04 23:50:48 (21 years ago)
Author:
beckerjc
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@471
Message:

A successful work-around for using const map reference as an output
parameter to Kruskal().

Location:
src/work/johanna
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/work/johanna/kruskal.h

    r349 r352  
    3838  }
    3939
     40  /* A work-around for running Kruskal with const-reference bool maps... */
     41
     42  template<typename Map>
     43  class NonConstMapWr {
     44    const Map &m;
     45  public:
     46    typedef typename Map::ValueType ValueType;
     47
     48    NonConstMapWr(const Map &_m) : m(_m) {}
     49
     50    template<typename KeyType>
     51    void set(KeyType const& k, ValueType const &v) const { m.set(k,v); }
     52  };
     53
     54  template <typename Graph, typename InputEdgeOrder, typename OutBoolMap>
     55  inline
     56  typename InputEdgeOrder::ValueType
     57  Kruskal(Graph const& G, InputEdgeOrder const& edges,
     58          OutBoolMap const& out_map)
     59  {
     60    NonConstMapWr<OutBoolMap> map_wr(out_map);
     61    return Kruskal(G, edges, map_wr);
     62  } 
    4063
    4164 
     
    5073  template<typename Iterator>
    5174  class SequenceOutput {
    52     Iterator it;
     75    mutable Iterator it;
    5376
    5477  public:
     
    5881
    5982    template<typename KeyType>
    60     void set(KeyType const& k, bool v) { if(v) {*it=k; ++it;} }
     83    void set(KeyType const& k, bool v) const { if(v) {*it=k; ++it;} }
    6184  };
    6285
     
    178201  /// Input is from an EdgeMap, output is a plain boolmap.
    179202  template <typename Graph, typename EdgeCostMap, typename RetEdgeBoolMap>
     203  inline
    180204  typename EdgeCostMap::ValueType
    181205  Kruskal_EdgeCostMapIn_BoolMapOut(Graph const& G,
     
    194218  /// Input is from an EdgeMap, output is to a sequence.
    195219  template <typename Graph, typename EdgeCostMap, typename RetIterator>
     220  inline
    196221  typename EdgeCostMap::ValueType
    197222  Kruskal_EdgeCostMapIn_IteratorOut(Graph const& G,
  • src/work/johanna/kruskal_test.cc

    r349 r352  
    101101
    102102  tree_edge_vec.clear();
    103   SequenceOutput< back_insert_iterator< vector<Edge> > >
    104     vec_filler(back_inserter(tree_edge_vec));
     103//   SequenceOutput< back_insert_iterator< vector<Edge> > >
     104//     vec_filler(back_inserter(tree_edge_vec));
     105//   cout << "Nemkonst koltseggel tarhatekonyabban: "
     106//        << Kruskal(G,
     107//                KruskalMapVec<ECostMap>(G, edge_cost_map),
     108//                vec_filler)
     109//        << endl;
    105110  cout << "Nemkonst koltseggel tarhatekonyabban: "
    106111       << Kruskal(G,
    107112                  KruskalMapVec<ECostMap>(G, edge_cost_map),
    108                   vec_filler)
     113                  makeSequenceOutput(back_inserter(tree_edge_vec))
     114                  )
    109115       << endl;
    110116
Note: See TracChangeset for help on using the changeset viewer.