Difference between revisions of "Boost/BGL/DirectedGraph"

From ProgrammingExamples
< Boost‎ | BGL
Jump to: navigation, search
(Created page with '==DirectedGraph.cpp== <source lang="cpp"> #include <iostream> #include <boost/graph/graph_traits.hpp> #include <boost/graph/adjacency_list.hpp> typedef boost::adjacency_list<boo…')
 
Line 5: Line 5:
 
#include <boost/graph/adjacency_list.hpp>
 
#include <boost/graph/adjacency_list.hpp>
  
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS> Graph; // only have access to out_edges
+
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> Graph; // only have access to out_edges
  
 
int main(int,char*[])
 
int main(int,char*[])

Revision as of 18:50, 15 November 2011

DirectedGraph.cpp

#include <iostream>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
 
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> Graph; // only have access to out_edges
 
int main(int,char*[])
{
  // Create a graph object
  Graph g(3);
 
  boost::add_edge(0,1,g);
  boost::add_edge(1,2,g);
 
  std::cout << "Out edges: " << std::endl;
  // Get a list of outgoing edges from vertex 1
  typedef boost::graph_traits < Graph >::out_edge_iterator out_edge_iterator;
  std::pair<out_edge_iterator, out_edge_iterator> outEdges =
    boost::out_edges(1, g);
 
  for(; outEdges.first != outEdges.second; ++outEdges.first)
    {
    std::cout << *outEdges.first << " ";
    }
 
  std::cout << std::endl;
 
  return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
Project(DirectedGraph)
 
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(DirectedGraph DirectedGraph.cpp)