如何绘制并行队列网络?

如何绘制并行队列网络?

我正在尝试使用 tikz 绘制此图。不幸的是,我没有成功。我真正关心的是 4 个队列、一个分类器和一个多路复用器以及它们的箭头。所以我需要绘制这个简单的图形。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{amsthm}
\usetikzlibrary{chains,shapes.multipart}
\usetikzlibrary{shapes,calc}
\usetikzlibrary{automata,positioning}

\tikzset{
buffer/.style={
    draw,
    shape border rotate=270,
    regular polygon,
    regular polygon sides=3,
%       fill=red,
    node distance=2cm,
    minimum height=4em
 }
 }

\begin{document}    
\title{}
\date{\today}
\author{}
\maketitle

\newpage

\section{Simulation}
    \begin{figure}
        \centering
        \begin{tikzpicture}[>=latex]
        % the rectangle with vertical rules
        \draw (0,0) -- ++(2cm,0) -- ++(0,-1.5cm) -- ++(-2cm,0);
        \foreach \i in {1,...,4}
        \draw (2cm-\i*10pt,0) -- +(0,-1.5cm);

        % the circle
        \draw (2.75,-0.75cm) circle [radius=0.75cm];

        % the arrows and labels
        \draw[->] (3.5,-0.75) -- +(20pt,0);
        \draw[<-] (0,-0.75) -- +(-20pt,0) node[left] {$\lambda$};
        \node at (2.75,-0.75cm) {$\mu$};
        \end{tikzpicture}
        \\
        \vspace*{1mm}
        \begin{tikzpicture}[>=latex]
        % the rectangle with vertical rules
        \draw (0,0) -- ++(2cm,0) -- ++(0,-1.5cm) -- ++(-2cm,0);
        \foreach \i in {1,...,3}
        \draw (2cm-\i*10pt,0) -- +(0,-1.5cm);

        % the circle
        \draw (2.75,-0.75cm) circle [radius=0.75cm];

        % the arrows and labels
        \draw[->] (3.5,-0.75) -- +(20pt,0);
        \draw[<-] (0,-0.75) -- +(-20pt,0) node[left] {$\lambda$};
        \node at (2.75,-0.75cm) {$\mu$};
        \end{tikzpicture}
        \\
        \vspace*{1mm}
        \begin{tikzpicture}[>=latex]
        % the rectangle with vertical rules
        \draw (0,0) -- ++(2cm,0) -- ++(0,-1.5cm) -- ++(-2cm,0);
        \foreach \i in {1,...,1}
        \draw (2cm-\i*10pt,0) -- +(0,-1.5cm);

        % the circle
        \draw (2.75,-0.75cm) circle [radius=0.75cm];

        % the arrows and labels
        \draw[->] (3.5,-0.75) -- +(20pt,0);
        \draw[<-] (0,-0.75) -- +(-20pt,0) node[left] {$\lambda$};
        \node at (2.75,-0.75cm) {$\mu$};
        \end{tikzpicture}
        \\
        \vspace*{1mm}
        \begin{tikzpicture}[>=latex]
        % the rectangle with vertical rules
        \draw (0,0) -- ++(2cm,0) -- ++(0,-1.5cm) -- ++(-2cm,0);
        \foreach \i in {1,...,5}
        \draw (2cm-\i*10pt,0) -- +(0,-1.5cm);

        % the circle
        \draw (2.75,-0.75cm) circle [radius=0.75cm];

        % the arrows and labels
        \draw[->] (3.5,-0.75) -- +(20pt,0);
        \draw[<-] (0,-0.75) -- +(-20pt,0) node[left] {$\lambda$};
        \node at (2.75,-0.75cm) (mu4) {$\mu$};
        \end{tikzpicture}

        \begin{tikzpicture}
        \node[buffer,right of=mu4]{Test};
        \end{tikzpicture}
        \caption{The model represented as a queuing system.}
        \label{fig:queue}
    \end{figure}
 \end{document}

在此处输入图片描述

如果您想要绘制一个更复杂/更漂亮的图形,您可以使用以下两个图形。

我非常感谢您的帮助!(评论、提示等)

图1

图 2

注意:代码不是我的。我使用了以下两个 TeX 问题,问题 1问题2

答案1

第二个的起点:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains,shapes.multipart}
\usetikzlibrary{shapes,calc}
\usetikzlibrary{automata,positioning}


\definecolor{myred}{RGB}{220,43,25}
\definecolor{mygreen}{RGB}{0,146,64}
\definecolor{myblue}{RGB}{0,143,224}

\tikzset{
myshape/.style={
  rectangle split,
  minimum height=1.5cm,
  rectangle split horizontal,
  rectangle split parts=8, 
  draw, 
  anchor=center,
  },
mytri/.style={
  draw,
  shape=isosceles triangle,
  isosceles triangle apex angle=60,
  inner xsep=0.65cm
  }
}

\begin{document}    

\begin{tikzpicture}[>=latex]
% the shapes
\node[
  myshape,
  rectangle split part fill={white,white,white,white,myred}
  ] 
  (shape1) {};
\node[
  myshape,
  rectangle split part fill={white,white,white,white,white,white,mygreen},
  below=of shape1
  ] 
  (shape2) {};
\node[
  myshape,
  rectangle split part fill={white,white,white,white,myblue},
  below=of shape2
  ] 
  (shape3) {};
\node[mytri,left=of shape2]
  (in) {};
\node[draw,circle,inner sep=0.6cm,right=of shape2]
  (out) {};
\draw 
  (out.east) -- ++(15pt,0pt) coordinate (end);  

% the arrows
\foreach \Ancla/\Color in {{north west}/myred,west/mygreen,{south west}/myblue}
{
  \draw[line width=1.5pt,\Color,->] ([xshift=-30pt]in.\Ancla) -- ([xshift=-5pt]in.\Ancla);
}
\foreach \Valor/\Color in {1/myred,2/mygreen,3/myblue}
{
  \draw[line width=1.5pt,->,\Color,shorten <= 4pt]
    (in.east) -- (shape\Valor.west);  
  \draw[line width=1.5pt,\Color,shorten <= 4pt]
    (shape\Valor.east) -- (out.west) ;  
}
\foreach \Ancla/\Color in {{north west}/myred,west/mygreen,{south west}/myblue}
{
  \draw[line width=1.5pt,\Color,->] 
    ([xshift=5pt]end|-out.\Ancla) -- ([xshift=30pt]end|-out.\Ancla);
}

% the labels
\node[align=center,anchor=south east]
  at ([yshift=10pt]in.north west) 
  {Classify \\ arrivals};
\foreach \Valor in {1,2,3}
{
  \node[anchor=west,fill=white] at (shape\Valor.east) {$W_{\Valor}$};
}
\node[anchor=south] 
  at (out.north)
  {Link};
\node[anchor=north] 
  at (end|-out.south)
  {Departures};
\end{tikzpicture}

\end{document}

在此处输入图片描述

第三种可能性(这个和下面的,使用语法pic):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains,shapes.multipart}
\usetikzlibrary{shapes,calc,fit}
\usetikzlibrary{automata,positioning}

\tikzset{
queuei/.pic={
  \draw[line width=1pt]
    (0,0) -- ++(2cm,0) -- ++(0,-1cm) -- ++(-2cm,0);
   \foreach \Val in {1,...,3}
     \draw ([xshift=-\Val*10pt]2cm,0) -- ++(0,-1cm);
   \node[above] at (1cm,0) {Queue $#1$ $w_{#1}$};   
  },
mytri/.style={
  draw,
  shape=isosceles triangle,
  isosceles triangle apex angle=60,
  inner xsep=0.65cm
  }
}

\begin{document}    

\begin{tikzpicture}[>=latex]
% the shapes
\path 
  (0,3cm) pic {queuei=1}
  (0,1cm) pic {queuei=2}
  (0,-3cm) pic {queuei=n};
\path 
  (1,4cm) coordinate (aux1)  
  (1,-4.5cm) coordinate (aux2)
  (-0.5,0cm) coordinate (aux3)
  (2.5,0cm) coordinate (aux4);
\node[draw,dashed,text width=2.5cm,fit={(aux1) (aux2) (aux3) (aux4)}] (dashed) {};
\node[draw,align=center,inner sep=10pt]
  at (-4,0) (class)
  {Packet \\ classifier};    
\node[draw,align=center,mytri]
  at (5.5,0) (multi)
  {}; 
\node[anchor=south]
  at ([yshift=10pt]multi.north)
  {Multiplexer};
\node[draw,circle,double,double distance=2.5pt,inner sep=0.4cm,below=of class]
  (control) 
  {};
\node[anchor=north,align=center]
  at (control.south)
  {Scheduling \\ control};
\node[draw,ellipse,dashed,minimum height=1.45cm]
  at ([xshift=-10pt]multi.west) (robin)
  {};
\node[align=center,anchor=east]
  at ([yshift=-3.5pt]robin.west)
  {Round-\\ robin};

%the arrows
\draw[->]
  ( $ (class.east)!0.8!(class.north east) $) --
  ++(10pt,0pt) |- node[above,pos=0.7] {Flow $1$} coordinate[pos=0.7] (aux5)
  (0.2,2.5);     
\draw[->]
  ( $ (class.east)!0.5!(class.north east) $) --
  ++(15pt,0pt) |- node[above,pos=0.67] {Flow $2$} coordinate (aux6)
  (0.2,0.5);     
\draw[->]
  ( $ (class.east)!0.8!(class.south east) $) --
  ++(15pt,0pt) |- node[above,pos=0.67] {Flow $n$} coordinate (aux7)
  (0.2,-3.5);
\draw[->] 
  (aux5)  to[out=0,in=120] ([yshift=-15pt]dashed.west|-aux5);     
\draw[->] 
  (aux5|-aux6)  to[out=0,in=120] ([yshift=-15pt]dashed.west|-aux6);     
\draw[->] 
  (aux5|-aux7)  to[out=0,in=120] ([yshift=-15pt]dashed.west|-aux7);     
\draw[->]
  (control.north) -- (class);
\draw[->]
  ([xshift=-3cm]class.west) -- 
    node[anchor=south,align=center] {Main stream of \\ all packets flow}
  (class.west);
\draw
   (2,2.5) --
  ++(40pt,0pt) |- 
  ( $ (multi.west)!0.8!(multi.north west) $);     
\draw
   (2,0.5) --
  ++(30pt,0pt) |- 
  ( $ (multi.west)!0.5!(multi.north west) $);     
\draw
   (2,-3.5) --
  ++(40pt,0pt) |- 
  ( $ (multi.west)!0.8!(multi.south west) $);     
\draw[->] 
  (multi.east) -- node[above] {$s$} ([xshift=20pt]multi.east);
\end{tikzpicture}

\end{document}

在此处输入图片描述

第一个:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains,shapes.multipart}
\usetikzlibrary{shapes,calc}
\usetikzlibrary{automata,positioning}

\tikzset{
queue/.pic={
  \draw[line width=1pt]
    (0,0) -- ++(2.75cm,0) -- ++(0,-1cm) -- ++(-2.75cm,0);
   \foreach \Val in {1,...,#1}
     \draw ([xshift=-\Val*10pt]2.75cm,0) -- ++(0,-1cm); 
  },
mytri/.style={
  draw,
  shape=isosceles triangle,
  isosceles triangle apex angle=60,
  inner xsep=0.65cm
  }
}

\begin{document}    

\begin{tikzpicture}[>=latex]
% the shapes
\path 
  (0,3cm) pic {queue=3}
  (0,1cm) pic {queue=6}
  (0,-1cm) pic {queue=4}
  (0,-3cm) pic {queue=3};
\node[draw,inner sep=0.6cm]
  (in) at (-2,0)
  {};  
\node[draw,mytri]
  (out) at (4.5,0)
  {};

% the arrows
\foreach \Pos in {-3.5,-1.5,0.5,2.5}
{
  \draw[->] (in.east) -- (0,\Pos);   
  \draw[->] (2.76,\Pos) -- (out.west);   
}
\draw[->] 
  ([xshift=-1cm]in.west) -- (in.west);
\draw[->]
  (out.east) -- ([xshift=1cm]out.east);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容