当前位置: 首页>>代码示例>>C++>>正文


C++ boost::edges方法代码示例

本文整理汇总了C++中boost::edges方法的典型用法代码示例。如果您正苦于以下问题:C++ boost::edges方法的具体用法?C++ boost::edges怎么用?C++ boost::edges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boost的用法示例。


在下文中一共展示了boost::edges方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: get

    void add_middle_vertex_to_edges
    (const InputGraph& in_g, OutputGraph& out_g, WeightTag w_tag,
     IndexMap i_map, Orig2CopyMap orig_to_copy_map)
    {
      using boost::vertices;
      using boost::edges;
      using boost::num_edges;
      using boost::source;
      using boost::target;
      using boost::clear_vertex;
      using boost::add_vertex;
      using boost::add_edge;

      typedef typename boost::graph_traits<OutputGraph>::vertex_descriptor
        Vertex;
      typedef typename boost::property_map<OutputGraph, boost::edge_all_t>::type
        EdgePropertyMap;
      typedef typename boost::property_traits<EdgePropertyMap>::value_type
        EdgePropertyValue;
      typedef typename boost::property_map<OutputGraph, WeightTag>::type
        WeightMap;
      typedef typename boost::property_traits<WeightMap>::value_type
        WeightValue;
      typedef boost::tuple<Vertex, Vertex, EdgePropertyValue, WeightValue>
        EdgeTuple;
      typedef std::vector<EdgeTuple> EdgeTuples;

      boost::copy_graph(in_g, out_g,
          boost::vertex_index_map(i_map). orig_to_copy(orig_to_copy_map));

      WeightMap w_map = get(w_tag, out_g);
      EdgePropertyMap e_all_map = get(boost::edge_all, out_g);
      EdgeTuples edge_tuples;
      edge_tuples.reserve(num_edges(out_g));

      typename boost::graph_traits<OutputGraph>::edge_iterator ei, ei_end;
      for (boost::tie(ei, ei_end) = edges(out_g); ei != ei_end; ++ei) {
        edge_tuples.push_back
          (make_tuple(source(*ei, out_g), target(*ei, out_g),
                      get(e_all_map, *ei), get(w_map, *ei) / 2));
      }

      typename boost::graph_traits<OutputGraph>::vertex_iterator vi, vi_end;
      for (boost::tie(vi, vi_end) = vertices(out_g); vi != vi_end; ++vi) {
        clear_vertex(*vi, out_g);
      }

      // add_vertex must not invalid vertex_descriptor
      for (typename EdgeTuples::const_iterator eti = edge_tuples.begin(),
          eti_end = edge_tuples.end(); eti != eti_end; ++eti) {
        const Vertex new_v = add_vertex(out_g);
        put(w_map,
            add_edge(get<0>(*eti), new_v, get<2>(*eti), out_g).first,
            get<3>(*eti));
        put(w_map,
            add_edge(new_v, get<1>(*eti), get<2>(*eti), out_g).first,
            get<3>(*eti));
      }
    }
开发者ID:amedama41,项目名称:Canard,代码行数:59,代码来源:utility.hpp


注:本文中的boost::edges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。