is_bipartite#
- graph_tool.topology.is_bipartite(g, partition=False, find_odd_cycle=False)[source]#
Test if the graph is bipartite.
- Parameters:
- g
Graph
Graph to be used.
- partitionbool (optional, default:
False
) If
True
, return the two partitions in case the graph is bipartite.- find_odd_cyclebool (optional, default:
False
) If
True
, return an odd cycle if the graph is not bipartite.
- g
- Returns:
- is_bipartite
bool
Whether or not the graph is bipartite.
- partition
VertexPropertyMap
(only ifpartition=True
) A vertex property map with the graph partitioning (or
None
) if the graph is not bipartite.- odd_cyclelist of vertices (only if
find_odd_cycle=True
) A list of vertices corresponding to an odd cycle, or
None
if none is found.
- is_bipartite
Notes
An undirected graph is bipartite if one can partition its set of vertices into two sets, such that all edges go from one set to the other.
This algorithm runs in \(O(V + E)\) time.
References
[boost-bipartite]Examples
>>> g = gt.lattice([10, 10]) >>> is_bi, part = gt.is_bipartite(g, partition=True) >>> print(is_bi) True >>> gt.graph_draw(g, vertex_fill_color=part, output="bipartite.pdf") <...>