0

I found a flowchart in the book "Algorithms for Optimization", specifically on page 107 (available here). I would like to recreate this flowchart in LaTeX. Below is the flowchart for reference: Flowchart Could anyone help me with the TikZ code to replicate this flowchart? I'm particularly interested in ensuring that the layout and styles match the original as closely as possible. Thank you!

4
  • 2
    May use a TikZ matrix. The entries are mechanical work; tip: Do not write longer texts in the matrix, but let them disappear in def or newcommand statements. So that it looks like the picture, the TikZ matrix parameter needs to be fine-tuned.
    – cis
    Commented Jul 7 at 16:20
  • 3
    Well, have you asked the author for the code - if it is written in LaTeX?
    – Mensch
    Commented Jul 7 at 17:53
  • 4
    Can you post some code showing what you've tried and where you are stuck? Questions which just ask for code to reproduce complicated things are not really reasonable ones on this site, where you're asking volunteers to help you do something rather than hiring somebody to do something for you. The site works best when questions include the code for a complete but minimal document which sets the problem up and gives people something to work with.
    – cfr
    Commented Jul 7 at 18:15
  • Although it can be seen easily, it can be a little complicated, but if you want to match a special style, in this case it is a neat style, but that does not mean that it is easy to replicate, there are many ways to do it and require a code base that is not It is a lot of text and in the end an answer would rewrite everything, in short an option using positioning and the calc library.
    – J Leon V.
    Commented Jul 7 at 19:51

1 Answer 1

6

Just for fun, learning and a little free time, an option using positioning and the calc library, the first to place nodes at a certain distance from others, then the calc library to find points relative to nodes where to land with the arrows or points where to do the curves. at a relative distance to the node that allows the rounded style to be placed.

RESULT:

enter image description here

MWE:

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{mathptmx}
\usetikzlibrary{arrows.meta,positioning,calc}

\begin{document}
    \begin{tikzpicture}[
        NoBox/.style 2 args = {
            draw=none,
            minimum height=#1,
            minimum width=#2,
            text width=#2-1em
        },
        Box/.style = {
        draw,
        thick
        },
        MyArrow/.style = {
            >={Classical TikZ Rightarrow[scale length=2, scale width=0.75]}, %Envronment arrow tip style.
            draw,
            line width=0.15em,
            rounded corners=1em
        },
        Lnode/.style = {
            draw=none,
            fill=white,
            rounded corners=0,
            pos=#1
        }
        ]
        \def\Ydist{1.5em}
        \def\Xdist{7em}
        %First text column
        \node(TB1){Initial Simplex};
        \node[below=\Ydist of TB1,NoBox={4em}{13.5em}](TB2){Sort the simplex entries \\ Compute $\bar{x}$ \\ Compute the reflection point: \\ $x_r = \bar{x}+\alpha (\bar{x}-x_h)$};
        \node[below=\Ydist of TB2,Box](TB3){$y_r < y_t ?$};
        \node[below=3*\Ydist of TB3,NoBox={2em}{13.5em}](TB4){Compute the expansión point: \\ $x_r = \bar{x}+\alpha (\bar{x}-x_h)$};
        \node[below=\Ydist of TB4,Box](TB5){$y_e < y_r ?$};
        \node[below=3*\Ydist of TB5](TB6){Replace $x_h$  with $x_e$};
        %Second text column
        \node[right=\Xdist of TB3,Box](TB7){$y_r \leq y_s ?$};
        \node at (TB7|-TB6)(TB8){Replace $x_h$  with $x_r$};
        \node[below=2*\Ydist of TB8,Box](TB9){Converged?};
        %third text column
        \node[right=\Xdist of TB7,Box](TB10){$y_h \leq y_r ?$};
        \node[below right=0.9*\Ydist and 0.1*\Xdist of TB10](TB11){Replace $x_h$  with $x_r$};
        \node[below=3*\Ydist of TB10,NoBox={2em}{14em}](TB12){Compute the contraction point: \\ $x_c = \bar{x}+\gamma (x_h-\bar{x})$};
        \node[below=\Ydist of TB12,Box](TB13){$y_c > y_h ?$};
        \node[below right=0.65*\Ydist and -1em of TB13,NoBox={2em}{11em}](TB14){Shrink by replacing all\\ $x^{(i)}$  with $(X^i + x_\ell)/2$};
        \node[below=3*\Ydist of TB13](TB15){Replace $x_h$  with $x_c$};
        %Add arrows
        %First Column
        \draw[MyArrow,->](TB1) -- (TB2);
        \draw[MyArrow,->](TB2) -- (TB3);
        \draw[MyArrow,-](TB3) -- (TB4) node[Lnode=0.5]{yes};
        \draw[MyArrow,->](TB4) -- (TB5);
        \draw[MyArrow](TB5) -- (TB6) node[Lnode=0.5]{yes};
        \draw[MyArrow,->](TB4) -- (TB5);
        %Second Column
        \draw[MyArrow,->](TB3) -- (TB7) node[Lnode=0.5]{no};
        \draw[MyArrow,->](TB7) -- (TB8) node[Lnode=0.15]{no};
        \draw[MyArrow](TB5) -| ($(TB5-|TB7)+(0,-0.5em)$) node[Lnode=0.2]{no};
        \draw[MyArrow,->](TB8) -- (TB9);
        \draw[MyArrow](TB6) |- ($(TB6.-90)+(\Xdist/2,-\Ydist)$) -|(TB9);
        %third Column
        \draw[MyArrow,->](TB7) -- (TB10) node[Lnode=0.5]{yes};
        \draw[MyArrow, rounded corners=0](TB10) -| (TB11) node[Lnode=0.5]{no};
        \draw[MyArrow, rounded corners=0](TB11) |- ($(TB12.90)+(0,0.6em)$);
        \draw[MyArrow](TB10) -- (TB12) node[Lnode=0.5]{yes};
        \draw[MyArrow,->](TB12) -- (TB13);
        \draw[MyArrow, rounded corners=0](TB13) -| (TB14) node[Lnode=0.5]{yes};
        \draw[MyArrow](TB13) -- (TB15) node[Lnode=0.5]{no};
        \draw[MyArrow](TB15) |- ($(TB15.-90)+(-\Xdist/2,-\Ydist)$) coordinate (temp) -|(TB9);
        \draw[MyArrow](TB14) |- (temp);
        %Last Arrows
        \draw[MyArrow,rounded corners=0](TB9) |- ($(TB9.-90)+(-\Xdist/2,-\Ydist)$) node[Lnode=0.5]{no} coordinate (temp);
        \draw[MyArrow,->](temp) -|($(TB2.north west)+(-2em,-0.7em)$) -- ++(2em,0);
        \draw[MyArrow,->](TB9.0) -- +(\Xdist,0)node[Lnode=0.5]{yes}node[Lnode=1,anchor=180]{Return best point};
            
    \end{tikzpicture} 
\end{document} 

Not the answer you're looking for? Browse other questions tagged .