string DFG::writeDot()
 {
   boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> bfg( mkBoostGraph() );
   stringstream ss;
   write_graphviz(ss, bfg, DFGNodeWriter(*this) );
   return ss.str();
 }
Пример #2
0
int main() {
    typedef b::adjacency_list<b::listS, b::vecS, b::undirectedS, vert, edge> Graph;
    Graph g;

    b::generate_random_graph(g, 10 /*100*/, 5 /*20*/, rng);

    write_graphviz(std::cout, g, boost::make_label_writer(boost::get(&vert::name, g)),
                   make_edge_writer(boost::get(&edge::weight, g), boost::get(&edge::capacity, g)));
}
Пример #3
0
inline void
write_graphviz(std::ostream& out, const Graph& g,
               VertexPropertiesWriter vpw,
               EdgePropertiesWriter epw,
               GraphPropertiesWriter gpw
               BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph,vertex_list_graph_tag))
{
    write_graphviz(out, g, vpw, epw, gpw, get(vertex_index, g));
}
Пример #4
0
void dump_dot_file(string fname, Graph &graphFOF)
	{
	if(true)
		{
		////////////////////////////////////////////////	
		// write
		dynamic_properties dp;
		dp.property("weight", get(edge_weight, graphFOF));
		dp.property("node_id", get(vertex_index, graphFOF));
		std::ofstream ofs( fname.c_str());
		std::cout << "write_graphviz:.....";
		write_graphviz(ofs, graphFOF, dp);
		ofs.close();
		std::cout << "Done" << std::endl;
		}else
			////////////////// WRITE BY HAND /////////////
		{
		///////////////////////////////////////////
		property_map < Graph, edge_weight_t >::type weight = get(edge_weight, graphFOF);
		std::vector < Edge > spanning_tree;

		kruskal_minimum_spanning_tree(graphFOF, std::back_inserter(spanning_tree));
		std::cout << "Print the edges in the MST:" << std::endl;
		for (std::vector < Edge >::iterator ei = spanning_tree.begin();
			ei != spanning_tree.end(); ++ei) {
				std::cout << source(*ei, graphFOF) << " <--> " << target(*ei, graphFOF)
					<< " with weight of " << weight[*ei]
				<< std::endl;
			}

		////////////////////////////////////////////////////////
		std::ofstream fout("kruskal.dot");
		fout << "graph A {\n"
			<< " rankdir=LR\n"
			<< " size=\"60,60\"\n"
			<< " ratio=\"filled\"\n"
			<< " edge[style=\"bold\"]\n" << " node[shape=\"circle\"]\n";
		graph_traits<Graph>::edge_iterator eiter, eiter_end;
		for (tie(eiter, eiter_end) = edges(graphFOF); eiter != eiter_end; ++eiter) {
			fout << source(*eiter, graphFOF) << " -- " << target(*eiter, graphFOF);
			if (std::find(spanning_tree.begin(), spanning_tree.end(), *eiter)
				!= spanning_tree.end())
				fout << "[color=\"blue\", label=\"" << get(edge_weight, graphFOF, *eiter)
				<< "\"];\n";
			else
				fout << "[color=\"red\", label=\"" << get(edge_weight, graphFOF, *eiter)
				<< "\"];\n";
			}
		fout << "}\n";
		fout.close();
			}
	}
int main(int argc, char ** argv)
{

	if(argc>1)
	{
   	// Test with the normal order
		Graph g(0);
		vertex_index_map m_index = get(boost::vertex_index, g);
		vertex_name_map m_name = get(boost::vertex_name, g);
		vertex_color_map m_color = get(boost::vertex_color, g);


		boost::dynamic_properties dp;
		
		// dp.property("node_id", m_index);
		// dp.property("label", m_name);
		
		dp.property("node_id", m_name);
		
		std::fstream infile(argv[1], std::ios::in);

		bool status = boost::read_graphviz(infile, g, dp, std::string("node_id"));

		std::vector<vertices_size_type> color_vec(num_vertices(g));
 
    	boost::iterator_property_map<vertices_size_type*, vertex_index_map> color(&color_vec.front(), boost::get(boost::vertex_index, g));
    	vertices_size_type num_colors = boost::sequential_vertex_coloring(g, color);


		int k=0;
		boost::graph_traits<Graph>::vertex_iterator v, v_end;
		for(boost::tie(v,v_end) = boost::vertices(g); v!=v_end; v++)
		{	
			m_color[*v]=static_cast<boost::default_color_type>(color_vec[k++]);
		}
	
		write_graphviz(std::cout, g, 
		graph_coloring::make_label_writer(m_name, m_color),
		boost::default_writer(),
		graph_coloring::graph_property_with_label_writer<vertices_size_type>(num_colors));
	}
	else 
		std::cout << "Put right args list!" << std::endl;

	return 0;
}
Пример #6
0
void parse_and_write_graph(std::istream & is)
{
   parsing::parser p(is);

   parsing::node * tree;
   try
   {
      tree = p.parse();
   }
   catch (std::exception & e)
   {
      std::cerr << "Unhandled exception: " << e.what() << std::endl;
      return;
   }

   std::vector<const char *> names;
   std::vector<edge_t> edges;
   dfs(tree, edges, names);
   graph_t graph(edges.begin(), edges.end(), names.size());
   write_graphviz(std::cout, graph, boost::make_label_writer(names.data()));
}
Пример #7
0
int Graph::toGraphviz(string filename){
	ofstream dotFile (filename.c_str());
	if( !dotFile.is_open()){
		return -1;
	}

	vector<string> ids;
	vector< pair< double, double> > locs;
	vector<nodeType> types;
	map< edge_d,string> edge_labels;

	//	cout << "Num vertices " << num_vertices(*this) << endl;
	//	property_map<MyGraphType, vertex_name_t>::type idmap = get(vertex_name_t(),*this);
	graph_traits<MyGraphType>::vertex_iterator vi, vi_end, next;
	tie(vi, vi_end) = vertices(*this);
	for (next = vi; next != vi_end; next++) {
		// printf("Vertex id [%d] = %s\n",*next,idmap[*next].c_str());
		ids.push_back((*this)[*next].id);
		locs.push_back( make_pair( (*this)[*next].x, (*this)[*next].y));
		types.push_back((*this)[*next].t);

	}
	
	graph_traits<MyGraphType>::edge_iterator ei,e_end,e_next;
	graph_traits<MyGraphType>::edge_descriptor e;
         tie(ei, e_end) = edges( (*this)); 
	 for(e_next = ei; e_next != e_end; e_next++) {
		 edge_labels[*e_next] = (*this)[*e_next].label;
	 }







	write_graphviz(dotFile, *this,make_position_writer(ids,locs,types),make_edge_writer(edge_labels),graph_writer());
	return 0;

}
Пример #8
0
void Internal_Graph::output()
{
	std::ofstream dotFile("dependencies.dot");
	write_graphviz(dotFile, g, graphnode_property_writer < VertexNodeMap > (*NodeMap));
	dotFile.flush();
}
Пример #9
0
void WriteDot(const DirectedGraph &g, std::string filename) {
    std::ofstream outfile(filename.c_str());
    write_graphviz(outfile, g);
}
Пример #10
0
void FamilyTree::saveGraphViz(const char* iFileName)
{
    std::ofstream ofs(iFileName, std::ofstream::out);
    LabelWriter<graph> lw(mGraph);
    write_graphviz(ofs, mGraph, lw);
}
void k_shell_snapshot(Graph& G, vector<int>& core, int core_num, string filename)
{
  srand(time(NULL));
  vector<int> keep_core;
  int size = num_vertices(G);
  //  long edgeCount = num_edges(G);
  vector<float> s(size,0);
  vector<float> p;
  vector<int> count(size,0);
  vector<int> indOrig(size,0);
  int ind;
  //float alpha = .2;
  //float eps   = .001;

  for(int i=0;i<core.size();i++)
    {
      if(core[i]==core_num)
	keep_core.push_back(i);
    }

  int r = 0;

  if(keep_core.size()>0)
    r = rand() % keep_core.size();
  else
    return;

  ind = keep_core[r];
  s[ind] = 1;
  /*
  p = approxPR(G,s,alpha,eps);

  for(int j=0; j<size; j++)
    {
      Vert v = vertex(j,G);
      count[j] = j;
      graph_traits<Graph>::degree_size_type outDegree = out_degree(v,G);
      p[j] = p[j]/outDegree;
    }
  

  sort(count.begin(),count.end(),compareInd<vector<float>&>(p));

  for(int j=0;j<size;j++)
    indOrig[count[j]] = j;

  long vol = 0;
  long out = 0;
  int maxC = 200;


  float c = 1.0;
  int cutInd = 0;
  for(int j=0; j<maxC; j++)
    {
      //   cout<<"Comm: "<<j<<"\n";
      vector<int>::iterator it;
	   
      Vert v    = vertex(count[j],G);
      //  cout<<"index: "<<index<<"\n";

      //Out edge iterators
      graph_traits<Graph>::out_edge_iterator out_i, out_e;

      //Create index map for Graph
      property_map<Graph, vertex_index_t>::type index = get(vertex_index, G);

      //Count outgoing edges for v
      graph_traits<Graph>::degree_size_type outDegree = out_degree(v,G);

      //update edges leaving cut set (out)
      out += outDegree;
      //update internal volume of cut set (vol)
      vol += outDegree;

      //Iterate over out going edges of v
      for(tie(out_i,out_e)=out_edges(v,G);out_i!=out_e;++out_i)
	{
	  Edge e = *out_i;
	  //	cout<<"node: "<<node1<<"\n";

	  Vert vt = target(e,G);

	  //Check if edge crosses set boundary, if so, update out and vol accordingly
	  if(indOrig[index[vt]]<j && indOrig[index[vt]]>=0)
	    {
	      out -= 2;  //note that 2 is due to outgoing/incoming edge as G is a directed graph representation of an undirected graph.
	      vol--;
	    }
	}
      //cout<<edgeCount<<"\n";
	
      //Pick minimum of cut set and complement volume
      if(vol>(edgeCount-vol))
	vol = edgeCount - vol;
      // cout<<"Comm size "<<j<<": "<<ctime2-ctime1<<"\n";
	    
	    
      //conductance c is now given by: c = out/vol
      float tempC = float(out)/vol;
	    
      //Check if this beats previous minimum
      if(tempC<c)
	{
	  c = tempC;
	  cutInd = j;
	}
    }

for(int j=0;j<=cutInd;j++)
    S.push_back(vertex(count[j],G));
  */
  vector<Vert> S;

  for(int j=0;j<=core.size();j++)
    {
      if(core[j]==core_num)
	S.push_back(vertex(j,G));
    }
  Graph localG = subset(G,S);
  //localG = connected(localG,-1);

  adjacency_list<vecS, vecS, undirectedS> localUGraph;

  copy_graph(localG,localUGraph);

  ofstream outViz;
  
  outViz.open(filename.c_str());


  write_graphviz(outViz,localUGraph);
  outViz.close();
}
Пример #12
0
 void write_graphviz(const std::string& filename, const subgraph<Graph>& g) {
   std::ofstream out(filename.c_str());
   write_graphviz(out, g);
 }
Пример #13
0
 inline void
 write_graphviz(std::ostream& out, const Graph& g) {
   default_writer dw;
   default_writer gw;
   write_graphviz(out, g, dw, dw, gw);
 }
Пример #14
0
void write_graphviz( const aig_graph& aig, const std::string& layout_algorithm, const std::string& render_format, std::ostream& os )
{
  std::map< aig_node, gv_node > node_map;
  std::map< aig_edge, gv_edge > edge_map;
  write_graphviz( aig, layout_algorithm, render_format, node_map, edge_map, os );
}
Пример #15
0
void evaluateGeodesicDist(GridSpecs grid_specs, std::vector<Polygon_2> polygons,
                          std::vector<Point> ref_points, IOSpecs io_specs)
{

  // -- grid definition --
 
  // no. of rows and columns
  int no_rows, no_cols;
  no_rows = (int)grid_specs.getGridSpecs().at(0);
  no_cols = (int)grid_specs.getGridSpecs().at(1);

  // grid points
  int no_gpoints;
  no_gpoints = (no_rows*no_cols);

  // spatial locations of the grid points
  std::vector<Point_2> grid_points;


  // evaluating the spatial locations of the grid points
  initGrid(grid_specs, grid_points);



  //--

  // -- graph definition --

  //
  // note that two different graphs need to be considered:
  //
  // 1) effective graph -
  //    graph associated with the complementary domain;
  //    the nodes of this graph do not include the grid points
  //    associated with the polygon(s);
  //
  // 2) BGL graph -
  //    graph processed by the BGL library;
  //    this graph coincides with the grid;
  //    the nodes of this graph coincide the grid points;
  //    the nodes associated with the polygon(s) are nodes
  //    with no edges, i.e. they are nodes of degree zero;
  //
  //
  //  no. of nodes (effective graph) < no. of nodes (BGL graph)
  //  no. of edges (effective graph) = no. of edges (BGL graph)
  //


  // grid points IDs associated with the polygon(s)
  std::vector<Polygon_gp_id> gpoints_id_pgn;
  // grid points IDs associated with the graph
  std::vector<int> gpoints_id_graph;


  // project the data to the grid;
  // evaluate the grid points IDs associated with the polygon(s) and
  // those associated with the complementary domain (graph)
  projectDataToGrid(grid_points, polygons, gpoints_id_pgn, gpoints_id_graph);


  // no. of grid points associated with the polygon
  int no_gpoints_png = gpoints_id_pgn.at(0).size();
  // no. of grid points associated with the graph
  int no_gpoints_graph = gpoints_id_graph.size();

  // writing output file `Dreses.dat'
  std::string outfile_name_1("Dreses.dat");

  OutputProcess_Dreses out1(io_specs.getAbsolutePathName(outfile_name_1));
  out1.toOutput(ref_points, polygons,
                grid_specs, no_gpoints_png, no_gpoints_graph);


  grid_points.clear();
  polygons.clear();

  
  // names of the nodes (vertices)
  std::vector<std::string> node_names;
  // edges
  std::vector<Edge> edges;

  // evaluating the node names and the edges of the `effective graph'
  initGraph(grid_specs, gpoints_id_pgn, gpoints_id_graph, node_names, edges);


  gpoints_id_pgn.clear();
  gpoints_id_graph.clear();


  // number of edges
  int no_edges;
  no_edges = edges.size();

  // weights
  float* weights = new float[no_edges];

  for (int i=0; i<no_edges; i++) {
    weights[i] = grid_specs.getGridSpecs().at(2);
  }


  // BGL graph
  GridGraph g(edges.begin(), edges.end(), weights, no_gpoints);
  GridGraph g_copy(edges.begin(), edges.end(), weights, no_gpoints);


  //--
  #ifdef DEBUG_GRAPH

    std::cout << "\n>> debug - graph" << std::endl;

    std::cout << "no. of nodes (effective graph): " << node_names.size() << std::endl;
    std::cout << "no. of nodes (BGL graph): " << no_gpoints << std::endl;
    std::cout << "no. of edges: " << edges.size() << std::endl;
    write_graphviz(std::cout, g);

  #endif // DEBUG_GRAPH
  //--


  // parents of the nodes
  std::vector<vertex_descriptor> parents(num_vertices(g));

  // source node ID
  // note that node ID = (grid point ID - 1)
  int s_node_id;
  s_node_id = (getGridPointID(ref_points.at(0).first, ref_points.at(0).second, grid_specs) - 1);

  // source node
  vertex_descriptor s_node = vertex(s_node_id, g);
  // the parent of `s_node' is `s_node' (distance = 0)
  parents[s_node] = s_node;

  // distances from the source to each node
  // (including the null distances - i.e. the distance from the source to itself
  // and the distances from the source to the nodes of degree zero)
  vertices_size_type distances[no_gpoints];
  std::fill_n(distances, no_gpoints, 0);

  // evaluating the distances by using the Breadth-First Search (BFS) algorithm
  breadth_first_search(g,
                       s_node,
                       visitor(make_bfs_visitor(std::make_pair(record_distances(distances,
                                                                                on_tree_edge()),
                                                               std::make_pair(record_predecessors(&parents[0],
                                                                                                  on_tree_edge()),
                                                                              copy_graph(g_copy,
                                                                                         on_examine_edge())
                                                                             )
                                                              )
                                               )
                              )
                      );


  // writing output file `distances.dat'
  std::string outfile_name_2("distances.dat");

  OutputProcess_Distances out2(io_specs.getAbsolutePathName(outfile_name_2));
  out2.toOutput(grid_specs, no_gpoints, s_node_id, node_names, distances);


  delete [] weights;


}
Пример #16
0
void DecayTree::print(std::ostream& os) const {
// boost::associative_property_map<IndexNameMap> propmapIndex(index_label_map);
  VertexWriter vertex_writer(decay_tree_);
  write_graphviz(os, decay_tree_, vertex_writer);
}
Пример #17
0
 inline void
 write_graphviz(std::ostream& out, const Graph& g,
                VertexWriter vw, EdgeWriter ew) {
   default_writer gw;
   write_graphviz(out, g, vw, ew, gw);
 }