Difference between revisions of "Boost/BGL/IO/ReadGraph"
From ProgrammingExamples
Daviddoria (Talk | contribs) (Created page with '==ReadGraph.cpp== <source lang="cpp"> // http://www.boost.org/doc/libs/1_37_0/libs/graph/doc/read_graphviz.html #include <iostream> #include <string> #include <fstream> #include…') |
Daviddoria (Talk | contribs) (Simplified) |
||
Line 16: | Line 16: | ||
return -1; | return -1; | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | // | + | typedef boost::property < boost::vertex_name_t, std::string> VertexProperty; |
− | graph_t graph | + | typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS, VertexProperty> graph_t; |
+ | //typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS, boost::no_property> graph_t; | ||
+ | //typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS, boost::null_property_map> graph_t; | ||
+ | graph_t graph; | ||
boost::dynamic_properties dp; | boost::dynamic_properties dp; | ||
Line 34: | Line 27: | ||
get(boost::vertex_name, graph); | get(boost::vertex_name, graph); | ||
dp.property("node_id",name); | dp.property("node_id",name); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
std::string filename = argv[1]; | std::string filename = argv[1]; | ||
Line 65: | Line 37: | ||
return 0; | return 0; | ||
} | } | ||
+ | |||
+ | </source> | ||
+ | |||
+ | ==HelloWorld.dot== | ||
+ | <source lang="text"> | ||
+ | digraph G {Hello->World} | ||
</source> | </source> | ||
Line 73: | Line 51: | ||
Project(ReadGraph) | Project(ReadGraph) | ||
− | + | FIND_PACKAGE(Boost) | |
− | FIND_PACKAGE(Boost | + | |
− | |||
LINK_DIRECTORIES(${LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS}) | LINK_DIRECTORIES(${LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS}) | ||
Line 83: | Line 59: | ||
− | |||
− | |||
− | |||
− | |||
− | |||
</source> | </source> |
Revision as of 19:36, 22 June 2011
ReadGraph.cpp
// http://www.boost.org/doc/libs/1_37_0/libs/graph/doc/read_graphviz.html #include <iostream> #include <string> #include <fstream> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/graphviz.hpp> int main(int argc, char*argv[]) { if(argc < 2) { std::cerr << "Required: filename.dot" << std::endl; return -1; } typedef boost::property < boost::vertex_name_t, std::string> VertexProperty; typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS, VertexProperty> graph_t; //typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS, boost::no_property> graph_t; //typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS, boost::null_property_map> graph_t; graph_t graph; boost::dynamic_properties dp; boost::property_map<graph_t, boost::vertex_name_t>::type name = get(boost::vertex_name, graph); dp.property("node_id",name); std::string filename = argv[1]; std::ifstream fin(filename.c_str()); bool status = boost::read_graphviz(fin,graph,dp,"node_id"); std::cout << "There are " << boost::num_vertices(graph) << " vertices." << std::endl; return 0; }
HelloWorld.dot
digraph G {Hello->World}
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) Project(ReadGraph) FIND_PACKAGE(Boost) LINK_DIRECTORIES(${LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS}) ADD_EXECUTABLE(ReadGraph ReadGraph.cpp) target_link_libraries(ReadGraph boost_graph)