TikZ-具有连续移动的博弈论树(表示为灰色三角形)

TikZ-具有连续移动的博弈论树(表示为灰色三角形)

在扩展形式的游戏(游戏树)中,我们通常会在玩家分支(策略)的背景中绘制一个(灰色)三角形,以表示玩家在该节点上可以采取一系列行动。例如,在下面发送的游戏树中,我手动绘制了玩家 PM 的三角形。玩家 PM 必须选择一个X(可以假设从 0 到 1 的任何值)。但是,我不知道如何使用 Ti 绘制三角形LaTeX 中的 Z。我正在发送我正在寻找的内容:

在此处输入图片描述

下面,我发送 Ti我编写的用于生成树的 Z 代码(当然,没有三角形):

\documentclass{article}
\usepackage{sgame, tikz} % Game theory packages
\usetikzlibrary{trees,backgrounds,calc,positioning,arrows}
\begin{document}
\begin{tikzpicture}[scale=2.5,font=\footnotesize]
\tikzset{
% Two node styles for game trees: solid and hollow
solid node/.style={circle,draw,inner sep=1.5,fill=black},
hollow node/.style={circle,draw,inner sep=1.5}
}
% Specify spacing for each level of the tree
\tikzstyle{level 1}=[level distance=8mm,sibling distance=20mm]
\tikzstyle{level 2}=[level distance=8mm,sibling distance=20mm]
\tikzstyle{level 3}=[level distance=8mm,sibling distance=20mm]
\tikzstyle{level 4}=[level distance=8mm,sibling distance=20mm]
\tikzstyle arrowstyle=[scale=2.5]
\tikzstyle directed=[postaction={decorate,decoration={markings,
mark=at position .5 with {\arrow[arrowstyle]{stealth}}}}]
% The Tree
\node(0)[hollow node,label=above:{$PM$}]{}
child{node(2)[solid node,label=right:{$l_{i}$}]{}
child{node(3)[hollow node,label=left:{$PM$}]{}
    child { node [solid node, label=left:$l_{i}$] {}
      child { 
        node {\emph{x}}
          edge from parent
            node[left, xshift=-3] {$Y$}}
        child { node [solid node, label=right:$l_{i}$] {}
          child { node [solid node,label=right:$l_{i}$] {}
            child { 
              node {\emph{ne}}
                edge from parent
                  node[left, xshift=-3] {$A$}}
            child { 
              node {$\ddots$}
                edge from parent
                  node[right, xshift=3] {$\neg A$}}
             edge from parent
               node[right] {}
              edge from parent
                node[left] {$VNC$}}
          child { 
            node {$\ddots$}
              edge from parent
                node[right] {$\neg VNC$}}
           edge from parent
             node[right] {}
          edge from parent
            node[right, xshift=2] {$N$}}
       edge from parent
         node[right] {$x$}}
edge from parent node[left, xshift=-3]{$A$}}
child{node(4)[label=below:{$SQ$}]{}
edge from parent node[right]{$\neg A$}
}
edge from parent node[right,xshift=3]{$p$}
};
\end{tikzpicture}
\end{document}

答案1

我可能会在背景层中添加三角形。为此,我加载了库backgrounds(并calc进行了坐标修补)。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds,calc}
\begin{document}
\begin{tikzpicture}[scale=2.5,font=\footnotesize]
\tikzset{
% Two node styles for game trees: solid and hollow
solid node/.style={circle,draw,inner sep=1.5,fill=black},
hollow node/.style={circle,draw,inner sep=1.5}
}
% Specify spacing for each level of the tree
\tikzstyle{level 1}=[level distance=8mm,sibling distance=20mm]
\tikzstyle{level 2}=[level distance=8mm,sibling distance=20mm]
\tikzstyle{level 3}=[level distance=8mm,sibling distance=20mm]
\tikzstyle{level 4}=[level distance=8mm,sibling distance=20mm]
\tikzstyle arrowstyle=[scale=2.5]
\tikzstyle directed=[postaction={decorate,decoration={markings,
mark=at position .5 with {\arrow[arrowstyle]{stealth}}}}]
% The Tree
\node(0)[hollow node,label=above:{$PM$}]{}
child{node(2)[solid node,label=right:{$l_{i}$}]{}
child{node[hollow node,label=left:{$PM$}](3){}
    child { node[solid node, label=left:$l_{i}$](5) {}
      child { 
        node{\emph{x}}
          edge from parent
            node[left, xshift=-3] {$Y$}}
        child { node [solid node, label=right:$l_{i}$] {}
          child { node [solid node,label=right:$l_{i}$] {}
            child { 
              node {\emph{ne}}
                edge from parent
                  node[left, xshift=-3] {$A$}}
            child { 
              node {$\ddots$}
                edge from parent
                  node[right, xshift=3] {$\neg A$}}
             edge from parent
               node[right] {}
              edge from parent
                node[left] {$VNC$}}
          child { 
            node {$\ddots$}
              edge from parent
                node[right] {$\neg VNC$}}
           edge from parent
             node[right] {}
          edge from parent
            node[right, xshift=2] {$N$}}
       edge from parent
         node[right] {$x$}}
edge from parent node[left, xshift=-3]{$A$}}
child{node(4)[label=below:{$SQ$}]{}
edge from parent node[right]{$\neg A$}
}
edge from parent node[right,xshift=3]{$p$}
};
\begin{scope}[on background layer]
\draw[fill=gray!40](0.south)--($(2)+(0.6cm,0)$)--($(2)-(0.6cm,0)$)--cycle;
\draw[fill=gray!40](3.south)--($(5)+(0.6cm,0)$)--($(5)-(0.6cm,0)$)--cycle;
\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

好吧,如果你必须画几棵树,森林会更容易。例如,你的树可以指定如下:

\begin{forest}
  dec tree,
  [PM
    [l_i, my label=p, cont
      [PM, my label=A
        [l_i, my label=x, cont
          [x, my label=Y]
          [l_i, my label=N
            [l_i, my label=VNC
              [ne, my label=A]
              [, my label=\lnot A]
            ]
            [, my label=\lnot VNC]
          ]
        ]
      ]
      [Sq, my label=\lnot A]
    ]
  ]
\end{forest}

其中my label设置边标签、dec tree启用整体样式并cont为当前节点的父节点设置一个三角形。

<code>dec 树</code>

您可以根据需要进行调整。(例如,您可能希望cont将其指定为父级,而不是子级之一。我这样做只是因为我最初想将其指定为子级edge。)

\documentclass[border=10pt]{standalone}
\usepackage{forest}
\forestset{
  declare toks={lpost}{left},
  my label/.style={
    if n=1{
      edge label={node [midway, left] {$#1$}}
    }{
      edge label={node [midway, right] {$#1$}}
    },
  },
  cont/.style={
    tikz+={
      \fill [fill=black, fill opacity=.5, blend mode=darken] (!u.children) -- ([xshift=25pt].center) -- ([xshift=-25pt].center) -- cycle;
    },
  },
  dec tree/.style={
    for tree={
      circle,
      inner sep=1.5pt,
      l sep'+=25pt,
      s sep'+=25pt,
      calign=fixed edge angles,
    },
    where n children=1{draw, fill=white}{
      if n children=2{draw, fill=black}{},
    },
    where level=0{lpost=above}{
      if n'=1{lpost=right}{},
    },
    before typesetting nodes={
      where content={}{content=\ddots, inner ysep=0pt, child anchor=parent first, math content}{
        label/.process={ OOw2{content}{lpost}{##2:$##1$} },
        delay={content=},
      },
    }  
  }
}
\begin{document}
\begin{forest}
  dec tree,
  [PM
    [l_i, my label=p, cont
      [PM, my label=A
        [l_i, my label=x, cont
          [x, my label=Y]
          [l_i, my label=N
            [l_i, my label=VNC
              [ne, my label=A]
              [, my label=\lnot A]
            ]
            [, my label=\lnot VNC]
          ]
        ]
      ]
      [Sq, my label=\lnot A]
    ]
  ]
\end{forest}
\end{document}

答案3

编辑:istgame版本 2.0

随着istgame版本 2 中,您可以使用新宏\istrootcntm(而不是使用\istcntm\istroot)绘制分支的连续体。使用 比\istrootcntm使用 更简单且功能更强大\istcntm(不鼓励使用过时的宏\istcntm)。另请参阅输入模式转换器 的使用\setistmathTF

在此处输入图片描述

\documentclass{standalone}    
\usepackage{istgame}    
\begin{document}

\begin{istgame}[scale=2.5,font=\footnotesize]
\setistmathTF111 % all labels are in math mode
\xtdistance{8mm}{20mm}
\istrootcntm(0)[initial node]{PM}+8mm..12mm+
  \istb{p}[r]
  \endist
\istroot(a)(0-1)<150>{l_2}
  \istb{A}[l]
  \istb{\neg A}[r]{SQ}
  \endist
\istrootcntm(1)(a-1)[initial node]<180>{PM}+8mm..12mm+
  \istb{x}[r]
  \endist
\istroot(b)(1-1)<150>{l_2}
  \istb{Y}[l]{x}[bl]
  \istb{N}[r]
  \endist
\istroot(c)(b-2){l_i}
  \istb{VNC}[l]
  \istb{\neg VNC}[r]{\ddots}[br]
  \endist
\istroot(d)(c-1){l_i}
  \istb{A}[l]{ne}[bl]
  \istb{\neg A}[r]{\ddots}[br]
  \endist
\end{istgame}
\end{document}

原始答案

这是使用包的另一种解决方案游戏,您可以使用它来\istcntm绘制一系列动作。

\documentclass{standalone}
\usepackage{istgame}
\begin{document}    
\begin{istgame}[scale=2.5,font=\footnotesize]
\xtdistance{8mm}{20mm}
\istcntm(ctm0)+8mm..12mm+
\istroot(0)(ctm0)[initial node]{$PM$}+\cntmlevdist..\cntmlevdist+
  \istb{p}[r]
  \endist
\istroot(a)(0-1)<150>{$l_2$}
  \istb{A}[l]
  \istb{\neg A}[r]{SQ}
  \endist
\istcntm(ctm1)(a-1)+8mm..12mm+
\istroot(1)(ctm1)[initial node]<180>{$PM$}+\cntmlevdist..\cntmlevdist+
  \istb{x}[r]
  \endist
\istroot(b)(1-1)<150>{$l_2$}
  \istb{Y}[l]{x}[bl]
  \istb{N}[r]
  \endist
\istroot(c)(b-2){$l_i$}
  \istb{VNC}[l]
  \istb{\neg VNC}[r]{\ddots}[br]
  \endist
\istroot(d)(c-1){$l_i$}
  \istb{A}[l]{ne}[bl]
  \istb{\neg A}[r]{\ddots}[br]
  \endist
\end{istgame}
\end{document}

相关内容