Difference between revisions of "Boost/BGL/AdjacentVertices"
From ProgrammingExamples
Daviddoria (Talk | contribs) (Created page with '==AdjacentVertices.cpp== <source lang="cpp"> #include <iostream> #include <boost/graph/graph_traits.hpp> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/adjacency…') |
Daviddoria (Talk | contribs) m |
||
Line 9: | Line 9: | ||
/* | /* | ||
− | adjacency_list< | + | adjacency_list<OutEdgeContainer, VertexContainer, Directedness, |
VertexProperties, EdgeProperties, | VertexProperties, EdgeProperties, | ||
GraphProperties, EdgeList> | GraphProperties, EdgeList> |
Revision as of 14:24, 12 June 2011
AdjacentVertices.cpp
#include <iostream> #include <boost/graph/graph_traits.hpp> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/adjacency_iterator.hpp> typedef boost::property<boost::vertex_property_tag, double> VertexProperty; /* adjacency_list<OutEdgeContainer, VertexContainer, Directedness, VertexProperties, EdgeProperties, GraphProperties, EdgeList> */ typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, VertexProperty> Graph; int main(int,char*[]) { // Create a graph object Graph g(3); // Create two edges boost::add_edge(0,1,g); boost::add_edge(1,2,g); typedef boost::property_map<Graph, boost::vertex_index_t>::type IndexMap; IndexMap index = get(boost::vertex_index, g); typedef boost::graph_traits < Graph >::adjacency_iterator adjacency_iterator; std::pair<adjacency_iterator, adjacency_iterator> neighbors = adjacent_vertices(1, g); for(; neighbors.first != neighbors.second; ++neighbors.first) { std::cout << index[*neighbors.first] << " "; } return 0; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) Project(AdjacentVertices) set(Boost_USE_MULTITHREADED ON) FIND_PACKAGE(Boost 1.38 COMPONENTS required) INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${Boost_INCLUDE_DIRS}) LINK_DIRECTORIES(${LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS}) ADD_EXECUTABLE(AdjacentVertices AdjacentVertices.cpp)