Difference between revisions of "Boost/BGL/RemoveEdge"
From ProgrammingExamples
Daviddoria (Talk | contribs) (Created page with '==RemoveEdge.cpp== <source lang="cpp"> #include <iostream> #include <boost/graph/graph_traits.hpp> #include <boost/graph/undirected_graph.hpp> typedef boost::undirected_graph<bo…') |
Daviddoria (Talk | contribs) |
||
Line 18: | Line 18: | ||
// Add edges | // Add edges | ||
− | + | std::pair<Graph::edge_descriptor, bool> e0 = g.add_edge(v0, v1); | |
− | + | std::pair<Graph::edge_descriptor, bool> e1 = g.add_edge(v1, v2); | |
− | + | ||
− | Graph::edge_descriptor e1 = g.add_edge(v1, v2); | + | |
std::cout << "There are " << g.num_edges() << " edges." << std::endl; | std::cout << "There are " << g.num_edges() << " edges." << std::endl; | ||
− | g.remove_edge(e0); | + | g.remove_edge(e0.first); |
std::cout << "There are " << g.num_edges() << " edges." << std::endl; | std::cout << "There are " << g.num_edges() << " edges." << std::endl; |
Revision as of 15:25, 11 June 2011
RemoveEdge.cpp
#include <iostream> #include <boost/graph/graph_traits.hpp> #include <boost/graph/undirected_graph.hpp> typedef boost::undirected_graph<boost::no_property> Graph; int main(int,char*[]) { // Create a graph object Graph g; // Add vertices Graph::vertex_descriptor v0 = g.add_vertex(); Graph::vertex_descriptor v1 = g.add_vertex(); Graph::vertex_descriptor v2 = g.add_vertex(); // Add edges std::pair<Graph::edge_descriptor, bool> e0 = g.add_edge(v0, v1); std::pair<Graph::edge_descriptor, bool> e1 = g.add_edge(v1, v2); std::cout << "There are " << g.num_edges() << " edges." << std::endl; g.remove_edge(e0.first); std::cout << "There are " << g.num_edges() << " edges." << std::endl; return 0; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) Project(RemoveEdge) 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(RemoveEdge RemoveEdge.cpp)