在概率自动机中将一条边分成两部分

在概率自动机中将一条边分成两部分

我目前正在尝试在 tikz 中分割自动机中的一条边。我已经拥有的是:在此处输入图片描述

我想要得到一些像这样的东西(不是红色的,只是为了突出显示):在此处输入图片描述 这个想法是拥有一个概率自动机。如果自动机获得输入 D,它以 2/3 的概率变为状态 q1,以 1/3 的概率保持在状态 q3。这就是为什么我希望从 q3 获得一个带有输入 D 的传出边,这条边应该会在一段时间后分裂,正如您在图片中看到的那样。我该如何实现呢?

这是我的代码(如果其他 tikzlibraries 用于我的原始代码的其他部分,那么我需要一些,所以不要混淆):

\documentclass[a4paper, 12pt, parskip=half+]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgffor}
\usetikzlibrary{automata,shapes.multipart} % Import library for 
     drawing automata
\usetikzlibrary{calc, trees} %For graphics
\usetikzlibrary{positioning} % ...positioning nodes
\usetikzlibrary{arrows,shapes} % ...customizing arrows
\usetikzlibrary{patterns,decorations.pathreplacing}
\tikzset{node distance=2.5cm, %Minimum distance between nodes
   every state/.style={minimum size=0pt, fill=gray!10, circle split, 
   align=center}, %properties for each state
   initial text={}, %No label on start state
   final/.style=accepting,
   every picture/.style={>=stealth'},
   brace/.style={decorate,decoration=brace}, semithick}

\begin{document}
\begin{figure}
  \centering
    \begin{tikzpicture}[{node distance=1.5cm, ,shorten >=1pt,%Minimum 
      distance between nodes
      every state/.style={minimum size=0pt, inner sep=1pt, 
      fill=gray!10, circle, align=center}, %properties for each state
      initial text={}, %No label on start arrow
      final/.style=accepting,
      every picture/.style={>=stealth'},
      brace/.style={decorate,decoration=brace}, semithick,
      every loop/.style={min distance=5mm,looseness=5}}]
   \node[state,initial] (q1) {$q_i^1$ \\ -------- \\ A}; 
   \node[state] (q2) [right=of q1] {$q_i^2$ \\ -------- \\ B}; 
   \node[state] (q3) [right=of q2] {$q_i^3$ \\ -------- \\ B}; 
   \draw[->] (q1) to[loop above] node [above] {\texttt{C}} (q1);
   \draw[->] (q1) edge node [above] {\texttt{D}} (q2);
   \draw[->] (q2) edge node [above] {\texttt{D}} (q3);
   \draw[->] (q3) to[loop above] node [above] {\texttt{C}} (q3); 
 \end{tikzpicture}
\end{figure}
\end{document}

抱歉,我刚刚意识到我所指的状态在图片中被命名为 q2。对此我深表歉意。如果不清楚的话,我指的是代码中名为 q3 的状态(我在代码中更改了它)。我非常感谢得到的任何帮助。您还可以找到我想要的很好的例子文章(第 4 页,图 2 和图 3)

答案1

使用 可以很容易地做到这一点decorations.markings。下面通过样式实现相同的功能。

\documentclass[a4paper, 12pt, parskip=half+]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgffor}
\usetikzlibrary{automata,shapes.multipart} % Import library for drawing automata
\usetikzlibrary{calc, trees} %For graphics
\usetikzlibrary{positioning} % ...positioning nodes
\usetikzlibrary{arrows,shapes} % ...customizing arrows
\usetikzlibrary{patterns,decorations.pathreplacing,decorations.markings}
\tikzset{node distance=2.5cm, %Minimum distance between nodes
   every state/.style={minimum size=0pt, fill=gray!10, circle split, 
   align=center}, %properties for each state
   initial text={}, %No label on start state
   final/.style=accepting,
   every picture/.style={>=stealth'},
   brace/.style={decorate,decoration=brace}, semithick}

\begin{document}
\begin{figure}
  \centering
    \begin{tikzpicture}[{node distance=1.5cm, ,shorten >=1pt,%Minimum 
      distance between nodes
      every state/.style={minimum size=0pt, inner sep=1pt, 
      fill=gray!10, circle, align=center}, %properties for each state
      initial text={}, %No label on start arrow
      final/.style=accepting,
      every picture/.style={>=stealth'},
      brace/.style={decorate,decoration=brace}, semithick,
      every loop/.style={min distance=5mm,looseness=5}}]
   \node[state,initial] (q1) {$q_i^1$ \\ -------- \\ A}; 
   \node[state] (q2) [right=of q1] {$q_i^2$ \\ -------- \\ B}; 
   \node[state] (q3) [right=of q2] {$q_i^3$ \\ -------- \\ B}; 
   \draw[->] (q1) to[loop above] node [above] {\texttt{C}} (q1);
   \draw[->] (q1) edge node [above] {\texttt{D}} (q2);
   \draw[->] (q2) edge node [above] {\texttt{D}} (q3);
   \draw[->] (q3) to[loop above] node [above] {\texttt{C}} (q3); 
   \draw[->,postaction={decorate,decoration={markings,
   mark=at position 0.25 with {\draw[->] (0pt,0pt) to[bend left] 
   coordinate[midway](aux) (q3);
   \pgftransformreset
   \node[above=2pt of aux]{$1/3$};}}}] (q3) to[out=135,in=45] 
   node[midway,above]{$2/3$}  (q1);
 \end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

这是同样的东西,只是风格不同

split connection=at <pos of splitting point> with ratio <label> to <additional target>

以及代码中的示例

\documentclass[a4paper, 12pt, parskip=half+]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgffor}
\usetikzlibrary{automata,shapes.multipart} % Import library for drawing automata
\usetikzlibrary{calc, trees} %For graphics
\usetikzlibrary{positioning} % ...positioning nodes
\usetikzlibrary{arrows,shapes} % ...customizing arrows
\usetikzlibrary{patterns,decorations.pathreplacing,decorations.markings}
\tikzset{node distance=2.5cm, %Minimum distance between nodes
   every state/.style={minimum size=0pt, fill=gray!10, circle split, 
   align=center}, %properties for each state
   initial text={}, %No label on start state
   final/.style=accepting,
   every picture/.style={>=stealth'},
   brace/.style={decorate,decoration=brace}, semithick}

\begin{document}
\begin{figure}
  \centering
    \begin{tikzpicture}[node distance=1.5cm, shorten >=1pt,%Minimum 
      distance between nodes
      every state/.style={minimum size=0pt, inner sep=1pt, 
      fill=gray!10, circle, align=center}, %properties for each state
      initial text={}, %No label on start arrow
      final/.style=accepting,
      every picture/.style={>=stealth'},
      brace/.style={decorate,decoration=brace}, semithick,
      every loop/.style={min distance=5mm,looseness=5},
      split connection/.style args={at #1 with ratio #2 to #3}{postaction={decorate,decoration={markings,
   mark=at position #1 with {\draw[->] (0pt,0pt) to[bend left] 
   coordinate[midway](aux) (#3);
   \pgftransformreset
   \node[above=2pt of aux]{$#2$};}}}}
   ]
   \node[state,initial] (q1) {$q_i^1$ \\ -------- \\ A}; 
   \node[state] (q2) [right=of q1] {$q_i^2$ \\ -------- \\ B}; 
   \node[state] (q3) [right=of q2] {$q_i^3$ \\ -------- \\ B}; 
   \draw[->] (q1) to[loop above] node [above] {\texttt{C}} (q1);
   \draw[->] (q1) edge node [above] {\texttt{D}} (q2);
   \draw[->] (q2) edge node [above] {\texttt{D}} (q3);
   \draw[->] (q3) to[loop above] node [above] {\texttt{C}} (q3); 
   \draw[->,split connection=at 0.25 with ratio $1/3$ to q3] (q3) to[out=135,in=45] 
   node[midway,above]{$2/3$}   node[midway,below]{\texttt{D}} (q1);
 \end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

答案2

使用线的选项..controls +(direction:module) and +(direction:module)..是因为路径中的节点node[pos=0_to_1_value]不适用于弯曲或 to[in.., out],使用路径中的节点允许将节点放置在某些位置,在这种情况下,对于 D 标签,在 0.12 处使用node[pos=0.12,below]...2/3 标签node[pos=0.8]...并将箭头拆分为一个空节点node[pos=0.25](temp){},temp 是节点名称,然后从 temp.center 到 (q3) 绘制一个箭头,再次使用控件将节点放置在带有标签 1/3 的路径中......

结果:

在此处输入图片描述

梅威瑟:

\documentclass[tikz,border=15pt]{standalone}
\usepackage[utf8]{inputenc}
\usetikzlibrary{automata,shapes.multipart} % Import library for drawing automata
\usetikzlibrary{calc, trees} %For graphics
\usetikzlibrary{positioning} % ...positioning nodes
\usetikzlibrary{arrows.meta,shapes} % ...customizing arrows
\usetikzlibrary{patterns,decorations.pathreplacing}
%Fonts MAnagement
\usepackage[scaled]{helvet} % For Sans Family
\usepackage{sansmath}
\sansmath 

\begin{document}
    \begin{tikzpicture}[
        %Environment Config
        node distance=1.5cm,
        shorten >=1pt,%Minimum distance between nodes
        semithick,
        font=\sffamily,
        >={Stealth},
        %Environment Styles
        every state/.style={
            minimum size=0pt,
            inner sep=1pt,
            fill=gray!10,
            circle,
            align=center
        }, %properties for each state
        initial text={}, %No label on start arrow
        final/.style={accepting},
        brace/.style={
            decorate,
            decoration=brace
        }, 
        every loop/.style={
            min distance=5mm,
            looseness=5}
    ]
    \node[state,initial] (q1) {$q_i^1$ \\ -------- \\ A}; 
    \node[state] (q2) [right=of q1] {$q_i^2$ \\ -------- \\ B}; 
    \node[state] (q3) [right=of q2] {$q_i^3$ \\ -------- \\ B}; 
    \draw[->] (q1) to[loop above] node [above] {\texttt{C}} (q1);
    \draw[->] (q1) edge node [above] {D} (q2);
    \draw[->] (q2) edge node [above] {D} (q3);
    \draw[->] (q3) to[loop above] node [above] {\texttt{C}} (q3);
    \draw[->] (q3) .. controls +(140:2.5) and +(40:2.5) .. (q1)
        node[pos=0.12,below]{D}
        node[pos=0.8,above]{\scriptsize $2/3$}
        node[pos=0.25](temp){};
    \draw[->] (temp.center) .. controls +(15:1) and +(120:1) .. (q3) node[pos=0.5,above]{\scriptsize $1/3$};
    \end{tikzpicture}
\end{document}

相关内容