创建分支限界

创建分支限界

我想创建一个像下面这样的图表!我想我应该使用森林包,但它不允许我(或者我无法做到这一点)在每个分支附近放置解释,例如“解决连续问题”。任何帮助都将不胜感激。

在此处输入图片描述

答案1

这里有一个使用库positioning和包含节点文本的解决方案shapes.multipart\textA,\textB,...,\textG只需根据需要进行更改。

为了将节点分成两部分,我们有rectangle splitrectangle split parts=来自shapes.multipart库的部分。

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.multipart}


\def\textA{$\text{min}\  x_1-2x_2$\\
subject to\\
\hspace{1cm}\vdots}

\def\textB{$\text{min}\  x_1-2x_2$\\
subject to\\
\hspace{1cm}\vdots
\nodepart{two}
{\scriptsize $x_1^*=1,x_2^*=2.1667$}
}

\def\textC{$\text{min}\  x_1-2x_2$\\
subject to\\
\hspace{1cm}\vdots
\nodepart{two}
{\scriptsize $x_1^*=1,x_2^*=2.1667$}
}

\def\textD{$\text{min}\  x_1-2x_2$\\
subject to\\
\hspace{1cm}\vdots
\nodepart{two}
{\scriptsize $x_1^*=1,x_2^*=2.1667$}}

\def\textE{$\text{min}\  x_1-2x_2$\\
subject to\\
\hspace{1cm}\vdots
\nodepart{two}
{\scriptsize $x_1^*=1,x_2^*=2.1667$}}

\def\textF{$\text{min}\  x_1-2x_2$\\
subject to\\
\hspace{1cm}\vdots
\nodepart{two}
{\scriptsize $x_1^*=1,x_2^*=2.1667$}}

\def\textG{$\text{min}\  x_1-2x_2$\\
subject to\\
\hspace{1cm}\vdots
\nodepart{two}
{\scriptsize $x_1^*=1,x_2^*=2.1667$}}

\tikzset{>=stealth,parent node/.style={rectangle split, rectangle split parts=2,align=left,text width=2.5cm,draw,node distance=1cm and 1cm}}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
\node[parent node,rectangle split parts=1](A){\textA};
\node[parent node,below =of A](B){\textB};
\node[parent node,below left =of B](C){\textC};
\node[parent node,below right =of B](D){\textD};
\node[parent node,node distance=1 and 0.3,below left =of C](E){\textE};
\node[parent node,node distance=1 and 0.3,below right =of C](F){\textF};
\node[parent node,node distance=1 and 0.3,below =of E](G){\textG};

\draw[->](A.south)--(B)node[midway,right]{\scriptsize solve as continous problem};
\draw[->](B.south)--+(0,-0.5)-|(D)node[right,near end]{\scriptsize $x_1\geq 2$};
\draw[->](B.south)--+(0,-0.5)-|(C)node[left,near end]{\scriptsize $x_1\leq 1$};
\draw[->](C.south)--+(0,-0.5)-|(E)node[left,near end]{\scriptsize $x_2\leq 2$};
\draw[->](C.south)--+(0,-0.5)-|(F)node[right,near end]{\scriptsize $x_2\geq $};
\draw[->](E.south)--(G)node[left,midway]{\scriptsize $x_1\geq 1$};
\end{tikzpicture}
\caption{Branch and Bound Methode Example:Integer bound of $x_1$}
\end{figure}

\end{document}  

输出

在此处输入图片描述

答案2

使用由萨利姆布,而 OP 拒绝提供,这里有两个 Forest 版本。但请注意,我并不认为 Forest 是这里的最佳选择。

\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{arrows.meta}
\usepackage{amsmath}
\usepackage{forest}
\useforestlibrary{edges}
\tikzset{%
  >=stealth,
  parent node/.style={%
    rectangle split,
    rectangle split parts=2,
    align=left,
    text width=2.5cm,
    draw,
    node distance=1cm and 1cm
  }
}
\begin{document}
\begin{forest}
  %forked edges,
  for tree={
    draw,
    inner xsep=0pt,
    align={l},
    edge={-Stealth},
    l sep+=20pt,
    %fork sep+=10pt,
  },
  before typesetting nodes={
    where level=0{}{
      split option={content}{:}{temptoksa,temptoksb},
      content/.wrap 2 pgfmath args={#1\\\hline #2}{temptoksa}{temptoksb},
      if={(n()==1)&&(level()>1)}{%
        edge label/.wrap value={%
          node [midway, left, font=\scriptsize] {#1}%
        },
      }{%
        edge label/.wrap value={%
          node [midway, right, font=\scriptsize] {#1}%
        },
      },
    },
  }
  [$\text{min}\  x_1-2x_2$\\subject to\\\dots
    [{$\text{min}\  x_1-2x_2$\\subject to\\\dots}:{$x_1^*=1,x_2^*=2.1667$}, edge label={solve as continuous problem}
      [{$\text{min}\  x_1-2x_2$\\subject to\\\dots}:{$x_1^*=1,x_2^*=2.1667$}, edge label={$x_1\geq 2$}
       [{$\text{min}\  x_1-2x_2$\\subject to\\\dots}:{$x_1^*=1,x_2^*=2.1667$}, edge label={$x_1\leq 1$}
         [{$\text{min}\  x_1-2x_2$\\subject to\\\dots}:{$x_1^*=1,x_2^*=2.1667$}, edge label={$x_2\leq 2$}
         ]
       ]
       [{$\text{min}\  x_1-2x_2$\\subject to\\\dots}:{$x_1^*=1,x_2^*=2.1667$}, edge label={$x_2\geq 7$}
       ]
     ]
      [{$\text{min}\  x_1-2x_2$\\subject to\\\dots}:{$x_1^*=1,x_2^*=2.1667$}, edge label={$x_1\geq 1$}
      ]
    ]
  ]
\end{forest}
\end{document}

标准版本:

标准树

分叉边缘:

分叉边缘

对于第二个版本,取消注释树序言中的两行注释。

相关内容