创建分支限界法

创建分支限界法

我正在尝试修改提供的答案@cfr这个问题。但是,我的结果中出现了奇怪的内容“高度”,请看每个框。有人能帮我解决这个问题吗?

我的代码是

\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=center,
    text width=2.5cm,
    draw,
    node distance=1cm and 1cm
  }
}
\begin{document}
\begin{forest}
  %forked edges,
  for tree={
    draw,
    inner xsep=1pt,
    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}%
        },
      },
    },
  }
  [$ILO$
    [{}, edge label={solve as continuous problem}
      [{$x_1^*=1,x_2^*=2.166$}, edge label={$x_1\geq 2$}
       [{$x_1^*=1,x_2^*=2.1667$}, edge label={$x_1\leq 1$}
         [{$x_1^*=1,x_2^*=2.1667$}, edge label={$x_2\leq 2$}
         ]
       ]
       [{$x_1^*=1,x_2^*=2.1667$}, edge label={$x_2\geq 7$}
       ]
     ]
      [{$x_1^*=1,x_2^*=2.1667$}, edge label={$x_1\geq 1$}
      ]
    ]
  ]
\end{forest}
\end{document}

我的结果是 在此处输入图片描述

答案1

我假设您只需要边缘标签代码,而不是将节点标签分成两部分并在两部分之间有一条线的代码(如链接的答案中所示)。在这种情况下,这就是您想要的:

\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=center,
    text width=2.5cm,
    draw,
    node distance=1cm and 1cm
  }
}
\begin{document}
\begin{forest}
  %forked edges,
  for tree={
    draw,
    inner xsep=1pt,
    edge={-Stealth},
    l sep+=20pt,
    %fork sep+=10pt,
  },
  before typesetting nodes={
    where level=0{}{
      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}%
        },
      },
    },
  }
  [$ILO$
    [{}, edge label={solve as continuous problem}
      [{$x_1^*=1,x_2^*=2.166$}, edge label={$x_1\geq 2$}
       [{$x_1^*=1,x_2^*=2.1667$}, edge label={$x_1\leq 1$}
         [{$x_1^*=1,x_2^*=2.1667$}, edge label={$x_2\leq 2$}
         ]
       ]
       [{$x_1^*=1,x_2^*=2.1667$}, edge label={$x_2\geq 7$}
       ]
     ]
      [{$x_1^*=1,x_2^*=2.1667$}, edge label={$x_1\geq 1$}
      ]
    ]
  ]
\end{forest}
\end{document}

代码输出

相关内容