复杂概率树

复杂概率树

为了进行博弈论练习,我一直在尝试使用 TiKz 包重新创建以下树。我不知道这个包是否是正确的方法,但这是我尝试复制的树: 在此处输入图片描述

如果有人可以提供执行这种特定类型的树所需的代码示例,那将会很有帮助,因为我可以将其复制到我必须处理的多个其他示例中。

我尤其为分支中的标签、虚线和开头的水平线而苦恼。这就是为什么我没有分享任何代码尝试,因为看起来一切都不对劲,而且这会对帖子造成损害。

如果需要我的序言,请参见下文:

**编辑:序言已清理

\documentclass[12pt, a4 paper]{article}

\usepackage{multicol} %Needed for \PDgame
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb}
\usepackage{parskip}
\usepackage{graphicx}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{verbatim}
\usepackage{subcaption}
\usepackage{indentfirst}
\usepackage{tikz}

% Margins
\usepackage[inner=2.0cm,outer=2.0cm,top=2.5cm,bottom=2.5cm]{geometry}
% Colour table cells
\usepackage[table]{xcolor}


\setlength{\marginparwidth}{2cm}
\begin{document}
\end{document}

答案1

请求的概率树

答案改编自这个问题。要连接节点,只需命名它们,然后就可以在它们之间画线。这就是虚线的制作方法。上面两条线只是硬编码的。可能有一种方法可以更自动地完成它,但我不知道。

\documentclass[border=25]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}

\tikzset{
    solid node/.style={circle,draw,inner sep=1.2,fill=black},
}

\begin{tikzpicture}[font=\footnotesize]
    \tikzset{
        level 1/.style={level distance=15mm,sibling distance=65mm},
        level 2/.style={level distance=15mm,sibling distance=30mm},
        level 3/.style={level distance=15mm,sibling distance=15mm},
        level 4/.style={level distance=15mm,sibling distance=10mm},
  }

    \node(top)[solid node,label=above left:{1},red]{}
        child{[red]node[solid node,label=above:{1}]{}
        child{[black]node[solid node,label=left:{2}]{}
        child{[red]node[solid node,label=below:{\((6, 0)\)}]{}edge from parent node[left]{\(\alpha_2\)}}
        child{[red]node[solid node,label=below:{\((3, 1)\)}]{}edge from parent node[right]{\(\beta_2\)}}
        edge from parent node[left]{\(A_1\)}
    }
        child{node[solid node,label=below:{\((4,1)\)}]{}  % This is the branch that ends early
        edge from parent node[right]{\(B_1\)}
    }
        edge from parent node[left,xshift=-10]{\(a_1\)}
    }
        child{node[solid node,label=above:{2}]{}
        child{[red]node(A2)[solid node]{}
        child{node[solid node,black,label=below:{\((3, 3)\)}]{}edge from parent node[left]{\(\alpha_1\)}}
        child{[black]node[solid node,label=below:{\((1,5)\)}]{}edge from parent node[right]{\(\beta_1\)}}
        edge from parent node[left]{\(A_2\)}
    }
        child{node(B2)[solid node]{}
        child{[red]node[solid node,label=below:{\((4, 2)\)}]{}edge from parent node[left]{\(\alpha_1\)}}
        child{node[solid node,label=below:{\((5,1)\)}]{}edge from parent node[right]{\(\beta_1\)}}
        edge from parent node[right]{\(B_2\)}
    }
        edge from parent node[right,xshift=10]{\(b_1\)}
    };
    \draw[dashed] (A2) -- (B2) node[midway, above] {1};
    \coordinate (right angle) at ($(top) + (0, 1.5)$);
    \draw[red] (top) -- (right angle) node[midway, right,black] {\(C\)};
    \node[solid node,red,label=above:{2}] at (right angle) {};
    \draw[red] (right angle) -- ($(right angle) + (1.5, 0)$) node[black, midway, above] {\(S\)} node[below,black] {\((1, 2)\)};
    
\end{tikzpicture}
\end{document}

答案2

您可能还会使用forest

\documentclass{article}
\usepackage[edges]{forest}
\newcommand{\ur}[2][red]{\textcolor{#1}{\underline{\textcolor{black}{#2}}}}
\begin{document}
\begin{forest}
er/.style={edge=red},r/.style={color=red},rer/.style={r,er},
el/.style={edge label={node[midway,auto,color=black]{\ensuremath{#1}}}},
el'/.style={edge label={node[midway,auto,color=black,swap]{\ensuremath{#1}}}},
for tree={l sep+=2em,s sep+=2em,
    if n children=0{math content}{circle,inner sep=1pt,fill},
    if level=3{tier=bottom}{}}
[,r,label={90:1},alias=r,
    tikz+={\path[draw=red] ()-- node[auto]{$S$} ++ (2,0) node[below]{$(1,\ur{2})$};}
 [,rer,el={C},label={135:1}
  [,er,el'={\alpha},label={90:1}
   [,el'={A_1},label={135:2}
    [{(6,0)},el'={\alpha_2}]
    [{(3,1)},el={\beta_2}]
   ]
   [{(4,\ur{1})},er,el={B_1}
   ]
  ]
  [,label={90:2},el={b_1}
   [,er,el'={A_2},tikz+={\path[draw,dotted] () -- (!s);}
    [{(3,3)},er,el'={\alpha_1}]
    [{(1,5)},el={\beta_1}]
   ]
   [,el={B_2}
    [{(4,2)},er,el'={\alpha_1}]
    [{(1,5)},el={\beta_1}]
   ]
  ]
 ] 
]
\end{forest}
\end{document}

在此处输入图片描述

答案3

使用游戏包中,你可以这样做:

  1. 绘制游戏树:

在此处输入图片描述

\documentclass[tikz]{standalone}
    
\usepackage{istgame}

\begin{document}

\begin{istgame}
\xtdistance{10mm}{20mm}
\istroot[-45](0){2}
  \istb{C}[r]                \istb{S}[a]{(1,2)}[b]     \endist
\xtdistance{15mm}{60mm}
\istroot(1)(0-1)<135>{1}
  \istb{a_1}[al]             \istb{b_1}[ar]            \endist
\xtdistance{15mm}{30mm}
\istroot(2)(1-1){1}
  \istb{A_1}[al]             \istb{B_1}[ar]{(4,1)}     \endist
\istroot(3)(1-2){2}
  \istb{A_2}[al]             \istb{B_2}[ar]            \endist
\xtdistance{15mm}{15mm}
\istroot(2a)(2-1)<135>{2}
  \istb{\alpha_2}[al]{(6,0)} \istb{\beta_2}[ar]{(3,1)} \endist
\istroot(3a)(3-1)
  \istb{\alpha_1}[al]{(3,3)} \istb{\beta_1}[ar]{(1,5)} \endist
\istroot(3b)(3-2)
  \istb{\alpha_1}[al]{(4,2)} \istb{\beta_1}[ar]{(5,1)} \endist
\xtInfoset(3a)(3b){1}
\end{istgame}

\end{document}
  1. 分析一下比赛:

在此处输入图片描述

\documentclass[tikz]{standalone}
    
\usepackage{istgame}

\begin{document}

\begin{istgame}
\tikzset{KK/.style={draw=red,very thick}}

\xtdistance{10mm}{20mm}
\istroot[-45](0){2}
  \istb[KK]{C}[r]
  \istb[KK]{S}[a]{(1,2)}[b]
  \endist
\xtdistance{15mm}{60mm}
\istroot(1)(0-1)<135>{1}
  \istb[KK]{a_1}[al]
  \istb    {b_1}[ar] 
  \endist
\xtdistance{15mm}{30mm}
\istroot(2)(1-1){1}
  \istb    {A_1}[al]
  \istb[KK]{B_1}[ar]{(4,1)}
  \endist
\istroot(3)(1-2){2}
  \istb[KK]{A_2}[al]
  \istb    {B_2}[ar]
  \endist
\xtdistance{15mm}{15mm}
\istroot(2a)(2-1)<135>{2}
  \istb    {\alpha_2}[al]{(6,0)}
  \istb[KK]{\beta_2}[ar]{(3,1)}
  \endist
\istroot(3a)(3-1)
  \istb[KK]{\alpha_1}[al]{(3,3)}
  \istb    {\beta_1}[ar]{(1,5)}
  \endist
\istroot(3b)(3-2)
  \istb[KK]{\alpha_1}[al]{(4,2)}
  \istb    {\beta_1}[ar]{(5,1)}
  \endist
\xtInfoset(3a)(3b){1}
\end{istgame}

\end{document}

相关内容