サイクルグラフの描き方

サイクルグラフの描き方

私は次のTEXコードを持っています

 \documentclass{minimal}
 \usepackage{tikz}
 \usetikzlibrary{arrows,positioning} 
 \tikzset{
    %Define standard arrow tip
     >=stealth',
    %Define style for boxes
    punkt/.style={
       rectangle,
       rounded corners,
       draw=black, very thick,
       text width=6.5em,
       minimum height=2em,
       text centered},
% Define arrow style
pil/.style={
       ->,
       thick,
       shorten <=2pt,
       shorten >=2pt,}
}

\begin{document}
  \begin{tikzpicture}[node distance=1cm, auto,]
    %nodes
    \node[punkt] (agent) {Agent};
    \node[below=of agent] (dummy) {};
    \node[left=2.0 of dummy] (state) {$X_t$}
        edge[pil, bend left=45] (agent.west);
    \node[left=3.0 of dummy] (reward) {$R_t$}
        edge[pil, bend left=45] (agent.west);
    \node[punkt, inner sep=5pt,below=1.0cm of dummy]
        (environment) {Environment};
    \draw (environment.west) edge[pil, bend left=45] (state.south)                
                       edge[pil, bend left=45] (reward.south);
    % We make a dummy figure to make everything look nice.
    \node[right=2.0cm of dummy] (action) {$A_t$}
        edge[pil,bend right=45] (agent.east)
        edge[pil, bend left=45] (environment.east); % .east since we want
                                         % consistent 
\end{tikzpicture}
\end{document}

をお願いします。

  • エージェントとアクションを結びつける
  • 環境ノードの左側の中央からエッジを開始する(@marsupilam のおかげですでに修正済み)

答え1

手順は次のとおりです。

  1. 必要なノードを定義する
  2. それらの間のエッジを描画します。

かなり論理的に聞こえませんか?

出力

ここに画像の説明を入力してください

コード

\documentclass[tikz]{standalone}
\usetikzlibrary{calc,positioning,arrows}
\begin{document}
\tikzset
{
  punkt/.style =
  {
    circle,
    draw,
  },
  pil/.style = 
  {
    red,
    -stealth',
    bend left=45,
  },
}
\begin{tikzpicture}[node distance=1cm, auto,]
  %nodes
  \node[punkt] (agent) {Agent};
  \node[below=of agent] (dummy) {};
  \node[left=2.0 of dummy] (state) {$X_t$} ;
  \node[left=3.0 of dummy] (reward) {$R_t$} ;
  \node[punkt, inner sep=5pt,below=1.0cm of dummy] (environment) {Environment}; 
  \node[right=2.0cm of dummy] (action) {$A_t$} ;

  % edges
  \path[every edge/.append style={pil}] 
  (environment.west) edge (state.south)                
                     edge (reward.south)
  (agent.east)       edge (action)  
  (action)           edge (environment.east)
  (state)            edge (agent.west)
  (reward)           edge (agent.west);
\end{tikzpicture}
\end{document}

答え2

ここに画像の説明を入力してください

与えられたMWEとマルスピラム回答ですが、次の変更が加えられています。

  • ノードの配置に対する異なるアプローチ。使用されるのは定義済みのノード距離のみ
  • arrow.metaエッジとライブラリが使用されbending、そのスタイルに個人的なタッチが加えられました(お好みに合わせて簡単に変更できます)。
  • エッジを描画するための簡略化されたコード

この変更により、MWE は少し簡潔になります。

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, bending, positioning}

\begin{document}

    \begin{tikzpicture}[
every node/.append style = {inner sep=1.5pt}, 
node distance = 12mm and 9mm,
 punkt/.style = {circle, draw, very thick},
   pil/.style = {line width=1mm, red, -{Stealth[length=4mm,bend]},
                 shorten >=1pt, shorten <=2pt, bend left=#1},
 pil/.default = 30
                    ]
%nodes
\node (reward)                                  {$R_t$} ;
\node (state)   [right=of reward]               {$X_t$} ;
\node (env)     [punkt,
                 below right=of state]          {Environment};
\node (action)  [above right=of env]            {$A_t$} ;
%
\node (agent)   [punkt, 
                 above=of state.north -| env]   {Agent};
% edges
\draw[pil]  (agent)     edge    (action)
            (action)    edge    (env)
            (env)       edge    (state)
            (env)       edge[pil=40]    (reward)
            (state)     edge    (agent)
            (reward)    edge[pil=40]    (agent);
\end{tikzpicture}
\end{document}

関連情報