Exemple #1
0
 // copy constructor
 subgraph(const subgraph& x)
     : m_parent(x.m_parent), m_edge_counter(x.m_edge_counter)
     , m_global_vertex(x.m_global_vertex), m_global_edge(x.m_global_edge)
 {
     if(x.is_root())
     {
      m_graph = x.m_graph;
     }
     // Do a deep copy (recursive).
     // Only the root graph is copied, the subgraphs contain
     // only references to the global vertices they own.
     typename subgraph<Graph>::children_iterator i,i_end;
     boost::tie(i,i_end) = x.children();
     for(; i != i_end; ++i)
     {         
      subgraph<Graph> child = this->create_subgraph();
      child = *i;
      vertex_iterator vi,vi_end;   
      boost::tie(vi,vi_end) = vertices(*i);
      for (;vi!=vi_end;++vi)  
      {
       add_vertex(*vi,child);
      }
    }
 }
Exemple #2
0
 // copy constructor
 subgraph(const subgraph& x)
     : m_parent(x.m_parent), m_edge_counter(0)
 {
     if(x.is_root())
     {
         m_graph = x.m_graph;
         m_edge_counter = x.m_edge_counter;
         m_global_vertex = x.m_global_vertex;
         m_global_edge = x.m_global_edge;
     }
     else
     {
         get_property(*this) = get_property(x);
         typename subgraph<Graph>::vertex_iterator vi,vi_end;
         boost::tie(vi, vi_end) = vertices(x);
         for(; vi != vi_end; ++vi)
         {
             add_vertex(x.local_to_global(*vi), *this);
         }
     }
     // Do a deep copy (recursive).
     // Only the root graph is copied, the subgraphs contain
     // only references to the global vertices they own.
     typename subgraph<Graph>::children_iterator i,i_end;
     boost::tie(i,i_end) = x.children();
     for(; i != i_end; ++i)
     {
         m_children.push_back(new subgraph<Graph>(*i));
         m_children.back()->m_parent = this;
     }
 }
Exemple #3
0
    void write_graphviz_subgraph (std::ostream& out, 
                                  const subgraph<Graph_>& g, 
                                  RandomAccessIterator vertex_marker,
                                  RandomAccessIterator edge_marker)
    {
      typedef subgraph<Graph_> Graph;
      typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
      typedef typename boost::graph_traits<Graph>::directed_category cat_type;
      typedef graphviz_io_traits<cat_type> Traits;

      typedef typename graph_property<Graph, graph_name_t>::type NameType;
      const NameType& g_name = get_property(g, graph_name);

      if ( g.is_root() )
        out << Traits::name() ;
      else
        out << "subgraph";

      out << " " << g_name << " {" << std::endl;

      typename Graph::const_children_iterator i_child, j_child;

      //print graph/node/edge attributes
      make_graph_attributes_writer(g)(out);

      //print subgraph
      for ( boost::tie(i_child,j_child) = g.children();
            i_child != j_child; ++i_child )
        write_graphviz_subgraph(out, *i_child, vertex_marker, edge_marker);

      // Print out vertices and edges not in the subgraphs.

      typename boost::graph_traits<Graph>::vertex_iterator i, end;
      typename boost::graph_traits<Graph>::edge_iterator ei, edge_end;

      for(boost::tie(i,end) = boost::vertices(g); i != end; ++i) {
        Vertex v = g.local_to_global(*i);
        int pos = get(get(vertex_index, g.root()), v);
        if ( vertex_marker[pos] ) {
          vertex_marker[pos] = false;
          out << v;
          make_vertex_attributes_writer(g.root())(out, v);
          out << ";" << std::endl;
        }
      }
      for (boost::tie(ei, edge_end) = edges(g); ei != edge_end; ++ei) {
        Vertex u = g.local_to_global(source(*ei,g)),
          v = g.local_to_global(target(*ei, g));
        int pos = get(get(edge_index, g.root()), g.local_to_global(*ei));
        if ( edge_marker[pos] ) {
          edge_marker[pos] = false;
          out << u << " " << Traits::delimiter() << " " << v;
          make_edge_attributes_writer(g)(out, *ei); //print edge properties
          out << ";" << std::endl;
        }
      }
      out << "}" << std::endl;
    }
    void write_graphviz_subgraph (std::ostream& out,
                                  const subgraph<Graph_>& g,
                                  RandomAccessIterator vertex_marker,
                                  RandomAccessIterator edge_marker)
    {
      typedef subgraph<Graph_> Graph;
      typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
      typedef typename graph_traits<Graph>::directed_category cat_type;
      typedef graphviz_io_traits<cat_type> Traits;

      typedef typename graph_property<Graph, graph_name_t>::type NameType;
      const NameType& g_name = get_property(g, graph_name);

      if ( g.is_root() )
        out << Traits::name() ;
      else
        out << "subgraph";

      out << " " << g_name << " {" << std::endl;

      typename Graph::const_children_iterator i_child, j_child;

      //print graph/node/edge attributes
#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
      typedef typename graph_property<Graph, graph_graph_attribute_t>::type
        GAttrMap;
      typedef typename graph_property<Graph, graph_vertex_attribute_t>::type
        NAttrMap;
      typedef typename graph_property<Graph, graph_edge_attribute_t>::type
        EAttrMap;
      GAttrMap gam = get_property(g, graph_graph_attribute);
      NAttrMap nam = get_property(g, graph_vertex_attribute);
      EAttrMap eam = get_property(g, graph_edge_attribute);
      graph_attributes_writer<GAttrMap, NAttrMap, EAttrMap> writer(gam, nam, eam);
      writer(out);
#else
      make_graph_attributes_writer(g)(out);
#endif

      //print subgraph
      for ( tie(i_child,j_child) = g.children();
            i_child != j_child; ++i_child )
        write_graphviz_subgraph(out, *i_child, vertex_marker, edge_marker);

      // Print out vertices and edges not in the subgraphs.

      typename graph_traits<Graph>::vertex_iterator i, end;
      typename graph_traits<Graph>::edge_iterator ei, edge_end;

      typename property_map<Graph, vertex_index_t>::const_type
        indexmap = get(vertex_index, g.root());

      for(tie(i,end) = vertices(g); i != end; ++i) {
        Vertex v = g.local_to_global(*i);
        int pos = get(indexmap, v);
        if ( vertex_marker[pos] ) {
          vertex_marker[pos] = false;
          out << pos;
#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
          typedef typename property_map<Graph, vertex_attribute_t>::const_type
            VertexAttributeMap;
          attributes_writer<VertexAttributeMap> vawriter(get(vertex_attribute,
                                                             g.root()));
          vawriter(out, v);
#else
          make_vertex_attributes_writer(g.root())(out, v);
#endif
          out << ";" << std::endl;
        }
      }

      for (tie(ei, edge_end) = edges(g); ei != edge_end; ++ei) {
        Vertex u = g.local_to_global(source(*ei,g)),
          v = g.local_to_global(target(*ei, g));
        int pos = get(get(edge_index, g.root()), g.local_to_global(*ei));
        if ( edge_marker[pos] ) {
          edge_marker[pos] = false;
          out << get(indexmap, u) << " " << Traits::delimiter()
              << " " << get(indexmap, v);
#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
          typedef typename property_map<Graph, edge_attribute_t>::const_type
            EdgeAttributeMap;
          attributes_writer<EdgeAttributeMap> eawriter(get(edge_attribute, g));
          eawriter(out, *ei);
#else
          make_edge_attributes_writer(g)(out, *ei); //print edge properties
#endif
          out << ";" << std::endl;
        }
      }
      out << "}" << std::endl;
    }