From c0abf64ee0219140b91ece9dc6d4a940326bc197 Mon Sep 17 00:00:00 2001 From: Paul ALNET Date: Sat, 3 Jun 2023 15:45:04 +0200 Subject: [PATCH] tex: move and write performance part --- latex/content.tex | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/latex/content.tex b/latex/content.tex index ad8f646..57611c5 100644 --- a/latex/content.tex +++ b/latex/content.tex @@ -117,11 +117,19 @@ with 10 packets. \subsubsection{Variables used in models} -\subsubsection{Complexity and implementation optimization} + +\cite{hofri:1987} +% TODO mettre de l'Histoire + +\section{Next Fit Dual Bin Packing algorithm} + +\section{Complexity and implementation optimization} The NFBP algorithm has a linear complexity $ O(n) $, as we only need to iterate over the items once. +\subsection{Performance optimization} + When implementing the statistical analysis, the intuitive way to do it is to run $ R $ simulations, store the results, then conduct the analysis. However, when running a large number of simulations, this can be very memory @@ -129,17 +137,34 @@ consuming. We can optimize the process by computing the statistics on the fly, by using sum formulae. This uses nearly constant memory, as we only need to store the current sum and the current sum of squares for different variables. +While the mean can easily be calculated by summing then dividing, the variance +can be calculated using the following formula: + +\begin{align} + {S_N}^2 & = \frac{1}{N-1} \sum_{i=1}^{N} (X_i - \overline{X})^2 \\ + & = \frac{1}{N-1} \sum_{i=1}^{N} X_i^2 - \frac{N}{N-1} \overline{X}^2 +\end{align} + +The sum $ \frac{1}{N-1} \sum_{i=1}^{N} X_i^2 $ can be calculated iteratively +after each simulation. + +\subsection{Effective resource consumption} + +We set out to study the resource consumption of the algorithms. We implemented +the above formulae to calculate the mean and variance of $ N = 10^6 $ random +numbers. We wrote the following algorithms : + +\begin{lstlisting}[language=python] +N = 10**6 +values = [random() for _ in range(N)] +mean = mean(values) +variance = variance(values) +\end{lstlisting} + + % TODO : code -% TODO : move this somewhere else ? % TODO : add a graph -\cite{hofri:1987} -% TODO mettre de l'Histoire - -\section{Next Fit Dual Bin Packing algorithm} - -\section{Algorithm comparisons and optimization} - \subsection{NFBP vs NFDBP} \subsection{Optimal algorithm}