Ticket #3151: bgl.diff

File bgl.diff, 18.3 KB (added by tkeitt@…, 13 years ago)

svn diff

  • adjacency_list_io.hpp

     
    287287                // assign indices to vertices
    288288                std::map<Vertex,int> indices;
    289289                int num = 0;
    290                 typename graph_traits<Graph>::vertex_iterator vi;
    291                 for (vi = vertices(graph).first; vi != vertices(graph).second; ++vi){
     290                typename graph_traits<Graph>::vertex_iterator vi, v_end;
     291                for (tie(vi, v_end) = vertices(graph); vi != v_end; ++vi){
    292292                        indices[*vi] = num++;
    293293                }
    294294
    295295                // write edges
    296296                PropertyPrinter<Graph, EdgeProperty> print_Edge(graph);
    297297                out << "e" << std::endl;
    298                 typename graph_traits<Graph>::edge_iterator ei;
    299                 for (ei = edges(graph).first; ei != edges(graph).second; ++ei){
     298                typename graph_traits<Graph>::edge_iterator ei, e_end;
     299                for (tie(ei, e_end) = edges(graph); ei != e_end; ++ei){
    300300                        out << indices[source(*ei,graph)] <<  " " << indices[target(*ei,graph)] << "  ";
    301301                        print_Edge(out,ei);
    302302                        out << std::endl;
     
    322322        {
    323323                PropertyPrinter<Graph, V> printNode(this->graph);
    324324                out << "v"<<std::endl;
    325                 typename graph_traits<Graph>::vertex_iterator vi;
    326                 for (vi = vertices(this->graph).first; vi != vertices(this->graph).second; ++vi){
     325                typename graph_traits<Graph>::vertex_iterator vi, v_end;
     326                for (tie(vi, v_end) = vertices(this->graph); vi != v_end; ++vi){
    327327                        printNode(out,vi);
    328328                        out << std::endl;
    329329                }
  • pair_util.hpp

     
     1//
     2//=======================================================================
     3// Copyright 2009 University of Texas at Austin.
     4// Authors: Tim Keitt
     5//
     6// Distributed under the Boost Software License, Version 1.0. (See
     7// accompanying file LICENSE_1_0.txt or copy at
     8// http://www.boost.org/LICENSE_1_0.txt)
     9//=======================================================================
     10//
     11#ifndef BOOST_PAIR_UTIL_HPP
     12#define BOOST_PAIR_UTIL_HPP
     13
     14#include <utility>
     15
     16//
     17// These could not go in graph_utility.hpp
     18// because that file includes depth_first_search.hpp
     19//
     20// Some simple convenience templates for comparing members of a pair
     21//
     22
     23namespace boost {
     24
     25template<class T>
     26bool
     27is_equal_pair(const std::pair<T, T>& x)
     28{
     29  return x.first == x.second;
     30}
     31 
     32template<class T>
     33bool
     34is_not_equal_pair(const std::pair<T, T>& x)
     35{
     36  return x.first != x.second;
     37}
     38
     39} /* namespace boost */
     40
     41#endif /* BOOST_PAIR_UTIL_HPP */
  • cuthill_mckee_ordering.hpp

     
    1212#define BOOST_GRAPH_CUTHILL_MCKEE_HPP
    1313
    1414#include <boost/config.hpp>
     15#include <boost/graph/pair_util.hpp>
    1516#include <boost/graph/detail/sparse_ordering.hpp>
    1617#include <algorithm>
    1718
     
    132133  cuthill_mckee_ordering(const Graph& G, OutputIterator permutation,
    133134                         ColorMap color, DegreeMap degree)
    134135  {
    135     if (vertices(G).first == vertices(G).second)
     136    if ( is_equal_pair(vertices(G)) )
    136137      return permutation;
    137138
    138139    typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
     
    168169  cuthill_mckee_ordering(const Graph& G, OutputIterator permutation,
    169170                         VertexIndexMap index_map)
    170171  {
    171     if (vertices(G).first == vertices(G).second)
     172    if ( is_equal_pair(vertices(G)) )
    172173      return permutation;
    173174   
    174175    typedef out_degree_property_map<Graph> DegreeMap;
  • isomorphism.hpp

     
    439439      return false;
    440440#endif
    441441 
    442     for (typename graph_traits<Graph1>::edge_iterator e1 = edges(g1).first;
    443          e1 != edges(g1).second; ++e1) {
     442    typename graph_traits<Graph1>::edge_iterator e1, e1_end;
     443    for (tie(e1, e1_end) = edges(g1); e1 != e1_end; ++e1) {
    444444      bool found_edge = false;
    445       for (typename graph_traits<Graph2>::edge_iterator e2 = edges(g2).first;
    446            e2 != edges(g2).second && !found_edge; ++e2) {
     445      typename graph_traits<Graph2>::edge_iterator e2, e2_end;
     446      for (tie(e2, e2_end) = edges(g2); e2 != e2_end && !found_edge; ++e2) {
    447447        if (source(*e2, g2) == get(iso_map, source(*e1, g1)) &&
    448448            target(*e2, g2) == get(iso_map, target(*e1, g1))) {
    449449          found_edge = true;
  • king_ordering.hpp

     
    1212#define BOOST_GRAPH_KING_HPP
    1313
    1414#include <boost/config.hpp>
     15#include <boost/graph/pair_util.hpp>
    1516#include <boost/graph/detail/sparse_ordering.hpp>
    1617
    1718/*
     
    262263  king_ordering(const Graph& G, OutputIterator permutation,
    263264                ColorMap color, DegreeMap degree, VertexIndexMap index_map)
    264265  {
    265     if (vertices(G).first == vertices(G).second)
     266    if ( is_equal_pair(vertices(G)) )
    266267      return permutation;
    267268
    268269    typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
     
    298299  king_ordering(const Graph& G, OutputIterator permutation,
    299300                VertexIndexMap index_map)
    300301  {
    301     if (vertices(G).first == vertices(G).second)
     302    if ( is_equal_pair(vertices(G)) )
    302303      return permutation;
    303304
    304305    typedef out_degree_property_map<Graph> DegreeMap;
  • bc_clustering.hpp

     
    99#ifndef BOOST_GRAPH_BETWEENNESS_CENTRALITY_CLUSTERING_HPP
    1010#define BOOST_GRAPH_BETWEENNESS_CENTRALITY_CLUSTERING_HPP
    1111
     12#include <boost/graph/pair_util.hpp>
    1213#include <boost/graph/betweenness_centrality.hpp>
    1314#include <boost/graph/graph_traits.hpp>
    1415#include <boost/pending/indirect_cmp.hpp>
     
    116117  typedef typename graph_traits<MutableGraph>::vertices_size_type
    117118    vertices_size_type;
    118119
    119   if (edges(g).first == edges(g).second) return;
     120  if (is_equal_pair(edges(g))) return;
    120121
    121122  // Function object that compares the centrality of edges
    122123  indirect_cmp<EdgeCentralityMap, std::less<centrality_type> >
     
    127128    brandes_betweenness_centrality(g,
    128129                                   edge_centrality_map(edge_centrality)
    129130                                   .vertex_index_map(vertex_index));
    130     edge_descriptor e = *max_element(edges(g).first, edges(g).second, cmp);
     131    edge_iterator ei, e_end;
     132    tie(ei, e_end) = edges(g);
     133    edge_descriptor e = *max_element(ei, e_end, cmp);
    131134    is_done = done(get(edge_centrality, e), e, g);
    132135    if (!is_done) remove_edge(e, g);
    133   } while (!is_done && edges(g).first != edges(g).second);
     136  } while (!is_done && is_not_equal_pair(edges(g)));
    134137}
    135138
    136139/**
  • depth_first_search.hpp

     
    1414#define BOOST_GRAPH_RECURSIVE_DFS_HPP
    1515
    1616#include <boost/config.hpp>
     17#include <boost/graph/pair_util.hpp>
    1718#include <boost/graph/graph_traits.hpp>
    1819#include <boost/graph/graph_concepts.hpp>
    1920#include <boost/graph/properties.hpp>
     
    214215  void
    215216  depth_first_search(const VertexListGraph& g, DFSVisitor vis, ColorMap color)
    216217  {
    217     if (vertices(g).first == vertices(g).second)
     218    if ( is_equal_pair(vertices(g)) )
    218219      return;
    219220
    220221    depth_first_search(g, vis, color, *vertices(g).first);
     
    284285  depth_first_search(const VertexListGraph& g,
    285286                     const bgl_named_params<P, T, R>& params)
    286287  {
    287     if (vertices(g).first == vertices(g).second)
     288    if ( is_equal_pair(vertices(g)) )
    288289      return;
    289290    using namespace boost::graph::keywords;
    290291    typedef bgl_named_params<P, T, R> params_type;
  • adj_list_serialize.hpp

     
    4949  // assign indices to vertices
    5050  std::map<Vertex,int> indices;
    5151  int num = 0;
    52   typename graph_traits<Graph>::vertex_iterator vi;
    53   for (vi = vertices(graph).first; vi != vertices(graph).second; ++vi) {
     52  typename graph_traits<Graph>::vertex_iterator vi, v_end;
     53  for (tie(vi, v_end) = vertices(graph); vi != v_end; ++vi) {
    5454    indices[*vi] = num++;
    5555    ar << serialization::make_nvp("vertex_property", get(vertex_all_t(), graph, *vi) );
    5656  }
    5757 
    5858  // write edges
    59   typename graph_traits<Graph>::edge_iterator ei;
    60   for (ei = edges(graph).first; ei != edges(graph).second; ++ei){
     59  typename graph_traits<Graph>::edge_iterator ei, e_end;
     60  for (tie(ei, e_end) = edges(graph); ei != e_end; ++ei){
    6161    ar << serialization::make_nvp("u" , indices[source(*ei,graph)]);
    6262    ar << serialization::make_nvp("v" , indices[target(*ei,graph)]);
    6363    ar << serialization::make_nvp("edge_property", get(edge_all_t(), graph, *ei) );
  • push_relabel_max_flow.hpp

     
    1919
    2020#include <boost/pending/queue.hpp>
    2121#include <boost/limits.hpp>
     22#include <boost/graph/pair_util.hpp>
    2223#include <boost/graph/graph_concepts.hpp>
    2324#include <boost/graph/named_function_params.hpp>
    2425
     
    121122        : g(g_), n(num_vertices(g_)), capacity(cap), src(src_), sink(sink_),
    122123          index(idx),
    123124          excess_flow(num_vertices(g_)),
    124           current(num_vertices(g_), out_edges(*vertices(g_).first, g_).second),
     125          current(num_vertices(g_), out_edges(*vertices(g_).first, g_)),
    125126          distance(num_vertices(g_)),
    126127          color(num_vertices(g_)),
    127128          reverse_edge(rev),
     
    149150        for (tie(u_iter, u_end) = vertices(g); u_iter != u_end; ++u_iter) {
    150151          vertex_descriptor u = *u_iter;
    151152          excess_flow[u] = 0;
    152           current[u] = out_edges(u, g).first;
     153          current[u] = out_edges(u, g);
    153154        }
    154155
    155156        bool overflow_detected = false;
     
    240241                && is_residual_edge(reverse_edge[a])) {
    241242              distance[v] = d_v;
    242243              color[v] = ColorTraits::gray();
    243               current[v] = out_edges(v, g).first;
     244              current[v] = out_edges(v, g);
    244245              max_distance = max BOOST_PREVENT_MACRO_SUBSTITUTION(d_v, max_distance);
    245246
    246247              if (excess_flow[v] > 0)
     
    262263        assert(excess_flow[u] > 0);
    263264        while (1) {
    264265          out_edge_iterator ai, ai_end;
    265           for (ai = current[u], ai_end = out_edges(u, g).second;
    266                ai != ai_end; ++ai) {
     266          for (tie(ai, ai_end) = current[u]; ai != ai_end; ++ai) {
    267267            edge_descriptor a = *ai;
    268268            if (is_residual_edge(a)) {
    269269              vertex_descriptor v = target(a, g);
     
    291291            if (distance[u] == n)
    292292              break;
    293293          } else {              // i is no longer active
    294             current[u] = ai;
     294            current[u].first = ai;
    295295            add_to_inactive_list(u, layer);
    296296            break;
    297297          }
     
    350350        ++min_distance;
    351351        if (min_distance < n) {
    352352          distance[u] = min_distance;     // this is the main action
    353           current[u] = min_edge_iter;
     353          current[u].first = min_edge_iter;
    354354          max_distance = max BOOST_PREVENT_MACRO_SUBSTITUTION(min_distance, max_distance);
    355355        }
    356356        return min_distance;
     
    444444          u = *u_iter;
    445445          color[u] = ColorTraits::white();
    446446          parent[u] = u;
    447           current[u] = out_edges(u, g).first;
     447          current[u] = out_edges(u, g);
    448448        }
    449449        // eliminate flow cycles and topologically order the vertices
    450450        for (tie(u_iter, u_end) = vertices(g); u_iter != u_end; ++u_iter) {
     
    455455            r = u;
    456456            color[r] = ColorTraits::gray();
    457457            while (1) {
    458               for (; current[u] != out_edges(u, g).second; ++current[u]) {
    459                 edge_descriptor a = *current[u];
     458              for (; is_not_equal_pair(current[u]); ++current[u].first) {
     459                edge_descriptor a = *current[u].first;
    460460                if (capacity[a] == 0 && is_residual_edge(a)) {
    461461                  vertex_descriptor v = target(a, g);
    462462                  if (color[v] == ColorTraits::white()) {
     
    469469                    FlowValue delta = residual_capacity[a];
    470470                    while (1) {
    471471                      BOOST_USING_STD_MIN();
    472                       delta = min BOOST_PREVENT_MACRO_SUBSTITUTION(delta, residual_capacity[*current[v]]);
     472                      delta = min BOOST_PREVENT_MACRO_SUBSTITUTION(delta, residual_capacity[*current[v].first]);
    473473                      if (v == u)
    474474                        break;
    475475                      else
    476                         v = target(*current[v], g);
     476                        v = target(*current[v].first, g);
    477477                    }
    478478                    // remove delta flow units
    479479                    v = u;
    480480                    while (1) {
    481                       a = *current[v];
     481                      a = *current[v].first;
    482482                      residual_capacity[a] -= delta;
    483483                      residual_capacity[reverse_edge[a]] += delta;
    484484                      v = target(a, g);
     
    488488
    489489                    // back-out of DFS to the first saturated edge
    490490                    restart = u;
    491                     for (v = target(*current[u], g); v != u; v = target(a, g)){
    492                       a = *current[v];
     491                    for (v = target(*current[u].first, g); v != u; v = target(a, g)){
     492                      a = *current[v].first;
    493493                      if (color[v] == ColorTraits::white()
    494494                          || is_saturated(a)) {
    495                         color[target(*current[v], g)] = ColorTraits::white();
     495                        color[target(*current[v].first, g)] = ColorTraits::white();
    496496                        if (color[v] != ColorTraits::white())
    497497                          restart = v;
    498498                      }
    499499                    }
    500500                    if (restart != u) {
    501501                      u = restart;
    502                       ++current[u];
     502                      ++current[u].first;
    503503                      break;
    504504                    }
    505505                  } // else if (color[v] == ColorTraits::gray())
    506506                } // if (capacity[a] == 0 ...
    507507              } // for out_edges(u, g)  (though "u" changes during loop)
    508508             
    509               if (current[u] == out_edges(u, g).second) {
     509              if ( is_equal_pair(current[u]) ) {
    510510                // scan of i is complete
    511511                color[u] = ColorTraits::black();
    512512                if (u != src) {
     
    521521                }
    522522                if (u != r) {
    523523                  u = parent[u];
    524                   ++current[u];
     524                  ++current[u].first;
    525525                } else
    526526                  break;
    527527              }
     
    533533        // note that the sink is not on the stack
    534534        if (! bos_null) {
    535535          for (u = tos; u != bos; u = topo_next[u]) {
    536             ai = out_edges(u, g).first;
    537             while (excess_flow[u] > 0 && ai != out_edges(u, g).second) {
     536            tie(ai, a_end) = out_edges(u, g);
     537            while (excess_flow[u] > 0 && ai != a_end) {
    538538              if (capacity[*ai] == 0 && is_residual_edge(*ai))
    539539                push_flow(*ai);
    540540              ++ai;
     
    632632
    633633      // will need to use random_access_property_map with these
    634634      std::vector< FlowValue > excess_flow;
    635       std::vector< out_edge_iterator > current;
     635      std::vector< std::pair<out_edge_iterator, out_edge_iterator> > current;
    636636      std::vector< distance_size_type > distance;
    637637      std::vector< default_color_type > color;
    638638
  • howard_cycle_ratio.hpp

     
    2525#include <boost/type_traits/remove_const.hpp>
    2626#include <boost/type_traits/is_signed.hpp>
    2727#include <boost/concept_check.hpp>
     28#include <boost/graph/pair_util.hpp>
    2829#include <boost/graph/adjacency_list.hpp>
    2930#include <boost/graph/reverse_graph.hpp>
    3031#include <boost/graph/breadth_first_search.hpp>
     
    172173          }
    173174        BGL_FORALL_VERTICES_T(vd1, m_g, TGraph)
    174175          {
    175             if (boost::out_edges(vd1, m_g).first == boost::out_edges(vd1, m_g).second) throw bad_graph(m_vim[vd1]);
     176            if ( is_equal_pair(boost::out_edges(vd1, m_g)) ) throw bad_graph(m_vim[vd1]);
    176177            mcr_edge_t ed = *boost::out_edges(vd1, m_g).first;
    177178            pi_edge_t pied = boost::add_edge(m_g2pi_g_vm[source(ed, m_g)], m_g2pi_g_vm[target(ed, m_g)], m_pi_g).first;
    178179            boost::put(boost::edge_weight, m_pi_g, pied, m_ew1m[ed]);
  • edge_connectivity.hpp

     
    132132    detail::neighbors(g, S.begin(), S.end(),
    133133                      std::inserter(neighbor_S, neighbor_S.begin()));
    134134
    135     std::set_difference(vertices(g).first, vertices(g).second,
     135    tie(vi, vi_end) = vertices(g);
     136    std::set_difference(vi, vi_end,
    136137                        neighbor_S.begin(), neighbor_S.end(),
    137138                        std::back_inserter(non_neighbor_S));
    138139
     
    153154      neighbor_S.insert(k);
    154155      detail::neighbors(g, k, std::inserter(neighbor_S, neighbor_S.begin()));
    155156      non_neighbor_S.clear();
    156       std::set_difference(vertices(g).first, vertices(g).second,
     157      tie(vi, vi_end) = vertices(g);
     158      std::set_difference(vi, vi_end,
    157159                          neighbor_S.begin(), neighbor_S.end(),
    158160                          std::back_inserter(non_neighbor_S));
    159161    }