/usr/include/boost/graph
NameSizeModeActions
detail/-0755rm
distributed/-0755rm
parallel/-0755rm
planar_detail/-0755rm
property_maps/-0755rm
accounting.hpp8760644editdlrm
adjacency_iterator.hpp28990644editdlrm
adjacency_list.hpp136920644editdlrm
adjacency_list_io.hpp118490644editdlrm
adjacency_matrix.hpp457430644editdlrm
adj_list_serialize.hpp45230644editdlrm
astar_search.hpp267360644editdlrm
bandwidth.hpp29920644editdlrm
bc_clustering.hpp59370644editdlrm
bellman_ford_shortest_paths.hpp82290644editdlrm
betweenness_centrality.hpp262900644editdlrm
biconnected_components.hpp167010644editdlrm
bipartite.hpp134920644editdlrm
boyer_myrvold_planar_test.hpp98490644editdlrm
boykov_kolmogorov_max_flow.hpp473420644editdlrm
breadth_first_search.hpp147510644editdlrm
bron_kerbosch_all_cliques.hpp117360644editdlrm
buffer_concepts.hpp24290644editdlrm
chrobak_payne_drawing.hpp86410644editdlrm
circle_layout.hpp19240644editdlrm
closeness_centrality.hpp60570644editdlrm
clustering_coefficient.hpp57260644editdlrm
compressed_sparse_row_graph.hpp698870644editdlrm
connected_components.hpp41340644editdlrm
copy.hpp212250644editdlrm
core_numbers.hpp136630644editdlrm
create_condensation_graph.hpp31590644editdlrm
cuthill_mckee_ordering.hpp59920644editdlrm
cycle_canceling.hpp66450644editdlrm
dag_shortest_paths.hpp60640644editdlrm
degree_centrality.hpp42360644editdlrm
depth_first_search.hpp154300644editdlrm
dijkstra_shortest_paths.hpp236870644editdlrm
dijkstra_shortest_paths_no_color_map.hpp96200644editdlrm
dimacs.hpp104480644editdlrm
directed_graph.hpp242140644editdlrm
dll_import_export.hpp8920644editdlrm
dominator_tree.hpp175530644editdlrm
eccentricity.hpp46110644editdlrm
edge_coloring.hpp68090644editdlrm
edge_connectivity.hpp67960644editdlrm
edge_list.hpp99480644editdlrm
edmonds_karp_max_flow.hpp101770644editdlrm
edmunds_karp_max_flow.hpp9820644editdlrm
erdos_renyi_generator.hpp72570644editdlrm
exception.hpp14660644editdlrm
exterior_property.hpp42890644editdlrm
filtered_graph.hpp200980644editdlrm
find_flow_cost.hpp18590644editdlrm
floyd_warshall_shortest.hpp85100644editdlrm
fruchterman_reingold.hpp173250644editdlrm
geodesic_distance.hpp80150644editdlrm
graphml.hpp134600644editdlrm
graphviz.hpp335030644editdlrm
graph_archetypes.hpp110080644editdlrm
graph_as_tree.hpp45320644editdlrm
graph_concepts.hpp197850644editdlrm
graph_mutability_traits.hpp49950644editdlrm
graph_selectors.hpp12740644editdlrm
graph_stats.hpp43940644editdlrm
graph_traits.hpp130650644editdlrm
graph_utility.hpp161820644editdlrm
grid_graph.hpp338300644editdlrm
gursoy_atun_layout.hpp132480644editdlrm
hawick_circuits.hpp145930644editdlrm
howard_cycle_ratio.hpp231070644editdlrm
incremental_components.hpp82240644editdlrm
isomorphism.hpp263080644editdlrm
is_kuratowski_subgraph.hpp102600644editdlrm
is_straight_line_drawing.hpp72300644editdlrm
iteration_macros.hpp116590644editdlrm
iteration_macros_undef.hpp6730644editdlrm
johnson_all_pairs_shortest.hpp76460644editdlrm
kamada_kawai_spring_layout.hpp280480644editdlrm
king_ordering.hpp121010644editdlrm
kruskal_min_spanning_tree.hpp57430644editdlrm
labeled_graph.hpp309140644editdlrm
leda_graph.hpp287890644editdlrm
lookup_edge.hpp18940644editdlrm
loop_erased_random_walk.hpp44360644editdlrm
make_biconnected_planar.hpp35130644editdlrm
make_connected.hpp26450644editdlrm
make_maximal_planar.hpp75780644editdlrm
matrix_as_graph.hpp72270644editdlrm
maximum_adjacency_search.hpp151250644editdlrm
maximum_weighted_matching.hpp497220644editdlrm
max_cardinality_matching.hpp310000644editdlrm
mcgregor_common_subgraphs.hpp434700644editdlrm
mesh_graph_generator.hpp56160644editdlrm
metis.hpp109820644editdlrm
metric_tsp_approx.hpp108090644editdlrm
minimum_degree_ordering.hpp270870644editdlrm
named_function_params.hpp396390644editdlrm
named_graph.hpp206140644editdlrm
neighbor_bfs.hpp117630644editdlrm
numeric_values.hpp18140644editdlrm
one_bit_color_map.hpp32770644editdlrm
overloading.hpp15840644editdlrm
page_rank.hpp61640644editdlrm
planar_canonical_ordering.hpp72030644editdlrm
planar_face_traversal.hpp60200644editdlrm
plod_generator.hpp77080644editdlrm
point_traits.hpp7820644editdlrm
prim_minimum_spanning_tree.hpp29600644editdlrm
profile.hpp13270644editdlrm
properties.hpp124170644editdlrm
property_iter_range.hpp43450644editdlrm
push_relabel_max_flow.hpp347370644editdlrm
random.hpp96720644editdlrm
random_layout.hpp9880644editdlrm
random_spanning_tree.hpp57750644editdlrm
read_dimacs.hpp120800644editdlrm
relax.hpp44000644editdlrm
reverse_graph.hpp224020644editdlrm
rmat_graph_generator.hpp192910644editdlrm
r_c_shortest_paths.hpp306730644editdlrm
sequential_vertex_coloring.hpp45620644editdlrm
simple_point.hpp6280644editdlrm
sloan_ordering.hpp155400644editdlrm
smallest_last_ordering.hpp54580644editdlrm
small_world_generator.hpp36700644editdlrm
ssca_graph_generator.hpp65640644editdlrm
stanford_graph.hpp201260644editdlrm
stoer_wagner_min_cut.hpp124150644editdlrm
strong_components.hpp130090644editdlrm
st_connected.hpp28520644editdlrm
subgraph.hpp399960644editdlrm
successive_shortest_path_nonnegative_weights.hpp104130644editdlrm
tiernan_all_cycles.hpp125470644editdlrm
topological_sort.hpp26110644editdlrm
topology.hpp203890644editdlrm
transitive_closure.hpp142600644editdlrm
transitive_reduction.hpp53260644editdlrm
transpose_graph.hpp11980644editdlrm
tree_traits.hpp13380644editdlrm
two_bit_color_map.hpp35100644editdlrm
two_graphs_common_spanning_trees.hpp349960644editdlrm
undirected_dfs.hpp106720644editdlrm
undirected_graph.hpp252760644editdlrm
use_mpi.hpp4370644editdlrm
vector_as_graph.hpp104740644editdlrm
vertex_and_edge_range.hpp55280644editdlrm
vf2_sub_graph_iso.hpp485850644editdlrm
visitors.hpp113180644editdlrm
wavefront.hpp39320644editdlrm
write_dimacs.hpp28890644editdlrm
Edit: /usr/include/boost/graph/bipartite.hpp (13492B)
/** * * Copyright (c) 2010 Matthias Walter (xammy@xammy.homelinux.net) * * Authors: Matthias Walter * * Distributed under the Boost Software License, Version 1.0. (See * accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * */ #ifndef BOOST_GRAPH_BIPARTITE_HPP #define BOOST_GRAPH_BIPARTITE_HPP #include #include #include #include #include #include #include namespace boost { namespace detail { /** * The bipartite_visitor_error is thrown if an edge cannot be colored. * The witnesses are the edges incident vertices. */ template < typename Vertex > struct BOOST_SYMBOL_VISIBLE bipartite_visitor_error : std::exception { std::pair< Vertex, Vertex > witnesses; bipartite_visitor_error(Vertex a, Vertex b) : witnesses(a, b) {} const char* what() const throw() { return "Graph is not bipartite."; } }; /** * Functor which colors edges to be non-monochromatic. */ template < typename PartitionMap > struct bipartition_colorize { typedef on_tree_edge event_filter; bipartition_colorize(PartitionMap partition_map) : partition_map_(partition_map) { } template < typename Edge, typename Graph > void operator()(Edge e, const Graph& g) { typedef typename graph_traits< Graph >::vertex_descriptor vertex_descriptor_t; typedef color_traits< typename property_traits< PartitionMap >::value_type > color_traits; vertex_descriptor_t source_vertex = source(e, g); vertex_descriptor_t target_vertex = target(e, g); if (get(partition_map_, source_vertex) == color_traits::white()) put(partition_map_, target_vertex, color_traits::black()); else put(partition_map_, target_vertex, color_traits::white()); } private: PartitionMap partition_map_; }; /** * Creates a bipartition_colorize functor which colors edges * to be non-monochromatic. * * @param partition_map Color map for the bipartition * @return The functor. */ template < typename PartitionMap > inline bipartition_colorize< PartitionMap > colorize_bipartition( PartitionMap partition_map) { return bipartition_colorize< PartitionMap >(partition_map); } /** * Functor which tests an edge to be monochromatic. */ template < typename PartitionMap > struct bipartition_check { typedef on_back_edge event_filter; bipartition_check(PartitionMap partition_map) : partition_map_(partition_map) { } template < typename Edge, typename Graph > void operator()(Edge e, const Graph& g) { typedef typename graph_traits< Graph >::vertex_descriptor vertex_descriptor_t; vertex_descriptor_t source_vertex = source(e, g); vertex_descriptor_t target_vertex = target(e, g); if (get(partition_map_, source_vertex) == get(partition_map_, target_vertex)) throw bipartite_visitor_error< vertex_descriptor_t >( source_vertex, target_vertex); } private: PartitionMap partition_map_; }; /** * Creates a bipartition_check functor which raises an error if a * monochromatic edge is found. * * @param partition_map The map for a bipartition. * @return The functor. */ template < typename PartitionMap > inline bipartition_check< PartitionMap > check_bipartition( PartitionMap partition_map) { return bipartition_check< PartitionMap >(partition_map); } /** * Find the beginning of a common suffix of two sequences * * @param sequence1 Pair of bidirectional iterators defining the first * sequence. * @param sequence2 Pair of bidirectional iterators defining the second * sequence. * @return Pair of iterators pointing to the beginning of the common suffix. */ template < typename BiDirectionalIterator1, typename BiDirectionalIterator2 > inline std::pair< BiDirectionalIterator1, BiDirectionalIterator2 > reverse_mismatch( std::pair< BiDirectionalIterator1, BiDirectionalIterator1 > sequence1, std::pair< BiDirectionalIterator2, BiDirectionalIterator2 > sequence2) { if (sequence1.first == sequence1.second || sequence2.first == sequence2.second) return std::make_pair(sequence1.first, sequence2.first); BiDirectionalIterator1 iter1 = sequence1.second; BiDirectionalIterator2 iter2 = sequence2.second; while (true) { --iter1; --iter2; if (*iter1 != *iter2) { ++iter1; ++iter2; break; } if (iter1 == sequence1.first) break; if (iter2 == sequence2.first) break; } return std::make_pair(iter1, iter2); } } /** * Checks a given graph for bipartiteness and fills the given color map with * white and black according to the bipartition. If the graph is not * bipartite, the contents of the color map are undefined. Runs in linear * time in the size of the graph, if access to the property maps is in * constant time. * * @param graph The given graph. * @param index_map An index map associating vertices with an index. * @param partition_map A color map to fill with the bipartition. * @return true if and only if the given graph is bipartite. */ template < typename Graph, typename IndexMap, typename PartitionMap > bool is_bipartite( const Graph& graph, const IndexMap index_map, PartitionMap partition_map) { /// General types and variables typedef typename property_traits< PartitionMap >::value_type partition_color_t; typedef typename graph_traits< Graph >::vertex_descriptor vertex_descriptor_t; /// Declare dfs visitor // detail::empty_recorder recorder; // typedef detail::bipartite_visitor dfs_visitor_t; dfs_visitor_t dfs_visitor // (partition_map, recorder); /// Call dfs try { depth_first_search(graph, vertex_index_map(index_map).visitor(make_dfs_visitor( std::make_pair(detail::colorize_bipartition(partition_map), std::make_pair(detail::check_bipartition(partition_map), put_property(partition_map, color_traits< partition_color_t >::white(), on_start_vertex())))))); } catch (const detail::bipartite_visitor_error< vertex_descriptor_t >&) { return false; } return true; } /** * Checks a given graph for bipartiteness. * * @param graph The given graph. * @param index_map An index map associating vertices with an index. * @return true if and only if the given graph is bipartite. */ template < typename Graph, typename IndexMap > bool is_bipartite(const Graph& graph, const IndexMap index_map) { typedef one_bit_color_map< IndexMap > partition_map_t; partition_map_t partition_map(num_vertices(graph), index_map); return is_bipartite(graph, index_map, partition_map); } /** * Checks a given graph for bipartiteness. The graph must * have an internal vertex_index property. Runs in linear time in the * size of the graph, if access to the property maps is in constant time. * * @param graph The given graph. * @return true if and only if the given graph is bipartite. */ template < typename Graph > bool is_bipartite(const Graph& graph) { return is_bipartite(graph, get(vertex_index, graph)); } /** * Checks a given graph for bipartiteness and fills a given color map with * white and black according to the bipartition. If the graph is not * bipartite, a sequence of vertices, producing an odd-cycle, is written to * the output iterator. The final iterator value is returned. Runs in linear * time in the size of the graph, if access to the property maps is in * constant time. * * @param graph The given graph. * @param index_map An index map associating vertices with an index. * @param partition_map A color map to fill with the bipartition. * @param result An iterator to write the odd-cycle vertices to. * @return The final iterator value after writing. */ template < typename Graph, typename IndexMap, typename PartitionMap, typename OutputIterator > OutputIterator find_odd_cycle(const Graph& graph, const IndexMap index_map, PartitionMap partition_map, OutputIterator result) { /// General types and variables typedef typename property_traits< PartitionMap >::value_type partition_color_t; typedef typename graph_traits< Graph >::vertex_descriptor vertex_descriptor_t; typedef typename graph_traits< Graph >::vertex_iterator vertex_iterator_t; vertex_iterator_t vertex_iter, vertex_end; /// Declare predecessor map typedef std::vector< vertex_descriptor_t > predecessors_t; typedef iterator_property_map< typename predecessors_t::iterator, IndexMap, vertex_descriptor_t, vertex_descriptor_t& > predecessor_map_t; predecessors_t predecessors( num_vertices(graph), graph_traits< Graph >::null_vertex()); predecessor_map_t predecessor_map(predecessors.begin(), index_map); /// Initialize predecessor map for (boost::tie(vertex_iter, vertex_end) = vertices(graph); vertex_iter != vertex_end; ++vertex_iter) { put(predecessor_map, *vertex_iter, *vertex_iter); } /// Call dfs try { depth_first_search(graph, vertex_index_map(index_map).visitor(make_dfs_visitor( std::make_pair(detail::colorize_bipartition(partition_map), std::make_pair(detail::check_bipartition(partition_map), std::make_pair( put_property(partition_map, color_traits< partition_color_t >::white(), on_start_vertex()), record_predecessors( predecessor_map, on_tree_edge()))))))); } catch (const detail::bipartite_visitor_error< vertex_descriptor_t >& error) { typedef std::vector< vertex_descriptor_t > path_t; path_t path1, path2; vertex_descriptor_t next, current; /// First path next = error.witnesses.first; do { current = next; path1.push_back(current); next = predecessor_map[current]; } while (current != next); /// Second path next = error.witnesses.second; do { current = next; path2.push_back(current); next = predecessor_map[current]; } while (current != next); /// Find beginning of common suffix std::pair< typename path_t::iterator, typename path_t::iterator > mismatch = detail::reverse_mismatch( std::make_pair(path1.begin(), path1.end()), std::make_pair(path2.begin(), path2.end())); /// Copy the odd-length cycle result = std::copy(path1.begin(), mismatch.first + 1, result); return std::reverse_copy(path2.begin(), mismatch.second, result); } return result; } /** * Checks a given graph for bipartiteness. If the graph is not bipartite, a * sequence of vertices, producing an odd-cycle, is written to the output * iterator. The final iterator value is returned. Runs in linear time in the * size of the graph, if access to the property maps is in constant time. * * @param graph The given graph. * @param index_map An index map associating vertices with an index. * @param result An iterator to write the odd-cycle vertices to. * @return The final iterator value after writing. */ template < typename Graph, typename IndexMap, typename OutputIterator > OutputIterator find_odd_cycle( const Graph& graph, const IndexMap index_map, OutputIterator result) { typedef one_bit_color_map< IndexMap > partition_map_t; partition_map_t partition_map(num_vertices(graph), index_map); return find_odd_cycle(graph, index_map, partition_map, result); } /** * Checks a given graph for bipartiteness. If the graph is not bipartite, a * sequence of vertices, producing an odd-cycle, is written to the output * iterator. The final iterator value is returned. The graph must have an * internal vertex_index property. Runs in linear time in the size of the * graph, if access to the property maps is in constant time. * * @param graph The given graph. * @param result An iterator to write the odd-cycle vertices to. * @return The final iterator value after writing. */ template < typename Graph, typename OutputIterator > OutputIterator find_odd_cycle(const Graph& graph, OutputIterator result) { return find_odd_cycle(graph, get(vertex_index, graph), result); } } #endif /// BOOST_GRAPH_BIPARTITE_HPP