Adopting this answer, the following signal-flow diagram has been created by representing the following set of state equations:
I would like to:
1- know how my code can be optimized and generalized to be more robust when the number of nodes and their connecting signals differ without having to manually edit it.
2- make the current output cleaner if possible.
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,positioning,arrows.meta}
\newif\iflabrev
\begin{document}
\begin{tikzpicture}
[
relative = false,
node distance = 15 mm,
label revd/.is if=labrev,
%label revd/.default=true,
amark/.style = {
decoration={
markings,
mark=at position {0.5} with {
\arrow{stealth},
\iflabrev \node[below] {#1};\else \node[above] {#1};\fi
}
},
postaction={decorate}
},
terminal/.style 2 args={draw,circle,inner sep=2pt,label={#1:#2}},
]
%
%Place the nodes
\node[terminal={left}{$R(S)$}] (a) at (0,0) {};
\node[terminal={below right}{$sX_3(s)$}] (b) [right=of a] {};
\node[terminal={below right}{$X_3(S)$}] (c) [right=of b] {};
\node[terminal={[xshift=-4mm]below right}{$sX_2(s)$}] (d) [right=of c] {};
\node[terminal={[xshift=-4mm]below right}{$X_2(s)$}] (e) [right=of d] {};
\node[terminal={[xshift=-4mm]below right}{$sX_1(s)$}] (f) [right=of e] {};
\node[terminal={[xshift=-4mm]below right}{$X_1(s)$}] (g) [right=of f] {};
\node[terminal={right}{$Y(s)$}] (h) [right=of g] {};
%
%Draw the connections
\foreach \target/\bend/\text/\loose in {b/0/7/0, d/90/5/1.5, f/90/2/1.5}
\draw[amark=\text] (a) to[bend left=\bend,looseness=\loose] (\target);
\draw[amark=1/s] (b) to (c);
\foreach \source/\text/\loose in {c/-4/2, e/-3/1.5, g/1/1.5}
\draw[amark=\text] (\source) to[bend left=90, looseness=\loose] (b);
\foreach \target/\text/\loose in { d/-6/1.5, f/2/2}
\draw[amark=\text] (g) to[bend left=90, looseness=\loose] (\target);
\foreach \source/\text in {c/9, e/6}
\draw[amark=\text] (\source) to[bend left=90, looseness=1.5] (h);
\draw[amark=2] (c) to (d);
\draw[amark=3] (c) to[bend right=90, looseness=1.5] (f);
\draw[amark=1/s] (d) to (e);
\draw[amark=-5] (e) to (f);
\draw[amark=-2,label revd] (e) to[bend left=90, looseness=2] (d);
\draw[amark=1/s] (f) to (g);
\draw[amark=-4] (g) to (h);
\end{tikzpicture}
\end{document}


