Petri 网中的转换

Petri 网中的转换

我必须创建一个 Petri 网作为大学家庭作业。在 Tikz 手册中,我找到了一个非常有用的教程,介绍如何使用 Tikz/PGF 创建 Petri 网。但是,该示例使用的转换样式与我的教授喜欢的样式不同。他使用的样式类似于维基百科上的样式:

请注意,过渡(t)由一个小黑条表示。但是,Tikz 教程中的示例如下所示:

在这里,过渡由矩形框表示。有人知道我该如何更改过渡的样式吗?我认为这可以很容易地完成,但请注意,我是 Tikz 的新手,我几乎不了解上述 petri 网的源代码。

这是来自 Tikz 指南的源代码:(我将其范围缩小了一些,因此它仅包含左 Petri 网)

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

\begin{document}

\begin{tikzpicture}[node distance=1.3cm,>=stealth',bend angle=45,auto]

  \tikzstyle{place}=[circle,thick,draw=blue!75,fill=blue!20,minimum size=6mm]
  \tikzstyle{transition}=[rectangle,thick,draw=black!75,
              fill=black!20,minimum size=4mm]

    \node [place,tokens=1] (w1)                                    {};
    \node [place] (c1) [below of=w1]                      {};
    \node [place] (s)  [below of=c1,label=above:$s\le 3$] {};
    \node [place] (c2) [below of=s]                       {};
    \node [place,tokens=1] (w2) [below of=c2]                      {};

    \node [transition] (e1) [left of=c1] {}
      edge [pre,bend left]                  (w1)
      edge [post,bend right]                (s)
      edge [post]                           (c1);

    \node [transition] (e2) [left of=c2] {}
      edge [pre,bend right]                 (w2)
      edge [post,bend left]                 (s)
      edge [post]                           (c2);

    \node [transition] (l1) [right of=c1] {}
      edge [pre]                            (c1)
      edge [pre,bend left]                  (s)
      edge [post,bend right] node[swap] {2} (w1);

    \node [transition] (l2) [right of=c2] {}
      edge [pre]                            (c2)
      edge [pre,bend right]                 (s)
      edge [post,bend left]  node {2}       (w2);
\end{tikzpicture}

\end{document}

非常感谢您的帮助!

答案1

transition例如,您可以将样式更改为

  transition/.style={
    rectangle,
    thick,
    fill=black,
    minimum width=8mm,
    inner ysep=2pt
    }

请注意,我将弃用的语法更改\tikzstyle为更合适的\tikzset语法。

\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
  },
  transition/.style={
    rectangle,
    thick,
    fill=black,
    minimum width=8mm,
    inner ysep=2pt
    }
  }            

\begin{document}

\begin{tikzpicture}[node distance=1.3cm,>=stealth',bend angle=45,auto]


    \node [place,tokens=1] (w1)                                    {};
    \node [place] (c1) [below of=w1]                      {};
    \node [place] (s)  [below of=c1,label=above:$s\le 3$] {};
    \node [place] (c2) [below of=s]                       {};
    \node [place,tokens=1] (w2) [below of=c2]                      {};

    \node [transition] (e1) [left of=c1] {}
      edge [pre,bend left]                  (w1)
      edge [post,bend right]                (s)
      edge [post]                           (c1);

    \node [transition] (e2) [left of=c2] {}
      edge [pre,bend right]                 (w2)
      edge [post,bend left]                 (s)
      edge [post]                           (c2);

    \node [transition] (l1) [right of=c1] {}
      edge [pre]                            (c1)
      edge [pre,bend left]                  (s)
      edge [post,bend right] node[swap] {2} (w1);

    \node [transition] (l2) [right of=c2] {}
      edge [pre]                            (c2)
      edge [pre,bend right]                 (s)
      edge [post,bend left]  node {2}       (w2);
\end{tikzpicture}

\end{document}

答案2

我稍微修改了一下代码,让它和你一开始展示的代码类似。试试看!

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

\tikzset{
place/.style={
circle,
thick,
draw=black,
%fill=blue!20,
minimum size=6mm
  },
  transition/.style={
    rectangle,
    thick,
        draw=black,
    minimum width=8mm,
    inner ysep=2pt
    }
  }     
\begin{document}

\begin{tikzpicture}[node distance=1.5cm,>=stealth',bend angle=45,auto]


    \node [place,tokens=2] (w1) [label=above:$N$]                    {};
        \node [place,inner sep=0pt, minimum size=0pt] (blank) [left of=w1] {};
    \node [place,tokens=2] (c1) [left of=blank, label=above:$H$]     {};

    \node [transition] (e1) [below of=blank, label=right:$s$] {}
      edge [pre]                  (w1)
      edge [pre]    node{2}       (c1);
    \node [place] (d1) [below of=e1, label=below:$N_2H$] {}
      edge [pre]                  (e1);
\end{tikzpicture}

\end{document}

相关内容