Debian Codegraph @

texmf-dist/doc/latex/sa-tikz/sa-tikz-doc.tex

raw
1 % Architectures examples: http://hal.archives-ouvertes.fr/docs/00/14/95/27/PDF/RR.pdf
2 \pdfminorversion=5
3 \pdfobjcompresslevel=2
4 \documentclass{ltxdoc}
5 \usepackage[T1]{fontenc}
6 \usepackage[utf8]{inputenc}
7 \usepackage{amsmath}
8 \usepackage{lmodern}
9 \usepackage[ruled, lined,linesnumbered]{algorithm2e}
10
11 %% Use the tikz package and loading the library
12 %\usepackage{tikz}
13 %\usetikzlibrary{switching-architectures}
14
15 %% Loading only the package
16 \usepackage{sa-tikz}
17
18 \usepackage{calc}
19 \usepackage{imakeidx}
20
21 \usepackage[naturalnames]{hyperref}
22 \hypersetup{%
23 colorlinks=true,
24 linkcolor=blue,
25 filecolor=blue,
26 urlcolor=blue,
27 citecolor=blue,
28 pdfborder=0 0 0,
29 }
30
31 % dedicated commands:
32 \newcommand\Tikz{Ti\textit kZ}
33 \newcommand{\saTikZ}{S\textit{a}-\Tikz}
34
35 \def\pgfautoxrefs{1}
36 \input ./macros/pgfmanual-en-macros.tex
37
38 \makeatletter
39 \def\index@prologue{%
40 \section*{Index}\addcontentsline{toc}{section}{Index}
41 }
42 \makeatother
43
44 \usepackage{pgfmanual}
45
46 \pgfkeys{
47 /pdflinks/search key prefixes in={/tikz/,/pgf/},
48 /pdflinks/internal link prefix=pgfp,
49 /pdflinks/codeexample links=true,
50 /pdflinks/warnings=false,
51 /pdflinks/show labels=false,
52 }
53 \makeindex
54 \newcommand{\version}{0.7a}
55 \newcommand{\versiondate}{January 29, 2014}
56
57 \title{\saTikZ\footnote{This package has version number \textit{v}\version\ of \versiondate; it is released under and subject to the \href{http://www.latex-project.org/lppl/}{\LaTeX\ Project Public License (LPPL)}.}}
58 \author{Claudio Fiandrino \\ \small\href{mailto:[email protected]}{\texttt{[email protected]}}}
59 \date{\versiondate}
60
61 \begin{document}
62 \maketitle
63 \tableofcontents
64
65 \section*{Introduction}
66 \addcontentsline{toc}{section}{Introduction}
67 The \saTikZ\ library is a tool for drawing \emph{switching-architectures}. In particular, one of its aims, is to help students to verify the correctness of their exercises, but it could also help teachers in preparing lecture notes. The official webpage of the project is hosted on \href{http://cfiandra.github.io/Sa-TikZ/}{http://cfiandra.github.io/Sa-TikZ/} and a public repository of the library can be found in \href{https://github.com/cfiandra/Sa-TikZ}{https://github.com/cfiandra/Sa-TikZ}.
68
69 The \saTikZ\ library can be loaded in a \LaTeX\ preamble by means of:
70 \begin{flushleft}
71 \verb|\usetikzlibrary{|\bgroup\color{red!75!black}\verb|switching-architectures|\egroup\verb|}|
72 \end{flushleft}
73 and in this case you should also load manually:
74 \begin{flushleft}
75 \verb|\usepackage{|\bgroup\color{red!75!black}\verb|tikz|\egroup\verb|}|
76 \end{flushleft}
77 or by means of:
78 \begin{flushleft}
79 \verb|\usepackage{|\bgroup\color{red!75!black}\verb|sa-tikz|\egroup\verb|}|
80 \end{flushleft}
81 In both cases the auxiliary \Tikz\ libraries \bgroup\color{red!75!black}\verb|calc|\egroup{}, \bgroup\color{red!75!black}\verb|decorations.pathreplacing|\egroup\ and \bgroup\color{red!75!black}\verb|positioning|\egroup\ are automatically loaded; in the latter case also the \Tikz\ package is loaded.
82
83 The version \textit{v}\version\ is compliant with \Tikz\ 3.0.0\footnote{In order to compile the documentation, and only for this scope, \Tikz\ 3.0.0 is \emph{mandatory}.} and provides a way to draw Clos Networks Strictly-non-Blocking (snb) and Rearrangeable (rear), Benes Networks and Banyan Networks (in particular Omega\footnote{Implementation of Omega Networks by João Gabriel Reis.} and Flip Networks); moreover, the package provides the possibility to fully customize the aspect of the drawn network: the dimensions of module, their distance and the font used are some examples. Finally, \saTikZ\ let users to draw connections among the stages by accessing the single ports of the modules.
84
85 \section{Basic usage}
86 The simplest use of the package is to define a
87 \begin{command}{{\node}}
88 Basic command definition.
89 \end{command}
90 with one of the following options
91 \begin{key}{/tikz/clos snb}
92 Option for drawing a Clos Network Strictly-non-Blocking.
93 \end{key}
94 \begin{key}{/tikz/clos rear}
95 Option for drawing a Clos Network Rearrangeable.
96 \end{key}
97 \begin{key}{/tikz/benes}
98 Option for drawing a Benes Network.
99 \end{key}
100 \begin{key}{/tikz/benes complete}
101 Option for drawing a Benes Network with the lowest level of recursion.
102 \end{key}
103 \begin{key}{/tikz/banyan omega}
104 Option for drawing an Banyan-Omega Network.
105 \end{key}
106 \begin{key}{/tikz/banyan flip}
107 Option for drawing an Banyan-Omega Network with inverse shuffle exchange (Flip).
108 \end{key}
109 inside a |tikzpicture| environment:
110 \begin{environment}{{tikzpicture}\opt{\oarg{options}}}
111 \end{environment}
112
113 \subsection{Examples of Clos Networks}
114
115 The following example shows a Rearrangeable Clos Network.
116
117 \begin{codeexample}[]
118 \begin{tikzpicture}
119 \node[clos rear] {};
120 \end{tikzpicture}
121 \end{codeexample}
122
123 The following example shows a Strictly-non-Blocking Clos Network.
124
125 \begin{codeexample}[]
126 \begin{tikzpicture}
127 \node[clos snb] {};
128 \end{tikzpicture}
129 \end{codeexample}
130
131 Notice from the examples that the library is able to compute \textit{automatically} the constraints defining a Clos Network to be Strictly-non-Blocking or Rearrangeable. The network drawn is characterized by:
132 \begin{itemize}
133 \item the first stage with:
134 \begin{itemize}
135 \item a number of modules equal to 5;
136 \item each one with two input ports;
137 \end{itemize}
138 \item the last stage with:
139 \begin{itemize}
140 \item a number of modules equal to 5;
141 \item each one with two output ports.
142 \end{itemize}
143 \end{itemize}
144 Each module of the network is numbered according to the stage it belongs to.
145
146 \subsection{Examples of Benes Networks}
147
148 The simplest example of a Benes Network:
149 \begin{codeexample}[]
150 \begin{tikzpicture}
151 \node[benes] {};
152 \end{tikzpicture}
153 \end{codeexample}
154 is a Benes Network in which there are 8 input and output ports. To draw a Benes Network in which all modules are visible, the key |benes complete| should be used rather than the |benes| key. An example:
155
156 \begin{codeexample}[]
157 \begin{tikzpicture}
158 \node[benes complete] {};
159 \end{tikzpicture}
160 \end{codeexample}
161
162 The algorithm in which the internal connections of the |benes complete| networks are drawn is explained in detail in the appendix \ref{sec:benesconnalg}.
163
164 \subsection{Examples of Banyan Networks}
165
166 The following examples show the two Banyan Network architectures that \saTikZ\ can draw.
167
168 \bgroup
169 \tikzset{every node/.append style={scale=0.9,transform shape}}
170 \begin{codeexample}[]
171 \begin{tikzpicture}
172 % Omega Network on the left
173 \node[banyan omega] {};
174 \begin{scope}[xshift=7.25cm]
175 % Flip network on the right
176 \node[banyan flip]{};
177 \end{scope}
178 \end{tikzpicture}
179 \end{codeexample}
180 \tikzset{every node/.append style={scale=1,transform shape}}
181 \egroup
182
183 \section{The options}
184 \subsection{Designing choices}
185 This subsection provides a detailed analysis of the options and parameters that can be used to draw Clos, Benes and Omega Networks. In particular:
186 \begin{itemize}
187 \item Clos Networks are analysed in \ref{subsubsec:clos};
188 \item Benes Networks are analysed in \ref{subsubsec:benes};
189 \item Banyan Networks are analysed in \ref{subsubsec:banyan}.
190 \end{itemize}
191 Each subsection presents the keys' definitions and simple examples to help the reader.
192
193 \subsubsection{Clos Networks}
194 \label{subsubsec:clos}
195 The two first important design parameters are the total number of input ports of the first stage and the total number of output ports of the last stage. These two parameters could be customized by means of:
196
197 \begin{key}{/tikz/N=\marg{value} (initially 10)}
198 This is the number of total input ports in the first stage.
199 \end{key}
200
201 \begin{key}{/tikz/M=\marg{value} (initially 10)}
202 This is the number of total output ports in the last stage.
203 \end{key}
204
205 Usually, a second important design parameter is the number of modules present in the first and last stage. \saTikZ\ defines:
206
207 \begin{key}{/tikz/r1=\marg{value} (initially 5)}
208 This is the number of modules in the first stage.
209 \end{key}
210
211 \begin{key}{/tikz/r3=\marg{value} (initially 5)}
212 This is the number of modules in the last stage.
213 \end{key}
214
215 The two design parameters provide the number of ports of each module:
216 \[m_1=\dfrac{N}{r_1} \hspace*{2cm} m_3=\dfrac{M}{r_3} \]
217
218 Some examples considering |N|=9, |r1|=3, |M|=9 and |r3|=3.
219 \begin{codeexample}[]
220 \begin{tikzpicture}
221 \node[N=9,r1=3,M=9,r3=3,clos rear] {};
222 \end{tikzpicture}
223 \end{codeexample}
224
225 \begin{codeexample}[]
226 \begin{tikzpicture}
227 \node[N=9,r1=3,M=9,r3=3,clos snb] {};
228 \end{tikzpicture}
229 \end{codeexample}
230
231 Notice a very important thing: when the keys are set within the \cs{node}, the type of the architecture should be loaded \emph{after} all the design parameters; if this constraint is not respected, you will end up with an architecture which has default values. For example:
232
233 \begin{codeexample}[]
234 \begin{tikzpicture}
235 \node[clos rear,N=9,r1=3,M=9,r3=3] {};
236 \end{tikzpicture}
237 \end{codeexample}
238
239 \subsubsection{Benes Networks}
240 \label{subsubsec:benes}
241 Benes Networks are Clos Rearrangeable Networks composed of $2 \times 2$ modules. Hence, as design choice, it just possible to select the number of input/output ports:
242
243 \begin{key}{/tikz/P=\marg{value} (initially 8)}
244 This is the number of total input/output ports in the first/third stage.
245 \end{key}
246
247 Notice that |P| could assume values
248 \[P=2^p \qquad p=2,3,4,\ldots\]
249 and the user is responsible to correctly set this parameter.
250
251 For low values of $p$ there are no problems in visualizing the network, but as $p$ increases, the user should take care of the modules' dimension and the modules' separation (vertical and horizontal): these parameters could be customized as explained in the subsection \ref{subsec:customization}. Actually, for |benes complete| networks, the number of $p$ is crucial: when it is above 7, namely the network is bigger than $128\times 128$, PGF can not properly work due to internal limitations.
252
253 Notice that, for |P|=4 the |benes| network and the |benes complete| network are indistinguishable:
254 \begin{codeexample}[]
255 \begin{tikzpicture}
256 \tikzset{module size=0.5cm,
257 pin length factor=0.5,
258 module ysep=1}
259 \node[P=4,benes] {};
260 \begin{scope}[xshift=6cm]
261 \node[module xsep=2.5,P=4,benes complete]{};
262 \end{scope}
263 \end{tikzpicture}
264 \end{codeexample}
265
266 Here is an example of Benes Network with |P|=16:
267 \begin{codeexample}[]
268 \begin{tikzpicture}
269 \node[P=16,benes] {};
270 \end{tikzpicture}
271 \end{codeexample}
272
273 It holds the same concept afore-mentioned for Clos Networks: set the parameter |P| before declaring the \cs{node} to be a Benes Network.
274
275 \subsubsection{Banyan Networks}
276 \label{subsubsec:banyan}
277 Banyan Networks are architectures based on Benes Networks: they have particular interconnections properties. As well as Benes Networks, only the number of inputs and outputs ports can be selected and it is |P|.
278
279 \saTikZ is able to represent Omega and Flip Banyan Networks. Omega networks are based on João Gabriel Reis' implementation. An example of $4\times 4$ |banyan omega| network:
280 \begin{codeexample}[]
281 \begin{tikzpicture}
282 \node[P=4,banyan omega] {};
283 \end{tikzpicture}
284 \end{codeexample}
285
286 An example of $4\times 4$ |banyan flip| network:
287 \begin{codeexample}[]
288 \begin{tikzpicture}
289 \node[P=4,banyan flip] {};
290 \end{tikzpicture}
291 \end{codeexample}
292
293 \subsection{Output customization}
294 \label{subsec:customization}
295 This subsection presents the keys devoted to customize the networks' aspect.
296
297 \begin{key}{/tikz/module size=\marg{value} (initially 1cm)}
298 This option allows to set the module dimension.
299 \end{key}
300
301 \begin{key}{/tikz/module ysep=\marg{value} (initially 1.5)}
302 This option allows to set the vertical module distance factor.
303 \end{key}
304
305 \begin{key}{/tikz/module xsep=\marg{value} (initially 3)}
306 This option allows to set the horizontal module distance factor.
307 \end{key}
308
309 \begin{key}{/tikz/module label opacity=\marg{value} (initially 1)}
310 This option allows to mask the module label when the \meta{value} is set to 0.
311 \end{key}
312
313 \begin{key}{/tikz/pin length factor=\marg{value} (initially 1)}
314 This option allows to reduce/increase the length of the pins drawn in input/output. Use a \meta{value} [0,1] to reduce the length or, viceversa, a \meta{value} greater than 1 to increase the length.
315 \end{key}
316
317 \begin{key}{/tikz/module font=\marg{font commands} (default \cs{normalfont})}
318 This option sets the font used for module labels. The \meta{font commands} that could be used are those ones related to the font size (i.e. \cs{Large}) and font shape (i.e \cs{itshape}).
319 \end{key}
320
321 \begin{key}{/tikz/connections disabled=\mchoice{true,false} (default false)}
322 This option, not active by default |connections disabled/.default=false|, allows to remove the connections between the stages when it is set to \opt{true}. Beware: this option is valid only for |clos snb|, |clos rear|, |benes| and |benes complete| networks, but it does not holds for the architectures explained in section \ref{sec:dida}.
323 \end{key}
324
325 The following example shows a Rearrangeable Clos Network with some custom options. Notice that the |module label opacity| should be given as parameter of the desired network.
326
327 \begin{codeexample}[]
328 \begin{tikzpicture}[N=9,r1=3,M=9,r3=3]
329 \node[module size=0.5cm,pin length factor=0.5,
330 module ysep=1, module xsep=1.25,
331 clos rear={module label opacity=0}] {};
332 \end{tikzpicture}
333 \end{codeexample}
334
335 The options could be also introduced with the standard \Tikz\ syntax:
336 \begin{command}{{\tikzset}\marg{options}}
337 Command that process the various \meta{options}: they should be provided separated by commas.
338 \end{command}
339
340 Therefore, the previous example can be modified into:
341 \begin{codeexample}[]
342 \tikzset{module size=0.5cm,pin length factor=0.5,
343 module ysep=1, module xsep=1.25,}
344 \begin{tikzpicture}[N=9,r1=3,M=9,r3=3]
345 \node[clos rear={module label opacity=0}] {};
346 \end{tikzpicture}
347 \end{codeexample}
348
349 It is also possible to declare \opt{styles} to set some options for later use: this helps to keep the code clean especially when the same options are re-used several times; an example:
350 \begin{codeexample}[code only]
351 \tikzset{module size definition/.style={
352 module size=0.75cm,
353 pin length factor=0.75,
354 module xsep=2,
355 module ysep=2,
356 }
357 }
358 \tikzset{module size definition,
359 P=16,
360 }
361 \begin{tikzpicture}
362 \node[benes] {};
363 \end{tikzpicture}
364 \end{codeexample}
365
366 Here is a Benes Network $4 \times 4$ which presents an extremely large font size for the module labels and its interconnection paths are disabled:
367 \begin{codeexample}[]
368 \tikzset{my style/.style={
369 module size=0.75cm,
370 pin length factor=0.75,
371 module xsep=2,
372 }
373 }
374 \tikzset{my style, P=4,
375 module font=\huge\slshape,
376 connections disabled=true
377 }
378 \begin{tikzpicture}
379 \node[benes complete] {};
380 \end{tikzpicture}
381 \end{codeexample}
382
383 The following example is a $16 \times 16$ Omega Network.
384 \begin{codeexample}[]
385 \tikzset{module size=0.6cm,pin length factor=0.6,
386 module ysep=0.65, module xsep=3.5,}
387 \begin{tikzpicture}[P=32]
388 \node[banyan omega] {};
389 \end{tikzpicture}
390 \end{codeexample}
391
392 \pagebreak
393
394 An example of Benes Network $32 \times 32$:
395 \begin{codeexample}[]
396 \tikzset{module size=0.6cm,pin length factor=0.6,
397 module ysep=0.9, module xsep=1.7,}
398 \begin{tikzpicture}[P=32]
399 \node[benes] {};
400 \end{tikzpicture}
401 \end{codeexample}
402 \pagebreak
403
404 and its complete form:
405 \begin{codeexample}[]
406 \tikzset{module size=0.6cm,pin length factor=0.6,
407 module ysep=1, module xsep=2.275}
408 \begin{tikzpicture}[P=32]
409 \node[benes complete={module label opacity=0}] {};
410 \end{tikzpicture}
411 \end{codeexample}
412
413
414 \section{Advanced usage}
415 This section presents some more advanced examples. More in detail, it is described how to add elements to the basic architecture; the elements can be:
416 \begin{itemize}
417 \item labels for the input and output ports;
418 \item paths interconnecting input and output ports.
419 \end{itemize}
420
421 \subsection{Identifying front input/output ports}
422 In this subsection it is shown how to reference the front input and output ports for the first and last stage. Each front input port could be accessed by means of:
423 \begin{flushleft}
424 \verb|r1-|\bgroup\color{red!75!black}\verb|module number|\egroup\verb|-|\bgroup\color{red!75!black}\verb|front input|\egroup\verb|-|\bgroup\color{red!75!black}\verb|port number|\egroup; example: \verb|r1-1-front input-1|;
425 \end{flushleft}
426 Each front output port could be accessed by means of:
427 \begin{flushleft}
428 \verb|r3-|\bgroup\color{red!75!black}\verb|module number|\egroup\verb|-|\bgroup\color{red!75!black}\verb|front output|\egroup\verb|-|\bgroup\color{red!75!black}\verb|port number|\egroup; example: \verb|r3-1-front output-1|;
429 \end{flushleft}
430 Noticed that the first stage is always 1, but the last stage may be different from 3 in case the |benes complete| network is drawn. Errors will occur in case the last stage number is not correct and the user is responsible for the correct setting.
431
432 A simple example with a Rearrangeable Clos network of 4 input and output ports; the first stage and the last one have both 2 modules.
433
434 \begin{codeexample}[]
435 \begin{tikzpicture}[module xsep=2]
436 \node[N=4,r1=2,M=4,r3=2,clos rear={module label opacity=0}] {};
437 \foreach \name
438 in {r1-1-front input-1,r1-1-front input-2,
439 r1-2-front input-1,r1-2-front input-2}
440 \node[left] at (\name) {\scriptsize{\texttt{\name}}};
441 \foreach \name
442 in {r3-1-front output-1,r3-1-front output-2,
443 r3-2-front output-1,r3-2-front output-2}
444 \node[right] at (\name) {\scriptsize{\texttt{\name}}};
445 \end{tikzpicture}
446 \end{codeexample}
447
448 The following is a Strictly-non-Blocking Clos network of 9 input and output ports in which the first and last stage have 3 modules each one.
449
450 \begin{codeexample}[]
451 \begin{tikzpicture}
452 \node[N=9,r1=3,M=9,r3=3,clos snb={module label opacity=0}] {};
453
454 \foreach \startmodule in {1,...,3}{
455 \foreach \port in {1,...,3}
456 \node[left] at (r1-\startmodule-front input-\port)
457 {\scriptsize{input \startmodule-\port}};
458 }
459 \foreach \startmodule in {1,...,3}{
460 \foreach \port in {1,...,3}
461 \node[right] at (r3-\startmodule-front output-\port)
462 {\scriptsize{output \startmodule-\port}};
463 }
464 \end{tikzpicture}
465 \end{codeexample}
466
467 The same applies also for Benes Networks:
468 \begin{codeexample}[]
469 \begin{tikzpicture}
470 \node[benes={module label opacity=0}] {};
471
472 \foreach \startmodule in {1,...,4}{
473 \foreach \port in {1,...,2}
474 \node[left] at (r1-\startmodule-front input-\port)
475 {\scriptsize{input \startmodule-\port}};
476 }
477 \foreach \startmodule in {1,...,4}{
478 \foreach \port in {1,...,2}
479 \node[right] at (r3-\startmodule-front output-\port)
480 {\scriptsize{output \startmodule-\port}};
481 }
482 \end{tikzpicture}
483 \end{codeexample}
484 and to the correspondent complete form:
485 \begin{codeexample}[]
486 \begin{tikzpicture}
487 \node[benes complete={module label opacity=0}] {};
488 \newcounter{port}
489 \setcounter{port}{0}
490 \foreach \startmodule in {1,...,4}{
491 \foreach \port in {1,...,2}
492 \stepcounter{port}
493 \node[left] at (r1-\startmodule-front input-\port)
494 {\scriptsize{input \theport}};
495 }
496 \setcounter{port}{0}
497 \foreach \startmodule in {1,...,4}{
498 \foreach \port in {1,...,2}
499 \stepcounter{port}
500 \node[right] at (r5-\startmodule-front output-\port)
501 {\scriptsize{output \theport}};
502 }
503 \end{tikzpicture}
504 \end{codeexample}
505 Notice that in this case to access the \verb|front output| ports, the stage number correct is 5 and not 3 as usual.
506
507 Ti\textit{k}Z has very useful \verb|bin(|$x$\verb|)| function: it converts $x$ (it is assumed to be a 10 base integer) into its binary representation. Exploiting this function for Omega or Flip Networks is very convenient. An example of Omega Network:
508 \begin{codeexample}[]
509 \begin{tikzpicture}
510 \node[banyan omega={module label opacity=0}] {};
511 \newcounter{porta}
512 \setcounter{porta}{0}
513 \foreach \module in {1,...,4}{
514 \foreach \port in {1,...,2}{
515 \stepcounter{porta}
516 \pgfmathbin{\theporta-1}% get the binary value of the counter
517 \node[left] at (r0-\module-front input-\port)
518 {\scriptsize{\pgfmathresult}};
519 \node[right] at (r3-\module-front output-\port)
520 {\scriptsize{\pgfmathresult}};
521 }
522 }
523 \end{tikzpicture}
524 \end{codeexample}
525
526 An example of Flip Network:
527 \begin{codeexample}[]
528 \begin{tikzpicture}
529 \node[banyan flip={module label opacity=0}] {};
530 \newcounter{portb}
531 \setcounter{portb}{0}
532 \foreach \module in {1,...,4}{
533 \foreach \port in {1,...,2}{
534 \stepcounter{portb}
535 \pgfmathbin{\theportb-1}
536 \node[left] at (r0-\module-front input-\port)
537 {\scriptsize{\pgfmathresult}};
538 \node[right] at (r3-\module-front output-\port)
539 {\scriptsize{\pgfmathresult}};
540 }
541 }
542 \end{tikzpicture}
543 \end{codeexample}
544 Notice that for Banyan Networks the first module is characterized by number 0 and not 1.
545
546 \subsection{Identifying input/output ports per module}
547
548 It is also possible to access, for each module of each stage, its input and output ports. The syntax is similar to the one used for the front input and output ports; each input port could be accessed by means of:
549 \begin{flushleft}
550 \verb|r|\bgroup\color{red!75!black}\verb|stage number|\egroup\verb|-|\bgroup\color{red!75!black}\verb|module number|\egroup\verb|-|\bgroup\color{red!75!black}\verb|input|\egroup\verb|-|\bgroup\color{red!75!black}\verb|port number|\egroup; example: \verb|r1-1-input-1|;
551 \end{flushleft}
552 Each output port could be accessed by means of:
553 \begin{flushleft}
554 \verb|r|\bgroup\color{red!75!black}\verb|stage number|\egroup\verb|-|\bgroup\color{red!75!black}\verb|module number|\egroup\verb|-|\bgroup\color{red!75!black}\verb|front output|\egroup\verb|-|\bgroup\color{red!75!black}\verb|port number|\egroup; example: \verb|r2-1-output-1|;
555 \end{flushleft}
556 This allows to derive connections from the first stage to the last stage. Here is an example.
557
558 \begin{codeexample}[]
559 \begin{tikzpicture}
560 \node[N=8,r1=4,M=8,r3=4,clos rear={module label opacity=0}] {};
561 \draw[red,ultra thick](r1-2-input-1)--(r1-2-output-2)
562 (r2-2-input-2)--(r2-2-output-3)
563 (r3-3-input-2)--(r3-3-output-2);
564 \draw[red,ultra thick](r1-4-input-1)--(r1-4-output-1)
565 (r2-1-input-4)--(r2-1-output-1)
566 (r3-1-input-1)--(r3-1-output-2);
567 \end{tikzpicture}
568 \end{codeexample}
569 Similarly, an example in a Benes Network:
570 \begin{codeexample}[]
571 \begin{tikzpicture}
572 \node[benes={module label opacity=0}] {};
573 \draw[red,ultra thick](r1-2-input-1)--(r1-2-output-2)
574 (r2-2-input-2)--(r2-2-output-3)
575 (r3-3-input-2)--(r3-3-output-2);
576 \draw[red,ultra thick](r1-4-input-1)--(r1-4-output-1)
577 (r2-1-input-4)--(r2-1-output-1)
578 (r3-1-input-1)--(r3-1-output-2);
579 \end{tikzpicture}
580 \end{codeexample}
581 and in its complete form:
582 \begin{codeexample}[]
583 \begin{tikzpicture}
584 \node[benes complete={module label opacity=0}] {};
585 \draw[red,ultra thick](r1-2-input-1)--(r1-2-output-2)--
586 (r2-3-input-2)--(r2-3-output-2)--
587 (r3-3-input-1)--(r3-3-output-2)--
588 (r4-4-input-1)--(r4-4-output-1)--
589 (r5-3-input-2)--(r5-3-output-2);
590 \draw[blue,ultra thick](r1-4-input-1)--(r1-4-output-1)--
591 (r2-2-input-2)--(r2-2-output-1)--
592 (r3-1-input-2)--(r3-1-output-1)--
593 (r4-1-input-1)--(r4-1-output-1)--
594 (r5-1-input-1)--(r5-1-output-2);
595 \end{tikzpicture}
596 \end{codeexample}
597
598 For Banyan Networks, due to the way in which the interconnections are established, it is advised to proceed as follows:
599 \begin{codeexample}[]
600 \begin{tikzpicture}
601 \node[banyan omega={module label opacity=0}] {};
602 \newcounter{portc}
603 \setcounter{portc}{0}
604 \foreach \module in {1,...,4}{
605 \foreach \port in {1,...,2}{
606 \stepcounter{portc}
607 \pgfmathbin{\theportc-1}
608 \node[left] at (r0-\module-front input-\port)
609 {\scriptsize{\pgfmathresult}};
610 \node[right] at (r3-\module-front output-\port)
611 {\scriptsize{\pgfmathresult}};
612 }
613 }
614 \draw[red,ultra thick]
615 (r0-1-front input-2)--(r0-1-front output-2)--
616 (r1-2-front input-1)--(r1-2-input-1)--
617 (r1-2-output-2)--(r1-2-front output-2)--
618 (r2-4-front input-1)--(r2-4-input-1)--
619 (r2-4-output-1)--(r2-4-front output-1)--
620 (r3-3-front input-2)-- (r3-3-input-2)--
621 (r3-3-output-2)--(r3-3-front output-2);
622 \end{tikzpicture}
623 \end{codeexample}
624
625 \section{Architectures for didactic purposes}
626 \label{sec:dida}
627 To quickly draw a Clos Network it is possible to exploit:
628 \begin{key}{/tikz/clos snb example}
629 Option for quickly drawing a Clos Network Strictly-non-Blocking.
630 \end{key}
631 \begin{key}{/tikz/clos rear example}
632 Option for quickly drawing a Clos Network Rearrangeable.
633 \end{key}
634 In this way the network is not seen in its whole complexity, but it is synthetically depicted. An example of a Strictly-non-Blocking Clos Network drawn with this approach:
635 \begin{codeexample}[]
636 \begin{tikzpicture}[N=12,r1=4,M=8,r3=4]
637 \node[clos snb example] {};
638 \end{tikzpicture}
639 \end{codeexample}
640
641 Similarly, an example of a Rearrangeable Clos Network:
642 \begin{codeexample}[]
643 \begin{tikzpicture}[N=12,r1=4,M=8,r3=4]
644 \node[clos rear example] {};
645 \end{tikzpicture}
646 \end{codeexample}
647
648 The networks drawn, automatically display the values at which the input parameters |N|, |M|, |r1| and |r3| have been set. However, to let the user to have the possibility of deploying labels rather than the input parameter values, the following option is available:
649
650 \begin{key}{/tikz/clos example with labels}
651 Option for quickly drawing a Clos Network with custom labels.
652 \end{key}
653
654 The labels could be customized by means of:
655 \begin{key}{/tikz/N label=\marg{value} (default N)}
656 This options sets the label representing the total number of ports in the first stage.
657 \end{key}
658
659 \begin{key}{/tikz/r1 label=\marg{value} (default r$_1$)}
660 This options sets the label representing the number of modules in the first stage.
661 \end{key}
662
663 \begin{key}{/tikz/m1 label=\marg{value} (default m$_1$)}
664 This options sets the label representing the number of ports per module in the first stage.
665 \end{key}
666
667 \begin{key}{/tikz/r2 label=\marg{value} (default r$_2$)}
668 This options sets the label representing the number of modules in the second stage.
669 \end{key}
670
671 \begin{key}{/tikz/M label=\marg{value} (default M)}
672 This options sets the label representing the total number of ports in the last stage.
673 \end{key}
674
675 \begin{key}{/tikz/r3 label=\marg{value} (default r$_3$)}
676 This options sets the label representing the number of modules in the last stage.
677 \end{key}
678
679 \begin{key}{/tikz/m3 label=\marg{value} (default m$_3$)}
680 This options sets the label representing the number of ports per module in the last stage.
681 \end{key}
682
683 An example with the default values for the labels:
684
685 \begin{codeexample}[]
686 %\tikzset{N=8,r1=4,M=8,r3=4} % here, setting the parameters is useless
687 \begin{tikzpicture}
688 \node[clos example with labels] {};
689 \end{tikzpicture}
690 \end{codeexample}
691
692 To have automatically all the labels in math mode, you can use:
693 \begin{key}{/tikz/set math mode labels=\mchoice{true,false} (default false)}
694 This option is normally disabled |set math mode labels/.default=false|; to ensure labels be set completely in math mode is sufficient set |set math mode labels=true| before the type of the network.
695 \end{key}
696
697 An example:
698 \begin{codeexample}[]
699 \begin{tikzpicture}[set math mode labels=true]
700 \node[clos example with labels] {};
701 \end{tikzpicture}
702 \end{codeexample}
703
704 This example, instead, represents a |clos example with labels| network with custom labels introduced by means of the |\tikzset| syntax.
705
706 \begin{codeexample}[]
707 \tikzset{N label={p$_1$ $\times$ q$_1$},M label={p$_3$ $\times$ q$_3$},
708 r1 label=p$_1$, m1 label=q$_1$, r2 label=p$_2$,r3 label=p$_3$, m3 label=q$_3$}
709 \begin{tikzpicture}
710 \node[clos example with labels] {};
711 \end{tikzpicture}
712 \end{codeexample}
713
714 Notice that it does not exist an equivalent of |clos example with labels| or |clos rear example| for Benes Networks: this because Benes Networks are a particular type of Rearrangeable Clos Networks where |P|=|N|=|M| and $m1$=$m3$=$z$=2, thus |r1|=|r3|=$q=P/z$.
715
716 For example:
717
718 \begin{codeexample}[]
719 \begin{tikzpicture}[N=8,r1=4,M=8,r3=4]
720 \node[clos rear example] {};
721 \end{tikzpicture}
722 \end{codeexample}
723
724 \begin{codeexample}[]
725 \tikzset{N label={P},M label={P},
726 r1 label=q, m1 label=z, r2 label=z,r3 label=q, m3 label=z}
727 \begin{tikzpicture}
728 \node[set math mode labels=true,clos example with labels] {};
729 \end{tikzpicture}
730 \end{codeexample}
731
732 \clearpage
733 \appendix
734
735 \section{Algorithm for drawing connections in Benes Networks}
736 \label{sec:benesconnalg}
737 To explain how the connections of the |benes complete| networks are drawn, the following reference example will be considered:
738 \begin{center}
739 \scalebox{0.75}{
740 \begin{tikzpicture}[module size=0.75cm, module ysep=1, module xsep=2.5]
741 \node[P=16, benes complete]{};
742 \end{tikzpicture}
743 }
744 \end{center}
745 The network is $16\times 16$ (|P|=16), thus the number of stages $\mathcal{S}$ is:
746 \[\mathcal{S}=2\log_2{P}-1 \implies \mathcal{S}_{16}=7\]
747 Indeed:
748 \begin{center}
749 \scalebox{0.75}{
750 \begin{tikzpicture}[module size=0.75cm, module ysep=1, module xsep=2.5]
751 \node[P=16, benes complete]{};
752 \foreach \x in {1,...,7}
753 \node[above of=r\x-1, red] {\x};
754 \draw[red,thick,decorate,decoration={brace}]([yshift=0.1cm]r1-1.north west)--([yshift=0.1cm]r7-1.north east);
755 \end{tikzpicture}
756 }
757 \end{center}
758 This parameter, therefore, allows to correctly draw all the modules of the network. As it will be pointed out later better, knowing |P| is also important to define the range of applicability of the algorithm among the stages. Notice the network symmetry: the connections from stage 1 to stage 4 are exactly identical to the connections from stage 7 to stage 4.
759 \pagebreak
760
761 The first step is \emph{labelling} modules and ports. \saTikZ\ uses this rationale:
762 \begin{itemize}
763 \item progressive numeration for modules of the same stage;
764 \item progressive numeration for ports of the same module.
765 \end{itemize}
766
767 Thus:
768 \begin{center}
769 \scalebox{0.75}{
770 \begin{tikzpicture}[module size=0.75cm, module ysep=1, module xsep=3.5, connections disabled=true]
771 \node[P=16, benes complete]{};
772 \foreach \stg in {2,...,6}{
773 \foreach \module in {1,...,8}{
774 \node[right,font=\scriptsize] at (r\stg-\module-output-1) {1};
775 \node[right,font=\scriptsize] at (r\stg-\module-output-2) {2};
776 \node[left,font=\scriptsize] at (r\stg-\module-input-1) {1};
777 \node[left,font=\scriptsize] at (r\stg-\module-input-2) {2};
778 }
779 }
780 \foreach \module in {1,...,8}{
781 \node[right,font=\scriptsize] at (r1-\module-output-1) {1};
782 \node[right,font=\scriptsize] at (r1-\module-output-2) {2};
783 }
784 \foreach \module in {1,...,8}{
785 \node[left,font=\scriptsize] at (r7-\module-input-1) {1};
786 \node[left,font=\scriptsize] at (r7-\module-input-2) {2};
787 }
788 \end{tikzpicture}
789 }
790 \end{center}
791
792 Due to the network symmetry, the attention will be focused only on the left side of the network initially. On the right part of the network, things are dual.
793
794 \begin{center}
795 \scalebox{0.75}{
796 \begin{tikzpicture}[module size=0.75cm, module ysep=1, module xsep=3.5, connections disabled=true]
797 \node[P=16, benes complete]{};
798 \foreach \stg in {2,...,6}{
799 \foreach \module in {1,...,8}{
800 \node[right,font=\scriptsize] at (r\stg-\module-output-1) {1};
801 \node[right,font=\scriptsize] at (r\stg-\module-output-2) {2};
802 \node[left,font=\scriptsize] at (r\stg-\module-input-1) {1};
803 \node[left,font=\scriptsize] at (r\stg-\module-input-2) {2};
804 }
805 }
806 \foreach \module in {1,...,8}{
807 \node[right,font=\scriptsize] at (r1-\module-output-1) {1};
808 \node[right,font=\scriptsize] at (r1-\module-output-2) {2};
809 }
810 \foreach \module in {1,...,8}{
811 \node[left,font=\scriptsize] at (r7-\module-input-1) {1};
812 \node[left,font=\scriptsize] at (r7-\module-input-2) {2};
813 }
814 \begin{pgfonlayer}{background}
815 \draw[dashed, ultra thick, red, fill=red!10]
816 ($(r1-1-front input-1)+(-0.2,0.5)$)--($(r4-1-output-1)+(0.5,0.5)$)--($(r4-8-output-2)-(-0.5,0.5)$)--($(r1-8-front input-2)-(0.2,0.5)$)--cycle;
817 \end{pgfonlayer}
818 \end{tikzpicture}
819 }
820 \end{center}
821 \pagebreak
822
823 Now, by drawing some connections, it is possible to find a common behaviour:
824
825 \begin{center}
826 \scalebox{0.75}{
827 \begin{tikzpicture}[module size=0.75cm, module ysep=1, module xsep=3.5, connections disabled=true]
828 \node[P=16, benes complete]{};
829 \foreach \stg in {2,...,6}{
830 \foreach \module in {1,...,8}{
831 \node[right,font=\scriptsize] at (r\stg-\module-output-1) {1};
832 \node[right,font=\scriptsize] at (r\stg-\module-output-2) {2};
833 \node[left,font=\scriptsize] at (r\stg-\module-input-1) {1};
834 \node[left,font=\scriptsize] at (r\stg-\module-input-2) {2};
835 }
836 }
837 \foreach \module in {1,...,8}{
838 \node[right,font=\scriptsize] at (r1-\module-output-1) {1};
839 \node[right,font=\scriptsize] at (r1-\module-output-2) {2};
840 }
841 \foreach \module in {1,...,8}{
842 \node[left,font=\scriptsize] at (r7-\module-input-1) {1};
843 \node[left,font=\scriptsize] at (r7-\module-input-2) {2};
844 }
845 % some connections
846 \begin{pgfonlayer}{background}
847 % first-second stage
848 \draw[thick,red](r1-1-output-1)--(r2-1-input-1);
849 \draw[thick,red](r1-1-output-2)--(r2-5-input-1);
850 \draw[thick,red](r1-2-output-1)--(r2-1-input-2);
851 \draw[thick,red](r1-2-output-2)--(r2-5-input-2);
852 % second-third stage
853 \draw[thick,red](r2-1-output-1)--(r3-1-input-1);
854 \draw[thick,red](r2-1-output-2)--(r3-3-input-1);
855 \draw[thick,red](r2-2-output-1)--(r3-1-input-2);
856 \draw[thick,red](r2-2-output-2)--(r3-3-input-2);
857 \draw[thick,red](r2-3-output-1)--(r3-2-input-1);
858 \draw[thick,red](r2-3-output-2)--(r3-4-input-1);
859 \draw[thick,red](r2-4-output-1)--(r3-2-input-2);
860 \draw[thick,red](r2-4-output-2)--(r3-4-input-2);
861 % third-fourth stage
862 \draw[thick,red](r3-1-output-1)--(r4-1-input-1);
863 \draw[thick,red](r3-1-output-2)--(r4-2-input-1);
864 \draw[thick,red](r3-2-output-1)--(r4-1-input-2);
865 \draw[thick,red](r3-2-output-2)--(r4-2-input-2);
866 \end{pgfonlayer}
867 \end{tikzpicture}
868 }
869 \end{center}
870 \begin{itemize}
871 \item if the start module $st$ and the output port are odd (i.e. module 1, port 1), then it will be connected to
872 \[\textrm{end module}=\dfrac{st+1}{2} \; , \; \textrm{port}=1 \]
873 \item if the start module $st$ is odd and the output port is even (i.e. module 1, port 2), then it will be connected to
874 \[\textrm{end module}=\dfrac{st+1+\gamma}{2} \; , \; \textrm{port}=1 \]
875 \item if the start module $st$ is even and the output port is odd (i.e. module 2, port 1), then it will be connected to
876 \[\textrm{end module}=\dfrac{st}{2} \; , \; \textrm{port}=2 \]
877 \item if the start module $st$ and the output port are even (i.e. module 2, port 2), then it will be connected to
878 \[\textrm{end module}=\dfrac{st+\gamma}{2}\; , \; \textrm{port}=2 \]
879 \end{itemize}
880
881 What is the term $\gamma$? It is a corrective term that depends on the starting stage. Consider, indeed, the connections of the output port 2 of module 1 in the first and in the second starting stages:
882 \begin{flushleft}
883 \texttt{r1-1-output-2} \tikz[baseline=-0.5ex]\draw[-stealth](0,0)--(0.5,0); \texttt{r2-5-input-1}\\
884 \texttt{r2-1-output-2} \tikz[baseline=-0.5ex]\draw[-stealth](0,0)--(0.5,0); \texttt{r3-3-input-1}
885 \end{flushleft}
886 In the first case it points to module 5 while in the second case to module 3, thus $\gamma=8$ and $\gamma=4$ in the first case and in the second case respectively. This suggest that $\gamma$ is related in some sense to the stage of the start module: in our example |P|=16, hence the relation is
887 \[\gamma=\dfrac{P}{2^{stage}}\]
888
889 However, following this strategy allows to draw just part of the connections:
890 \begin{center}
891 \scalebox{0.75}{
892 \begin{tikzpicture}[module size=0.75cm, module ysep=1, module xsep=3.5, connections disabled=true]
893 \node[P=16, benes complete]{};
894 \foreach \stg in {2,...,6}{
895 \foreach \module in {1,...,8}{
896 \node[right,font=\scriptsize] at (r\stg-\module-output-1) {1};
897 \node[right,font=\scriptsize] at (r\stg-\module-output-2) {2};
898 \node[left,font=\scriptsize] at (r\stg-\module-input-1) {1};
899 \node[left,font=\scriptsize] at (r\stg-\module-input-2) {2};
900 }
901 }
902 \foreach \module in {1,...,8}{
903 \node[right,font=\scriptsize] at (r1-\module-output-1) {1};
904 \node[right,font=\scriptsize] at (r1-\module-output-2) {2};
905 }
906 \foreach \module in {1,...,8}{
907 \node[left,font=\scriptsize] at (r7-\module-input-1) {1};
908 \node[left,font=\scriptsize] at (r7-\module-input-2) {2};
909 }
910 % some connections
911 \begin{pgfonlayer}{background}
912 \foreach \stg[evaluate=\stg as \nextstg using int(\stg+1)] in {1,...,3}{
913 \pgfmathtruncatemacro\applicationon{16/(2^\stg)}% number of modules over which the algorithm is applied
914 \foreach \startmodule in {1,...,\applicationon}{
915 \pgfmathisodd{\startmodule}
916 \ifnum\pgfmathresult=1
917 % if odd
918 \pgfmathtruncatemacro\endmodulei{int((\startmodule+1)/2)}
919 \pgfmathtruncatemacro\endmoduleii{int(ceil(\startmodule+1+\applicationon)/2)}
920 \draw[red](r\stg-\startmodule-output-1)--(r\nextstg-\endmodulei-input-1);
921 \draw[red](r\stg-\startmodule-output-2)--(r\nextstg-\endmoduleii-input-1);
922 \else
923 % if even
924 \pgfmathtruncatemacro\endmodulei{int((\startmodule)/2)}
925 \pgfmathtruncatemacro\endmoduleii{int((\startmodule+\applicationon)/2)}
926 \draw[red](r\stg-\startmodule-output-1)--(r\nextstg-\endmodulei-input-2);
927 \draw[red](r\stg-\startmodule-output-2)--(r\nextstg-\endmoduleii-input-2);
928 \fi
929 }
930 }
931 \end{pgfonlayer}
932 \end{tikzpicture}
933 }
934 \end{center}
935 thus it is possible to claim that the algorithm has a \emph{module applicability range} that ultimately depends on the stage:
936 \begin{itemize}
937 \item in the first stage it could be applied for all modules;
938 \item in the second stage it could be applied for half of the modules;
939 \item in the third stage it could be applied just for two modules.
940 \end{itemize}
941 Since in the first stage $\gamma=8$ ($P/2^1$), in the second stage $\gamma=4$ ($P/2^2$) and in the third stage $\gamma=2$ ($P/2^3$): this means that $\gamma$ defines the \emph{module applicability range}.
942
943 Notice now, that for the second stage and the third stage, the algorithm should be simply repeated:
944 \begin{itemize}
945 \item in the second stage 2 times;
946 \item in the third stage 4 times.
947 \end{itemize}
948 The repetition $\psi$ depends on the stage according to the following relation:
949 \[\psi= 2^{stage-1}\]
950 Now, to draw automatically all the connections, the algorithm should know which are the starting module and ending module of the \emph{module applicability range} during the repetitions: for example, in the second stage, how to identify automatically the applicability range \texttt{1-4}, \texttt{5-8}?
951
952 \begin{center}
953 \scalebox{0.75}{
954 \begin{tikzpicture}[module size=0.75cm, module ysep=1, module xsep=3.5, connections disabled=true]
955 \node[P=16, benes complete]{};
956 \foreach \stg in {2,...,6}{
957 \foreach \module in {1,...,8}{
958 \node[right,font=\scriptsize] at (r\stg-\module-output-1) {1};
959 \node[right,font=\scriptsize] at (r\stg-\module-output-2) {2};
960 \node[left,font=\scriptsize] at (r\stg-\module-input-1) {1};
961 \node[left,font=\scriptsize] at (r\stg-\module-input-2) {2};
962 }
963 }
964 \foreach \module in {1,...,8}{
965 \node[right,font=\scriptsize] at (r1-\module-output-1) {1};
966 \node[right,font=\scriptsize] at (r1-\module-output-2) {2};
967 }
968 \foreach \module in {1,...,8}{
969 \node[left,font=\scriptsize] at (r7-\module-input-1) {1};
970 \node[left,font=\scriptsize] at (r7-\module-input-2) {2};
971 }
972 % some connections
973 \begin{pgfonlayer}{background}
974 \filldraw[fill=blue!10,draw=white,rounded corners]($(r2-4)-(0.75,0.5)$)rectangle ($(r2-1)+(0.75,0.5)$);
975 \filldraw[fill=green!10,draw=white,rounded corners]($(r2-8)-(0.75,0.5)$)rectangle ($(r2-5)+(0.75,0.5)$);
976 \foreach \stg[evaluate=\stg as \nextstg using int(\stg+1)] in {1,...,3}{
977 \pgfmathtruncatemacro\applicationon{16/(2^\stg)}% number of modules over which the algorithm is applied
978 \foreach \startmodule in {1,...,\applicationon}{
979 \pgfmathisodd{\startmodule}
980 \ifnum\pgfmathresult=1
981 % if odd
982 \pgfmathtruncatemacro\endmodulei{int((\startmodule+1)/2)}
983 \pgfmathtruncatemacro\endmoduleii{int(ceil(\startmodule+1+\applicationon)/2)}
984 \draw[red](r\stg-\startmodule-output-1)--(r\nextstg-\endmodulei-input-1);
985 \draw[red](r\stg-\startmodule-output-2)--(r\nextstg-\endmoduleii-input-1);
986 \else
987 % if even
988 \pgfmathtruncatemacro\endmodulei{int((\startmodule)/2)}
989 \pgfmathtruncatemacro\endmoduleii{int((\startmodule+\applicationon)/2)}
990 \draw[red](r\stg-\startmodule-output-1)--(r\nextstg-\endmodulei-input-2);
991 \draw[red](r\stg-\startmodule-output-2)--(r\nextstg-\endmoduleii-input-2);
992 \fi
993 }
994 }
995
996 \draw($(r2-8)-(1,1)$)rectangle ($(r3-1)+(1,1)$);
997 \end{pgfonlayer}
998 \end{tikzpicture}
999 }
1000 \end{center}
1001
1002 They could be defined as:
1003 \begin{itemize}
1004 \item starting module: $st_m=1+(\psi-1)\cdot\gamma $;
1005 \item ending module: $end_m=(st_m+\gamma)-1$.
1006 \end{itemize}
1007 Indeed, for the second stage we have that $\gamma=4$ and $\psi=2\implies \{1,\, 2\}$, hence there are two starting and ending modules:
1008 \begin{itemize}
1009 \item starting modules: $st_{m_1}=1+(1-1)\cdot 4=1$ and $st_{m_2}=1+(2-1)\cdot 4=5$;
1010 \item ending modules: $end_{m_1}=(1+4)-1=4$ and $end_{m_2}=(5+4)-1=8$.
1011 \end{itemize}
1012 Unfortunately, the knowledge of the starting and ending modules of each stage is not sufficient to reach the goal: the reason is that the algorithm works and draws the connections in a correct manner when the module labels start with 1. However, during the repetitions the new starting module labels are different, thus the computation of the end connection point fails. This difference should be compensated with \emph{shifts} of the ending modules that depend on the level of repetition. The rules are:
1013 \begin{itemize}
1014 \item if $\psi=1$ (the algorithm works for all modules of the stage), then the ending module of the connection is computed as:
1015 \begin{itemize}
1016 \item if the start module $st$ and the output port are odd (i.e. module 1, port 1), then it will be connected to
1017 \[\textrm{end module}=\dfrac{st+1}{2} \; , \; \textrm{port}=1 \]
1018 \item if the start module $st$ is odd and the output port is even (i.e. module 1, port 2), then it will be connected to
1019 \[\textrm{end module}=\dfrac{st+1+\gamma}{2}\; , \; \textrm{port}=1 \]
1020 \item if the start module $st$ is even and the output port is odd (i.e. module 2, port 1), then it will be connected to
1021 \[\textrm{end module}=\dfrac{st}{2} \; , \; \textrm{port}=2 \]
1022 \item if the start module $st$ and the output port are even (i.e. module 2, port 2), then it will be connected to
1023 \[\textrm{end module}=\dfrac{st+\gamma}{2}\; , \; \textrm{port}=2 \]
1024 \end{itemize}
1025 \item if $\psi=2$ (the algorithm should be repeated twice), then the ending module of the connection is computed as
1026 \begin{itemize}
1027 \item if the start module $st$ and the output port are odd (i.e. module 1, port 1), then it will be connected to
1028 \[\textrm{end module}=\dfrac{st+1}{2}+\dfrac{\gamma}{2} \; , \; \textrm{port}=1 \]
1029 \item if the start module $st$ is odd and the output port is even (i.e. module 1, port 2), then it will be connected to
1030 \[\textrm{end module}=\dfrac{st+1+\gamma}{2}+\dfrac{\gamma}{2}\; , \; \textrm{port}=1 \]
1031 \item if the start module $st$ is even and the output port is odd (i.e. module 2, port 1), then it will be connected to
1032 \[\textrm{end module}=\dfrac{st}{2}+\dfrac{\gamma}{2} \; , \; \textrm{port}=2 \]
1033 \item if the start module $st$ and the output port are even (i.e. module 2, port 2), then it will be connected to
1034 \[\textrm{end module}=\dfrac{st+\gamma}{2}+\dfrac{\gamma}{2}\; , \; \textrm{port}=2 \]
1035 \end{itemize}
1036 \item if $\psi>2\implies t=3,\ldots, \psi$ (the algorithm should be repeated more than twice), then the ending module of the connection is computed as:
1037 \begin{itemize}
1038 \item if the start module $st$ and the output port are odd (i.e. module 1, port 1), then it will be connected to
1039 \[\textrm{end module}=\dfrac{st+1}{2}+\left(\dfrac{\gamma}{2}\cdot (t-2)\right) \; , \; \textrm{port}=1 \]
1040 \item if the start module $st$ is odd and the output port is even (i.e. module 1, port 2), then it will be connected to
1041 \[\textrm{end module}=\dfrac{st+1+\gamma}{2}+\dfrac{\gamma}{2}+\left(\dfrac{\gamma}{2}\cdot (t-2)\right)\; , \; \textrm{port}=1 \]
1042 \item if the start module $st$ is even and the output port is odd (i.e. module 2, port 1), then it will be connected to
1043 \[\textrm{end module}=\dfrac{st}{2}+\left(\dfrac{\gamma}{2}\cdot (t-2)\right)\; , \; \textrm{port}=2 \]
1044 \item if the start module $st$ and the output port are even (i.e. module 2, port 2), then it will be connected to
1045 \[\textrm{end module}=\dfrac{st+\gamma}{2}+\dfrac{\gamma}{2}+\left(\dfrac{\gamma}{2}\cdot (t-2)\right)\; , \; \textrm{port}=2 \]
1046 \end{itemize}
1047 \end{itemize}
1048 Unfortunately, the rule $\psi>2$ when it is applied to the intermediate stages
1049 \[I_1=\lfloor\mathcal{S}\div 2\rfloor \hspace*{1cm} I_2=\mathcal{S}-(I_1-1)\]
1050 does not work; this implies that:
1051 \begin{itemize}
1052 \item on the left side of the network the applicability of the algorithm is from the starting stage 1 up to the starting stage $I_1-1$ (in the example |P|=16: from the starting stage 1 up to the starting stage 2);
1053 \item on the right side of the network the applicability of the algorithm is from the starting stage $\mathcal{S}$ up to the starting stage $I_2-1$ (in the example |P|=16: from the starting stage 7 up to the starting stage 6);
1054 \item for the intermediate starting stages $I_1$ and $I_2$ (in the example |P|=16: the stages 3 and 5) another rule should be used:
1055 \begin{itemize}
1056 \item if the start module $st$ and the output port are odd (i.e. module 1, port 1), then it will be connected to
1057 \[\textrm{end module}=st\; , \; \textrm{port}=1 \]
1058 \item if the start module $st$ is odd and the output port is even (i.e. module 1, port 2), then it will be connected to
1059 \[\textrm{end module}=st+1\; , \; \textrm{port}=1 \]
1060 \item if the start module $st$ is even and the output port is odd (i.e. module 2, port 1), then it will be connected to
1061 \[\textrm{end module}=st-1 \; , \; \textrm{port}=2 \]
1062 \item if the start module $st$ and the output port are even (i.e. module 2, port 2), then it will be connected to
1063 \[\textrm{end module}=st\; , \; \textrm{port}=2 \]
1064 \end{itemize}
1065 \end{itemize}
1066
1067 To summarize, the algorithm to \textbf{d}raw \textbf{B}enes \textbf{n}etwork \textbf{c}onnections (dBnc) is reported in~\ref{algo_dBnc}: for the rules, please refer to the afore-mentioned description.
1068
1069 \begin{algorithm}
1070 compute $\mathcal{S}=2\log_2{P}-1$\;
1071 compute $I_1=\lfloor\mathcal{S}\div 2\rfloor$\;
1072 compute $I_2=\mathcal{S}-(I_1-1)$\;
1073 \emph{from left to right}\;
1074 \For{$stg\leftarrow 1$ \KwTo $(I_1-1)$}{
1075 compute $\gamma=P\div 2^{stg}$\;
1076 compute $\psi=2^{stg-1}$\;
1077 \For{$t\leftarrow 1$ \KwTo $\psi$}{
1078 compute starting point $x=1+((t-1)\cdot\gamma)$\;
1079 compute ending point $y=(x+\gamma)-1$\;
1080 \ForEach{$\textrm{ start module } s \textrm{ in set } (x,y)$}{
1081 \uIf{$t==1$}{
1082 \uIf{$s$ is odd}{
1083 use rules $\psi=1$ for starting module odd\;
1084 }
1085 \Else{
1086 use rules $\psi=1$ for starting module even\;
1087 }
1088 }
1089 \uIf{$t==2$}{
1090 \uIf{$s$ is odd}{
1091 use rules $\psi=2$ for starting module odd\;
1092 }
1093 \Else{
1094 use rules $\psi=2$ for starting module even\;
1095 }
1096 }
1097 \uIf{$t>2$}{
1098 \uIf{$s$ is odd}{
1099 use rules $\psi>2$ for starting module odd\;
1100 }
1101 \Else{
1102 use rules $\psi>2$ for starting module even\;
1103 }
1104 }
1105 }
1106 }
1107 }
1108 \emph{from right to left}\;
1109 \For{$stg\leftarrow \mathcal{S}$ \KwTo $(I_2-1)$}{
1110 repeat in dual mode $\textbf{6}-\textbf{32}$\;
1111 }
1112 \emph{complete with intermediate stages}\;
1113 \ForEach{$stg$ in set $(I_1,\, I_2)$}{
1114 use rules for intermediate stages\;
1115 }
1116 \caption{\textbf{d}raw \textbf{B}enes \textbf{n}etwork \textbf{c}onnections (dBnc)}\label{algo_dBnc}
1117 \end{algorithm}
1118
1119
1120 % * * * * * * * * * * * * * * * * * * * * * * * * * *
1121 % belongs to \usepackage{makeindex}
1122 \printindex
1123 \end{document}