.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/02_visualization/plot_03_control_cacti.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_02_visualization_plot_03_control_cacti.py: Control cacti: a picture of why a system is controllable ======================================================== Lin's theorem states that a structured system is controllable iff its graph is spanned by *cacti*: a stem (a path starting at an input) with buds (cycles, each entered by one extra edge) hanging from it. A design found by maximum matching contains such a certificate: its matched edges form the stems and the cycles, and an edge from an already attached node anchors every cycle. :func:`nocad.viz.control_cacti` extracts the decomposition and :func:`nocad.viz.plot_control_cacti` draws every input on its own lane with the buds hanging free of the stems; the observation cacti are drawn mirrored, the stems running into the outputs. .. GENERATED FROM PYTHON SOURCE LINES 16-18 The NOCAD example ----------------- .. GENERATED FROM PYTHON SOURCE LINES 18-36 .. code-block:: Python import matplotlib.pyplot as plt from nocad.datasets import load_nocad_example, make_cycle_example, make_hen_case_study from nocad.viz import control_cacti, plot_control_cacti adj = load_nocad_example().adj # [snippet:cacti] cacti = control_cacti(adj, method="path_finding") for k, stem in enumerate(cacti.stems): print(f"u{k + 1}: stem", [f"x{v + 1}" for v in stem]) for bud, (u, v), owner in zip(cacti.buds, cacti.attach, cacti.owner, strict=True): print("bud", [f"x{w + 1}" for w in bud], f"attached by x{u + 1}->x{v + 1} to the cactus of u{owner + 1}") # [/snippet:cacti] fig, ax = plt.subplots(figsize=(6.0, 3.6)) plot_control_cacti(adj, ax=ax, title="control cactus of the NOCAD example") fig, ax = plt.subplots(figsize=(6.0, 3.6)) plot_control_cacti(adj, kind="observation", ax=ax, title="observation cacti of the NOCAD example") .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/02_visualization/images/sphx_glr_plot_03_control_cacti_001.png :alt: control cactus of the NOCAD example :srcset: /auto_examples/02_visualization/images/sphx_glr_plot_03_control_cacti_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/02_visualization/images/sphx_glr_plot_03_control_cacti_002.png :alt: observation cacti of the NOCAD example :srcset: /auto_examples/02_visualization/images/sphx_glr_plot_03_control_cacti_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none u1: stem ['x8', 'x6', 'x7', 'x9'] bud ['x1', 'x2', 'x3'] attached by x4->x2 to the cactus of u1 bud ['x4', 'x5'] attached by x6->x4 to the cactus of u1 .. GENERATED FROM PYTHON SOURCE LINES 37-41 Signal sharing: a bud fed by a shared input ------------------------------------------- With signal sharing the perfectly matched source cycle is not opened; it hangs from the shared input itself (dotted arrow). .. GENERATED FROM PYTHON SOURCE LINES 41-47 .. code-block:: Python fig, axes = plt.subplots(1, 2, figsize=(8.4, 2.8)) cyc = make_cycle_example().adj plot_control_cacti(cyc, method="signal_sharing", ax=axes[0], legend=False, title="signal sharing") plot_control_cacti(cyc, method="path_finding", ax=axes[1], legend=False, title="path finding") fig.tight_layout() .. image-sg:: /auto_examples/02_visualization/images/sphx_glr_plot_03_control_cacti_003.png :alt: signal sharing, path finding :srcset: /auto_examples/02_visualization/images/sphx_glr_plot_03_control_cacti_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 48-54 Parameter study: a heat exchanger network ----------------------------------------- Every heat exchanger cell of the network contributes a two-node cycle (hot and cold outlet temperatures) and every unit a self-loop; one input controls the whole network through a long stem with many buds. The exact minimum and path finding give the same number of stems here. .. GENERATED FROM PYTHON SOURCE LINES 54-62 .. code-block:: Python hen = make_hen_case_study() for method in ("path_finding", "minimum"): c = control_cacti(hen.adj, method=method) print(f"{method:13s} stems={len(c.stems)} buds={len(c.buds)} deepest bud={max(c.depth, default=0)}") fig, ax = plt.subplots(figsize=(9.0, 4.6)) plot_control_cacti(hen.adj, ax=ax, labels=hen.labels, node_size=300, show_other_edges=False, title="control cactus of the heat exchanger network (cactus edges only)") .. image-sg:: /auto_examples/02_visualization/images/sphx_glr_plot_03_control_cacti_004.png :alt: control cactus of the heat exchanger network (cactus edges only) :srcset: /auto_examples/02_visualization/images/sphx_glr_plot_03_control_cacti_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none path_finding stems=1 buds=21 deepest bud=7 minimum stems=1 buds=21 deepest bud=7 .. GENERATED FROM PYTHON SOURCE LINES 63-66 **Take-away.** The cactus view turns a matching into a certificate a reader can check: every state lies on a stem or on a cycle that is anchored, directly or through other cycles, to a stem. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.280 seconds) .. _sphx_glr_download_auto_examples_02_visualization_plot_03_control_cacti.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/nocad/main?urlpath=lab/tree/notebooks/auto_examples/02_visualization/plot_03_control_cacti.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_control_cacti.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_control_cacti.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_control_cacti.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_