关于绘制有限自动机的问题

关于绘制有限自动机的问题

两个问题:第一个问题:1-我如何让从 q2 到 q6 的线绕过 q5 而不绕过 q4 和 q5?我试过 [向左弯曲 = 120] 和其他数字,但无论我将其作为数字输入什么,我都无法绕过它。

第二个是: 2- 我如何使从 q1 到 q4 的箭头成为两个独立的箭头并且不允许它们共享箭头?

这是我的代码:

\documentclass{article}

 \usepackage{tikz}

\usetikzlibrary{automata,positioning}
  \begin{document}

 \begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto] 
 \node[state,initial] (q_0)   {$q_0$}; 
 \node[state,accepting] (q_1) [ right=of q_0] {$q_1$}; 
 \node[state] (q_2) [right=of q_1] {$q_2$}; 
 \node[state] (q_3) [ below=of q_0] {$q_3$}; 
 \node[state] (q_4) [ below=of q_1] {$q_4$}; 
 \node[state] (q_5) [ below=of q_2] {$q_5$}; 
 \node[state] (q_6) [ below=of q_3] {$q_6$}; 
 \path[->] 
 (q_0) edge  node {a} (q_1)
 edge  node {c} (q_3)
 edge  node {b} (q_4)
 (q_1) edge  node  {c} (q_2)
 edge  node {a} (q_4)
 edge [loop above] node {b} ()
 (q_2)edge  node {a} (q_4) 
 edge  node {a} (q_4)
 edge  [bend left] node {b} (q_6)
 edge [loop above] node {c} ()
 (q_3) edge  node  {b} (q_6)
 edge  node {a} (q_1)
 edge [loop left] node {c} ()
 (q_4) edge  node  {c} (q_5)
 edge  node {a} (q_1)
 edge [loop left] node {b} ()
 (q_5) edge  node  {b} (q_6)
 edge  node {a} (q_2)
 edge [loop right] node {c} ()
 (q_6) 
 edge [loop left] node {a,b,c} ();

 \end{tikzpicture}

 \end{document}  

这是我的画

答案1

您可以使用参数inoutlooseness(结合节点的最终重新排列)来避免边缘交叉。第二个问题可以通过弯曲边缘来解决,请参阅bend left=15

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{automata,positioning}

\begin{document}

\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto] 
\node[state,initial] (q_0)   {$q_0$}; 
\node[state,accepting] (q_1) [ right=of q_0] {$q_1$}; 
\node[state] (q_2) [right=of q_1] {$q_2$}; 
\node[state] (q_3) [ below=of q_0] {$q_3$}; 
\node[state] (q_4) [ below=of q_1] {$q_4$}; 
\node[state] (q_5) [ below=of q_2] {$q_5$}; 
\node[state] (q_6) [ below=of q_4] {$q_6$}; 
\path[->] 
(q_0) edge node {a} (q_1)
      edge node {c} (q_3)
      edge node {b} (q_4)
(q_1) edge node  {c} (q_2)
      edge [bend left=15] node {a} (q_4)
      edge [loop above] node {b} ()
(q_2) edge node {a} (q_4) 
      edge node {a} (q_4)
      edge [out=0, in=315] node {b} (q_6)
      edge [loop above] node {c} ()
(q_3) edge node {b} (q_6)
      edge [out=160, looseness=3] node {a} (q_1)
      edge [loop below] node {c} ()
(q_4) edge node {c} (q_5)
      edge [bend left=15] node {a} (q_1)
      edge [loop left] node {b} ()
(q_5) edge node {b} (q_6)
      edge node {a} (q_2)
      edge [loop below] node {c} ()
(q_6) edge [loop left] node {a,b,c} ();
\end{tikzpicture}

\end{document}  

当然,结果还可以进一步改善。

无交叉边的自动机图

答案2

在此处输入图片描述

\documentclass[border=0.5cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,positioning}

\begin{document}

\begin{tikzpicture}[%
    shorten >=1pt,
    node distance=2cm,
    on grid,
    auto] 
\node[state, initial] (q_0)   {$q_0$}; 
\node[state, accepting] (q_1) [ right=of q_0] {$q_1$}; 
\node[state] (q_2) [right=of q_1] {$q_2$}; 
\node[state] (q_3) [ below=of q_0] {$q_3$}; 
\node[state] (q_4) [ below=of q_1] {$q_4$}; 
\node[state] (q_5) [ below=of q_2] {$q_5$}; 
\node[state] (q_6) [ below=of q_3] {$q_6$}; 
\path[->] 
(q_0) edge node {a} (q_1)
      edge node {c} (q_3)
      edge node[left, near end] {b} (q_4)
(q_1) edge node {c} (q_2)
      edge [bend left=10] node {a} (q_4)
      edge [loop above] node {b} ()
(q_2) edge node {a} (q_4) 
      edge [bend left, out=120, in=90, looseness=1.5] node {b} (q_6)
      edge [loop above] node {c} ()
(q_3) edge node  {b} (q_6)
      edge node[left, near end] {a} (q_1)
      edge [loop left] node {c} ()
(q_4) edge node  {c} (q_5)
      edge [bend left=10] node {a} (q_1)
      edge [loop left] node {b} ()
(q_5) edge node  {b} (q_6)
      edge node {a} (q_2)
      edge [loop right] node {c} ()
(q_6) edge [loop left] node {a,b,c} ();
\end{tikzpicture}

\end{document}

相关内容