Note
Go to the end to download the full example code or to run this example in your browser via Binder.
Comparing the five placement methods#
nocad.placement.improve_configuration() runs the five methods of the third NOCAD
module for drivers and sensors with the same bound and reports the size, the cost, the
maximal and mean relative order and the structural controllability (observability) of
every configuration; nocad.robustness_table() adds the share of single-node
failures each one tolerates (MATLAB extendData and robust).
The NOCAD example with bound 2#
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import nocad
from nocad.datasets import load_nocad_example, make_hen_case_study
from nocad.placement import improve_configuration
pd.set_option("display.width", 140)
adj = load_nocad_example().adj
# [snippet:compare]
table = improve_configuration(adj, r_max=2, beta=0.5, n_iter=300, n_runs=5, random_state=0)
shown = table.assign(nodes=table.nodes.apply(lambda v: " ".join(f"x{i + 1}" for i in v)))
print(shown[["kind", "method", "nodes", "cost", "max_order", "mean_order", "structural"]].round(4).to_string(index=False))
configs = {m: (table.query("kind == 'drivers' and method == @m").nodes.iloc[0],
table.query("kind == 'sensors' and method == @m").nodes.iloc[0]) for m in table.method.unique()}
labels = [f"x{i + 1}" for i in range(9)]
print(nocad.robustness_table(adj, configs, labels=labels).round(3).to_string(index=False))
# [/snippet:compare]
kind method nodes cost max_order mean_order structural
drivers set_cover x4 x8 1.5556 2.0 1.1111 True
drivers retrofit x4 x8 1.5556 2.0 1.1111 True
drivers centrality x4 x8 1.5556 2.0 1.1111 True
drivers mclasa x5 x8 1.5556 2.0 1.1111 True
drivers gdfcmsa x4 x8 1.5556 2.0 1.1111 True
sensors set_cover x2 x7 x9 1.4444 2.0 0.8889 True
sensors retrofit x1 x4 x9 1.3889 2.0 0.7778 True
sensors centrality x1 x7 x9 1.3889 2.0 0.7778 True
sensors mclasa x1 x4 x9 1.3889 2.0 0.7778 True
sensors gdfcmsa x1 x7 x9 1.3889 2.0 0.7778 True
configuration control_robustness observe_robustness control_critical observe_critical
set_cover 0.556 0.444 [x2, x4, x7, x8] [x1, x2, x4, x6, x7]
retrofit 0.556 0.667 [x2, x4, x7, x8] [x1, x6, x9]
centrality 0.556 0.778 [x2, x4, x7, x8] [x1, x6]
mclasa 0.778 0.667 [x2, x7] [x1, x6, x9]
gdfcmsa 0.556 0.778 [x2, x4, x7, x8] [x1, x6]
Parameter study: the heat exchanger network#
hen = make_hen_case_study()
fig, axes = plt.subplots(1, 2, figsize=(9.6, 3.4), sharey=True)
for ax, r in zip(axes, (1, 3), strict=True):
t = improve_configuration(hen.adj, r_max=r, n_iter=300, n_runs=4, random_state=0)
for k, kind in enumerate(("drivers", "sensors")):
sub = t[t.kind == kind]
x = np.arange(len(sub))
ax.bar(x + (k - 0.5) * 0.38, sub.n_nodes, width=0.38, color=nocad.plotting.PALETTE[k], label=kind)
for xi, (n, ok) in enumerate(zip(sub.n_nodes, sub.structural, strict=True)):
if not ok:
ax.text(xi + (k - 0.5) * 0.38, n + 0.2, "×", ha="center", fontsize=9, color="0.2")
ax.set_xticks(np.arange(len(sub)))
ax.set_xticklabels([m.replace("_", "\n") for m in sub.method], fontsize=8)
ax.set_title(f"HEN, bound r_max = {r} (× : structure lost)", fontsize=10)
ax.grid(True, axis="y", color="0.9")
axes[0].set_ylabel("number of nodes")
axes[0].legend(frameon=False, fontsize=8)
fig.tight_layout()

Take-away. All five methods meet the bound; the annealing methods reach it with the fewest additional nodes while keeping the matching-based nodes, and only grassroot set covering can lose controllability or observability.
Total running time of the script: (0 minutes 1.389 seconds)