.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/09_problems/plot_31_sensor_placement.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_31_sensor_placement.py: Covering and hitting: minimal monitoring sets ============================================= Which resources must be monitored so that every activity involves at least one monitored resource? This is a minimum hitting set (transversal) of the activity hyperedges. Which activities must be observed so that every resource is seen at least once? That is a minimum set cover. Both are solved exactly by integer programming and approximately by the greedy rule; the minimal transversals of a small sub-system are enumerated with Berge's algorithm. .. GENERATED FROM PYTHON SOURCE LINES 15-38 .. code-block:: Python import matplotlib.pyplot as plt import hatvis as hv from hatvis import problems from hatvis.plotting import draw_hypergraph H = hv.datasets.load_wire_harness() people = H.restrict_nodes([v for v in H.nodes if H.node_data.loc[v, "type"] in ("operator", "robot", "AGV", "machine")]) people = people.remove_empty_edges() # [snippet:cover] hs_exact = problems.hitting_set(people) hs_greedy = problems.greedy_hitting_set(people) sc_exact = problems.set_cover(people) sc_greedy = problems.greedy_set_cover(people) # [/snippet:cover] print(f"hitting set: exact {len(hs_exact)} {hs_exact}, greedy {len(hs_greedy)}") print(f"set cover: exact {len(sc_exact)}, greedy {len(sc_greedy)}") small = people.restrict_edges([e for e in people.edges if people.edge_data.loc[e, "step"].startswith("Crimping1") or people.edge_data.loc[e, "step"].startswith("Assembly1")]).remove_isolated() tr = problems.minimal_transversals(small) print("minimal transversals of the line-1 cell:", [sorted(t) for t in tr]) .. rst-class:: sphx-glr-script-out .. code-block:: none hitting set: exact 9 ['O2', 'O3', 'O4', 'O5', 'O6', 'O7', 'R2', 'R5', 'AGV'], greedy 9 set cover: exact 9, greedy 10 minimal transversals of the line-1 cell: [['M1', 'O3'], ['O2', 'O3']] .. GENERATED FROM PYTHON SOURCE LINES 39-45 .. code-block:: Python fig, ax = plt.subplots(figsize=(8, 6.5)) color = {v: hv.plotting.PALETTE[1] if v in hs_exact else hv.plotting.INK for v in people.nodes} draw_hypergraph(people, layout="force", style="smooth", node_color=color, edge_color="#9CC3E6", alpha=0.05, ax=ax, legend=False, pad=0.015, random_state=1, title=f"minimum hitting set ({len(hs_exact)} resources, orange)") plt.tight_layout() .. image-sg:: /auto_examples/09_problems/images/sphx_glr_plot_31_sensor_placement_001.png :alt: minimum hitting set (9 resources, orange) :srcset: /auto_examples/09_problems/images/sphx_glr_plot_31_sensor_placement_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.241 seconds) .. _sphx_glr_download_auto_examples_09_problems_plot_31_sensor_placement.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_31_sensor_placement.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_31_sensor_placement.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_31_sensor_placement.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_31_sensor_placement.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_