循環圖怎麼畫

循環圖怎麼畫

我有以下 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.metabending庫以及它們的風格給出了一些我個人的風格(可以根據您的輕鬆更改)
  • 繪製邊緣的簡化程式碼

此更改導致 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}

相關內容