Advertisement
Guest User

pbgl remove vertex

a guest
Apr 6th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <boost/graph/use_mpi.hpp>
  2. #include <boost/graph/distributed/adjacency_list.hpp>
  3. #include <boost/graph/distributed/mpi_process_group.hpp>
  4.  
  5. // METIS Input
  6. #include <boost/graph/metis.hpp>
  7. #include <boost/graph/distributed/graphviz.hpp>
  8.  
  9. //#include <cstring>
  10.  
  11. using namespace boost;
  12. using boost::graph::distributed::mpi_process_group;
  13.  
  14. int main(int argc, char* argv[])
  15. {
  16.   mpi::environment env(argc, argv);
  17.  
  18.   typedef adjacency_list<vecS,
  19.                          distributedS<mpi_process_group, vecS>,
  20.                          undirectedS,
  21.                          property<vertex_centrality_t,float>,
  22.                          property<edge_weight_t, int> > Graph;
  23.  
  24.   const char* filename = "weighted_graph.gr";
  25.  
  26.   std::ifstream in(filename);
  27.   graph::metis_reader reader(in);
  28.  
  29.   Graph g(reader.begin(), reader.end(), reader.weight_begin(),
  30.           reader.num_vertices());
  31.  
  32.  
  33.     //clear edges and remove first vertex
  34.     boost::graph_traits<Graph>::vertex_descriptor v = vertex(0,g);
  35.    
  36.     if(owner(v) == process_id(process_group(g)))
  37.     {
  38.         clear_vertex(v,g);     
  39.     }
  40.    
  41.     synchronize(g);
  42.    
  43.     if(owner(v) == process_id(process_group(g)))
  44.     {
  45.         remove_vertex(v,g);
  46.     }
  47.     synchronize(g);
  48.  
  49.   // Output a Graphviz DOT file
  50.   std::string outfile = filename;
  51.     size_t i = outfile.rfind('.');
  52.     if (i != std::string::npos)
  53.         outfile.erase(outfile.begin() + i, outfile.end());
  54.     outfile += "-dijkstra-2.dot";
  55.  
  56.   if (process_id(process_group(g)) == 0) {
  57.      int pcount = num_processes(process_group(g));
  58.     std::cout << "Writing GraphViz output to " << outfile << "..." << pcount << "... ";
  59.     std::cout.flush();
  60.   }
  61.   write_graphviz(outfile, g,
  62.                  make_label_writer(get(vertex_index, g)),
  63.                  make_label_writer(get(edge_weight, g)));
  64.   if (process_id(process_group(g)) == 0)
  65.     std::cout << "Done." << std::endl;
  66.        
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement