# Still some of the flows missing in the flowchart

I have posted this question few days back but still I can't complete the algortihm.

This is the uncompleted work done so far

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains}

\begin{document}

% Define block styles
\tikzset{
desicion/.style={
diamond,
draw,
text width=4em,
inner sep=0pt
},
block/.style={
rectangle,
draw,
text width=10em,
text centered,
rounded corners
},
cloud/.style={
draw,
ellipse,
minimum height=2em
},
descr/.style={
fill=white,
inner sep=2.5pt
},
connector/.style={
-latex,
font=\scriptsize
},
rectangle connector/.style={
connector,
to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
pos=0.5
},
rectangle connector/.default=-2cm,
straight connector/.style={
connector,
to path=--(\tikztotarget) \tikztonodes
}
}

\begin{tikzpicture}
\matrix (m)[matrix of nodes, column  sep=2cm,row  sep=8mm, align=center, nodes={rectangle,draw, anchor=center} ]{
|[block]| {Start}              &  \\
|[block]| {Assume that $a=c$ the optimilalty cretierin given by }               &                                            \\
|[desicion]| {Locally optimal}          &                                             \\
|[block]| {Assume that $a=d$ the optimilalty cretierin given by}    &                                             \\
|[desicion]| {Locally optimal}         &           |[block]| {Stop}                                   \\
|[block]| {Assume that $a=e$ the optimilalty cretierin given by}    &    |[desicion]| {Locally optimal}                                          \\
|[desicion]| {Locally optimal}         &       |[block]| {Assume that $a=k$ the optimilalty cretierin given by}                                      \\
|[block]| {Assume that $a=f$ the optimilalty cretierin given by}    &   |[desicion]| {Locally optimal}                                         \\
};
\path [>=latex,->] (m-1-1) edge (m-2-1);
\path [>=latex,->] (m-2-1) edge (m-3-1);
\path [>=latex,->] (m-3-1) edge (m-4-1);
\path [>=latex,->] (m-4-1) edge (m-5-1);
\path [>=latex,->] (m-5-1) edge (m-6-1);
\path [>=latex,->] (m-6-1) edge (m-7-1);
\path [>=latex,->] (m-7-1) edge (m-8-1);
\path [>=latex,->] (m-8-1) edge (m-8-2);
\path [>=latex,->] (m-8-2) edge (m-7-2);
\path [>=latex,->] (m-7-2) edge (m-6-2);
\path [>=latex,->] (m-6-2) edge (m-5-2);

\end{tikzpicture}

\end{document}


How do I fix the paths according the flow chart shows in first figure?

• Have you tried to use more nodes to handle all those arrows? Commented Apr 5, 2014 at 5:56
• Note for readers: the original question is here. Commented Apr 5, 2014 at 6:35
• @Jesse how about line connecting "No" Commented Apr 12, 2014 at 3:46
• The system may think we are chatting so I posted here \foreach \f/\l/\p[evaluate=\f as \t using int(\f+1)] in {3/a/1,5/b/2,7/c/3,9/d/4}{ \draw [line,red] (m-\f-1.east) --node[midway,above,text=black]{Yes, Pass (a\p,c\p)} ++ (2.5cm,0)coordinate[](\l); \draw [line,red] (m-\f-1.east) -| ([xshift=1.5cm]m-\t-1.north); }, For step 6 at line 71, you need to change it manually. Actually, once you understand the line 71, you can repeated it without using foreach loop. Commented Apr 12, 2014 at 6:53
• @Jesse did you modify the code in your answer? Commented Apr 12, 2014 at 6:59

An attempt where foreach loop to draw lines is used if possible. a line style is newly added.

Code

\documentclass[a4paper,10pt]{article}
\usepackage[margin=1cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains,calc}

\begin{document}

% Define block styles
\tikzset{
desicion/.style={
diamond,
draw, thick,
text width=4em,
inner sep=0pt
},
block/.style={
rectangle,
draw, thick,
text width=10em,
text centered,
rounded corners
},
cloud/.style={
draw,
ellipse,
minimum height=2em
},
descr/.style={
fill=white,
inner sep=2.5pt
},
connector/.style={
-latex,
font=\scriptsize
},
rectangle connector/.style={
connector,
to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
pos=0.5
},
rectangle connector/.default=-2cm,
straight connector/.style={
connector,
to path=--(\tikztotarget) \tikztonodes
},
line/.style={>=latex,->,thick}
}

\begin{tikzpicture}
\matrix (m)[matrix of nodes, column  sep=3cm,row  sep=8mm, align=center, nodes={rectangle,draw, anchor=center} ]
{
|[block]| {Start}       &   & \\
|[block]| {Assume that $a=c$ the optimilalty cretierin given by }  &  &                                  \\
|[desicion]| {Locally optimal}          &           &                                 \\
|[block]| {Assume that $a=d$ the optimilalty cretierin given by}    &                                            & \\
|[desicion]| {Locally optimal}         &               &                           \\
|[block]| {Assume that $a=e$ the optimilalty cretierin given by}    &       |[block]| {$A=c^2$ \\ $A=b^2$}           &        |[block]| {Globsl \\  Optimal \\ Configuration}                 \\
|[desicion]| {Locally optimal}         &    &                       \\
|[block]| {Assume that $a=f$ the optimilalty cretierin given by}    &   &   \\
|[desicion]| {Locally optimal}               & &  |[block]| {Stop}  \\
|[block]| {Assume that $a=k$ the optimilalty cretierin given by}    &    |[desicion]| {Locally optimal}    &     \\
};
\foreach \f/\t[evaluate=\f as \t using int(\f+1)]  in {1,2,3,4,5,6,7,8,9}{
\path [line] (m-\f-1) edge (m-\t-1);
}
\path [line,red] (m-10-1) edge (m-10-2);
\draw[line,red] (m-10-2) -- (m-6-2) node[pos=0.3,right,text=black]{ Yes, Pass (a,c)};
\draw [line] (m-6-2) --node[midway,below,text=black]{Yes, Pass (a,c)} node[midway,above,text=black]{Step 6} (m-6-3);
\path [line,red] (m-6-3) edge (m-9-3);
\draw [line,red] (m-10-2) -| (m-9-3);

\foreach \f/\l[evaluate=\f as \t using int(\f+1)] in {3/a,5/b,7/c,9/d}{
\draw [line,red] (m-\f-1.east) --node[midway,above,text=black]{Yes, Pass (a,c)} ++ (2.5cm,0)coordinate[](\l);
\draw [line,red] (m-\f-1.east) -| ([xshift=1.5cm]m-\t-1.north);
}

\node[xshift=-2cm] at (m-3-1){Step 1(4)};
\node[xshift=-2cm] at (m-5-1){Step 2 (7)};
\node[xshift=-2cm] at (m-7-1){Step 3 (9)};
\node[xshift=-2cm] at (m-9-1){Step 4 (3)};
\node[xshift=-2cm,above] at (m-10-2){Step 5};
\draw [>=latex,-,red,thick] (a) --(d);
\draw [line,red] ($(a)!0.5!(d)$) -- (m-6-2);
\end{tikzpicture}

\end{document}


Edit: On the OP's request, I run the case in report class with the required info from OP of course. Here is the result

Related code

\documentclass[a4paper,11pt]{report}
\usepackage[margin=1cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains,calc}

\begin{document}

% Define block styles
\tikzset{
desicion/.style={
diamond,
draw, thick,
text width=4em,
inner sep=0pt
},
block/.style={
rectangle,
draw, thick,
text width=10em,
text centered,
rounded corners
},
cloud/.style={
draw,
ellipse,
minimum height=2em
},
descr/.style={
fill=white,
inner sep=2.5pt
},
connector/.style={
-latex,
font=\scriptsize
},
rectangle connector/.style={
connector,
to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
pos=0.5
},
rectangle connector/.default=-2cm,
straight connector/.style={
connector,
to path=--(\tikztotarget) \tikztonodes
},
line/.style={>=latex,->,thick}
}

\begin{figure}[!htpb]
\begin{tikzpicture}
\matrix (m)[matrix of nodes, column  sep=3cm,row  sep=8mm, align=center, nodes={rectangle,draw, anchor=center} ]
{
|[block]| {Start}       &   & \\
|[block]| {Assume that $a=c$ the optimilalty cretierin given by }  &  &                                  \\
|[desicion]| {Locally optimal}          &           &                                 \\
|[block]| {Assume that $a=d$ the optimilalty cretierin given by}    &                                            & \\
|[desicion]| {Locally optimal}         &               &                           \\
|[block]| {Assume that $a=e$ the optimilalty cretierin given by}    &       |[block]| {$A=c^2$ \\ $A=b^2$}           &        |[block]| {Globsl \\  Optimal \\ Configuration}                 \\
|[desicion]| {Locally optimal}         &    &                       \\
|[block]| {Assume that $a=f$ the optimilalty cretierin given by}    &   &   \\
|[desicion]| {Locally optimal}               & &  |[block]| {Stop}  \\
|[block]| {Assume that $a=k$ the optimilalty cretierin given by}    &    |[desicion]| {Locally optimal}    &     \\
};
\foreach \f/\t[evaluate=\f as \t using int(\f+1)]  in {1,2,3,4,5,6,7,8,9}{
\draw [line] (m-\f-1) -- node[midway,right]{No} (m-\t-1);
}
\path [line,red] (m-10-1) edge (m-10-2);
\draw[line,red] (m-10-2) -- (m-6-2) node[pos=0.3,right,text=black]{ Yes, Pass (a,c)};
\draw [line] (m-6-2) --node[midway,below,text=black]{Yes, Pass (a,c)} node[midway,above,text=black]{Step 6} (m-6-3);
\path [line,red] (m-6-3) edge (m-9-3);
\draw [line,red] (m-10-2) -| (m-9-3);

\foreach \f/\l[evaluate=\f as \t using int(\f+1)] in {3/a,5/b,7/c,9/d}{
\draw [line,red] (m-\f-1.east) --node[midway,above,text=black]{Yes, Pass (a,c)} ++ (2.5cm,0)coordinate[](\l);
\draw [line,red] (m-\f-1.east) -| ([xshift=1.5cm]m-\t-1.north);
}
\node[xshift=4cm] at (m-1-1) {A,b,c,d,k given};
\node[xshift=-2cm] at (m-3-1){Step 1(4)};
\node[xshift=-2cm] at (m-5-1){Step 2 (7)};
\node[xshift=-2cm] at (m-7-1){Step 3 (9)};
\node[xshift=-2cm] at (m-9-1){Step 4 (3)};
\node[xshift=-2cm,above] at (m-10-2){Step 5};
\node[above,xshift=1.5cm] at (m-10-2){No};
\draw [>=latex,-,red,thick] (a) --(d);
\draw [line,red] ($(a)!0.5!(d)$) -- (m-6-2);
\end{tikzpicture}
\end{figure}
\end{document}


Edit 2: Lastly, after several discussions, this is it.

Code

\documentclass[a4paper,11pt]{report}
\usepackage[margin=1cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains,calc}

\begin{document}

% Define block styles
\tikzset{
desicion/.style={
diamond,
draw, thick,
text width=4em,
inner sep=0pt
},
block/.style={
rectangle,
draw, thick,
text width=9em,
text centered,
rounded corners
},
cloud/.style={
draw,
ellipse,
minimum height=2em
},
descr/.style={
fill=white,
inner sep=2.5pt
},
connector/.style={
-latex,
font=\scriptsize
},
rectangle connector/.style={
connector,
to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
pos=0.5
},
rectangle connector/.default=-2cm,
straight connector/.style={
connector,
to path=--(\tikztotarget) \tikztonodes
},
line/.style={>=latex,->,thick}
}

\begin{figure}[!htpb]
\begin{tikzpicture}
\matrix (m)[matrix of nodes, column  sep=3cm, row  sep=8mm, align=center, nodes={rectangle,draw, anchor=center} ]
{
|[block]| {Start}       &   & \\
|[block]| {Assume that $a=c$ the optimilalty cretierin given by }  &  &                                  \\
|[desicion]| {Locally optimal}          &           &                                 \\
|[block]| {Assume that $a=d$ the optimilalty cretierin given by}    &                                            & \\
|[desicion]| {Locally optimal}         &               &                           \\
|[block]| {Assume that $a=e$ the optimilalty cretierin given by}    &       |[block]| {$A=c^2$ \\ $A=b^2$}           &        |[block]| {Globsl \\  Optimal \\ Configuration}                 \\
|[desicion]| {Locally optimal}         &    &                       \\
|[block]| {Assume that $a=f$ the optimilalty cretierin given by}    &   &   \\
|[desicion]| {Locally optimal}               & &  |[block]| {Stop}  \\
|[block]| {Assume that $a=k$ the optimilalty cretierin given by}    &    |[desicion]| {Locally optimal}    &     \\
};
\foreach \f/\t[evaluate=\f as \t using int(\f+1)]  in {3,4,5,6,7,8,9}{
\draw [line] (m-\f-1) -- node[midway,right]{No} (m-\t-1);
}
\node[above,xshift=1.5cm] at (m-10-2){No};
\foreach \f/\t[evaluate=\f as \t using int(\f+1)]  in {1,2}{
\draw [line] (m-\f-1) --  (m-\t-1);
}
\path  [line,red] (m-10-1) edge (m-10-2);
\path  [line,red] (m-6-3) edge (m-9-3);
\draw [line,red] (m-10-2) -| (m-9-3);

\draw [line,red] (m-3-1.east) --node[midway,above,text=black]{Yes, Pass (a1,c1)} ++ (2.8cm,0)coordinate[](a);
\draw [line,red] (m-3-1.east) -| ([xshift=1.5cm]m-4-1.north);
\draw [line,red] (m-5-1.east) --node[midway,above,text=black]{Yes, Pass (a2,c2)} ++ (2.8cm,0)coordinate[](b);
\draw [line,red] (m-5-1.east) -| ([xshift=1.5cm]m-6-1.north);
\draw [line,red] (m-7-1.east) --node[midway,above,text=black]{Yes, Pass (a3,c3)} ++ (2.8cm,0)coordinate[](c);
\draw [line,red] (m-7-1.east) -| ([xshift=1.5cm]m-8-1.north);
\draw [line,red] (m-9-1.east) --node[midway,above,text=black]{Yes, Pass (a4,c4)} ++ (2.8cm,0)coordinate[](d);
\draw [line,red] (m-9-1.east) -| ([xshift=1.5cm]m-10-1.north);
\draw[line,red] (m-10-2) -- (m-6-2) node[pos=0.3,right,text=black]{Yes, Pass (a5,c5)};
\draw [line] (m-6-2) --node[midway,below,text=black]{Yes, Pass (a6,c6)} node[midway,above,text=black]{Step 6} (m-6-3);

\node[xshift=4cm] at (m-1-1) {A,b,c,d,k given};
\node[xshift=-2cm] at (m-3-1){Step 1(4)};
\node[xshift=-2cm] at (m-5-1){Step 2 (7)};
\node[xshift=-2cm] at (m-7-1){Step 3 (9)};
\node[xshift=-2cm] at (m-9-1){Step 4 (3)};
\node[xshift=-2cm,above] at (m-10-2){Step 5};
\draw [>=latex,-,red,thick] (a) --(d);
\draw [line,red] ($(a)!0.5!(d)$) -- (m-6-2);
\end{tikzpicture}

• Add a new line \node[above,xshift=1.5cm] at (m-10-2){No}; and change the \path ... command in the first foreach at(near) line 66 to \draw [line] (m-\f-1) -- node[midway,right]{No} (m-\t-1); Commented Apr 12, 2014 at 4:32
• Weird!!! I cut and paste the code and did the modification just now. I confirmed the results before I posted. Could you please check again. For the second question \begin{figure}[!htbp] tikz environment here \caption{...} \end{figure}`. I also confirmed the caption issue correctly on my end here. Commented Apr 12, 2014 at 5:03