我正在使用 tikz 和 forest 来绘制它,但距离它还很远。具体来说:我想 1. 在不同的节点中包含不同玩家的名称(简单地说是“玩家 1”和“玩家 2”);2. 为玩家 1 创建第二个节点(包含信息集)(其中策略是“提出建议”);3. 正确绘制最后两个信息集(用蓝色和红色突出显示)。
我正在发送迄今为止的代码:
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage[edges]{forest}
\usepackage[outline]{contour}
\usetikzlibrary{fit,shapes.misc,arrows.meta,positioning}
\tikzset{rconnect/.style args={#1 and #2}{insert path={
($(#1)+ (270+\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/r adius})$)
arc(270+\pgfkeysvalueof{/tikz/rconnect/angle}:90+\pgfkeysvalueof{/tikz/rcon nect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})
to[out=\pgfkeysvalueof{/tikz/rconnect/angle},in=180- \pgfkeysvalueof{/tikz/rconnect/angle}]
($(#2)+(90- \pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius })$)
arc(90-\pgfkeysvalueof{/tikz/rconnect/angle}:-90- \pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius })
to[in=\pgfkeysvalueof{/tikz/rconnect/angle},out=180- \pgfkeysvalueof{/tikz/rconnect/angle}]
cycle}},rconnect/.cd,radius/.initial=6.5pt,angle/.initial=-12}
\begin{document}
\begin{forest}
for tree={s sep=0.1cm,l sep=1.2cm,font=\scriptsize,
where n children=0{align=center,draw,edge={thick,-{Circle}}} {circle,fill,inner sep=0pt,minimum size=2mm},
where n=1{edge label={node[midway,above left=0pt,font=\scriptsize]{S}}} {edge
label={node[midway,above right=0pt,font=\scriptsize]{E}}},
edge={thick}
}
[,label=above:Nature,alias=T
[,alias=L
[,alias=LL
[
[{$B-C$ \\ $0$}]
[{$B$ \\ $X$}]
]
[
[{$B-L$ \\ $R-L$}]
[{$B-L$ \\ $X-L$}]
]
]
[,alias=LR
[
[{$B-C$ \\ $0$}]
[{$B$ \\ $X$}]
]
[
[{$B-L$ \\ $R-L$}]
[{$B-L$ \\ $X-L$}]
]
]
]
[,alias=R
[,alias=RL
[
[{$B-C$ \\ $\bar{R}$}]
[{$B$ \\ $X$}]
]
[
[{$B-L$ \\ $R-L$}]
[{$B-L$ \\ $X-L$}]
]
]
[,alias=RR
[
[{$B-C$ \\ $\bar{R}$}]
[{$B$ \\ $X$}]
]
[
[{$B-L$ \\ $R-L$}]
[{$B-L$ \\ $X-L$}]
]
]
]
]
\node[draw,dashed,rounded rectangle,fit=(L) (R)] (F1){};
\node[draw,dashed,rounded rectangle,fit=(LR) (RL)]{};
\draw[dashed] let \p1=($(F1.north)-(F1.center)$) in
[/tikz/rconnect/radius=\y1] [rconnect=LL and RR];
\end{forest}
\end{document}
答案1
另一种解决方案是使用游戏包裹:
\documentclass{standalone}
\usepackage{amsmath}
\usepackage{makecell}
\usepackage{istgame}
\NewDocumentCommand\mact{m}
{\makecell[c]{#1}}
\NewDocumentCommand\mpay{m}
{\begin{pmatrix}#1\end{pmatrix}}
\begin{document}
\begin{istgame}[font=\footnotesize]
\setistmathTF*001
\xtShowEndPoints
% top part
\xtdistance{25mm}{120mm}
\istroot(0)[chance node]{Nature}
\istb{\mact{$R=O$\\(Cooperative\\Player)}}[above left,xshift=-10pt]
\istb{\mact{$R=\bar R$\\(Competitive\\Player)}}[above right,xshift=10pt] \endist
\xtdistance{25mm}{50mm}
\istroot(A)(0-1)%<180>{Player 1}
\istb{\mact{Introduce\\Proposal}}[l] \endist
\istroot(B)(0-2)%<0>{Player 1}
\istb{\mact{Introduce\\Proposal}}[r] \endist
% left part
\xtdistance{25mm}{60mm}
\istroot(A0)(A-1)<180>{Player 2}
\istb{Go}[al] \istb{Stay}[ar] \endist
\xtdistance{25mm}{30mm}
\istroot(A1)(A0-1)<0>{$(B-C,O)$}
\istb{\mact{Introduce\\Proposal\\(I)}}[al] \istb{\mact{Delay\\(D)}}[ar] \endist
\istroot(A2)(A0-2)<180>{$(B,X)$}
\istb{I}[al] \istb{D}[ar] \endist
\xtdistance{25mm}{15mm}
\istroot(A3)(A1-1)<180>{Player 2}
\istb{Go (G)}[l]{\mpay{B-C\\O}} \istb{Stay (S)}[r]{\mpay{B\\X}} \endist
\istroot(A4)(A1-2)<180>{Player 2}
\istb{G}[l]{\mpay{B-L\\X-L}} \istb{S}[r]{\mpay{B-C\\O}} \endist
\istroot(A5)(A2-1)<180>{Player 2}
\istb{G}[l]{\mpay{B\\X}} \istb{S}[r]{\mpay{B-L\\X-L}} \endist
\istroot(A6)(A2-2)<180>{Player 2}
\istb{G}[l]{\mpay{B\\O}} \istb{S}[r]{\mpay{L\\O}} \endist
% right part
\xtdistance{25mm}{60mm}
\istroot(B0)(B-1)<180>{Player 2}
\istb{Go}[al] \istb{Stay}[ar] \endist
\xtdistance{25mm}{30mm}
\istroot(B1)(B0-1)<0>{$(B-C,\bar R)$}
\istb{I}[al] \istb{D}[ar] \endist
\istroot(B2)(B0-2)<180>{$(B,X)$}
\istb{I}[al] \istb{D}[ar] \endist
\xtdistance{25mm}{15mm}
\istroot(B3)(B1-1)<180>{Player 2}
\istb{G}[l]{\mpay{B\\-L}} \istb{S}[r]{\mpay{B-L\\R-L}} \endist
\istroot(B4)(B1-2)<180>{Player 2}
\istb{G}[l]{\mpay{B\\\bar R}} \istb{S}[r]{\mpay{B\\O}} \endist
\istroot(B5)(B2-1)<180>{Player 2}
\istb{G}[l]{\mpay{B\\\bar R}} \istb{S}[r]{\mpay{B-L\\L}} \endist
\istroot(B6)(B2-2)<180>{Player 2}
\istb{G}[l]{\mpay{B-R\\\bar R}} \istb{S}[r]{\mpay{B-L\\X-L}} \endist
% information sets
\setxtinfosetstyle{dashed}
\xtInfosetO(A)(B){Player 1}(1.5em)
\xtCInfosetO[blue](A1)!.35!(B1)<1.15>{Player 1}(1.5em)
\xtCInfosetO[red](A2)!.5!(B2)<.75>{Player 1}(1.5em)
\end{istgame}
\end{document}
答案2
发布此内容的主要动机是消除样式中添加的空格rconnect
,这些空格会导致上述代码出现错误。除此之外,您还可以使用标签添加玩家。我不明白另一个要求,因为我不是在研究博弈论,所以我不知道这些术语是什么意思。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage[edges]{forest}
\usepackage[outline]{contour}
\usetikzlibrary{fit,shapes.misc,arrows.meta,positioning}
\tikzset{rconnect/.style args={#1 and #2}{insert path={
($(#1)+(270+\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})$)
arc(270+\pgfkeysvalueof{/tikz/rconnect/angle}:90+\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})
to[out=\pgfkeysvalueof{/tikz/rconnect/angle},in=180-\pgfkeysvalueof{/tikz/rconnect/angle}]
($(#2)+(90-\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})$)
arc(90-\pgfkeysvalueof{/tikz/rconnect/angle}:-90-\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})
to[in=\pgfkeysvalueof{/tikz/rconnect/angle},out=180-\pgfkeysvalueof{/tikz/rconnect/angle}]
cycle}},rconnect/.cd,radius/.initial=6.5pt,angle/.initial=-12}
\begin{document}
\begin{forest}
for tree={s sep=0.1cm,l sep=1.2cm,font=\scriptsize,
where n children=0{align=center,draw,edge={thick,-{Circle}}} {circle,fill,inner sep=0pt,minimum size=2mm},
where n=1{edge label={node[midway,above left=0pt,font=\scriptsize]{S}}} {edge
label={node[midway,above right=0pt,font=\scriptsize]{E}}},
edge={thick}
}
[,label=above:Nature,alias=T
[,label=above left:Player 1,alias=L
[,label=above left:Player 2,alias=LL
[
[{$B-C$ \\ $0$}]
[{$B$ \\ $X$}]
]
[
[{$B-L$ \\ $R-L$}]
[{$B-L$ \\ $X-L$}]
]
]
[,label=above right:Player 2,alias=LR
[
[{$B-C$ \\ $0$}]
[{$B$ \\ $X$}]
]
[
[{$B-L$ \\ $R-L$}]
[{$B-L$ \\ $X-L$}]
]
]
]
[,label=above right:Player 1,alias=R
[,label=above left:Player 2,alias=RL
[
[{$B-C$ \\ $\bar{R}$}]
[{$B$ \\ $X$}]
]
[
[{$B-L$ \\ $R-L$}]
[{$B-L$ \\ $X-L$}]
]
]
[,label=above right:Player 2,alias=RR
[
[{$B-C$ \\ $\bar{R}$}]
[{$B$ \\ $X$}]
]
[
[{$B-L$ \\ $R-L$}]
[{$B-L$ \\ $X-L$}]
]
]
]
]
\node[draw,dashed,rounded rectangle,fit=(L) (R)] (F1){};
\draw[dashed,blue] let \p1=($(F1.north)-(F1.center)$) in
[/tikz/rconnect/radius=\y1] [rconnect=LL and RL];
\draw[dashed,red] let \p1=($(F1.north)-(F1.center)$) in
[/tikz/rconnect/radius=\y1] [rconnect=LR and RR];
\end{forest}
\end{document}
至于你的评论:uisng这个很好的答案可以这样做:将左侧或右侧的项目存储在列表中,然后根据级别附加项目。(如果你真的需要的话,您可以用其他东西替换“Hibernate”。;-)
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage[edges]{forest}
\usepackage[outline]{contour}
\usetikzlibrary{fit,shapes.misc,arrows.meta,positioning}
\tikzset{rconnect/.style args={#1 and #2}{insert path={
($(#1)+(270+\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})$)
arc(270+\pgfkeysvalueof{/tikz/rconnect/angle}:90+\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})
to[out=\pgfkeysvalueof{/tikz/rconnect/angle},in=180-\pgfkeysvalueof{/tikz/rconnect/angle}]
($(#2)+(90-\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})$)
arc(90-\pgfkeysvalueof{/tikz/rconnect/angle}:-90-\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})
to[in=\pgfkeysvalueof{/tikz/rconnect/angle},out=180-\pgfkeysvalueof{/tikz/rconnect/angle}]
cycle}},rconnect/.cd,radius/.initial=6.5pt,angle/.initial=-12}
\begin{document}
\edef\LstLeft{0,"$p$","Go","Wait","A"}
\edef\LstRight{0,"$1-p$","Stay","Hibernate","B"}
\begin{forest}
for tree={s sep=0.1cm,l sep=1.2cm,font=\scriptsize,
where n children=0{align=center,draw,edge={thick,-{Circle}}}{circle,fill,inner sep=0pt,minimum size=2mm},
before drawing tree={
if level=0{}{
if n'=1{
edge label/.wrap pgfmath arg={node [midway, right=.5em]
{\pgfmathparse{{\LstLeft}[#1]}\pgfmathresult}}{level()},
}{
edge label/.wrap pgfmath arg={node [midway, left=.5em]
{\pgfmathparse{{\LstRight}[#1]}\pgfmathresult}}{level()},
},
}{}
},
%where n=1{edge label={node[midway,above left=0pt,font=\scriptsize]{S}}}{edge label={node[midway,above right=0pt,font=\scriptsize]{E}}},
edge={thick}
}
[,label=above:Nature,alias=T
[,label=above left:Player 1,alias=L
[,label=above left:Player 2,alias=LL
[
[{$B-C$ \\ $0$}]
[{$B$ \\ $X$}]
]
[
[{$B-L$ \\ $R-L$}]
[{$B-L$ \\ $X-L$}]
]
]
[,label=above right:Player 2,alias=LR
[
[{$B-C$ \\ $0$}]
[{$B$ \\ $X$}]
]
[
[{$B-L$ \\ $R-L$}]
[{$B-L$ \\ $X-L$}]
]
]
]
[,label=above right:Player 1,alias=R
[,label=above left:Player 2,alias=RL
[
[{$B-C$ \\ $\bar{R}$}]
[{$B$ \\ $X$}]
]
[
[{$B-L$ \\ $R-L$}]
[{$B-L$ \\ $X-L$}]
]
]
[,label=above right:Player 2,alias=RR
[
[{$B-C$ \\ $\bar{R}$}]
[{$B$ \\ $X$}]
]
[
[{$B-L$ \\ $R-L$}]
[{$B-L$ \\ $X-L$}]
]
]
]
]
\node[draw,dashed,rounded rectangle,fit=(L) (R)] (F1){};
\draw[dashed,blue] let \p1=($(F1.north)-(F1.center)$) in
[/tikz/rconnect/radius=\y1] [rconnect=LL and RL];
\draw[dashed,red] let \p1=($(F1.north)-(F1.center)$) in
[/tikz/rconnect/radius=\y1] [rconnect=LR and RR];
\end{forest}
\end{document}