[Tex/LaTex] Drawing birth and death process diagram with Tikz

tikz-pgf

I am trying to draw birth and death process diagram under queuing theory with text on top and bottom of the diagram. I am using TikzEdt software. When I compile the code I received an error message as:

'Couldn't parse code. MismatchedTokenException: Expected token '}'. Instead found "1." which is of type FLOAT_WO_EXP in line 17 at position 125.
Couldn't parse code. MismatchedTokenException: Expected token '}'. Instead found "1." which is of type FLOAT_WO_EXP in line 17 at position 125.
Compilation failed with exit code 1''

Also I found it difficult to write under the bottom of the arcs.
I have the following code:

\begin{tikzpicture}

 \draw  (-4.5,4) rectangle (10,-3);

[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
 \clip(-2.84,-1.3) rectangle (9.04,3.58);
 \draw(0.,1.) circle (0.5003998401278722cm);
 \draw(2.,1.) circle (0.46173585522460786cm);
 \draw(4.,1.) circle (0.44045431091090476cm);
 \draw(6.,1.) circle (0.44181444068749043cm);
 \draw(8.,1.) circle (0.44045431091090476cm);
 \draw(-2.,1.) circle (0.523450093132096cm);
 \draw (-2.08,1.14) node[anchor=north west] {0};
 \draw (-0.08,1.16) node[anchor=north west] {1};
 \draw (1.92,1.2) node[anchor=north west] {2};
 \draw (3.76,1.16) node[anchor=north west] {n-1};
 \draw (5.92,1.2) node[anchor=north west] {n};
 \draw (7.5,1.16) node[anchor=north west] {n+1};
 \draw [shift={(-0.9815173101890807,1.5112413590134577)}] plot[domain=-0.011986604704742554:3.1296060488850506,variable=\t]({1.*1.018555861321933*cos(\t r)+0.*1.018555861321933*sin(\t r)},{0.*1.018555861321933*cos(\t r)+1.*1.018555861321933*sin(\t r)});
 \draw [shift={(1.0368933040163526,1.4796489900153262)}] plot[domain=-0.019382604449061702:3.1222100491407314,variable=\t]({1.*1.000115782939687*cos(\t r)+0.*1.000115782939687*sin(\t r)},{0.*1.000115782939687*cos(\t r)+1.*1.000115782939687*sin(\t r)});
 \draw [shift={(3.0184106142054334,1.4503598330233691)},line width=2.pt,dash pattern=on 2pt off 2pt]  plot[domain=-0.010090966788127709:3.131501686801665,variable=\t]({1.*0.9816393643659953*cos(\t r)+0.*0.9816393643659953*sin(\t r)},{0.*0.9816393643659953*cos(\t r)+1.*0.9816393643659953*sin(\t r)});
 \draw [shift={(4.990803512086236,1.4409428653857879)}] plot[domain=4.930891234521944E-4:3.1420857427132454,variable=\t]({1.*0.9908036325366876*cos(\t r)+0.*0.9908036325366876*sin(\t r)},{0.*0.9908036325366876*cos(\t r)+1.*0.9908036325366876*sin(\t r)});
 \draw [shift={(6.999605559480942,1.4407668947979961)}] plot[domain=-6.527759571728353E-4:3.1409398776326203,variable=\t]({1.*1.0179987522014697*cos(\t r)+0.*1.0179987522014697*sin(\t r)},{0.*1.0179987522014697*cos(\t r)+1.*1.0179987522014697*sin(\t r)});
 \draw [shift={(6.980403063500899,0.559301340676507)}] plot[domain=-3.1409328928241607:6.597607656324556E-4,variable=\t]({1.*1.0004650415559373*cos(\t r)+0.*1.0004650415559373*sin(\t r)},{0.*1.0004650415559373*cos(\t r)+1.*1.0004650415559373*sin(\t r)});
 \draw [shift={(4.98996911984415,0.5590934811158415)}] plot[domain=3.1411358636427766:6.28272851723257,variable=\t]({1.*0.9899692231261799*cos(\t r)+0.*0.9899692231261799*sin(\t r)},{0.*0.9899692231261799*cos(\t r)+1.*0.9899692231261799*sin(\t r)});
 \draw [shift={(2.990388842416927,0.5491050625508038)},line width=2.pt,dash pattern=on 2pt off 2pt]  plot[domain=-3.131251786904409:0.010340866685384142,variable=\t]({1.*1.0096651406276953*cos(\t r)+0.*1.0096651406276953*sin(\t r)},{0.*1.0096651406276953*cos(\t r)+1.*1.0096651406276953*sin(\t r)});
 \draw [shift={(0.9903888424169273,0.5191322979423201)}] plot[domain=-3.1218735235713657:0.0197191300184274,variable=\t]({1.*0.9905814270424891*cos(\t r)+0.*0.9905814270424891*sin(\t r)},{0.*0.9905814270424891*cos(\t r)+1.*0.9905814270424891*sin(\t r)});
 \draw [shift={(-1.,0.4880750333700159)}] plot[domain=-3.1300680373355956:0.01152461625419754,variable=\t]({1.*1.0000664120651637*cos(\t r)+0.*1.0000664120651637*sin(\t r)},{0.*1.0000664120651637*cos(\t r)+1.*1.0000664120651637*sin(\t r)});
 \draw (-1.24,3) node[anchor=north west] {$\lambda_0$};
 \draw (0.92,3.) node[anchor=north west] {$\lambda_1$};
 \draw (4.74,3.) node[anchor=north west] {$\lambda_{n-1}$};
 \draw (6.84,3.02) node[anchor=north west] {$\lambda_n$};
 \draw (-1.24,-3.5) node[anchor=north west] {$\mu_0$};
  \draw (0.92,-6) node[anchor=north west] {$\2mu$};
  \draw (4.74,-3.) node[anchor=north west] {$\3mu$};
 \draw (6.84,-3.02) node[anchor=north west] {$\4mu$};
\draw (-2.,0.476549906867904)-- (-2.28,0.14);
 \draw (-2.,0.476549906867904)-- (-1.64,0.26);
 \draw (0.,0.4996001598721278)-- (-0.28,0.26);
 \draw (0.,0.4996001598721278)-- (0.28,0.26);
 \draw (1.9807776848338545,0.5386644360125123)-- (1.64,0.28);
 \draw (1.9807776848338545,0.5386644360125123)-- (2.26,0.34);
 \draw (4.,0.5595456890890953)-- (4.3,0.32);
 \draw (4.,0.5595456890890953)-- (3.7,0.36);
 \draw (5.9799382396883,0.5586412731425877)-- (5.66,0.34);
 \draw (5.9799382396883,0.5586412731425877)-- (6.24,0.3);
 \draw (0.03696537962184012,1.4990326248949253)-- (-0.2,1.82);
 \draw (0.03696537962184012,1.4990326248949253)-- (0.42,1.8);
 \draw (2.0369572896787735,1.469470391582537)-- (1.78,1.72);
 \draw (2.0369572896787735,1.469470391582537)-- (2.4,1.72);
 \draw (4.0000498342454085,1.4508921413779512)-- (3.74,1.76);
 \draw (4.0000498342454085,1.4508921413779512)-- (4.42,1.76);
 \draw (5.974507837021575,1.5593389774478226)-- (5.76,1.82);
 \draw (5.974507837021575,1.5593389774478226)-- (6.32,1.74);
 \draw (8.012632698570675,1.5412530876377109)-- (7.78,1.74);
 \draw (8.012632698570675,1.5412530876377109)-- (8.36,1.74);
 \begin{scriptsize}
 \draw[color=black] (3.82,1.14) ;
 \draw[color=black] (-0.02,0.3) ;
 \draw[color=black] (4.,0.36) ;
 \draw[color=black] (6.38,1.6) ;
 \draw[color=black] (8.2,2.12) ;
 \end{scriptsize}
\end{tikzpicture}

Someone should help me as to how the values \mu, 2\mu, 3\mu and 4\mu appear at the bottom of the diagram. Thanks so much

Best Answer

Is this what you are looking for?

birth death diagram

I accidentally trimmed the right edge off when getting the screenshot.

If so you can get it with the following code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}


\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
 \draw  (-4.5,4) rectangle (10,-3);
 \clip(-2.84,-1.3) rectangle (9.04,3.58);
 \node (zero) [draw, circle, minimum size=1cm] at (-2,1cm) {$0$};
 \node (one) [draw, circle, minimum size=1cm] at (0,1cm) {$1$};
 \node (two) [draw, circle, minimum size=1cm] at (2,1cm) {$2$};
 \node (enminusone) [draw, circle, minimum size=1cm] at (4,1cm) {$n-1$};
 \node (en) [draw, circle, minimum size=1cm] at (6,1cm) {$n$};
 \node (enplusone) [draw, circle, minimum size=1cm] at (8,1cm) {$n+1$};

 \draw [->] (zero) .. controls +(0,2) and +(0,2) .. node [midway, above] {$\lambda_0$} (one);
 \draw [->] (one) .. controls +(0,2) and +(0,2) .. node [midway, above] {$\lambda_1$} (two);
 \draw [->, very thick, dashed] (two) .. controls +(0,2) and +(0,2) .. (enminusone);
 \draw [->] (enminusone) .. controls +(0,2) and +(0,2) .. node [midway, above] {$\lambda_{n-1}$} (en);
 \draw [->] (en) .. controls +(0,2) and +(0,2) .. node [midway, above] {$\lambda_n$} (enplusone);

 \draw [->] (enplusone) .. controls +(0,-2) and +(0,-2) .. node [midway, below] {$\mu_4$} (en);
 \draw [->] (en) .. controls +(0,-2) and +(0,-2) .. node [midway, below] {$\mu_3$} (enminusone);
 \draw [->, very thick, dashed] (enminusone) .. controls +(0,-2) and +(0,-2) .. (two);
 \draw [->] (two) .. controls +(0,-2) and +(0,-2) .. node [midway, below] {$\mu_2$} (one);
 \draw [->] (one) .. controls +(0,-2) and +(0,-2) .. node [midway, below] {$\mu_0$} (zero);

\end{tikzpicture}
\end{document}

Notice how I was able to draw, name, and print text inside each circle by making them each a node, this permitted the easy creation of the arrows between each node referencing the name of each circle.

This can be improved upon visually by separating the arrows a little bit, this gives more clarity about which line points where. See the below sample:

improved birth death diagram

The changes appear in the code below.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}


\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
 \draw  (-4.5,4) rectangle (10,-3);
 \clip(-2.84,-1.3) rectangle (9.04,3.58);
 \node (zero) [draw, circle, minimum size=1cm] at (-2,1cm) {$0$};
 \node (one) [draw, circle, minimum size=1cm] at (0,1cm) {$1$};
 \node (two) [draw, circle, minimum size=1cm] at (2,1cm) {$2$};
 \node (enminusone) [draw, circle, minimum size=1cm] at (4,1cm) {$n-1$};
 \node (en) [draw, circle, minimum size=1cm] at (6,1cm) {$n$};
 \node (enplusone) [draw, circle, minimum size=1cm] at (8,1cm) {$n+1$};

 \draw [->] (zero) .. controls +(0.5,1.5) and +(-0.5,1.5) .. node [midway, above] {$\lambda_0$} (one);
 \draw [->] (one) .. controls +(0.5,1.5) and +(-0.5,1.5) .. node [midway, above] {$\lambda_1$} (two);
 \draw [->, very thick, dashed] (two) .. controls +(0.5,1.5) and +(-0.5,1.5) .. (enminusone);
 \draw [->] (enminusone) .. controls +(0.5,1.5) and +(-0.5,1.5) .. node [midway, above] {$\lambda_{n-1}$} (en);
 \draw [->] (en) .. controls +(0.5,1.5) and +(-0.5,1.5) .. node [midway, above] {$\lambda_n$} (enplusone);

 \draw [->] (enplusone) .. controls +(-0.5,-1.5) and +(0.5,-1.5) .. node [midway, below] {$\mu_4$} (en);
 \draw [->] (en) .. controls +(-0.5,-1.5) and +(0.5,-1.5) .. node [midway, below] {$\mu_3$} (enminusone);
 \draw [->, very thick, dashed] (enminusone) .. controls +(-0.5,-1.5) and +(0.5,-1.5) .. (two);
 \draw [->] (two) .. controls +(-0.5,-1.5) and +(0.5,-1.5) .. node [midway, below] {$\mu_2$} (one);
 \draw [->] (one) .. controls +(-0.5,-1.5) and +(0.5,-1.5) .. node [midway, below] {$\mu_0$} (zero);

\end{tikzpicture}
\end{document}