2

Please consider this code:

\documentclass[a4,12pt]{article}

\usepackage{tikz}
\usetikzlibrary{automata,arrows,positioning,calc}
\usepgflibrary{arrows.meta}

\begin{document}

\begin{tikzpicture}
\tikzstyle{vertex} = [circle, draw=black]
\tikzstyle{edge} = [->, thick]

\node[vertex](i) at (3,4) {Facility $i$};
\node[vertex](j) at (8,4) {Facility $j$};

\path (i) edge [loop left] (i);
\path (j) edge [loop right] (j);

\draw[black,->,shifted path=from i to j by 10pt];
\draw[black,->,shifted path=from j to i by 10pt];

\draw [-Stealth](3,7) -- (3,5);
\draw [-Stealth](8,7) -- (8,5);

\draw [-Stealth](3,3) -- (3,1);
\draw [-Stealth](8,3) -- (8,1);

\draw[step=1cm, gray, very thin] (0,0) grid (13,9);
\foreach \x in {0,1,2,3,4,5,6,7,8,9,10,11,12,13}
   \draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
\foreach \y in {0,1,2,3,4,5,6,7,8,9}
    \draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};

\end{tikzpicture}

\end{document}

This produces: enter image description here

I use the grid lines just as a guide, and will remove them later. But regardless, this is what I want to achieve:

enter image description here

How can I achieve this? Is it possible to edit my code to achieve that, or do I need to reconsider my whole approach?

1
  • the shifted path creates a problem
    – js bibra
    Sep 28, 2020 at 14:35

2 Answers 2

3

Edit: I forgot on vertical arrows ... Now added.

Two examples:

  • for labels on arrows are used quotes library: they used its syntax, for example: edge["$x_y$"]
  • with bended arrows between vertices
  • straight arrows between vertices, where is shifted canvas up (for top arrow) and down (bottom arrow):

enter image description here

\documentclass[tikz, 12pt, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, automata,
                positioning,
                quotes}

\begin{document}
    \begin{tikzpicture}[
    node distance = 12mm and 24mm,
    vertex/.style = {circle, draw, text width=4.4em, align=center},
every edge/.style = {-Straight Barb, draw, semithick}
                        ]
% vertex
\node (i) [vertex]              {Facility $i$};
\node (j) [vertex, right=of i]  {Facility $j$};
%
\draw   (i) edge [loop  left,"$p_{ii}$"] (i)
        (i) edge [bend left,"$p_{ij}$"]  (j)
        (j) edge [bend left,"$p_{ji}$"]  (i)
        (j) edge [loop right,"$p_{jj}$"] (j);
%
\node (ri)  [above=of i] {$r_j$};
\node (out) [below=of i] {$\mathit{out}$};
    \draw   (ri) edge (i)
            (i)  edge (out);
\node (ri)  [above=of j] {$r_j$};
\node (out) [below=of j] {$\mathit{out}$};
    \draw   (ri) edge (j)
            (j)  edge (out);
    \end{tikzpicture}
%
    \begin{tikzpicture}[
    node distance = 12mm and 24mm,
    vertex/.style = {circle, draw, text width=4.4em, align=center},
every edge/.style = {-Straight Barb, draw, semithick}
                        ]
% vertex
\node (i) [vertex]              {Facility $i$};
\node (j) [vertex, right=of i]  {Facility $j$};
%
\draw   (i) edge [loop  left,"$p_{ii}$"] (i)
        (j) edge [loop right,"$p_{jj}$"] (j);
\draw[transform canvas={yshift=+1ex}]   (i) edge ["$p_{ij}$"]  (j);
\draw[transform canvas={yshift=-1ex}]   (j) edge ["$p_{ji}$"]  (i);
%
\node (ri)  [above=of i] {$r_j$};
\node (out) [below=of i] {$\mathit{out}$};
    \draw   (ri) edge (i)
            (i)  edge (out);
\node (ri)  [above=of j] {$r_j$};
\node (out) [below=of j] {$\mathit{out}$};
    \draw   (ri) edge (j)
            (j)  edge (out);
    \end{tikzpicture}
\end{document}
5
  • 1
    aah - @Zarko was faster !!
    – js bibra
    Sep 28, 2020 at 14:42
  • Thank you very much! I actually did want the bended arrows between vertices but I could not figure out how. How about the arrows coming into the facilities (r_i and r_j) and arrows coming out of the facilities (out and out)?
    – Aziz
    Sep 28, 2020 at 14:56
  • 1
    @Aziz, see edited answer (in rush I forgot on the vertical arrow s). Other part of code should be self-explanatory:-)
    – Zarko
    Sep 28, 2020 at 15:01
  • @Zarko, you are a legend. I would have needed a week to get this done, which is time I really do not have. Thank you very much for your help!
    – Aziz
    Sep 28, 2020 at 15:05
  • @Aziz, you are welcome!
    – Zarko
    Sep 28, 2020 at 15:09
3

Replace the path command to get labels on the sides of the self loops

\path (i) edge [loop left]node[](){a} (i);
\path (j) edge [loop right]node[](){b} (j);

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .