.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/09_problems/plot_33_directed_assembly.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 or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_09_problems_plot_33_directed_assembly.py: Directed hypergraphs: assembly feasibility and cost =================================================== An assembly step needs *all* its input parts — an AND dependency that ordinary graphs cannot express. Modelled as a directed hypergraph (tail = inputs, head = outputs), B-reachability tells which products can be made from the available parts, and minimum B-hyperpaths give the total effort (sum over all sub-assemblies) or the makespan with parallel preparation (max). .. GENERATED FROM PYTHON SOURCE LINES 13-37 .. code-block:: Python import matplotlib.pyplot as plt import pandas as pd import hatvis as hv from hatvis import problems # [snippet:assembly] D = hv.DirectedHypergraph({ "cut wires": (["wire"], ["cut wire"]), "crimp": (["cut wire", "terminal"], ["crimped wire"]), "mount housing": (["housing", "seal"], ["connector"]), "insert": (["crimped wire", "connector"], ["sub-harness"]), "tape": (["sub-harness", "tape"], ["taped sub-harness"]), "route": (["taped sub-harness", "jig"], ["harness"]), "buy harness": (["supplier"], ["harness"]), "test": (["harness", "tester"], ["tested harness"]), }, weights=[2, 3, 3, 4, 2, 5, 30, 3]) available = ["wire", "terminal", "housing", "seal", "tape", "jig", "tester"] print("producible:", sorted(problems.b_reachable(D, available) - set(available))) cost = pd.DataFrame({"sum": problems.shortest_hyperpaths(D, available, "sum"), "max": problems.shortest_hyperpaths(D, available, "max")}) # [/snippet:assembly] print(cost.loc[["crimped wire", "connector", "sub-harness", "harness", "tested harness", "supplier"]]) .. rst-class:: sphx-glr-script-out .. code-block:: none producible: ['connector', 'crimped wire', 'cut wire', 'harness', 'sub-harness', 'taped sub-harness', 'tested harness'] sum max crimped wire 5.0 5.0 connector 3.0 3.0 sub-harness 12.0 9.0 harness 19.0 16.0 tested harness 22.0 19.0 supplier inf inf .. GENERATED FROM PYTHON SOURCE LINES 38-43 .. code-block:: Python fig, ax = plt.subplots(figsize=(7, 3.6)) c = cost.drop(index=available + ["supplier"]) c.sort_values("sum").plot.barh(ax=ax, color=hv.plotting.PALETTE[:2]) ax.set_xlabel("minimum hyperpath cost") plt.tight_layout() .. image-sg:: /auto_examples/09_problems/images/sphx_glr_plot_33_directed_assembly_001.png :alt: plot 33 directed assembly :srcset: /auto_examples/09_problems/images/sphx_glr_plot_33_directed_assembly_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.111 seconds) .. _sphx_glr_download_auto_examples_09_problems_plot_33_directed_assembly.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/hatvis/main?urlpath=lab/tree/notebooks/auto_examples/09_problems/plot_33_directed_assembly.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_33_directed_assembly.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_33_directed_assembly.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_33_directed_assembly.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_