| 1 |
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 2 |
% |
| 3 |
% Sa-TikZ package v0.7a * * (C) Claudio Fiandrino 2012-2014 |
| 4 |
% |
| 5 |
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 6 |
\NeedsTeXFormat{LaTeX2e} |
| 7 |
\ProvidesPackage{sa-tikz}[2014/1/29 v0.7a Switching architectures design library.] |
| 8 |
\RequirePackage{tikz} |
| 9 |
\usetikzlibrary{backgrounds,calc,positioning,decorations.pathreplacing} |
| 10 |
|
| 11 |
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 12 |
% UTILITY |
| 13 |
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 14 |
|
| 15 |
% PGFMATHISODD: 1 = true, 0 = false |
| 16 |
% from TikZ 3.0.0 |
| 17 |
% Test for checking whether \pgfmathisodd is defined or not |
| 18 |
% for compatibility with TikZ 2.10 |
| 19 |
% |
| 20 |
\@ifundefined{pgfmathisodd}{ |
| 21 |
\pgfmathdeclarefunction{isodd}{1}{% |
| 22 |
\begingroup |
| 23 |
\pgfmathsetcount\c@pgfmath@counta{abs(int(#1))}% |
| 24 |
\ifodd\c@pgfmath@counta |
| 25 |
\def\pgfmathresult{1}% |
| 26 |
\else |
| 27 |
\def\pgfmathresult{0}% |
| 28 |
\fi |
| 29 |
\pgfmath@smuggleone\pgfmathresult |
| 30 |
\endgroup} |
| 31 |
}{} |
| 32 |
|
| 33 |
% PGFMATHOMEGAROTATION: |
| 34 |
% |
| 35 |
% #1: number to be rotated |
| 36 |
% #2: numbers of bits |
| 37 |
% #3: output macro |
| 38 |
% |
| 39 |
\newcommand*{\pgfmathomegarotation}[3]{ |
| 40 |
\pgfmathisodd{#1} |
| 41 |
\ifnum\pgfmathresult=1 |
| 42 |
\pgfmathparse{#1/2 + 2^#2} |
| 43 |
\else |
| 44 |
\pgfmathparse{#1/2} |
| 45 |
\fi |
| 46 |
\pgfmathtruncatemacro\res\pgfmathresult |
| 47 |
\global\expandafter\edef\csname #3\endcsname{\res} |
| 48 |
} |
| 49 |
|
| 50 |
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 51 |
% KEY DEFINITION - Design choices |
| 52 |
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 53 |
|
| 54 |
% * * * * * * * * * * * * * * * * * * |
| 55 |
% CLOS |
| 56 |
% * * * * * * * * * * * * * * * * * * |
| 57 |
|
| 58 |
% N is the key representing the number of inputs x number of modules first stage |
| 59 |
\pgfkeys{/tikz/.cd,% |
| 60 |
N/.store in=\N,% |
| 61 |
N=10,% |
| 62 |
}% |
| 63 |
|
| 64 |
% N label |
| 65 |
\pgfkeys{/tikz/.cd,% |
| 66 |
N label/.store in=\Nlabel,% |
| 67 |
N label=N,% |
| 68 |
}% |
| 69 |
|
| 70 |
% r1 is the number of modules first stage |
| 71 |
% m1 is the number of inputs first stage per module |
| 72 |
|
| 73 |
\pgfkeys{/tikz/.cd,% |
| 74 |
r1/.store in=\rone,% |
| 75 |
r1=5,% |
| 76 |
}% |
| 77 |
|
| 78 |
% r1 label |
| 79 |
\pgfkeys{/tikz/.cd,% |
| 80 |
r1 label/.store in=\ronelabel,% |
| 81 |
r1 label={r\ensuremath{_1}},% |
| 82 |
}% |
| 83 |
|
| 84 |
% m1 label |
| 85 |
\pgfkeys{/tikz/.cd,% |
| 86 |
m1 label/.store in=\monelabel,% |
| 87 |
m1 label={m\ensuremath{_1}},% |
| 88 |
}% |
| 89 |
|
| 90 |
% r2 label |
| 91 |
\pgfkeys{/tikz/.cd,% |
| 92 |
r2 label/.store in=\rtwolabel,% |
| 93 |
r2 label={r\ensuremath{_2}},% |
| 94 |
}% |
| 95 |
|
| 96 |
% M is the key representing the number of inputs x number of modules last stage |
| 97 |
\pgfkeys{/tikz/.cd,% |
| 98 |
M/.store in=\M,% |
| 99 |
M=10,% |
| 100 |
}% |
| 101 |
|
| 102 |
% M label |
| 103 |
\pgfkeys{/tikz/.cd,% |
| 104 |
M label/.store in=\Mlabel,% |
| 105 |
M label=M,% |
| 106 |
}% |
| 107 |
|
| 108 |
% r3 is the number of modules last stage |
| 109 |
% m3 is the number of inputs last stage per module |
| 110 |
\pgfkeys{/tikz/.cd,% |
| 111 |
r3/.store in=\rthree,% |
| 112 |
r3=5 |
| 113 |
}% |
| 114 |
|
| 115 |
% r3 label |
| 116 |
\pgfkeys{/tikz/.cd,% |
| 117 |
r3 label/.store in=\rthreelabel,% |
| 118 |
r3 label={r\ensuremath{_3}},% |
| 119 |
}% |
| 120 |
|
| 121 |
% m3 label |
| 122 |
\pgfkeys{/tikz/.cd, |
| 123 |
m3 label/.store in=\mthreelabel,% |
| 124 |
m3 label={m\ensuremath{_3}},% |
| 125 |
}% |
| 126 |
|
| 127 |
% * * * * * * * * * * * * * * * * * * |
| 128 |
% BENES |
| 129 |
% * * * * * * * * * * * * * * * * * * |
| 130 |
|
| 131 |
% P is the number of input/output ports |
| 132 |
\pgfkeys{/tikz/.cd,% |
| 133 |
P/.store in=\P,% |
| 134 |
P=8,% |
| 135 |
}% |
| 136 |
|
| 137 |
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 138 |
% GENERAL SETTINGS - Keys and styles |
| 139 |
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 140 |
|
| 141 |
% module customization |
| 142 |
\pgfkeys{/tikz/.cd,% |
| 143 |
module size/.store in=\modulesize,% |
| 144 |
module size={1cm},% |
| 145 |
}% |
| 146 |
|
| 147 |
\pgfkeys{/tikz/.cd,% |
| 148 |
module ysep/.store in=\moduleysep,% |
| 149 |
module ysep={1.5}, |
| 150 |
}% |
| 151 |
|
| 152 |
\pgfkeys{/tikz/.cd,% |
| 153 |
module xsep/.store in=\modulexsep,% |
| 154 |
module xsep={3},% |
| 155 |
}% |
| 156 |
|
| 157 |
\pgfkeys{/tikz/.cd,% |
| 158 |
module font/.store in=\modulefont,% |
| 159 |
module font={\normalfont},% |
| 160 |
}% |
| 161 |
|
| 162 |
\tikzset{module/.style={% |
| 163 |
draw,rectangle, minimum size=\modulesize, |
| 164 |
font=\modulefont, |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
\tikzset{module extensible/.style={% |
| 169 |
draw,rectangle, minimum size=#1, |
| 170 |
}, |
| 171 |
module extensible/.default={\modulesize} |
| 172 |
} |
| 173 |
|
| 174 |
\pgfkeys{/tikz/.cd,% |
| 175 |
module label opacity/.store in=\modulelabelopacity,% |
| 176 |
module label opacity={1},% |
| 177 |
}% |
| 178 |
|
| 179 |
\tikzset{module opacity/.style={ |
| 180 |
text opacity=\modulelabelopacity, |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
\pgfkeys{/tikz/.cd,% |
| 185 |
pin length factor/.store in=\pinlength,% |
| 186 |
pin length factor={1},% |
| 187 |
}% |
| 188 |
|
| 189 |
% setting labels in math mode |
| 190 |
|
| 191 |
\tikzset{math mode labels/.style={% |
| 192 |
execute at begin node=$,% |
| 193 |
execute at end node=$,% |
| 194 |
} |
| 195 |
} |
| 196 |
\pgfkeys{/tikz/.cd,% |
| 197 |
use math mode labels/.is choice,% |
| 198 |
use math mode labels/true/.style={math mode labels},% |
| 199 |
use math mode labels/false/.style={},% |
| 200 |
}% |
| 201 |
|
| 202 |
\tikzset{set math mode labels/.style={% |
| 203 |
use math mode labels=#1,% |
| 204 |
},% |
| 205 |
set math mode labels/.default=false,% |
| 206 |
} |
| 207 |
|
| 208 |
% disable the connections |
| 209 |
\newif\ifconnectiondisabled% |
| 210 |
\pgfkeys{/tikz/.cd, connections disabled/.is if=connectiondisabled}% |
| 211 |
\pgfkeys{/tikz/.cd, connections disabled/.default=false}% |
| 212 |
|
| 213 |
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 214 |
% CODE |
| 215 |
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 216 |
|
| 217 |
% CLOS SNB |
| 218 |
\tikzset{clos snb/.code={ |
| 219 |
|
| 220 |
% Number of ports per module |
| 221 |
\pgfmathtruncatemacro{\mone}{\N/\rone} |
| 222 |
\pgfmathtruncatemacro{\mthree}{\M/\rthree} |
| 223 |
|
| 224 |
% COMPUTATION SNB CONDITION |
| 225 |
\pgfmathtruncatemacro\rtwo{\mone+\mthree-1} |
| 226 |
|
| 227 |
% MODULE 1 |
| 228 |
\foreach \i in {1,...,\rone}{ |
| 229 |
\path let \n1 = {int(0-\i)}, \n2={0-\i*\moduleysep} |
| 230 |
in |
| 231 |
node[module,#1,module opacity,yshift=1cm] (r1-\i) at +(0,\n2) {\pgfmathparse{int(multiply(\n1,-1))}\pgfmathresult}; |
| 232 |
|
| 233 |
% INPUTS MODULE 1 |
| 234 |
% the number of inputs module one is exactly \mone |
| 235 |
\pgfmathsetmacro\roneintervalspace{1/(\mone+1)} |
| 236 |
\foreach \roneinput[evaluate=\roneinput as \roneinterval using \roneintervalspace*\roneinput] |
| 237 |
in {1,...,\mone} |
| 238 |
\draw ($(r1-\i.north west)!\roneinterval!(r1-\i.south west)-(0.5*\pinlength,0)$)node[scale=0.1](r1-\i-front input-\roneinput){}--($(r1-\i.north west)!\roneinterval!(r1-\i.south west)$) node[circle,draw,scale=0.1] (r1-\i-input-\roneinput) {}; |
| 239 |
|
| 240 |
% OUTPUTS MODULE 1 |
| 241 |
% the number of outputs of module one is the number of modules stage 2 \rtwo |
| 242 |
\pgfmathsetmacro\roneintervalspace{1/(\rtwo+1)} |
| 243 |
\foreach \roneoutput[evaluate=\roneoutput as \roneinterval using \roneintervalspace*\roneoutput] |
| 244 |
in {1,...,\rtwo} |
| 245 |
\node[circle,draw,scale=0.1] (r1-\i-output-\roneoutput)at($(r1-\i.north east)!\roneinterval!(r1-\i.south east)$) {}; |
| 246 |
} |
| 247 |
|
| 248 |
% MODULE 2 |
| 249 |
\foreach \i in {1,...,\rtwo}{ |
| 250 |
\path let \n1 = {int(0-\i)}, \n2={0-\i*\moduleysep} |
| 251 |
in |
| 252 |
node[module,#1,module opacity,yshift=1cm] (r2-\i) at +(\modulexsep,\n2) {\pgfmathparse{int(multiply(\n1,-1))}\pgfmathresult}; |
| 253 |
|
| 254 |
% INPUTS MODULE 2 |
| 255 |
% the number of inputs of module two is the number of modules stage 1 \rone |
| 256 |
\pgfmathsetmacro\rtwointervalspace{1/(\rone+1)} |
| 257 |
\foreach \rtwoinput[evaluate=\rtwoinput as \rtwointerval using \rtwointervalspace*\rtwoinput] |
| 258 |
in {1,...,\rone} |
| 259 |
\node[circle,draw,scale=0.1] (r2-\i-input-\rtwoinput)at($(r2-\i.north west)!\rtwointerval!(r2-\i.south west)$) {}; |
| 260 |
|
| 261 |
% OUTPUTS MODULE 2 |
| 262 |
% the number of outputs module two is exactly \rthree |
| 263 |
\pgfmathsetmacro\rtwointervalspace{1/(\rthree+1)} |
| 264 |
\foreach \rtwooutput[evaluate=\rtwooutput as \rtwointerval using \rtwointervalspace*\rtwooutput] |
| 265 |
in {1,...,\rthree} |
| 266 |
\node[circle,draw,scale=0.1] (r2-\i-output-\rtwooutput)at ($(r2-\i.north east)!\rtwointerval!(r2-\i.south east)$) {}; |
| 267 |
|
| 268 |
} |
| 269 |
|
| 270 |
% MODULE 3 |
| 271 |
\foreach \i in {1,...,\rthree}{ |
| 272 |
\path let \n1 = {int(0-\i)}, \n2={0-\i*\moduleysep} |
| 273 |
in |
| 274 |
node[module,#1,module opacity,yshift=1cm] (r3-\i) at +(2*\modulexsep,\n2) {\pgfmathparse{int(multiply(\n1,-1))}\pgfmathresult}; |
| 275 |
|
| 276 |
% INPUTS MODULE 3 |
| 277 |
% the number of inputs of module three is the number of modules stage 2 \rtwo |
| 278 |
\pgfmathsetmacro\rthreeintervalspace{1/(\rtwo+1)} |
| 279 |
\foreach \rthreeinput[evaluate=\rthreeinput as \rthreeinterval using \rthreeintervalspace*\rthreeinput] |
| 280 |
in {1,...,\rtwo} |
| 281 |
\node[circle,draw,scale=0.1] (r3-\i-input-\rthreeinput)at($(r3-\i.north west)!\rthreeinterval!(r3-\i.south west)$) {}; |
| 282 |
|
| 283 |
% OUTPUTS MODULE 3 |
| 284 |
% the number of outputs module three is exactly \mthree |
| 285 |
\pgfmathsetmacro\rthreeintervalspace{1/(\mthree+1)} |
| 286 |
\foreach \rthreeoutput[evaluate=\rthreeoutput as \rthreeinterval using \rthreeintervalspace*\rthreeoutput] |
| 287 |
in {1,...,\mthree} |
| 288 |
\draw ($(r3-\i.north east)!\rthreeinterval!(r3-\i.south east)+(0.5*\pinlength,0)$)node[scale=0.1](r3-\i-front output-\rthreeoutput){}--($(r3-\i.north east)!\rthreeinterval!(r3-\i.south east)$) node[circle,draw,scale=0.1] (r3-\i-output-\rthreeoutput) {}; |
| 289 |
|
| 290 |
} |
| 291 |
|
| 292 |
% Test if connections should be removed |
| 293 |
\ifconnectiondisabled |
| 294 |
\relax |
| 295 |
\else |
| 296 |
% DRAWING CONNECTIONS |
| 297 |
%% from r1 to r2 |
| 298 |
\foreach \startmodule in {1,...,\rone}{ |
| 299 |
\foreach \conn in {1,...,\rtwo} |
| 300 |
\draw(r1-\startmodule-output-\conn)--(r2-\conn-input-\startmodule); |
| 301 |
} |
| 302 |
%% from r2 to r3 |
| 303 |
\foreach \startmodule in {1,...,\rthree}{ |
| 304 |
\foreach \conn in {1,...,\rtwo} |
| 305 |
\draw(r3-\startmodule-input-\conn)--(r2-\conn-output-\startmodule); |
| 306 |
} |
| 307 |
\fi |
| 308 |
}, |
| 309 |
} |
| 310 |
|
| 311 |
\tikzset{clos snb example/.code={ |
| 312 |
|
| 313 |
% Number of ports per module |
| 314 |
\pgfmathtruncatemacro{\mone}{\N/\rone} |
| 315 |
\pgfmathtruncatemacro{\mthree}{\M/\rthree} |
| 316 |
|
| 317 |
% COMPUTATION SNB CONDITION |
| 318 |
\pgfmathtruncatemacro\rtwo{\mone+\mthree-1} |
| 319 |
|
| 320 |
% MODULE 1 |
| 321 |
\node[module,#1,module opacity](r1-1) at (0,0) {1}; |
| 322 |
\node[below of=r1-1,yshift=0.75ex](r1-dots) {\vdots}; |
| 323 |
\node[module,#1,module opacity,below of=r1-dots](r1-2) {\rone}; |
| 324 |
|
| 325 |
\foreach \i in {1,2}{ |
| 326 |
% INPUTS MODULE 1 |
| 327 |
% just two modules |
| 328 |
\pgfmathsetmacro\roneintervalspace{1/(2+1)} |
| 329 |
\foreach \roneinput[evaluate=\roneinput as \roneinterval using \roneintervalspace*\roneinput] |
| 330 |
in {1,2} |
| 331 |
\draw ($(r1-\i.north west)!\roneinterval!(r1-\i.south west)-(0.5*\pinlength,0)$)node[scale=0.1](r1-\i-front input-\roneinput){}--($(r1-\i.north west)!\roneinterval!(r1-\i.south west)$) node[circle,draw,scale=0.1] (r1-\i-input-\roneinput) {}; |
| 332 |
|
| 333 |
% OUTPUTS MODULE 1 |
| 334 |
% just two modules |
| 335 |
\pgfmathsetmacro\roneintervalspace{1/(2+1)} |
| 336 |
\foreach \roneoutput[evaluate=\roneoutput as \roneinterval using \roneintervalspace*\roneoutput] |
| 337 |
in {1,2} |
| 338 |
\node[circle,draw,scale=0.1] (r1-\i-output-\roneoutput)at($(r1-\i.north east)!\roneinterval!(r1-\i.south east)$) {}; |
| 339 |
} |
| 340 |
|
| 341 |
% MODULE 2 |
| 342 |
\node[module,#1,module opacity](r2-1) at (\modulexsep,0) {1}; |
| 343 |
\node[below of=r2-1,yshift=0.75ex](r2-dots) {\vdots}; |
| 344 |
\node[module,#1,module opacity,below of=r2-dots](r2-2) {\rtwo}; |
| 345 |
|
| 346 |
\foreach \i in {1,2}{ |
| 347 |
% INPUTS MODULE 2 |
| 348 |
% just two modules |
| 349 |
\pgfmathsetmacro\rtwointervalspace{1/(2+1)} |
| 350 |
\foreach \rtwoinput[evaluate=\rtwoinput as \rtwointerval using \rtwointervalspace*\rtwoinput] |
| 351 |
in {1,2} |
| 352 |
\node[circle,draw,scale=0.1] (r2-\i-input-\rtwoinput)at($(r2-\i.north west)!\rtwointerval!(r2-\i.south west)$) {}; |
| 353 |
|
| 354 |
% OUTPUTS MODULE 2 |
| 355 |
% just two modules |
| 356 |
\pgfmathsetmacro\rtwointervalspace{1/(2+1)} |
| 357 |
\foreach \rtwooutput[evaluate=\rtwooutput as \rtwointerval using \rtwointervalspace*\rtwooutput] |
| 358 |
in {1,2} |
| 359 |
\node[circle,draw,scale=0.1] (r2-\i-output-\rtwooutput)at ($(r2-\i.north east)!\rtwointerval!(r2-\i.south east)$) {}; |
| 360 |
} |
| 361 |
|
| 362 |
% MODULE 3 |
| 363 |
\node[module,#1,module opacity](r3-1) at (2*\modulexsep,0) {1}; |
| 364 |
\node[below of=r3-1,yshift=0.75ex](r3-dots) {\vdots}; |
| 365 |
\node[module,#1,module opacity,below of=r3-dots](r3-2) {\rthree}; |
| 366 |
|
| 367 |
\foreach \i in {1,2}{ |
| 368 |
% INPUTS MODULE 3 |
| 369 |
% just two modules |
| 370 |
\pgfmathsetmacro\rthreeintervalspace{1/(2+1)} |
| 371 |
\foreach \rthreeinput[evaluate=\rthreeinput as \rthreeinterval using \rthreeintervalspace*\rthreeinput] |
| 372 |
in {1,2} |
| 373 |
\node[circle,draw,scale=0.1] (r3-\i-input-\rthreeinput)at($(r3-\i.north west)!\rthreeinterval!(r3-\i.south west)$) {}; |
| 374 |
|
| 375 |
% OUTPUTS MODULE 3 |
| 376 |
% just two modules |
| 377 |
\pgfmathsetmacro\rthreeintervalspace{1/(2+1)} |
| 378 |
\foreach \rthreeoutput[evaluate=\rthreeoutput as \rthreeinterval using \rthreeintervalspace*\rthreeoutput] |
| 379 |
in {1,2} |
| 380 |
\draw ($(r3-\i.north east)!\rthreeinterval!(r3-\i.south east)+(0.5*\pinlength,0)$)node[scale=0.1](r3-\i-front output-\rthreeoutput){}--($(r3-\i.north east)!\rthreeinterval!(r3-\i.south east)$) node[circle,draw,scale=0.1] (r3-\i-output-\rthreeoutput) {}; |
| 381 |
} |
| 382 |
|
| 383 |
% DRAWING CONNECTIONS |
| 384 |
%% from r1 to r2 |
| 385 |
\foreach \startmodule in {1,2}{ |
| 386 |
\foreach \conn in {1,2} |
| 387 |
\draw(r1-\startmodule-output-\conn)--(r2-\conn-input-\startmodule); |
| 388 |
} |
| 389 |
%% from r2 to r3 |
| 390 |
\foreach \startmodule in {1,2}{ |
| 391 |
\foreach \conn in {1,2} |
| 392 |
\draw(r3-\startmodule-input-\conn)--(r2-\conn-output-\startmodule); |
| 393 |
} |
| 394 |
|
| 395 |
% SETTING LABELS |
| 396 |
\node[below of=r1-2,set math mode labels] {\mone~\ensuremath{\times}~\rtwo}; |
| 397 |
\node[below of=r2-2,set math mode labels] {\rone~\ensuremath{\times}~\rthree}; |
| 398 |
\node[below of=r3-2,set math mode labels] {\rtwo~\ensuremath{\times}~\mthree}; |
| 399 |
\draw[decorate,decoration={brace}]($(r1-2-front input-2)-(0.1,0)$)--($(r1-1-front input-1)-(0.1,0)$) node[midway,left=0.1cm,set math mode labels]{\N}; |
| 400 |
\draw[decorate,decoration={brace}]($(r3-1-front output-1)+(0.1,0)$)--($(r3-2-front output-2)+(0.1,0)$) node[midway,right=0.1cm,set math mode labels]{\M}; |
| 401 |
}, |
| 402 |
} |
| 403 |
|
| 404 |
% CLOS REAR |
| 405 |
|
| 406 |
\tikzset{clos rear/.code={ |
| 407 |
|
| 408 |
% Number of ports per module |
| 409 |
\pgfmathtruncatemacro{\mone}{\N/\rone} |
| 410 |
\pgfmathtruncatemacro{\mthree}{\M/\rthree} |
| 411 |
|
| 412 |
% COMPUTATION REAR CONDITION |
| 413 |
\pgfmathtruncatemacro\rtwo{max(\mone,\mthree)} |
| 414 |
|
| 415 |
% MODULE 1 |
| 416 |
\foreach \i in {1,...,\rone}{ |
| 417 |
\path let \n1 = {int(0-\i)}, \n2={0-\i*\moduleysep} |
| 418 |
in |
| 419 |
node[module,#1,module opacity,yshift=1cm] (r1-\i) at +(0,\n2) {\pgfmathparse{int(multiply(\n1,-1))}\pgfmathresult}; |
| 420 |
|
| 421 |
% INPUTS MODULE 1 |
| 422 |
% the number of inputs module one is exactly \mone |
| 423 |
\pgfmathsetmacro\roneintervalspace{1/(\mone+1)} |
| 424 |
\foreach \roneinput[evaluate=\roneinput as \roneinterval using \roneintervalspace*\roneinput] |
| 425 |
in {1,...,\mone} |
| 426 |
\draw ($(r1-\i.north west)!\roneinterval!(r1-\i.south west)-(0.5*\pinlength,0)$)node[scale=0.1](r1-\i-front input-\roneinput){}--($(r1-\i.north west)!\roneinterval!(r1-\i.south west)$) node[circle,draw,scale=0.1] (r1-\i-input-\roneinput) {}; |
| 427 |
|
| 428 |
% OUTPUTS MODULE 1 |
| 429 |
% the number of outputs of module one is the number of modules stage 2 \rtwo |
| 430 |
\pgfmathsetmacro\roneintervalspace{1/(\rtwo+1)} |
| 431 |
\foreach \roneoutput[evaluate=\roneoutput as \roneinterval using \roneintervalspace*\roneoutput] |
| 432 |
in {1,...,\rtwo} |
| 433 |
\node[circle,draw,scale=0.1] (r1-\i-output-\roneoutput)at($(r1-\i.north east)!\roneinterval!(r1-\i.south east)$) {}; |
| 434 |
} |
| 435 |
|
| 436 |
% MODULE 2 |
| 437 |
\foreach \i in {1,...,\rtwo}{ |
| 438 |
\path let \n1 = {int(0-\i)}, \n2={0-\i*\moduleysep} |
| 439 |
in |
| 440 |
node[module,#1,module opacity,yshift=1cm] (r2-\i) at +(\modulexsep,\n2) {\pgfmathparse{int(multiply(\n1,-1))}\pgfmathresult}; |
| 441 |
|
| 442 |
% INPUTS MODULE 2 |
| 443 |
% the number of inputs of module two is the number of modules stage 1 \rone |
| 444 |
\pgfmathsetmacro\rtwointervalspace{1/(\rone+1)} |
| 445 |
\foreach \rtwoinput[evaluate=\rtwoinput as \rtwointerval using \rtwointervalspace*\rtwoinput] |
| 446 |
in {1,...,\rone} |
| 447 |
\node[circle,draw,scale=0.1] (r2-\i-input-\rtwoinput)at($(r2-\i.north west)!\rtwointerval!(r2-\i.south west)$) {}; |
| 448 |
|
| 449 |
% OUTPUTS MODULE 2 |
| 450 |
% the number of outputs module two is exactly \rthree |
| 451 |
\pgfmathsetmacro\rtwointervalspace{1/(\rthree+1)} |
| 452 |
\foreach \rtwooutput[evaluate=\rtwooutput as \rtwointerval using \rtwointervalspace*\rtwooutput] |
| 453 |
in {1,...,\rthree} |
| 454 |
\node[circle,draw,scale=0.1] (r2-\i-output-\rtwooutput)at ($(r2-\i.north east)!\rtwointerval!(r2-\i.south east)$) {}; |
| 455 |
|
| 456 |
} |
| 457 |
|
| 458 |
% MODULE 3 |
| 459 |
\foreach \i in {1,...,\rthree}{ |
| 460 |
\path let \n1 = {int(0-\i)}, \n2={0-\i*\moduleysep} |
| 461 |
in |
| 462 |
node[module,#1,module opacity,yshift=1cm] (r3-\i) at +(2*\modulexsep,\n2) {\pgfmathparse{int(multiply(\n1,-1))}\pgfmathresult}; |
| 463 |
|
| 464 |
% INPUTS MODULE 3 |
| 465 |
% the number of inputs of module three is the number of modules stage 2 \rtwo |
| 466 |
\pgfmathsetmacro\rthreeintervalspace{1/(\rtwo+1)} |
| 467 |
\foreach \rthreeinput[evaluate=\rthreeinput as \rthreeinterval using \rthreeintervalspace*\rthreeinput] |
| 468 |
in {1,...,\rtwo} |
| 469 |
\node[circle,draw,scale=0.1] (r3-\i-input-\rthreeinput)at($(r3-\i.north west)!\rthreeinterval!(r3-\i.south west)$) {}; |
| 470 |
|
| 471 |
% OUTPUTS MODULE 3 |
| 472 |
% the number of outputs module three is exactly \mthree |
| 473 |
\pgfmathsetmacro\rthreeintervalspace{1/(\mthree+1)} |
| 474 |
\foreach \rthreeoutput[evaluate=\rthreeoutput as \rthreeinterval using \rthreeintervalspace*\rthreeoutput] |
| 475 |
in {1,...,\mthree} |
| 476 |
\draw ($(r3-\i.north east)!\rthreeinterval!(r3-\i.south east)+(0.5*\pinlength,0)$)node[scale=0.1](r3-\i-front output-\rthreeoutput){}--($(r3-\i.north east)!\rthreeinterval!(r3-\i.south east)$) node[circle,draw,scale=0.1] (r3-\i-output-\rthreeoutput) {}; |
| 477 |
} |
| 478 |
|
| 479 |
% Test if connections should be removed |
| 480 |
\ifconnectiondisabled |
| 481 |
\relax |
| 482 |
\else |
| 483 |
% DRAWING CONNECTIONS |
| 484 |
%% from r1 to r2 |
| 485 |
\foreach \startmodule in {1,...,\rone}{ |
| 486 |
\foreach \conn in {1,...,\rtwo} |
| 487 |
\draw(r1-\startmodule-output-\conn)--(r2-\conn-input-\startmodule); |
| 488 |
} |
| 489 |
%% from r2 to r3 |
| 490 |
\foreach \startmodule in {1,...,\rthree}{ |
| 491 |
\foreach \conn in {1,...,\rtwo} |
| 492 |
\draw(r3-\startmodule-input-\conn)--(r2-\conn-output-\startmodule); |
| 493 |
} |
| 494 |
\fi |
| 495 |
} |
| 496 |
} |
| 497 |
|
| 498 |
\tikzset{clos rear example/.code={ |
| 499 |
|
| 500 |
% Number of ports per module |
| 501 |
\pgfmathtruncatemacro{\mone}{\N/\rone} |
| 502 |
\pgfmathtruncatemacro{\mthree}{\M/\rthree} |
| 503 |
|
| 504 |
% COMPUTATION REAR CONDITION |
| 505 |
\pgfmathtruncatemacro\rtwo{max(\mone,\mthree)} |
| 506 |
|
| 507 |
% MODULE 1 |
| 508 |
\node[module,#1,module opacity](r1-1) at (0,0) {1}; |
| 509 |
\node[below of=r1-1,yshift=0.75ex](r1-dots) {\vdots}; |
| 510 |
\node[module,#1,module opacity,below of=r1-dots](r1-2) {\rone}; |
| 511 |
|
| 512 |
\foreach \i in {1,2}{ |
| 513 |
% INPUTS MODULE 1 |
| 514 |
% just two modules |
| 515 |
\pgfmathsetmacro\roneintervalspace{1/(2+1)} |
| 516 |
\foreach \roneinput[evaluate=\roneinput as \roneinterval using \roneintervalspace*\roneinput] |
| 517 |
in {1,2} |
| 518 |
\draw ($(r1-\i.north west)!\roneinterval!(r1-\i.south west)-(0.5*\pinlength,0)$)node[scale=0.1](r1-\i-front input-\roneinput){}--($(r1-\i.north west)!\roneinterval!(r1-\i.south west)$) node[circle,draw,scale=0.1] (r1-\i-input-\roneinput) {}; |
| 519 |
|
| 520 |
% OUTPUTS MODULE 1 |
| 521 |
% just two modules |
| 522 |
\pgfmathsetmacro\roneintervalspace{1/(2+1)} |
| 523 |
\foreach \roneoutput[evaluate=\roneoutput as \roneinterval using \roneintervalspace*\roneoutput] |
| 524 |
in {1,2} |
| 525 |
\node[circle,draw,scale=0.1] (r1-\i-output-\roneoutput)at($(r1-\i.north east)!\roneinterval!(r1-\i.south east)$) {}; |
| 526 |
} |
| 527 |
|
| 528 |
% MODULE 2 |
| 529 |
\node[module,#1,module opacity](r2-1) at (\modulexsep,0) {1}; |
| 530 |
\node[below of=r2-1,yshift=0.75ex](r2-dots) {\vdots}; |
| 531 |
\node[module,#1,module opacity,below of=r2-dots](r2-2) {\rtwo}; |
| 532 |
|
| 533 |
\foreach \i in {1,2}{ |
| 534 |
% INPUTS MODULE 2 |
| 535 |
% just two modules |
| 536 |
\pgfmathsetmacro\rtwointervalspace{1/(2+1)} |
| 537 |
\foreach \rtwoinput[evaluate=\rtwoinput as \rtwointerval using \rtwointervalspace*\rtwoinput] |
| 538 |
in {1,2} |
| 539 |
\node[circle,draw,scale=0.1] (r2-\i-input-\rtwoinput)at($(r2-\i.north west)!\rtwointerval!(r2-\i.south west)$) {}; |
| 540 |
|
| 541 |
% OUTPUTS MODULE 2 |
| 542 |
% just two modules |
| 543 |
\pgfmathsetmacro\rtwointervalspace{1/(2+1)} |
| 544 |
\foreach \rtwooutput[evaluate=\rtwooutput as \rtwointerval using \rtwointervalspace*\rtwooutput] |
| 545 |
in {1,2} |
| 546 |
\node[circle,draw,scale=0.1] (r2-\i-output-\rtwooutput)at ($(r2-\i.north east)!\rtwointerval!(r2-\i.south east)$) {}; |
| 547 |
} |
| 548 |
|
| 549 |
% MODULE 3 |
| 550 |
\node[module,#1,module opacity](r3-1) at (2*\modulexsep,0) {1}; |
| 551 |
\node[below of=r3-1,yshift=0.75ex](r3-dots) {\vdots}; |
| 552 |
\node[module,#1,module opacity,below of=r3-dots](r3-2) {\rthree}; |
| 553 |
|
| 554 |
\foreach \i in {1,2}{ |
| 555 |
% INPUTS MODULE 3 |
| 556 |
% just two modules |
| 557 |
\pgfmathsetmacro\rthreeintervalspace{1/(2+1)} |
| 558 |
\foreach \rthreeinput[evaluate=\rthreeinput as \rthreeinterval using \rthreeintervalspace*\rthreeinput] |
| 559 |
in {1,2} |
| 560 |
\node[circle,draw,scale=0.1] (r3-\i-input-\rthreeinput)at($(r3-\i.north west)!\rthreeinterval!(r3-\i.south west)$) {}; |
| 561 |
|
| 562 |
% OUTPUTS MODULE 3 |
| 563 |
% just two modules |
| 564 |
\pgfmathsetmacro\rthreeintervalspace{1/(2+1)} |
| 565 |
\foreach \rthreeoutput[evaluate=\rthreeoutput as \rthreeinterval using \rthreeintervalspace*\rthreeoutput] |
| 566 |
in {1,2} |
| 567 |
\draw ($(r3-\i.north east)!\rthreeinterval!(r3-\i.south east)+(0.5*\pinlength,0)$)node[scale=0.1](r3-\i-front output-\rthreeoutput){}--($(r3-\i.north east)!\rthreeinterval!(r3-\i.south east)$) node[circle,draw,scale=0.1] (r3-\i-output-\rthreeoutput) {}; |
| 568 |
} |
| 569 |
|
| 570 |
% DRAWING CONNECTIONS |
| 571 |
%% from r1 to r2 |
| 572 |
\foreach \startmodule in {1,2}{ |
| 573 |
\foreach \conn in {1,2} |
| 574 |
\draw(r1-\startmodule-output-\conn)--(r2-\conn-input-\startmodule); |
| 575 |
} |
| 576 |
%% from r2 to r3 |
| 577 |
\foreach \startmodule in {1,2}{ |
| 578 |
\foreach \conn in {1,2} |
| 579 |
\draw(r3-\startmodule-input-\conn)--(r2-\conn-output-\startmodule); |
| 580 |
} |
| 581 |
|
| 582 |
% SETTING LABELS |
| 583 |
\node[below of=r1-2, set math mode labels] {\mone~\ensuremath{\times}~\rtwo}; |
| 584 |
\node[below of=r2-2, set math mode labels] {\rone~\ensuremath{\times}~\rthree}; |
| 585 |
\node[below of=r3-2, set math mode labels] {\rtwo~\ensuremath{\times}~\mthree}; |
| 586 |
\draw[decorate,decoration={brace}]($(r1-2-front input-2)-(0.1,0)$)--($(r1-1-front input-1)-(0.1,0)$) node[midway,left=0.1cm, set math mode labels]{\N}; |
| 587 |
\draw[decorate,decoration={brace}]($(r3-1-front output-1)+(0.1,0)$)--($(r3-2-front output-2)+(0.1,0)$) node[midway,right=0.1cm, set math mode labels]{\M}; |
| 588 |
}, |
| 589 |
} |
| 590 |
|
| 591 |
% CLOS EXAMPLE WITH LABELS |
| 592 |
|
| 593 |
\tikzset{clos example with labels/.code={ |
| 594 |
|
| 595 |
% Number of ports per module |
| 596 |
\pgfmathtruncatemacro{\mone}{\N/\rone} |
| 597 |
\pgfmathtruncatemacro{\mthree}{\M/\rthree} |
| 598 |
|
| 599 |
% COMPUTATION REAR CONDITION |
| 600 |
\pgfmathtruncatemacro\rtwo{max(\mone,\mthree)} |
| 601 |
|
| 602 |
% MODULE 1 |
| 603 |
\node[module,#1,module opacity](r1-1) at (0,0) {1}; |
| 604 |
\node[below of=r1-1,yshift=0.75ex](r1-dots) {\vdots}; |
| 605 |
\node[module,#1,module opacity,below of=r1-dots](r1-2) {\ronelabel}; |
| 606 |
|
| 607 |
\foreach \i in {1,2}{ |
| 608 |
% INPUTS MODULE 1 |
| 609 |
% just two modules |
| 610 |
\pgfmathsetmacro\roneintervalspace{1/(2+1)} |
| 611 |
\foreach \roneinput[evaluate=\roneinput as \roneinterval using \roneintervalspace*\roneinput] |
| 612 |
in {1,2} |
| 613 |
\draw ($(r1-\i.north west)!\roneinterval!(r1-\i.south west)-(0.5*\pinlength,0)$)node[scale=0.1](r1-\i-front input-\roneinput){}--($(r1-\i.north west)!\roneinterval!(r1-\i.south west)$) node[circle,draw,scale=0.1] (r1-\i-input-\roneinput) {}; |
| 614 |
|
| 615 |
% OUTPUTS MODULE 1 |
| 616 |
% just two modules |
| 617 |
\pgfmathsetmacro\roneintervalspace{1/(2+1)} |
| 618 |
\foreach \roneoutput[evaluate=\roneoutput as \roneinterval using \roneintervalspace*\roneoutput] |
| 619 |
in {1,2} |
| 620 |
\node[circle,draw,scale=0.1] (r1-\i-output-\roneoutput)at($(r1-\i.north east)!\roneinterval!(r1-\i.south east)$) {}; |
| 621 |
} |
| 622 |
|
| 623 |
% MODULE 2 |
| 624 |
\node[module,#1,module opacity](r2-1) at (\modulexsep,0) {1}; |
| 625 |
\node[below of=r2-1,yshift=0.75ex](r2-dots) {\vdots}; |
| 626 |
\node[module,#1,module opacity,below of=r2-dots](r2-2) {\rtwolabel}; |
| 627 |
|
| 628 |
\foreach \i in {1,2}{ |
| 629 |
% INPUTS MODULE 2 |
| 630 |
% just two modules |
| 631 |
\pgfmathsetmacro\rtwointervalspace{1/(2+1)} |
| 632 |
\foreach \rtwoinput[evaluate=\rtwoinput as \rtwointerval using \rtwointervalspace*\rtwoinput] |
| 633 |
in {1,2} |
| 634 |
\node[circle,draw,scale=0.1] (r2-\i-input-\rtwoinput)at($(r2-\i.north west)!\rtwointerval!(r2-\i.south west)$) {}; |
| 635 |
|
| 636 |
% OUTPUTS MODULE 2 |
| 637 |
% just two modules |
| 638 |
\pgfmathsetmacro\rtwointervalspace{1/(2+1)} |
| 639 |
\foreach \rtwooutput[evaluate=\rtwooutput as \rtwointerval using \rtwointervalspace*\rtwooutput] |
| 640 |
in {1,2} |
| 641 |
\node[circle,draw,scale=0.1] (r2-\i-output-\rtwooutput)at ($(r2-\i.north east)!\rtwointerval!(r2-\i.south east)$) {}; |
| 642 |
} |
| 643 |
|
| 644 |
% MODULE 3 |
| 645 |
\node[module,#1,module opacity](r3-1) at (2*\modulexsep,0) {1}; |
| 646 |
\node[below of=r3-1,yshift=0.75ex](r3-dots) {\vdots}; |
| 647 |
\node[module,#1,module opacity,below of=r3-dots](r3-2) {\rthreelabel}; |
| 648 |
|
| 649 |
\foreach \i in {1,2}{ |
| 650 |
% INPUTS MODULE 3 |
| 651 |
% just two modules |
| 652 |
\pgfmathsetmacro\rthreeintervalspace{1/(2+1)} |
| 653 |
\foreach \rthreeinput[evaluate=\rthreeinput as \rthreeinterval using \rthreeintervalspace*\rthreeinput] |
| 654 |
in {1,2} |
| 655 |
\node[circle,draw,scale=0.1] (r3-\i-input-\rthreeinput)at($(r3-\i.north west)!\rthreeinterval!(r3-\i.south west)$) {}; |
| 656 |
|
| 657 |
% OUTPUTS MODULE 3 |
| 658 |
% just two modules |
| 659 |
\pgfmathsetmacro\rthreeintervalspace{1/(2+1)} |
| 660 |
\foreach \rthreeoutput[evaluate=\rthreeoutput as \rthreeinterval using \rthreeintervalspace*\rthreeoutput] |
| 661 |
in {1,2} |
| 662 |
\draw ($(r3-\i.north east)!\rthreeinterval!(r3-\i.south east)+(0.5*\pinlength,0)$)node[scale=0.1](r3-\i-front output-\rthreeoutput){}--($(r3-\i.north east)!\rthreeinterval!(r3-\i.south east)$) node[circle,draw,scale=0.1] (r3-\i-output-\rthreeoutput) {}; |
| 663 |
} |
| 664 |
|
| 665 |
% DRAWING CONNECTIONS |
| 666 |
%% from r1 to r2 |
| 667 |
\foreach \startmodule in {1,2}{ |
| 668 |
\foreach \conn in {1,2} |
| 669 |
\draw(r1-\startmodule-output-\conn)--(r2-\conn-input-\startmodule); |
| 670 |
} |
| 671 |
%% from r2 to r3 |
| 672 |
\foreach \startmodule in {1,2}{ |
| 673 |
\foreach \conn in {1,2} |
| 674 |
\draw(r3-\startmodule-input-\conn)--(r2-\conn-output-\startmodule); |
| 675 |
} |
| 676 |
|
| 677 |
% SETTING LABELS |
| 678 |
\node[below of=r1-2,set math mode labels] {\monelabel~\ensuremath{\times}~\rtwolabel}; |
| 679 |
\node[below of=r2-2,set math mode labels] {\ronelabel~\ensuremath{\times}~\rthreelabel}; |
| 680 |
\node[below of=r3-2,set math mode labels] {\rtwolabel~\ensuremath{\times}~\mthreelabel}; |
| 681 |
\draw[decorate,decoration={brace}]($(r1-2-front input-2)-(0.1,0)$)--($(r1-1-front input-1)-(0.1,0)$) node[midway,left=0.1cm,set math mode labels]{\Nlabel}; |
| 682 |
\draw[decorate,decoration={brace}]($(r3-1-front output-1)+(0.1,0)$)--($(r3-2-front output-2)+(0.1,0)$) node[midway,right=0.1cm,set math mode labels]{\Mlabel}; |
| 683 |
}, |
| 684 |
} |
| 685 |
|
| 686 |
% BENES |
| 687 |
% uses modules 2x2 |
| 688 |
|
| 689 |
\tikzset{benes/.code={ |
| 690 |
|
| 691 |
% Number of ports per module |
| 692 |
\pgfmathtruncatemacro{\m}{2} |
| 693 |
|
| 694 |
% Numbers of modules in the second stage |
| 695 |
\pgfmathtruncatemacro\rtwo{\m} |
| 696 |
|
| 697 |
% Number of modules in the first/third stage |
| 698 |
\pgfmathtruncatemacro{\r}{\P/\m} |
| 699 |
|
| 700 |
\ifnum\P=4 |
| 701 |
\def\increment{0-\i*0.5*\r*\moduleysep} |
| 702 |
\def\xincrement{\r*0.25*\modulexsep} |
| 703 |
\else |
| 704 |
\def\increment{0-\i*0.39*\r*\moduleysep} |
| 705 |
\def\xincrement{\r*0.2*\modulexsep} |
| 706 |
\fi |
| 707 |
|
| 708 |
% MODULE 1 |
| 709 |
\foreach \i in {1,...,\r}{ |
| 710 |
\path let \n1 = {int(0-\i)}, \n2={0-\i*\moduleysep} |
| 711 |
in |
| 712 |
node[module,#1,module opacity,yshift=1cm] (r1-\i) at +(0,\n2) {\pgfmathparse{int(multiply(\n1,-1))}\pgfmathresult}; |
| 713 |
|
| 714 |
% INPUTS MODULE 1 |
| 715 |
% the number of inputs module one is exactly \mone |
| 716 |
\pgfmathsetmacro\roneintervalspace{1/(\m+1)} |
| 717 |
\foreach \roneinput[evaluate=\roneinput as \roneinterval using \roneintervalspace*\roneinput] |
| 718 |
in {1,...,\m} |
| 719 |
\draw ($(r1-\i.north west)!\roneinterval!(r1-\i.south west)-(0.5*\pinlength,0)$)node[scale=0.1](r1-\i-front input-\roneinput){}--($(r1-\i.north west)!\roneinterval!(r1-\i.south west)$) node[circle,draw,scale=0.1] (r1-\i-input-\roneinput) {}; |
| 720 |
|
| 721 |
% OUTPUTS MODULE 1 |
| 722 |
% the number of outputs of module one is the number of modules stage 2 \rtwo |
| 723 |
\pgfmathsetmacro\roneintervalspace{1/(\rtwo+1)} |
| 724 |
\foreach \roneoutput[evaluate=\roneoutput as \roneinterval using \roneintervalspace*\roneoutput] |
| 725 |
in {1,...,\rtwo} |
| 726 |
\node[circle,draw,scale=0.1] (r1-\i-output-\roneoutput)at($(r1-\i.north east)!\roneinterval!(r1-\i.south east)$) {}; |
| 727 |
} |
| 728 |
|
| 729 |
% MODULE 2 |
| 730 |
\foreach \i in {1,...,\rtwo}{ |
| 731 |
|
| 732 |
\path let \n1 = {int(0-\i)}, \n2={\increment} |
| 733 |
in |
| 734 |
node[module extensible={\r*0.5*\modulesize},#1,module opacity,yshift=1cm] (r2-\i) at +(\xincrement,\n2) {\pgfmathparse{int(multiply(\n1,-1))}\pgfmathresult}; |
| 735 |
|
| 736 |
% INPUTS MODULE 2 |
| 737 |
% the number of inputs of module two is the number of modules stage 1 \rone |
| 738 |
\pgfmathsetmacro\rtwointervalspace{1/(\r+1)} |
| 739 |
\foreach \rtwoinput[evaluate=\rtwoinput as \rtwointerval using \rtwointervalspace*\rtwoinput] |
| 740 |
in {1,...,\r} |
| 741 |
\node[circle,draw,scale=0.1] (r2-\i-input-\rtwoinput)at($(r2-\i.north west)!\rtwointerval!(r2-\i.south west)$) {}; |
| 742 |
|
| 743 |
% OUTPUTS MODULE 2 |
| 744 |
% the number of outputs module two is exactly \rthree |
| 745 |
\pgfmathsetmacro\rtwointervalspace{1/(\r+1)} |
| 746 |
\foreach \rtwooutput[evaluate=\rtwooutput as \rtwointerval using \rtwointervalspace*\rtwooutput] |
| 747 |
in {1,...,\r} |
| 748 |
\node[circle,draw,scale=0.1] (r2-\i-output-\rtwooutput)at ($(r2-\i.north east)!\rtwointerval!(r2-\i.south east)$) {}; |
| 749 |
|
| 750 |
} |
| 751 |
|
| 752 |
% MODULE 3 |
| 753 |
\foreach \i in {1,...,\r}{ |
| 754 |
\path let \n1 = {int(0-\i)}, \n2={0-\i*\moduleysep} |
| 755 |
in |
| 756 |
node[module,#1,module opacity,yshift=1cm] (r3-\i) at +(2*\xincrement,\n2) {\pgfmathparse{int(multiply(\n1,-1))}\pgfmathresult}; |
| 757 |
|
| 758 |
% INPUTS MODULE 3 |
| 759 |
% the number of inputs of module three is the number of modules stage 2 \rtwo |
| 760 |
\pgfmathsetmacro\rthreeintervalspace{1/(\rtwo+1)} |
| 761 |
\foreach \rthreeinput[evaluate=\rthreeinput as \rthreeinterval using \rthreeintervalspace*\rthreeinput] |
| 762 |
in {1,...,\rtwo} |
| 763 |
\node[circle,draw,scale=0.1] (r3-\i-input-\rthreeinput)at($(r3-\i.north west)!\rthreeinterval!(r3-\i.south west)$) {}; |
| 764 |
|
| 765 |
% OUTPUTS MODULE 3 |
| 766 |
% the number of outputs module three is exactly \m |
| 767 |
\pgfmathsetmacro\rthreeintervalspace{1/(\m+1)} |
| 768 |
\foreach \rthreeoutput[evaluate=\rthreeoutput as \rthreeinterval using \rthreeintervalspace*\rthreeoutput] |
| 769 |
in {1,...,\m} |
| 770 |
\draw ($(r3-\i.north east)!\rthreeinterval!(r3-\i.south east)+(0.5*\pinlength,0)$)node[scale=0.1](r3-\i-front output-\rthreeoutput){}--($(r3-\i.north east)!\rthreeinterval!(r3-\i.south east)$) node[circle,draw,scale=0.1] (r3-\i-output-\rthreeoutput) {}; |
| 771 |
} |
| 772 |
|
| 773 |
% Test if connections should be removed |
| 774 |
\ifconnectiondisabled |
| 775 |
\relax |
| 776 |
\else |
| 777 |
% DRAWING CONNECTIONS |
| 778 |
%% from r1 to r2 |
| 779 |
\foreach \startmodule in {1,...,\r}{ |
| 780 |
\foreach \conn in {1,...,\rtwo} |
| 781 |
\draw(r1-\startmodule-output-\conn)--(r2-\conn-input-\startmodule); |
| 782 |
} |
| 783 |
%% from r2 to r3 |
| 784 |
\foreach \startmodule in {1,...,\r}{ |
| 785 |
\foreach \conn in {1,...,\rtwo} |
| 786 |
\draw(r3-\startmodule-input-\conn)--(r2-\conn-output-\startmodule); |
| 787 |
} |
| 788 |
\fi |
| 789 |
} |
| 790 |
} |
| 791 |
|
| 792 |
% BENES COMPLETE |
| 793 |
|
| 794 |
\tikzset{benes complete/.code={ |
| 795 |
|
| 796 |
% Number of ports per module |
| 797 |
\pgfmathtruncatemacro{\m}{2} |
| 798 |
|
| 799 |
% Number of modules in the first/third stage |
| 800 |
\pgfmathtruncatemacro{\r}{\P/\m} |
| 801 |
|
| 802 |
% Number of stages |
| 803 |
\pgfmathtruncatemacro{\stages}{2*round(log2(\P))-1} |
| 804 |
|
| 805 |
% MODULES for all stages |
| 806 |
\foreach \s [evaluate=\s as \numstage using int(\s-1)] in {1,...,\stages}{ |
| 807 |
\ifnum\s=1 |
| 808 |
% FIRST MODULE |
| 809 |
\foreach \i in {1,...,\r}{ |
| 810 |
\path let \n1 = {int(0-\i)}, \n2={0-\i*\moduleysep} |
| 811 |
in |
| 812 |
node[module,#1,module opacity,yshift=1cm] (r\s-\i) at +(0,\n2) {\pgfmathparse{int(multiply(\n1,-1))}\pgfmathresult}; |
| 813 |
|
| 814 |
% INPUTS MODULE 1 |
| 815 |
% the number of inputs module one is exactly \mone |
| 816 |
\pgfmathsetmacro\roneintervalspace{1/(\m+1)} |
| 817 |
\foreach \roneinput[evaluate=\roneinput as \roneinterval using \roneintervalspace*\roneinput] |
| 818 |
in {1,...,\m} |
| 819 |
\draw ($(r1-\i.north west)!\roneinterval!(r1-\i.south west)-(0.5*\pinlength,0)$)node[scale=0.1](r1-\i-front input-\roneinput){}--($(r1-\i.north west)!\roneinterval!(r1-\i.south west)$) node[circle,draw,scale=0.1] (r1-\i-input-\roneinput) {}; |
| 820 |
|
| 821 |
% OUTPUTS MODULE 1 |
| 822 |
% the number of outputs of module one is the number of modules stage 2 |
| 823 |
\pgfmathsetmacro\roneintervalspace{1/(\m+1)} |
| 824 |
\foreach \roneoutput[evaluate=\roneoutput as \roneinterval using \roneintervalspace*\roneoutput] |
| 825 |
in {1,...,\m} |
| 826 |
\node[circle,draw,scale=0.1] (r1-\i-output-\roneoutput)at($(r1-\i.north east)!\roneinterval!(r1-\i.south east)$) {}; |
| 827 |
} |
| 828 |
\fi |
| 829 |
\ifnum\s=\stages |
| 830 |
% FINAL MODULE |
| 831 |
\foreach \i in {1,...,\r}{ |
| 832 |
\path let \n1 = {int(0-\i)}, \n2={0-\i*\moduleysep} |
| 833 |
in |
| 834 |
node[module,#1,module opacity,yshift=1cm] (r\s-\i) at +(\numstage*0.6*\modulexsep,\n2) {\pgfmathparse{int(multiply(\n1,-1))}\pgfmathresult}; |
| 835 |
|
| 836 |
% INPUTS MODULE \s |
| 837 |
% the number of inputs of module three is the number of modules stage 2 \rtwo |
| 838 |
\pgfmathsetmacro\rintervalspace{1/(\m+1)} |
| 839 |
\foreach \rinput[evaluate=\rinput as \rinterval using \rintervalspace*\rinput] |
| 840 |
in {1,...,\m} |
| 841 |
\node[circle,draw,scale=0.1] (r\s-\i-input-\rinput)at($(r\s-\i.north west)!\rinterval!(r\s-\i.south west)$) {}; |
| 842 |
|
| 843 |
% OUTPUTS MODULE \s |
| 844 |
% the number of outputs module three is exactly \mthree |
| 845 |
\pgfmathsetmacro\rintervalspace{1/(\m+1)} |
| 846 |
\foreach \routput[evaluate=\routput as \rinterval using \rintervalspace*\routput] |
| 847 |
in {1,...,\m} |
| 848 |
\draw ($(r\s-\i.north east)!\rinterval!(r\s-\i.south east)+(0.5*\pinlength,0)$)node[scale=0.1](r\s-\i-front output-\routput){}--($(r\s-\i.north east)!\rinterval!(r\s-\i.south east)$) node[circle,draw,scale=0.1] (r\s-\i-output-\routput) {}; |
| 849 |
} |
| 850 |
\fi |
| 851 |
\pgfmathparse{and(\s>1,\s<\stages)} |
| 852 |
\let\cond\pgfmathresult |
| 853 |
\ifnum\cond=1 |
| 854 |
% INTERMEDIATE MODULEs |
| 855 |
\foreach \i in {1,...,\r}{ |
| 856 |
\path let \n1 = {int(0-\i)}, \n2={0-\i*\moduleysep} |
| 857 |
in |
| 858 |
node[module,#1,module opacity,yshift=1cm] (r\s-\i) at +(\numstage*0.6*\modulexsep,\n2) {\pgfmathparse{int(multiply(\n1,-1))}\pgfmathresult}; |
| 859 |
|
| 860 |
% INPUTS MODULE \s |
| 861 |
% the number of inputs of module three is the number of modules stage 2 \rtwo |
| 862 |
\pgfmathsetmacro\rintervalspace{1/(\m+1)} |
| 863 |
\foreach \rinput[evaluate=\rinput as \rinterval using \rintervalspace*\rinput] |
| 864 |
in {1,...,\m} |
| 865 |
\node[circle,draw,scale=0.1] (r\s-\i-input-\rinput)at($(r\s-\i.north west)!\rinterval!(r\s-\i.south west)$) {}; |
| 866 |
|
| 867 |
% OUTPUTS MODULE \s |
| 868 |
% the number of outputs module three is exactly \mthree |
| 869 |
\pgfmathsetmacro\rintervalspace{1/(\m+1)} |
| 870 |
\foreach \routput[evaluate=\routput as \rinterval using \rintervalspace*\routput] |
| 871 |
in {1,...,\m} |
| 872 |
\node[circle,draw,scale=0.1] (r\s-\i-output-\routput) at($(r\s-\i.north east)!\rinterval!(r\s-\i.south east)$) {}; |
| 873 |
} |
| 874 |
\fi |
| 875 |
} |
| 876 |
% end modules |
| 877 |
|
| 878 |
|
| 879 |
% Test if connections should be removed |
| 880 |
\ifconnectiondisabled |
| 881 |
\relax |
| 882 |
\else |
| 883 |
% CONNECTIONS |
| 884 |
|
| 885 |
% the algorithm works for all the stages a part from the two in the middle |
| 886 |
\ifnum\P>4 % in this case there are just two stages, thus the algorithm fails: treat it separately |
| 887 |
% Compute \stages/2: they are the stages from left to the middle or from right to the middle |
| 888 |
\pgfmathparse{floor(divide(\stages,2))} |
| 889 |
\pgfmathtruncatemacro\stagesondirection{\pgfmathresult-1} |
| 890 |
|
| 891 |
% on left |
| 892 |
\foreach \stg[evaluate=\stg as \nextstg using int(\stg+1)] in {1,...,\stagesondirection}{ |
| 893 |
\pgfmathtruncatemacro\applicationon{\P/(2^\stg)}% number of modules over which the algorithm is applied |
| 894 |
\pgfmathtruncatemacro\repetition{int(2^(\stg-1))}% the algorithm should be repeated for \repetition times |
| 895 |
\foreach \t in {1,...,\repetition}{ |
| 896 |
\pgfmathtruncatemacro\startingpoint{1+((\t-1)*\applicationon)} |
| 897 |
\pgfmathtruncatemacro\endingpoint{(\startingpoint+\applicationon)-1} |
| 898 |
\foreach \startmodule in {\startingpoint,...,\endingpoint}{ |
| 899 |
\pgfmathisodd{\startmodule} |
| 900 |
\ifnum\t=1 |
| 901 |
\ifnum\pgfmathresult=1 |
| 902 |
% if odd |
| 903 |
\pgfmathtruncatemacro\endmodulei{int((\startmodule+1)/2)} |
| 904 |
\pgfmathtruncatemacro\endmoduleii{int((\startmodule+1+\applicationon)/2)} |
| 905 |
\draw(r\stg-\startmodule-output-1)--(r\nextstg-\endmodulei-input-1); |
| 906 |
\draw(r\stg-\startmodule-output-2)--(r\nextstg-\endmoduleii-input-1); |
| 907 |
\else |
| 908 |
% if even |
| 909 |
\pgfmathtruncatemacro\endmodulei{int((\startmodule)/2)} |
| 910 |
\pgfmathtruncatemacro\endmoduleii{int((\startmodule+\applicationon)/2)} |
| 911 |
\draw(r\stg-\startmodule-output-1)--(r\nextstg-\endmodulei-input-2); |
| 912 |
\draw(r\stg-\startmodule-output-2)--(r\nextstg-\endmoduleii-input-2); |
| 913 |
\fi |
| 914 |
\fi |
| 915 |
\ifnum\t=2 |
| 916 |
\ifnum\pgfmathresult=1 |
| 917 |
% if odd |
| 918 |
\pgfmathtruncatemacro\endmodulei{int((\startmodule+1)/2+(\applicationon/2))} |
| 919 |
\pgfmathtruncatemacro\endmoduleii{int((\startmodule+1+\applicationon)/2+(\applicationon/2))} |
| 920 |
\draw(r\stg-\startmodule-output-1)--(r\nextstg-\endmodulei-input-1); |
| 921 |
\draw(r\stg-\startmodule-output-2)--(r\nextstg-\endmoduleii-input-1); |
| 922 |
\else |
| 923 |
% if even |
| 924 |
\pgfmathtruncatemacro\endmodulei{int((\startmodule)/2+(\applicationon/2))} |
| 925 |
\pgfmathtruncatemacro\endmoduleii{int((\startmodule+\applicationon)/2+(\applicationon/2))} |
| 926 |
\draw(r\stg-\startmodule-output-1)--(r\nextstg-\endmodulei-input-2); |
| 927 |
\draw(r\stg-\startmodule-output-2)--(r\nextstg-\endmoduleii-input-2); |
| 928 |
\fi |
| 929 |
\fi |
| 930 |
\ifnum\t>2 |
| 931 |
\ifnum\pgfmathresult=1 |
| 932 |
% if odd |
| 933 |
\pgfmathtruncatemacro\endmodulei{int((\startmodule+1)/2+(\applicationon/2)+((\applicationon/2)*(\t-2)))} |
| 934 |
\pgfmathtruncatemacro\endmoduleii{int((\startmodule+1+\applicationon)/2+(\applicationon/2)+((\applicationon/2)*(\t-2)))} |
| 935 |
\draw(r\stg-\startmodule-output-1)--(r\nextstg-\endmodulei-input-1); |
| 936 |
\draw(r\stg-\startmodule-output-2)--(r\nextstg-\endmoduleii-input-1); |
| 937 |
\else |
| 938 |
% if even |
| 939 |
\pgfmathtruncatemacro\endmodulei{int((\startmodule)/2+(\applicationon/2)+((\applicationon/2)*(\t-2)))} |
| 940 |
\pgfmathtruncatemacro\endmoduleii{int((\startmodule+\applicationon)/2+(\applicationon/2)+((\applicationon/2)*(\t-2)))} |
| 941 |
\draw(r\stg-\startmodule-output-1)--(r\nextstg-\endmodulei-input-2); |
| 942 |
\draw(r\stg-\startmodule-output-2)--(r\nextstg-\endmoduleii-input-2); |
| 943 |
\fi |
| 944 |
\fi |
| 945 |
} |
| 946 |
} |
| 947 |
} |
| 948 |
|
| 949 |
% on the right |
| 950 |
|
| 951 |
\foreach \stg[evaluate=\stg as \currstg using int(\stages-(\stg-1)), |
| 952 |
evaluate=\stg as \nextstg using int(\currstg-1)] in {1,...,\stagesondirection}{ |
| 953 |
\pgfmathtruncatemacro\applicationon{\P/(2^\stg)}% number of modules over which the algorithm is applied |
| 954 |
\pgfmathtruncatemacro\repetition{int(2^(\stg-1))}% the algorithm should be repeated for \repetition times |
| 955 |
\foreach \t in {1,...,\repetition}{ |
| 956 |
\pgfmathtruncatemacro\startingpoint{1+((\t-1)*\applicationon)} |
| 957 |
\pgfmathtruncatemacro\endingpoint{(\startingpoint+\applicationon)-1} |
| 958 |
\foreach \startmodule in {\startingpoint,...,\endingpoint}{ |
| 959 |
\pgfmathisodd{\startmodule} |
| 960 |
\ifnum\t=1 |
| 961 |
\ifnum\pgfmathresult=1 |
| 962 |
% if odd |
| 963 |
\pgfmathtruncatemacro\endmodulei{int((\startmodule+1)/2)} |
| 964 |
\pgfmathtruncatemacro\endmoduleii{int((\startmodule+1+\applicationon)/2)} |
| 965 |
\draw(r\currstg-\startmodule-input-1)--(r\nextstg-\endmodulei-output-1); |
| 966 |
\draw(r\currstg-\startmodule-input-2)--(r\nextstg-\endmoduleii-output-1); |
| 967 |
\else |
| 968 |
% if even |
| 969 |
\pgfmathtruncatemacro\endmodulei{int((\startmodule)/2)} |
| 970 |
\pgfmathtruncatemacro\endmoduleii{int((\startmodule+\applicationon)/2)} |
| 971 |
\draw(r\currstg-\startmodule-input-1)--(r\nextstg-\endmodulei-output-2); |
| 972 |
\draw(r\currstg-\startmodule-input-2)--(r\nextstg-\endmoduleii-output-2); |
| 973 |
\fi |
| 974 |
\fi |
| 975 |
\ifnum\t=2 |
| 976 |
\ifnum\pgfmathresult=1 |
| 977 |
% if odd |
| 978 |
\pgfmathtruncatemacro\endmodulei{int((\startmodule+1)/2+(\applicationon/2))} |
| 979 |
\pgfmathtruncatemacro\endmoduleii{int((\startmodule+1+\applicationon)/2+(\applicationon/2))} |
| 980 |
\draw(r\currstg-\startmodule-input-1)--(r\nextstg-\endmodulei-output-1); |
| 981 |
\draw(r\currstg-\startmodule-input-2)--(r\nextstg-\endmoduleii-output-1); |
| 982 |
\else |
| 983 |
% if even |
| 984 |
\pgfmathtruncatemacro\endmodulei{int((\startmodule)/2+(\applicationon/2))} |
| 985 |
\pgfmathtruncatemacro\endmoduleii{int((\startmodule+\applicationon)/2+(\applicationon/2))} |
| 986 |
\draw(r\currstg-\startmodule-input-1)--(r\nextstg-\endmodulei-output-2); |
| 987 |
\draw(r\currstg-\startmodule-input-2)--(r\nextstg-\endmoduleii-output-2); |
| 988 |
\fi |
| 989 |
\fi |
| 990 |
\ifnum\t>2 |
| 991 |
\ifnum\pgfmathresult=1 |
| 992 |
% if odd |
| 993 |
\pgfmathtruncatemacro\endmodulei{int((\startmodule+1)/2+(\applicationon/2)+((\applicationon/2)*(\t-2)))} |
| 994 |
\pgfmathtruncatemacro\endmoduleii{int((\startmodule+1+\applicationon)/2+(\applicationon/2)+((\applicationon/2)*(\t-2)))} |
| 995 |
\draw(r\currstg-\startmodule-input-1)--(r\nextstg-\endmodulei-output-1); |
| 996 |
\draw(r\currstg-\startmodule-input-2)--(r\nextstg-\endmoduleii-output-1); |
| 997 |
\else |
| 998 |
% if even |
| 999 |
\pgfmathtruncatemacro\endmodulei{int((\startmodule)/2+(\applicationon/2)+((\applicationon/2)*(\t-2)))} |
| 1000 |
\pgfmathtruncatemacro\endmoduleii{int((\startmodule+\applicationon)/2+(\applicationon/2)+((\applicationon/2)*(\t-2)))} |
| 1001 |
\draw(r\currstg-\startmodule-input-1)--(r\nextstg-\endmodulei-output-2); |
| 1002 |
\draw(r\currstg-\startmodule-input-2)--(r\nextstg-\endmoduleii-output-2); |
| 1003 |
\fi |
| 1004 |
\fi |
| 1005 |
} |
| 1006 |
} |
| 1007 |
} |
| 1008 |
|
| 1009 |
\fi |
| 1010 |
|
| 1011 |
|
| 1012 |
% * * * * |
| 1013 |
% 2 Intermediate stages |
| 1014 |
|
| 1015 |
% Compute \stages/2 |
| 1016 |
\pgfmathparse{floor(divide(\stages,2))} |
| 1017 |
\pgfmathtruncatemacro\middlestage{\pgfmathresult} |
| 1018 |
\pgfmathtruncatemacro\middlestagei{int(\middlestage+1)} |
| 1019 |
\pgfmathtruncatemacro\middlestageii{int(\middlestagei+1)} |
| 1020 |
|
| 1021 |
% Drawing |
| 1022 |
\foreach \startmodule in {1,...,\r}{ |
| 1023 |
\pgfmathisodd{\startmodule} |
| 1024 |
\ifnum\pgfmathresult=1 |
| 1025 |
% if odd |
| 1026 |
\pgfmathtruncatemacro\endmodule{int(\startmodule+1)} |
| 1027 |
\draw(r\middlestage-\startmodule-output-1)--(r\middlestagei-\startmodule-input-1); |
| 1028 |
\draw(r\middlestage-\startmodule-output-2)--(r\middlestagei-\endmodule-input-1); |
| 1029 |
\draw(r\middlestagei-\startmodule-output-1)--(r\middlestageii-\startmodule-input-1); |
| 1030 |
\draw(r\middlestagei-\startmodule-output-2)--(r\middlestageii-\endmodule-input-1); |
| 1031 |
\else |
| 1032 |
% if even |
| 1033 |
\pgfmathtruncatemacro\endmodule{int(\startmodule-1)} |
| 1034 |
\draw(r\middlestage-\startmodule-output-1)--(r\middlestagei-\endmodule-input-2); |
| 1035 |
\draw(r\middlestage-\startmodule-output-2)--(r\middlestagei-\startmodule-input-2); |
| 1036 |
\draw(r\middlestagei-\startmodule-output-1)--(r\middlestageii-\endmodule-input-2); |
| 1037 |
\draw(r\middlestagei-\startmodule-output-2)--(r\middlestageii-\startmodule-input-2); |
| 1038 |
\fi |
| 1039 |
} |
| 1040 |
% end connections |
| 1041 |
\fi % disable connections |
| 1042 |
} |
| 1043 |
} |
| 1044 |
|
| 1045 |
% BANYAN NETWORKS |
| 1046 |
|
| 1047 |
% BANYAN-OMEGA (thanks to João Gabriel Reis) |
| 1048 |
|
| 1049 |
\tikzset{banyan omega/.code={ |
| 1050 |
% Number of ports per module |
| 1051 |
\pgfmathtruncatemacro{\m}{2} |
| 1052 |
|
| 1053 |
% Number of modules in each stage |
| 1054 |
\pgfmathtruncatemacro{\r}{\P/\m} |
| 1055 |
|
| 1056 |
% Number of stages |
| 1057 |
\pgfmathtruncatemacro{\stages}{round(log2(\P))} |
| 1058 |
|
| 1059 |
% Modules for all stages |
| 1060 |
\foreach \s [evaluate=\s as \numstage using int(\s-1)] in {0,...,\stages}{ |
| 1061 |
\ifnum\s=0 |
| 1062 |
% Invisible modules |
| 1063 |
\foreach \i in {1,...,\r}{ |
| 1064 |
\path let \n2={-\i*\moduleysep} in |
| 1065 |
node[rectangle,minimum height=\modulesize,#1,module opacity,xshift=\modulesize/2,yshift=1cm] |
| 1066 |
(r\s-\i) at +(-0.6*\modulexsep,\n2) {}; |
| 1067 |
|
| 1068 |
% Invisible modules outputs |
| 1069 |
\pgfmathsetmacro\rintervalspace{1/(\m+1)} |
| 1070 |
\foreach \routput[evaluate=\routput as \rinterval using \rintervalspace*\routput] in {1,...,\m} |
| 1071 |
\draw ($(r\s-\i.north east)!\rinterval!(r\s-\i.south east)+(0.5*0.3*\pinlength,0)$) node[coordinate] (r\s-\i-front output-\routput) {} -- |
| 1072 |
($(r\s-\i.north east)!\rinterval!(r\s-\i.south east)$)node[coordinate](r\s-\i-output-\routput) {}; |
| 1073 |
\foreach \routput[evaluate=\routput as \rinterval using \rintervalspace*\routput] in {1,...,\m} |
| 1074 |
\draw ($(r\s-\i.north east)!\rinterval!(r\s-\i.south east)-(0.5*0.3*\pinlength,0)$) node[circle,draw,scale=0.1] (r\s-\i-front input-\routput) {} -- |
| 1075 |
($(r\s-\i.north east)!\rinterval!(r\s-\i.south east)$)node[coordinate](r\s-\i-input-\routput) {}; |
| 1076 |
} |
| 1077 |
\fi |
| 1078 |
\ifnum\s=\stages |
| 1079 |
% Final Module |
| 1080 |
\foreach \i in {1,...,\r}{ |
| 1081 |
\path let \n1 = {int(0-\i)}, \n2={0-\i*\moduleysep} in node[module,#1,module opacity,yshift=1cm] (r\s-\i) at |
| 1082 |
+(\numstage*0.6*\modulexsep,\n2) {\pgfmathparse{int(multiply(\n1,-1))}\pgfmathresult}; |
| 1083 |
|
| 1084 |
% Final module inputs |
| 1085 |
\pgfmathsetmacro\roneintervalspace{1/(\m+1)} |
| 1086 |
\foreach \roneinput[evaluate=\roneinput as \roneinterval using \roneintervalspace*\roneinput] in {1,...,\m} |
| 1087 |
\draw ($(r\s-\i.north west)!\roneinterval!(r\s-\i.south west)-(0.5*0.3*\pinlength,0)$) node[coordinate](r\s-\i-front input-\roneinput) {} -- |
| 1088 |
($(r\s-\i.north west)!\roneinterval!(r\s-\i.south west)$)node[circle,draw,scale=0.1] (r\s-\i-input-\roneinput) {}; |
| 1089 |
|
| 1090 |
% Final module outputs |
| 1091 |
\pgfmathsetmacro\rintervalspace{1/(\m+1)} |
| 1092 |
\foreach \routput[evaluate=\routput as \rinterval using \rintervalspace*\routput] in {1,...,\m} |
| 1093 |
\draw ($(r\s-\i.north east)!\rinterval!(r\s-\i.south east)+(0.5*0.3*\pinlength,0)$) node[coordinate](r\s-\i-front output-\routput) {} -- |
| 1094 |
($(r\s-\i.north east)!\rinterval!(r\s-\i.south east)$)node[circle,draw,scale=0.1] (r\s-\i-output-\routput) {}; |
| 1095 |
} |
| 1096 |
\fi |
| 1097 |
|
| 1098 |
\pgfmathparse{and(\s>0,\s<\stages)} |
| 1099 |
\let\cond\pgfmathresult |
| 1100 |
\ifnum\cond=1 |
| 1101 |
% Intermediate modules |
| 1102 |
\foreach \i in {1,...,\r}{ |
| 1103 |
\path let \n1 = {int(0-\i)}, \n2={0-\i*\moduleysep} in node[module,#1,module opacity,yshift=1cm] |
| 1104 |
(r\s-\i) at +(\numstage*0.6*\modulexsep,\n2) {\pgfmathparse{int(multiply(\n1,-1))}\pgfmathresult}; |
| 1105 |
|
| 1106 |
% Intermediate modules inputs |
| 1107 |
\pgfmathsetmacro\roneintervalspace{1/(\m+1)} |
| 1108 |
\foreach \roneinput[evaluate=\roneinput as \roneinterval using \roneintervalspace*\roneinput] in {1,...,\m} |
| 1109 |
\draw ($(r\s-\i.north west)!\roneinterval!(r\s-\i.south west)-(0.5*0.3*\pinlength,0)$) node[coordinate](r\s-\i-front input-\roneinput) {} -- |
| 1110 |
($(r\s-\i.north west)!\roneinterval!(r\s-\i.south west)$)node[circle,draw,scale=0.1] (r\s-\i-input-\roneinput) {}; |
| 1111 |
|
| 1112 |
% Intermediate modules outputs |
| 1113 |
\pgfmathsetmacro\rintervalspace{1/(\m+1)} |
| 1114 |
\foreach \routput[evaluate=\routput as \rinterval using \rintervalspace*\routput] in {1,...,\m} |
| 1115 |
\draw ($(r\s-\i.north east)!\rinterval!(r\s-\i.south east)+(0.5*0.3*\pinlength,0)$) node[coordinate](r\s-\i-front output-\routput) {} -- |
| 1116 |
($(r\s-\i.north east)!\rinterval!(r\s-\i.south east)$)node[circle,draw,scale=0.1] (r\s-\i-output-\routput) {}; |
| 1117 |
} |
| 1118 |
\fi |
| 1119 |
} |
| 1120 |
|
| 1121 |
% Test if connections should be removed |
| 1122 |
\ifconnectiondisabled |
| 1123 |
\relax |
| 1124 |
\else |
| 1125 |
% Connections |
| 1126 |
\foreach \stg[evaluate=\stg as \prevstg using int(\stg - 1)] in {1,...,\stages}{ |
| 1127 |
\foreach \startmod in {1,...,\r}{ |
| 1128 |
\pgfmathomegarotation{2*(\startmod - 1)}{\stages - 1}{address} |
| 1129 |
\pgfmathtruncatemacro\endmodi{\address/2 + 1} |
| 1130 |
\pgfmathtruncatemacro\endmodii{\endmodi + \r/2} |
| 1131 |
\pgfmathtruncatemacro\cond{mod(\startmod,2)} |
| 1132 |
\ifnum\cond=0 |
| 1133 |
\draw(r\stg-\startmod-front input-1)--(r\prevstg-\endmodi-front output-2); |
| 1134 |
\draw(r\stg-\startmod-front input-2)--(r\prevstg-\endmodii-front output-2); |
| 1135 |
\else |
| 1136 |
\draw(r\stg-\startmod-front input-1)--(r\prevstg-\endmodi-front output-1); |
| 1137 |
\draw(r\stg-\startmod-front input-2)--(r\prevstg-\endmodii-front output-1); |
| 1138 |
\fi |
| 1139 |
} |
| 1140 |
} |
| 1141 |
\fi |
| 1142 |
} |
| 1143 |
} |
| 1144 |
|
| 1145 |
% BANYAN-FLIP |
| 1146 |
|
| 1147 |
\tikzset{banyan flip/.code={ |
| 1148 |
% Number of ports per module |
| 1149 |
\pgfmathtruncatemacro{\m}{2} |
| 1150 |
|
| 1151 |
% Number of modules in each stage |
| 1152 |
\pgfmathtruncatemacro{\r}{\P/\m} |
| 1153 |
|
| 1154 |
% Number of stages |
| 1155 |
\pgfmathtruncatemacro{\stages}{round(log2(\P))} |
| 1156 |
|
| 1157 |
% Modules for all stages |
| 1158 |
\foreach \s [evaluate=\s as \numstage using int(\s-1)] in {0,...,\stages}{ |
| 1159 |
\ifnum\s=0 |
| 1160 |
% Final Module |
| 1161 |
\foreach \i in {1,...,\r}{ |
| 1162 |
\path let \n1 = {int(0-\i)}, \n2={0-\i*\moduleysep} in node[module,#1,module opacity,yshift=1cm] (r\s-\i) at |
| 1163 |
+(\numstage*0.6*\modulexsep,\n2) {\pgfmathparse{int(multiply(\n1,-1))}\pgfmathresult}; |
| 1164 |
|
| 1165 |
% Final module inputs |
| 1166 |
\pgfmathsetmacro\roneintervalspace{1/(\m+1)} |
| 1167 |
\foreach \roneinput[evaluate=\roneinput as \roneinterval using \roneintervalspace*\roneinput] in {1,...,\m} |
| 1168 |
\draw ($(r\s-\i.north west)!\roneinterval!(r\s-\i.south west)-(0.5*0.3*\pinlength,0)$) node[coordinate](r\s-\i-front input-\roneinput) {} -- |
| 1169 |
($(r\s-\i.north west)!\roneinterval!(r\s-\i.south west)$) node[circle,draw,scale=0.1] (r\s-\i-input-\roneinput) {}; |
| 1170 |
|
| 1171 |
% Final module outputs |
| 1172 |
\pgfmathsetmacro\rintervalspace{1/(\m+1)} |
| 1173 |
\foreach \routput[evaluate=\routput as \rinterval using \rintervalspace*\routput] in {1,...,\m} |
| 1174 |
\draw ($(r\s-\i.north east)!\rinterval!(r\s-\i.south east)+(0.5*0.3*\pinlength,0)$) node[coordinate](r\s-\i-front output-\routput) {} -- |
| 1175 |
($(r\s-\i.north east)!\rinterval!(r\s-\i.south east)$) node[circle,draw,scale=0.1] (r\s-\i-output-\routput) {}; |
| 1176 |
} |
| 1177 |
\fi |
| 1178 |
\ifnum\s=\stages |
| 1179 |
% Invisible modules |
| 1180 |
\foreach \i in {1,...,\r}{ |
| 1181 |
\path let \n2={-\i*\moduleysep} in |
| 1182 |
node[rectangle,minimum height=\modulesize,#1,module opacity,xshift=\modulesize/2,yshift=1cm] |
| 1183 |
(r\s-\i) at +(\numstage*0.415*\modulexsep,\n2) {}; |
| 1184 |
|
| 1185 |
% Invisible modules outputs |
| 1186 |
\pgfmathsetmacro\rintervalspace{1/(\m+1)} |
| 1187 |
\foreach \roneinput[evaluate=\roneinput as \rinterval using \rintervalspace*\roneinput] in {1,...,\m} |
| 1188 |
\draw ($(r\s-\i.north west)!\rinterval!(r\s-\i.south west)$)node [coordinate](r\s-\i-input-\roneinput) {} -- |
| 1189 |
($(r\s-\i.north west)!\rinterval!(r\s-\i.south west)-(0.5*0.3*\pinlength,0)$) |
| 1190 |
node [coordinate] (r\s-\i-front input-\roneinput) {}; |
| 1191 |
\foreach \roneinput[evaluate=\roneinput as \rinterval using \rintervalspace*\roneinput] in {1,...,\m} |
| 1192 |
\draw ($(r\s-\i.north west)!\rinterval!(r\s-\i.south west)$)node [coordinate](r\s-\i-input-\roneinput) {} -- |
| 1193 |
($(r\s-\i.north west)!\rinterval!(r\s-\i.south west)+(0.5*0.3*\pinlength,0)$) |
| 1194 |
node [circle,draw,scale=0.1] (r\s-\i-front output-\roneinput) {}; |
| 1195 |
} |
| 1196 |
\fi |
| 1197 |
\pgfmathparse{and(\s>0,\s<\stages)} |
| 1198 |
\let\cond\pgfmathresult |
| 1199 |
\ifnum\cond=1 |
| 1200 |
% Intermediate modules |
| 1201 |
\foreach \i in {1,...,\r}{ |
| 1202 |
\path let \n1 = {int(0-\i)}, \n2={0-\i*\moduleysep} in node[module,#1,module opacity,yshift=1cm] |
| 1203 |
(r\s-\i) at +(\numstage*0.6*\modulexsep,\n2) {\pgfmathparse{int(multiply(\n1,-1))}\pgfmathresult}; |
| 1204 |
|
| 1205 |
% Intermediate modules inputs |
| 1206 |
\pgfmathsetmacro\roneintervalspace{1/(\m+1)} |
| 1207 |
\foreach \roneinput[evaluate=\roneinput as \roneinterval using \roneintervalspace*\roneinput] in {1,...,\m} |
| 1208 |
\draw ($(r\s-\i.north west)!\roneinterval!(r\s-\i.south west)-(0.5*0.3*\pinlength,0)$) node[coordinate](r\s-\i-front input-\roneinput) {} -- |
| 1209 |
($(r\s-\i.north west)!\roneinterval!(r\s-\i.south west)$) node[circle,draw,scale=0.1] (r\s-\i-input-\roneinput) {}; |
| 1210 |
|
| 1211 |
% Intermediate modules outputs |
| 1212 |
\pgfmathsetmacro\rintervalspace{1/(\m+1)} |
| 1213 |
\foreach\routput[evaluate=\routput as \rinterval using \rintervalspace*\routput] in {1,...,\m} |
| 1214 |
\draw ($(r\s-\i.north east)!\rinterval!(r\s-\i.south east)+(0.5*0.3*\pinlength,0)$) node[coordinate](r\s-\i-front output-\routput) {} -- |
| 1215 |
($(r\s-\i.north east)!\rinterval!(r\s-\i.south east)$) node[circle,draw,scale=0.1] (r\s-\i-output-\routput) {}; |
| 1216 |
} |
| 1217 |
\fi |
| 1218 |
} |
| 1219 |
|
| 1220 |
% Test if connections should be removed |
| 1221 |
\ifconnectiondisabled |
| 1222 |
\relax |
| 1223 |
\else |
| 1224 |
% Connections |
| 1225 |
\foreach \stg[evaluate=\stg as \prevstg using int(\stg - 1)] in {1,...,\stages}{ |
| 1226 |
\foreach \startmod in {1,...,\r}{ |
| 1227 |
\pgfmathomegarotation{2*(\startmod - 1)}{\stages - 1}{address} |
| 1228 |
\pgfmathtruncatemacro\endmodi{\address/2 + 1} |
| 1229 |
\pgfmathtruncatemacro\endmodii{\endmodi + \r/2} |
| 1230 |
\pgfmathtruncatemacro\cond{mod(\startmod,2)} |
| 1231 |
\ifnum\cond=0 |
| 1232 |
\draw(r\stg-\startmod-front input-1)--(r\prevstg-\endmodi-front output-2); |
| 1233 |
\draw(r\stg-\startmod-front input-2)--(r\prevstg-\endmodii-front output-2); |
| 1234 |
\else |
| 1235 |
\draw(r\stg-\startmod-front input-1)--(r\prevstg-\endmodi-front output-1); |
| 1236 |
\draw(r\stg-\startmod-front input-2)--(r\prevstg-\endmodii-front output-1); |
| 1237 |
\fi |
| 1238 |
} |
| 1239 |
} |
| 1240 |
\fi |
| 1241 |
} |
| 1242 |
} |
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
\endinput |