2

I modified the flowchart code given here a bit, to produce this:

enter image description here

This is the modified code:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}

% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=yellow!20, 
    text width=6em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=gray!20, 
    text width=12em, text centered, rounded corners, minimum height=4em]
\tikzstyle{small_block} = [circle, draw, fill=white!20, 
    text width=0em, text centered, rounded corners, minimum height=0em]    
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
    minimum height=2em]

\begin{tikzpicture}[node distance = 2cm, auto]
    % Place nodes
    \node [block] (init) {\textbf{START} \\ Randomly generate $n$ groups of $p$ strings.};
    \node [block, below of=init] (identify) {Choose the leader string for each group.};
    \node [block, below of=identify] (mutate) {Mutate each string according to the given rule.};
    \node [block, below of=mutate] (transfer) {Carry out parameter transfer for each group, from other groups.};
    \node [block, below of=transfer] (evaluate) {Calculate the fidelity for all the strings in all the groups.};
    \node [small_block, left of=evaluate, node distance=5cm] (update) {};
    \node [decision, below of=evaluate] (decide) {Termination condition satisfied ?};
    \node [block, below of=decide, node distance=3cm] (stop) {\textbf{STOP}};
    % Draw edges
    \path [line] (init) -- (identify);
    \path [line] (identify) -- (mutate);
    \path [line] (mutate) -- (transfer);
    \path [line] (transfer) -- (evaluate);
    \path [line] (evaluate) -- (decide);
    \path [line] (decide) -| node [near start] {No} (update);
    \path [line] (update) |- (identify);
    \path [line] (decide) -- node {Yes}(stop);
\end{tikzpicture}
\end{document}

Question 1:

Now, I want to get rid of the small white circle, which lies in the path of the "No" arrow. But to do that, if I delete the \node [small_block, left of=evaluate, node distance=5cm] (update) {};, I get an error: that is, the "No" arrow passes straight through the other blocks, and it looks ugly. What would be the correct way to fix this?

Question 2:

If I modify the code further to draw a separate "START" cloud on the top of the flowchart, instead of grouping it with the "Randomly generate..." block, like:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}

% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=yellow!20, 
    text width=6em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=gray!20, 
    text width=12em, text centered, rounded corners, minimum height=4em]
\tikzstyle{small_block} = [circle, draw, fill=white!20, 
    text width=0em, text centered, rounded corners, minimum height=0em]    
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
    minimum height=2em]

\begin{tikzpicture}[node distance = 2cm, auto]
    % Place nodes
    \node [cloud] (start) {\textbf{START}};
    \node [block] (init) {Randomly generate $n$ groups of $p$ strings.};
    \node [block, below of=init] (identify) {Choose the leader string for each group.};
    \node [block, below of=identify] (mutate) {Mutate each string according to the given rule.};
    \node [block, below of=mutate] (transfer) {Carry out parameter transfer for each group, from other groups.};
    \node [block, below of=transfer] (evaluate) {Calculate the fidelity for all the strings in all the groups.};
    \node [small_block, left of=evaluate, node distance=5cm] (update) {};
    \node [decision, below of=evaluate] (decide) {Termination condition satisfied ?};
    \node [block, below of=decide, node distance=3cm] (stop) {\textbf{STOP}};
    % Draw edges
    \path [line] (start) -- (init);
    \path [line] (init) -- (identify);
    \path [line] (identify) -- (mutate);
    \path [line] (mutate) -- (transfer);
    \path [line] (transfer) -- (evaluate);
    \path [line] (evaluate) -- (decide);
    \path [line] (decide) -| node [near start] {No} (update);
    \path [line] (update) |- (identify);
    \path [line] (decide) -- node {Yes}(stop);
\end{tikzpicture}
\end{document}

I get:

enter image description here

Clearly, the "START" cloud is not appearing! Where did I go wrong?

1

Several comments:

  1. \tikzstyle is deprecated, use \tikset{.../.style={...}} instead.
  2. Using the positioning library simplifies things a lot.
  3. You get the error because the node update is undefined if you drop the node, but you are using it later in a path. You can just insert a coordinate.
  4. There is no problem adding the cloud if you use positioning.

Here is the code:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
\begin{document}
\pagestyle{empty}

% Define block styles
\tikzset{decision/.style={diamond, draw, fill=yellow!20, 
    text width=6em, text badly centered, node distance=3cm, inner sep=0pt},
block/.style={rectangle, draw, fill=gray!20, 
    text width=12em, text centered, rounded corners, minimum height=4em},
small_block/.style={circle, draw, fill=white!20, 
    text width=0em, text centered, rounded corners, minimum height=0em},    
line/.style={draw, -latex'},
cloud/.style={draw, ellipse,fill=red!20, node distance=3cm,
    minimum height=2em},}

\begin{tikzpicture}[node distance = 1cm, auto]
    % Place nodes
    \node [block] (init) {Randomly generate $n$ groups of $p$ strings.};
    \node [cloud,font=\bfseries,above=1cm of init] (start) {START};
    \node [block, below=of init] (identify) {Choose the leader string for each group.};
    \node [block, below=of identify] (mutate) {Mutate each string according to the given rule.};
    \node [block, below=of mutate] (transfer) {Carry out parameter transfer for each group, from other groups.};
    \node [block, below=of transfer] (evaluate) {Calculate the fidelity for all the strings in all the groups.};
    % changed to coordinate
    \coordinate [left of=evaluate, node distance=5cm] (update) {};
    \node [decision, below of=evaluate] (decide) {Termination condition satisfied ?};
    \node [block, below of=decide, node distance=3cm] (stop) {\textbf{STOP}};
    % Draw edges
    \path [line] (start) -- (init); 
    \path [line] (init) -- (identify);
    \path [line] (identify) -- (mutate);
    \path [line] (mutate) -- (transfer);
    \path [line] (transfer) -- (evaluate);
    \path [line] (evaluate) -- (decide);
    %\path [line] (decide) -| node [near start] {No} (update);
    %\path [line] (update) |- (identify);
    \path [line] (decide) -| node [near start] {No} (update) |- (identify);
    \path [line] (decide) -- node {Yes}(stop);
\end{tikzpicture}
\end{document}

enter image description here

  • Thanks! :) I suggested an edit to remove the redundant "START" in the (init) box and to add an arrow from the "START" cloud to the (init) box. – Blue Oct 18 '18 at 13:52
  • @Blue Thanks! (I misread the request, sorry!) – user121799 Oct 18 '18 at 13:53
1

your simple flowchart is simple to draw with help of the tikz libraries chains, positioning and quotes. considering them, the code for flowchart is organized as follows:

  • nodes are connected in chain with "START" on its beginning and "END" on the its end,
  • lines between nodes in chain is drawn by macro join provided by library chains,
  • feedback loop is drawn by use of relative coordinate for the first path's stage,
  • for labeling of path is used the quotes library

the resulting code is much shorter and simple:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,       % <---
                positioning,  % <---
                quotes,       % <---
                shapes.geometric}
\usepackage{siunitx}

\tikzset{FlowChart/.style={   % <--- named tikzset
    block/.style = {rectangle, rounded corners, draw, fill=gray!20,
                    text width=12em, minimum height=1cm, align=flush center,
                    on chain, join=by line},
    cloud/.style = {draw, ellipse, fill=red!20, minimum height=1cm,
                    on chain, join=by line},
 decision/.style = {diamond, aspect=1.3, draw, fill=green!30,
                    text width=6em, minimum height=1cm, align=flush center,
                    on chain, join=by line},
     line/.style = {semithick,-Triangle}
                            }% end of styles
     }% end of tikzset
\begin{document}
\pagestyle{empty}
    \begin{tikzpicture}[FlowChart,
node distance = 8mm,
  start chain = going below
                    ]
% Place nodes
\node [cloud,font=\bfseries] (start) {START};
\node [block] (init)        {Randomly generate $n$ groups of $p$ strings.};
\node [block] (identify)    {Choose the leader string for each group.};
\node [block] (mutate)      {Mutate each string according to the given rule.};
\node [block] (transfer)    {Carry out parameter transfer for each group, from other groups.};
\node [block] (evaluate)    {Calculate the fidelity for all the strings in all the groups.};
\node [decision] (decide)   {Termination condition satisfied ?};
\node [block] (stop)        {\textbf{STOP}};
% Draw edges o included with "join" macro
\draw[line] (decide.west) to ["No"] ++ (-1.5,0) |- (identify);
\path       (decide) to ["Yes"] (stop);
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.