Skip to content

Instantly share code, notes, and snippets.

@JakWai01
Created November 19, 2024 11:51
Show Gist options
  • Select an option

  • Save JakWai01/2e95b4613298ccba6bac5d1133b8df38 to your computer and use it in GitHub Desktop.

Select an option

Save JakWai01/2e95b4613298ccba6bac5d1133b8df38 to your computer and use it in GitHub Desktop.
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\section{Graphical Time-Demand Analysis}
\begin{tikzpicture} % Scale the graph for better visibility
\begin{axis}[
width=15cm,
height=15cm,
axis lines = middle,
grid = both,
xlabel = {Time},
ylabel = {Demand},
xmin = 0, xmax = 26,
ymin = 0, ymax = 26,
xtick = {0, 2, 4, ..., 26}, % Label only even steps on x-axis
ytick = {0, 2, 4, ..., 26}, % Label only even steps on y-axis
minor x tick num = 1, % Add one minor tick between each major x-tick
minor y tick num = 1, % Add one minor tick between each major y-tick
legend pos = south east
]
% Plot the function
\addplot[domain=0:25, blue, thick] {x};
\addlegendentry{Supply function $w(t) = t$}
% A
\addplot+[const plot, no marks, red, thick] coordinates {(0,2) (5, 2) (5, 4)} node[above,pos=.5,red] {$A$};
\addplot+[dashed, no marks, red, thick] coordinates {(5, 4) (10, 4) (10, 6) (15, 6) (15, 8) (20, 8)(20, 10) (25, 10) (25, 12) (30, 12)};
\draw[dashed, red, <-] (axis cs:5,0) -- (axis cs:5,2); % Vertical line at x = 5
% B
\addplot+[const plot, no marks, orange, thick] coordinates {(0,5) (5, 5) (5, 7) (7, 7)} node[above ,pos=.4,orange] {$B$};
\addplot+[dashed, no marks, orange, thick] coordinates {(7, 7) (7, 10) (10, 10) (10, 12) (14, 12) (14, 15) (15, 15) (15, 17) (20, 17) (20, 19) (21, 19) (21, 22) (25, 22) (25, 24) (26, 24)};
\draw[dashed, orange, <-] (axis cs:7,0) -- (axis cs:7,7); % Vertical line at x = 5
% C
\addplot+[const plot, no marks, cyan, thick, solid] coordinates {(0, 6) (5, 6) (5, 8) (7, 8) (7, 11) (10, 11) (10, 13) (14, 13) (14, 16) (15, 16) (15, 18) (17, 18)} node[above ,pos=.125,cyan] {$C$};
\addplot+[dashed, no marks, cyan, thick] coordinates {(17, 18) (20, 18) (20, 20) (21, 20) (21, 23) (25, 23) (25, 25) (26, 25)};
\draw[dashed, cyan, <-] (axis cs:17,0) -- (axis cs:17,18); % Vertical line at x = 5
\end{axis}
\end{tikzpicture}
All three tasks are schedulable since the functions of all three tasks $\omega_i(t)$ touch the supply function $\omega(t)$ before their respective deadline $d_i$
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment