8

I am trying to draw this figure with tikz. Unfortunately, I am not succeeding. I really care about 4 queues, one classifier and one multiplexer and with their arrows. So I need to draw this simple figure.

\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}

enter image description here

If you would like to draw a complex/nicer one you can use the following two figures.

I really appreciate your helps! (comments, hints, etc.)

figure 1

figure 2

N.B. The code is not mine. I used the following two TeX questions, question 1 and question 2.

11

A starting point for the second one:

\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}

enter image description here

A possibility for the third one (this one and the following, use the pic syntax):

\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}

enter image description here

The first one:

\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}

enter image description here

  • 1
    @Jika I updated my answer with some code for the first image. I have to leave now, but in some hours I'll add some code for the third one. – Gonzalo Medina Mar 2 '15 at 19:23
  • I really appreciate your help. Thank you very much for your time. – Jika Mar 2 '15 at 19:34
  • 1
    Those are nice diagrams. – R. Schumacher Mar 2 '15 at 21:00
  • @Jika You're welcome. I've added the code for the other one. – Gonzalo Medina Mar 2 '15 at 21:30
  • 1
    I'm not sure if I agree with the a starting point part :) – Manuel Mar 2 '15 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.