.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/network_science/plot_max_bipartite_matching.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_network_science_plot_max_bipartite_matching.py: Maximum Bipartite Matching by Maximum Flow ========================================== This example from `igraph` presents how to visualise bipartite matching using maximum flow, with edge linewidth and vertex facecolor styling. .. GENERATED FROM PYTHON SOURCE LINES 9-55 .. code-block:: Python import igraph as ig import iplotx as ipx # We start by creating the bipartite directed graph. g = ig.Graph( 9, [(0, 4), (0, 5), (1, 4), (1, 6), (1, 7), (2, 5), (2, 7), (2, 8), (3, 6), (3, 7)], directed=True, ) # We assign: # - nodes 0-3 to one side # - nodes 4-8 to the other side g.vs[range(4)]["type"] = True g.vs[range(4, 9)]["type"] = False # Then we add a source (vertex 9) and a sink (vertex 10) g.add_vertices(2) g.add_edges([(9, 0), (9, 1), (9, 2), (9, 3)]) # connect source to one side g.add_edges([(4, 10), (5, 10), (6, 10), (7, 10), (8, 10)]) # ... and sinks to the other # Compute maximum flow flow = g.maxflow(9, 10) # To achieve a pleasant visual effect, we set the positions of source and sink # manually: layout = g.layout_bipartite() layout[9] = (2, -1) layout[10] = (2, 2) ipx.network( g, layout=layout, vertex_labels=True, style={ "vertex": { "size": 30, "facecolor": ["black" if i < 9 else "darkorange" for i in range(11)], }, "edge": { "linewidth": [1.0 + flow.flow[i] for i in range(g.ecount())], }, }, ) .. image-sg:: /gallery/network_science/images/sphx_glr_plot_max_bipartite_matching_001.png :alt: plot max bipartite matching :srcset: /gallery/network_science/images/sphx_glr_plot_max_bipartite_matching_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. GENERATED FROM PYTHON SOURCE LINES 56-60 If you want to have dark labels on light background, you can set the vertex style accordingly, perhaps with pronounced vertex borders to increase constrast: .. GENERATED FROM PYTHON SOURCE LINES 60-79 .. code-block:: Python ipx.network( g, layout=layout, vertex_labels=True, style={ "vertex": { "size": 30, "facecolor": ["lightblue" if i < 9 else "orange" for i in range(11)], "edgecolor": "black", "linewidth": 1.5, "label": { "color": "black", }, }, "edge": { "linewidth": [1.0 + flow.flow[i] for i in range(g.ecount())], }, }, ) # .. image-sg:: /gallery/network_science/images/sphx_glr_plot_max_bipartite_matching_002.png :alt: plot max bipartite matching :srcset: /gallery/network_science/images/sphx_glr_plot_max_bipartite_matching_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.115 seconds) .. _sphx_glr_download_gallery_network_science_plot_max_bipartite_matching.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_max_bipartite_matching.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_max_bipartite_matching.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_max_bipartite_matching.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_