在 LaTeX 中繪製自動機

在 LaTeX 中繪製自動機

我有這個自動機,我需要在 LaTeX 中重現它:

在此輸入影像描述

到目前為止我已經有了這個,但我有點困惑如何定位邊緣。

\begin{figure}[htbp]
\centering
\begin{tikzpicture}[->,>=stealth',shorten >=5pt,auto,node distance=2.8cm,semithick]
\node[state] (q0)                    {$q_a$};
\node[state]         (q1) [above,right of=q0] {$q_b$};
\node[state]         (q2) [right of=q1] {$q_c$};

\path (q0) edge [loop left]   node {a} (q0);

     (q1) edge [loop right] node {b} (q1);

     (q2) edge [loop right] node {c} (q2);

\end{tikzpicture}
\caption{Beispiel für einen NSA/DSA}
\end{figure}

例如,如何移動節點?

答案1

像這樣?

在此輸入影像描述

\documentclass[tikz,
               border=3mm
               ]{standalone}
\usetikzlibrary{arrows, automata,
                quotes,
                positioning
                }

\begin{document}
    \begin{tikzpicture}[
    node distance = 12mm and 22mm,
every edge/.style = {draw, -stealth', shorten >=1pt},
every edge quotes/.style = {inner sep=1pt, auto},
    semithick
                    ]
\node (q0) [state]                   {$q_a$};
\node (q1) [state,above right=of q0] {$q_b$};
\node (q2) [state,below right=of q0] {$q_c$};
%
\path (q0) edge [loop  left,"$a$"] (q0)
      (q1) edge [loop right,"$b$"] (q1)
      (q2) edge [loop right,"$c$"] (q2)
%
      (q0.45)  edge [bend left,"$b$"] (q1.180)
      (q1.210) edge [bend left,"$a$"] (q0.30)
%
      (q0.330) edge [bend left,"$c$"] (q2.150)
      (q2.180) edge [bend left,"$a$"] (q0.300)
%
      (q1.285) edge [bend left,"$c$"] (q2.75)
      (q2.105) edge [bend left,"$b$"] (q1.265)
      ;
    \end{tikzpicture}
\end{document}

節點位置是使用 TikZ 庫確定的positioning,邊的標籤使用 TikZ 庫quotes

相關內容