我想在自动机中绘制一个如下所示的转换。从状态 q7 到状态 q1

我想在自动机中绘制一个如下所示的转换。从状态 q7 到状态 q1

我已经制作了这个自动机。但我无法以完全相同的方式制作这一行,我感到非常沮丧

图像要制作。我想要完全相同的线条,但我无法修复它

以下是代码

\documentclass[landscape, 12pt]{report}

\usepackage{tikz}
\usepackage{lipsum}
\usepackage{enumitem,amsmath,amssymb,latexsym}
\usepackage{mathtools}
\usepackage{cmap}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\usepackage{textcomp}
\usepackage{verbatim}
\usepackage{pgf}
\usetikzlibrary{arrows,automata}
\usepackage{ragged2e}
\usepackage{graphicx}
\usepackage{geometry}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\usetikzlibrary{babel,positioning,shapes}
\usepackage{amstext}
\geometry{
    a4paper,
    total={170.00 mm,257.00 mm},
    left=20.00 mm,
    top=20.00 mm,
}
\begin{document}

    \textbf{Modify the following PDA so  that an equivalent CFG can be obtained.\\}
    \newline\newline

    \tikzstyle{line} = [draw, -latex']
    \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=4.1cm,
    thick]
    \tikzstyle{every state}=[fill=gray,text=white]

    \node[initial above,state] (q1)              {$q_{1}$};
    \node[state]         (q2)  [below  left=2.5cm and 3.25cm of q1]{$q_{2}$};

    \node[state]         (q3) [below  right=2.5cm and 3.25cm of q1] {$q_{3}$};
    \node[state]         (q4) [below =2cm of q2] {$q_{4}$};
    \node[state]         (q5) [below =2cm of q3] {$q_{5}$};

    \node[state]         (q6) [below right=2.5cm and 3.25cm of q4] {$q_{6}$};



    \node[state]         (q7) [below= 1.5cm of q6] {$q_{7}$};

    \node[state]         (q8) [below= 2.5 of q1] {$q_{8}$};

    \node[state]         (qaccept) [below=6cm =q8] {$_{qaccept}$};

    \path[->] 

    (q1) edge node[sloped,align=center, anchor=center, above, text width=2.0cm] {0 $\rightarrow$ x , R} (q2)

    (q1) edge node[sloped,align=center, anchor=center, above, text width=2.0cm] {\# $\rightarrow$ R} (q8)

    (q8) edge node[sloped,align=center, anchor=center, above, text width=2.0cm] {u $\rightarrow$ R} (qaccept)

    (q1) edge node[sloped,align=center, anchor=center, above, text width=2.0cm] {1 $\rightarrow$ x , R} (q3)


    (q2) edge node[align=center,left] {\# $\rightarrow$ R} (q4)

    (q3) edge node[align=center,right] {\# $\rightarrow$ R} (q5)

    (q4) edge node[align=center,sloped, anchor=center, below, text width=2.0cm] {0$\rightarrow$x , L} (q6)

    (q5) edge node[align=center,sloped, anchor=center, below, text width=2.0cm] {1$\rightarrow$x , L} (q6)

    (q6) edge node {\# $\rightarrow$ L} (q7)

    (q2) edge [align=center,loop left] node {0,1 $\rightarrow$ R} (q2)
    (q3) edge [align=center,loop right] node {0,1 $\rightarrow$ R} (q3)
    (q4) edge [align=center,loop left] node {x $\rightarrow$ R} (q4)
    (q5) edge [align=center,loop right] node {x $\rightarrow$ R} (q5)
    (q6) edge [align=center,loop right] node {0,1,x $\rightarrow$ L} (q6)
    (q7) edge [align=center,loop right] node {0,1 $\rightarrow$ L} (q7)
    (q8) edge [align=center,loop right] node {x $\rightarrow$ R} (q8)

    ;

    \end{tikzpicture}
\end{document}

答案1

% arara: pdflatex

\documentclass[landscape,12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,positioning}
\usepackage{mathtools}
\usepackage{geometry}
\geometry{
    a4paper,
    total={170.00 mm,257.00 mm},
    left=20.00 mm,
    top=20.00 mm,
}

\begin{document}
\begin{tikzpicture}[%
    ,->
    ,>=stealth'
    ,shorten >=1pt
    ,node distance=4.1cm
    ,thick
    ,auto
    ,state/.append style={fill=gray,text=white}
    ]
    \node[initial above,state] (q1)              {$q_{1}$};
    \node[state]         (q2)  [below  left=2.5cm and 3.25cm of q1]{$q_{2}$};   
    \node[state]         (q3) [below  right=2.5cm and 3.25cm of q1] {$q_{3}$};
    \node[state]         (q4) [below =2cm of q2] {$q_{4}$};
    \node[state]         (q5) [below =2cm of q3] {$q_{5}$}; 
    \node[state]         (q6) [below right=2.5cm and 3.25cm of q4] {$q_{6}$};   
    \node[state]         (q7) [below= 1.5cm of q6] {$q_{7}$};   
    \node[state]         (q8) [below= 2.5 of q1] {$q_{8}$}; 
    \node[state]         (qaccept) [below=6cm =q8] {$q_\text{accept}$};

    \path   
    (q1) edge node[sloped,align=center, anchor=center, above, text width=2.0cm] {0 $\rightarrow$ x , R} (q2)    
    (q1) edge node[sloped,align=center, anchor=center, above, text width=2.0cm] {\# $\rightarrow$ R} (q8)   
    (q8) edge node[sloped,align=center, anchor=center, above, text width=2.0cm] {u $\rightarrow$ R} (qaccept)   
    (q1) edge node[sloped,align=center, anchor=center, above, text width=2.0cm] {1 $\rightarrow$ x , R} (q3)    
    (q2) edge node[align=center,left] {\# $\rightarrow$ R} (q4) 
    (q3) edge node[align=center,right] {\# $\rightarrow$ R} (q5)    
    (q4) edge node[align=center,sloped, anchor=center, below, text width=2.0cm] {0$\rightarrow$x , L} (q6)  
    (q5) edge node[align=center,sloped, anchor=center, below, text width=2.0cm] {1$\rightarrow$x , L} (q6)  
    (q6) edge node {\# $\rightarrow$ L} (q7)    
    (q2) edge [align=center,loop left] node {0,1 $\rightarrow$ R} (q2)
    (q3) edge [align=center,loop right] node {0,1 $\rightarrow$ R} (q3)
    (q4) edge [align=center,loop left] node {x $\rightarrow$ R} (q4)
    (q5) edge [align=center,loop right] node {x $\rightarrow$ R} (q5)
    (q6) edge [align=center,loop right] node {0,1,x $\rightarrow$ L} (q6)
    (q7) edge [align=center,loop right] node {0,1 $\rightarrow$ L} (q7)
    (q8) edge [align=center,loop right] node {x $\rightarrow$ R} (q8);
    \draw [rounded corners=20](q7.west) -- ++(-6.7,0) node[pos=.4,above]{x $\rightarrow$ R} |- (q1.west);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容