[Tex/LaTex] Transition in Petri Net

automatadiagramstikz-pgf

I am newbie in Tikz,

After reading this question Transitions in Petri nets

I want to create this enter image description here

And this is my code, you can access with this link https://www.writelatex.com/read/bxwwcmmghpmw

\documentclass{article}

\usepackage[version=0.96]{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,automata,petri}

\tikzset{
    place/.style={
        circle,
        thick,
        draw=blue!75,
        fill=blue!20,
        minimum size=6mm,
    },
    transitionH/.style={
        rectangle,
        thick,
        fill=black,
        minimum width=8mm,
        inner ysep=2pt
    },
    transitionV/.style={
        rectangle,
        thick,
        fill=black,
        minimum height=8mm,
        inner xsep=2pt
    }
}

\begin{document}

\begin{tikzpicture}[node distance=1.3cm,>=stealth',bend angle=45,auto]
    \node [place,label=above:$P_1$] (p1) {};
    \node [transitionV,label=above:$T_1$] (t1) [right of=p1] {}
        edge[pre]   (p1);
    \node [place,tokens=1,label=above:$P_2$] (p2) [right of=t1] {}
        edge[pre]   (t1);
    \node [place,tokens=2,label=above:$P_3$] (p3) [below of=p2] {}
        edge[pre]   (t1);
    \node [transitionV,label=above:$T_2$] (t2) [right of=p3] {}
        edge[pre]   (p2)
        edge[pre]   (p3)
        edge[post, bend left]  (p1);
    \node [place,tokens=1, label=above:$P_4$] (p4) [right of=t2] {}
        edge[pre]   (t2);
\end{tikzpicture}

\end{document}

I am not quite happy with the edge from T2 –> P1, and I want them center in vertical.

Thank you very much for your help.

Best Answer

Perhaps something like this:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,automata,petri,positioning}

\tikzset{
    place/.style={
        circle,
        thick,
        draw=blue!75,
        fill=blue!20,
        minimum size=6mm,
    },
    transitionH/.style={
        rectangle,
        thick,
        fill=black,
        minimum width=8mm,
        inner ysep=2pt
    },
    transitionV/.style={
        rectangle,
        thick,
        fill=black,
        minimum height=8mm,
        inner xsep=2pt
    }
}

\begin{document}

\begin{tikzpicture}[node distance=0.5cm and 1cm,>=stealth',bend angle=45,auto]
    \node [place,label=above:$P_1$] (p1) {};
    \node [transitionV,label=above:$T_1$] (t1) [right= of p1] {}
        edge[pre]   (p1);
    \node [place,tokens=1,label=above:$P_2$] (p2) [above right=of t1] {}
        edge[pre]   (t1);
    \node [place,tokens=2,label=above:$P_3$] (p3) [below right=of t1] {}
        edge[pre]   (t1);
    \node [transitionV,label=above:$T_2$] (t2) [above right=of p3] {}
        edge[pre]   (p2)
        edge[pre]   (p3)
        edge[post,out=-110,in=-50,looseness=2,overlay]  (p1);
    \node [place,tokens=1, label=above:$P_4$] (p4) [above right=of t2] {}
        edge[pre]   (t2);
\end{tikzpicture}

\end{document}

enter image description here

The main changes were the switch from the obsolete of= syntax to of= (with the positioning library for relative positioning, and the use of out=<angle>, in=<angle>, together with looseness, for the edge (adjust the settings to your liking).

Another option, using this time a to path instead of edge:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,automata,petri,positioning}

\tikzset{
    place/.style={
        circle,
        thick,
        draw=blue!75,
        fill=blue!20,
        minimum size=6mm,
    },
    transitionH/.style={
        rectangle,
        thick,
        fill=black,
        minimum width=8mm,
        inner ysep=2pt
    },
    transitionV/.style={
        rectangle,
        thick,
        fill=black,
        minimum height=8mm,
        inner xsep=2pt
    }
}

\begin{document}

\begin{tikzpicture}[node distance=0.4cm and 1cm,>=stealth',bend angle=45,auto]
    \node [place,label=above:$P_1$] (p1) {};
    \node [transitionV,label=above:$T_1$] (t1) [right= of p1] {}
        edge[pre]   (p1);
    \node [place,tokens=1,label=above:$P_2$] (p2) [above right=of t1] {}
        edge[pre]   (t1);
    \node [place,tokens=2,label=above:$P_3$] (p3) [below right=of t1] {}
        edge[pre]   (t1);
    \node [transitionV,label=above:$T_2$] (t2) [above right=of p3] {}
        edge[pre]   (p2)
        edge[pre]   (p3);
    \node [place,tokens=1, label=above:$P_4$] (p4) [above right=of t2] {}
        edge[pre]   (t2);
   \draw[post] (t2.east)  to[out=-30,in=210,overlay,looseness=2.3]  (p1);     
\end{tikzpicture}

\end{document}

enter image description here

Related Question