"""
An operability dashboard
========================

:func:`nocad.viz.plot_operability_summary` combines four views of one network: the SCC
hierarchy with the designed inputs and outputs, the control and observation depth maps
and the operability plane. Here it is applied to a random scale-free network with
self-loops on a share of its nodes.
"""

# %%
# One call, four panels
# ---------------------
import matplotlib.pyplot as plt

import nocad
from nocad.datasets import make_random_network
from nocad.viz import plot_operability_summary

net = make_random_network(40, 1.6, kind="scale_free", self_loops=0.3, random_state=2)
# [snippet:summary]
fig = plot_operability_summary(net.adj, method="path_finding", title="scale-free network, 40 states")
# [/snippet:summary]

# %%
# Parameter study: the design method
# ----------------------------------
# The exact minimum may need fewer dedicated driver nodes than path finding; the
# counts for the same network:
for method in ("matching", "signal_sharing", "path_finding", "minimum"):
    d = nocad.InputOutputDesign(method).fit(net.adj)
    print(f"{method:15s} inputs={d.n_inputs_:2d} drivers={d.n_drivers_:2d} outputs={d.n_outputs_:2d} "
          f"sensors={d.n_sensors_:2d} controllable={d.is_controllable()} observable={d.is_observable()}")
plt.show()

# %%
# **Take-away.** A single figure answers the questions a designer asks first: where must
# the inputs and outputs go, how deep is the network, and which states are hard to
# reach.
