# Help for one simple diagram about genetic algorithmic

I would like to produce the following diagram.

Thanks to the following comments and one example from TeXample.net, I have done the following code. There is some problems. How can I fix them ?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

\tikzstyle{frame} = [
rectangle, draw,
text width=2em, text centered,
minimum height=4em
]
\tikzstyle{line} = [draw, -latex']

\begin{document}

\begin{tikzpicture}[node distance = 3cm]
\node [frame] (pop) {Population};
\node [above of=pop, left of=pop] (init) {Initialisation};
\node [below of=pop, left of=pop] (term) {Termination};
\node [frame, above of=pop, right of=pop] (parents)  {Parents};
\node [frame, below of=pop, right of=pop] (off)  {Offspring};

\path [line] (parents) -- node[right,pos=.4] {Recombination} node[right,pos=.6] {Mutation} (off);
\path [line] (init) |- (pop);
\path [line] (pop) -| (term);
\path [line] (off) -| node[below,pos=.25] {Survivor selection}(pop);
\path [line] (pop) |- node[above,pos=.75] {Parents selection} (parents);
\end{tikzpicture}

\end{document}

Here is my huggly output !

• TikZ: five nodes and five edges with four nodes attached to them. Jan 23, 2013 at 20:20
• How can I place text near edges ? Jan 23, 2013 at 20:21
• For example: \draw[nodes=right] (Parents) edge node[pos=.33] {Recombination} node[pos=.67] {Mutation} (Offspring); Or \draw (Population) |- node[above,pos=.75] {Parent selection} (Parents); And the arrows library provides a few arrow styles (e.g. -triangle 45). Nodes not attached to the liens can be placed either manually or with the help of the positioning library. Jan 23, 2013 at 20:24
• Take a look, have a try. Jan 23, 2013 at 20:29
• That is the meaning of my question. I've updated it. Jan 23, 2013 at 20:31

I've made a couple of adjustments to the text width and node distance settings in your examples, have got to something which is nearly there, but you might want to make the arrowheads bigger?

https://www.writelatex.com/37459xjfzxh

Screenshot attached Update: Thanks to whoever made the edits to the wL document, they reached the updated image shown below, which is pretty close to the desired result

\documentclass[margin=3pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\tikzset{
frame/.style={
rectangle, draw,
text width=6em, text centered,
rounded corners,
},
line/.style={
draw, -latex',rounded corners=3mm,
}
}

\begin{document}
\begin{tikzpicture}[font=\small\sffamily\bfseries,very thick,node distance = 4cm]
\node [frame] (pop) {Population};
\node [above=2cm, left of=pop] (init) {Initialisation};
\node [below=2cm, left of=pop] (term) {Termination};
\node [frame, above=2cm, right of=pop] (parents)  {Parents};
\node [frame, below=2cm, right of=pop] (off)  {Offspring};

\path [line] (parents)
-- node[right,align=left,pos=.5] {Recombination\\[3mm]Mutation}
(off);
\path [line] (init) |- (pop.170);
\path [line] (pop.190) -| (term);
\path [line] (off) -| node[below,pos=.25, align=center] {Survivor\\ selection}(pop);
\path [line] (pop) |- node[above,pos=.75, align=center] {Parents\\ selection}(parents);
\end{tikzpicture}
\end{document}

• PS: If someone can improve this, please feel free to edit the wL doc. Jan 24, 2013 at 0:36
• PPS: This is amazing - I'm now watching someone who clearly knows what they're doing editing the wL doc & making improvements...it's quite hypnotising! Jan 24, 2013 at 0:47
• Instead of screenshots and a link to a rolling code, you should include the code itself... Jan 24, 2013 at 6:55
• @JohnHammersley: Hello, thanks for the secund pretty output BUT there is two things to ameliorate. First, the arrows from/to INITIALISATION and TERMINATION overlap each other. That's not wanted (see the first picture in my question). Secundly, a lot of vertical space is wasted. Is there a way to use less vertical space ? Just one last question. Is there a way to add a backreturn so as to put "Parents" above "selection" (see the arrows from POPULATION to PARENTS). Jan 24, 2013 at 7:28
• @PaulGaborit Thanks for the pointer, I'm still learning here so will remember to post the code in future. Jan 24, 2013 at 10:09