Probleme beim Führen von Linien zwischen Elementen mit Tikz

Probleme beim Führen von Linien zwischen Elementen mit Tikz

Im folgenden Code möchte ich eine Linie vom letzten Diamanten zum obersten Diamanten zeichnen, wie in der ASCII-Grafik unten gezeigt

                     /\ 
                |---/  \
        /\      |   \  /
       /  \     |    \/
       \  /------
        \/

Können Sie mir bitte zeigen, wie ich die obige Anordnung erreiche? Und wie kann ich circle2mit horizontal ausrichten setloadavg?

Bei meinem aktuellen Code überlappen sich die vertikalen Linien. Meine Ausgabe des Tex-Codes sieht folgendermaßen aus: Bildbeschreibung hier eingeben

\documentclass{article}
\usepackage{tikz}
\usepackage{fixltx2e}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>
\begin{document}
\pagestyle{empty}

% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=blue!20, 
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, 
    text width=10em, text centered, rounded corners, minimum height=4em]
\tikzstyle{mycircle} = [circle, thick, draw=orange, minimum height=4mm]

\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
    minimum height=2em]

\begin{tikzpicture}[align=center,node distance = 2cm, auto]
    % Place nodes
    \node [block] (init) {Read system data};
    \node [mycircle, below left of=init, node distance=4cm] (circle2) {2};
    \node [block, below of=init, node distance=2cm] (setloadavg) {Set average loading level to L\textsubscript{avg}=[0.8,0.9,1,1.1]};
    \node [decision, right of=setloadavg, node distance=8cm] (final) {Is K=N(no. of runs)?};
    \node [mycircle, right of=final, node distance=3cm] (circle5) {2};
    \node [mycircle, below of=final, node distance=3cm] (circle6) {1};
    \node [block, below of=setloadavg, node distance=2cm] (startsim) {Start simulation (run 1) to generate cascade data, K=0};
    \node [block, below of=startsim, node distance=2cm] (setloadlevel) {Set Loading level=L\textsubscript{avg} where varies between +0.5 to -0.5, K=K+1};
    \node [block, below of=setloadlevel, node distance=2cm] (runloadflow) {Remove line randomly and run load flow};
    \node [block, below of=runloadflow, node distance=2cm] (checkoverload) {Check for line overloads};

    \node [decision, below of=checkoverload, node distance=3cm] (decision1) {Is any line overloaded?};
    \node [mycircle, right of=decision1, node distance=3cm] (circle3) {1};
    \node [block, below of=decision1, node distance=3cm] (trip) {Trip the line and note the instant time of trip};
    \node [decision, below of=trip] (reachedsat) {Reached saturation?};
    \node [mycircle, below of=reachedsat, node distance=2cm] (circle4) {1};


    % Draw edges
    \path [line] (init) -- (setloadavg);
    \path [line] (circle2) -- (setloadavg);
    \path [line] (setloadavg) -- (startsim);
    \path [line] (startsim) -- (setloadlevel);
    \path [line] (setloadlevel) -- (runloadflow);
    \path [line] (runloadflow) -- (checkoverload);
    \path [line] (checkoverload) -- (decision1);

    \path [line] (decision1) -- node [near start] {No} (circle3);
    \path [line] (decision1) -- node [near start] {Yes} (trip);

    \path [line] (trip) -- (reachedsat);
    \path [line] (reachedsat) -- node [near start] {No} (circle4);
    \path [line] (reachedsat) -| node [near start] {Yes} (final);

    \path [line] (final) -- node [near start] {No} (circle5);
    \path [line] (final) -- node [near start] {Yes} (circle6);


\end{tikzpicture}
\end{document}

Danke

Antwort1

\path [line] (reachedsat) -- node [near start] {Yes} ++(5,0) |-  (final);

Hier ist Ihr bereinigter Code:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}
\usepackage{fixltx2e}

\begin{document}
\pagestyle{empty}

% Define block styles
\tikzset{decision/.style = {diamond, draw, fill=blue!20,
         text width=4.5em, text badly centered,  inner sep=0pt},
    block/.style = {rectangle, draw, fill=blue!20,
         text width=10em, text centered, rounded corners, minimum height=4em},
    mycircle/.style = {circle, thick, draw=orange, minimum height=4mm},
    line/.style = {draw, -latex'},
    cloud/.style = {draw, ellipse,fill=red!20, minimum height=2em}
}

\begin{tikzpicture}[align=center, auto]
    % Place nodes
    \node [block] (init) {Read system data};
    \node [block, below = of init] (setloadavg) {Set average loading level to L\textsubscript{avg}=[0.8,0.9,1,1.1]};
    \node [mycircle, left = of setloadavg] (circle2) {2};
    \node [decision, right = 4cm of setloadavg, ] (final) {Is K=N(no. of runs)?};
    \node [mycircle, right =of final, ] (circle5) {2};
    \node [mycircle, below = of final, ] (circle6) {1};
    \node [block, below = of setloadavg, ] (startsim) {Start simulation (run 1) to generate cascade data, K=0};
    \node [block, below = of startsim, ] (setloadlevel) {Set Loading level=L\textsubscript{avg} where varies between +0.5 to -0.5, K=K+1};
    \node [block, below =of setloadlevel, ] (runloadflow) {Remove line randomly and run load flow};
    \node [block, below =of runloadflow, ] (checkoverload) {Check for line overloads};

    \node [decision, below = of checkoverload, ] (decision1) {Is any line overloaded?};
    \node [mycircle, right = of decision1, ] (circle3) {1};
    \node [block, below = of decision1,] (trip) {Trip the line and note the instant time of trip};
    \node [decision, below =of trip] (reachedsat) {Reached saturation?};
    \node [mycircle, below = of reachedsat, ] (circle4) {1};


    % Draw edges
    \path [line] (init) -- (setloadavg);
    \path [line] (circle2) -- (setloadavg);
    \path [line] (setloadavg) -- (startsim);
    \path [line] (startsim) -- (setloadlevel);
    \path [line] (setloadlevel) -- (runloadflow);
    \path [line] (runloadflow) -- (checkoverload);
    \path [line] (checkoverload) -- (decision1);

    \path [line] (decision1) -- node [near start] {No} (circle3);
    \path [line] (decision1) -- node [near start] {Yes} (trip);

    \path [line] (trip) -- (reachedsat);
    \path [line] (reachedsat) -- node [near start] {No} (circle4);
    \path [line] (reachedsat) -- node [near start] {Yes} ++(4,0) |-  (final);

    \path [line] (final) -- node [near start] {No} (circle5);
    \path [line] (final) -- node [near start] {Yes} (circle6);


\end{tikzpicture}
\end{document}

Bildbeschreibung hier eingeben

verwandte Informationen