图中资源分配图怎么画?

图中资源分配图怎么画?

我在 tikz 上找到了一些类似的解决方案。这是链接。

https://github.com/MartinThoma/LaTeX-examples/blob/master/tikz/resource-allocation-graph/resource-allocation-graph.tex

https://github.com/MartinThoma/LaTeX-examples/tree/master/tikz/resource-allocation-graph

但书中的图表有一些变化。

矩形中有一些点,并且一些线来自点而不是矩形。

因此,如果有基于该解决方案的解决方案能够满足要求,那就太好了。谢谢。

RAG

答案1

不确定我是否真的回答了你的问题,但还是给你。圆圈上的阴影不太正确,但我认为其余部分相当接近。

enter image description here

代码:

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{xcolor}

\definecolor{sqBlue}{RGB}{218,234,233}
\definecolor{ballBlue}{RGB}{40,156,156}

\begin{document}
\begin{tikzpicture}[x=0.6in,y=0.6in]

%% Draw the rectangles
\draw[fill = sqBlue] (-0.5,0) rectangle (0.5,1);
\node at (0,0.75) {Ra};
\draw[fill = sqBlue] (-0.5,-3.5) rectangle (0.5,-2.5);
\node at (0,-3.25) {Rb};

%% Draw the big circles
\fill[ball color = ballBlue] (1.6875,-1.25) circle[radius=0.5] node {P2};
\fill[ball color = ballBlue] (-1.6875,-1.25) circle[radius=0.5] node {P1};

%% Draw the small dots
\coordinate (a) at (-0.344,0.19);
\coordinate (b) at (-0.0625,0.19);
\coordinate (c) at (0.25,0.19);
\coordinate (d) at (-0.0625,-2.69);
\coordinate (e) at (0.22,-2.69);

\draw[fill = black] (a) circle[radius=0.075];
\draw[fill = black] (b) circle[radius=0.075];
\draw[fill = black] (c) circle[radius=0.075];
\draw[fill = black] (d) circle[radius=0.075];
\draw[fill = black] (e) circle[radius=0.075];

%% Draw the arrows
\draw[-latex', very thick] (b) to node[sloped, above, inner sep = 2pt] {\footnotesize\hspace{1em}Held by} (1.37,-0.88);
\draw[latex'-, very thick] (0.375,-2.5) to node[sloped, above, inner sep = 2pt] {\footnotesize Requests} (1.37,-1.63);
\draw[-latex', very thick] (d) to node[sloped, above, inner sep = 2pt] {\footnotesize Held by} (-1.37,-1.63);
\draw[-latex', very thick] (-1.37,-0.88) to node[sloped, above, inner sep = 2pt] {\footnotesize\hspace{-2em}Requests} (-0.19,0);

\end{tikzpicture}
\end{document}

相关内容