diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/.devcontainer/.dockerignore b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/.devcontainer/.dockerignore new file mode 100644 index 000000000..553a2df3e --- /dev/null +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/.devcontainer/.dockerignore @@ -0,0 +1,5 @@ +.dockerignore +devcontainer.json +docker-compose.yml +Dockerfile +README.md \ No newline at end of file diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/.devcontainer/Dockerfile b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/.devcontainer/Dockerfile new file mode 100644 index 000000000..022f3896f --- /dev/null +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/.devcontainer/Dockerfile @@ -0,0 +1,14 @@ +FROM qmcgaw/latexdevcontainer + +# update del package manager +RUN tlmgr update --self + +# installo pacchetti necessari +RUN tlmgr install \ + listings caption xcolor float wrapfig \ + footmisc emoji fontspec emptypage pgf \ + babel-italian etoolbox \ + && texhash + +# installo font emoji +RUN apt install fonts-noto-color-emoji \ No newline at end of file diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/.devcontainer/devcontainer.json b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/.devcontainer/devcontainer.json new file mode 100644 index 000000000..7fde1b647 --- /dev/null +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/.devcontainer/devcontainer.json @@ -0,0 +1,56 @@ +{ + "name": "project-dev", + "dockerComposeFile": [ + "docker-compose.yml" + ], + "service": "vscode", + "runServices": [ + "vscode" + ], + "shutdownAction": "stopCompose", + "workspaceFolder": "/workspace", + "postCreateCommand": "if [ -f 'requirements.txt' ]; then tlmgr install `cat requirements.txt` && texhash; fi", + + "customizations": { + "vscode": { + "extensions": [ + "james-yu.latex-workshop", + // Git + "eamodio.gitlens", + // Other helpers + "shardulm94.trailing-spaces", + "stkb.rewrap", // rewrap comments after n characters on one line + // Other + "vscode-icons-team.vscode-icons", + // spell checker + "streetsidesoftware.code-spell-checker", + "streetsidesoftware.code-spell-checker-italian" + ], + "settings": { + // General settings + "files.eol": "\n", + // vscode + "editor.rulers": [ + 80, + 120 + ], + // Latex settings + "latex-workshop.chktex.enabled": true, + "latex-workshop.latex.recipe.default": "latexmk (lualatex)", + "latex-workshop.latex.clean.subfolder.enabled": true, + "latex-workshop.latex.autoClean.run": "onBuilt", + "editor.formatOnSave": true, + "files.associations": { + "*.tex": "latex" + }, + "latex-workshop.latexindent.path": "latexindent", + "latex-workshop.latexindent.args": [ + "-c", + "%DIR%/", + "%TMPFILE%", + "-y=defaultIndent: '%INDENT%'" + ] + } + } + } +} \ No newline at end of file diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/.devcontainer/docker-compose.yml b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/.devcontainer/docker-compose.yml new file mode 100644 index 000000000..763258778 --- /dev/null +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/.devcontainer/docker-compose.yml @@ -0,0 +1,23 @@ +version: "3.2" + +services: + vscode: + build: . + image: latexdevcontainer + volumes: + - ../:/workspace + # Docker socket to access Docker server + - /var/run/docker.sock:/var/run/docker.sock + # SSH directory + # - ~/.ssh:/root/.ssh + # For Windows without WSL, a copy will be made + # from /tmp/.ssh to ~/.ssh to fix permissions + # - ~/.ssh:/tmp/.ssh:ro + # Shell history persistence + # - ~/.zsh_history:/root/.zsh_history:z + # Git config + - ~/.gitconfig:/root/.gitconfig + environment: + - TZ= + entrypoint: ["zsh", "-c", "while sleep 1000; do :; done"] + \ No newline at end of file diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/.gitignore b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/.gitignore new file mode 100644 index 000000000..cd0515c09 --- /dev/null +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/.gitignore @@ -0,0 +1,276 @@ +## Core latex/pdflatex auxiliary files: +*.aux +*.lof +*.log +*.lot +*.fls +*.out +*.toc +*.fmt +*.fot +*.cb +*.cb2 +.*.lb + +## Intermediate documents: +*.dvi +*.xdv +*-converted-to.* +# these rules might exclude image files for figures etc. +# *.ps +# *.eps +# *.pdf + +## Generated if empty string is given at "Please type another file name for output:" +main.pdf + +## Bibliography auxiliary files (bibtex/biblatex/biber): +*.bbl +*.bcf +*.blg +*-blx.aux +*-blx.bib +*.run.xml + +## Build tool auxiliary files: +*.fdb_latexmk +*.synctex +*.synctex(busy) +*.synctex.gz +*.synctex.gz(busy) +*.pdfsync + +## Build tool directories for auxiliary files +# latexrun +latex.out/ + +## Auxiliary and intermediate files from other packages: +# algorithms +*.alg +*.loa + +# achemso +acs-*.bib + +# amsthm +*.thm + +# beamer +*.nav +*.pre +*.snm +*.vrb + +# changes +*.soc + +# comment +*.cut + +# cprotect +*.cpt + +# elsarticle (documentclass of Elsevier journals) +*.spl + +# endnotes +*.ent + +# fixme +*.lox + +# feynmf/feynmp +*.mf +*.mp +*.t[1-9] +*.t[1-9][0-9] +*.tfm + +#(r)(e)ledmac/(r)(e)ledpar +*.end +*.?end +*.[1-9] +*.[1-9][0-9] +*.[1-9][0-9][0-9] +*.[1-9]R +*.[1-9][0-9]R +*.[1-9][0-9][0-9]R +*.eledsec[1-9] +*.eledsec[1-9]R +*.eledsec[1-9][0-9] +*.eledsec[1-9][0-9]R +*.eledsec[1-9][0-9][0-9] +*.eledsec[1-9][0-9][0-9]R + +# glossaries +*.acn +*.acr +*.glg +*.glo +*.gls +*.glsdefs +*.lzo +*.lzs + +# uncomment this for glossaries-extra (will ignore makeindex's style files!) +# *.ist + +# gnuplottex +*-gnuplottex-* + +# gregoriotex +*.gaux +*.gtex + +# htlatex +*.4ct +*.4tc +*.idv +*.lg +*.trc +*.xref + +# hyperref +*.brf + +# knitr +*-concordance.tex +# TODO Comment the next line if you want to keep your tikz graphics files +*.tikz +*-tikzDictionary + +# listings +*.lol + +# luatexja-ruby +*.ltjruby + +# makeidx +*.idx +*.ilg +*.ind + +# minitoc +*.maf +*.mlf +*.mlt +*.mtc[0-9]* +*.slf[0-9]* +*.slt[0-9]* +*.stc[0-9]* + +# minted +_minted* +*.pyg + +# morewrites +*.mw + +# nomencl +*.nlg +*.nlo +*.nls + +# pax +*.pax + +# pdfpcnotes +*.pdfpc + +# sagetex +*.sagetex.sage +*.sagetex.py +*.sagetex.scmd + +# scrwfile +*.wrt + +# sympy +*.sout +*.sympy +sympy-plots-for-*.tex/ + +# pdfcomment +*.upa +*.upb + +# pythontex +*.pytxcode +pythontex-files-*/ + +# tcolorbox +*.listing + +# thmtools +*.loe + +# TikZ & PGF +*.dpth +*.md5 +*.auxlock + +# todonotes +*.tdo + +# vhistory +*.hst +*.ver + +# easy-todo +*.lod + +# xcolor +*.xcp + +# xmpincl +*.xmpi + +# xindy +*.xdy + +# xypic precompiled matrices and outlines +*.xyc +*.xyd + +# endfloat +*.ttt +*.fff + +# Latexian +TSWLatexianTemp* + +## Editors: +# WinEdt +*.bak +*.sav + +# Texpad +.texpadtmp + +# LyX +*.lyx~ + +# Kile +*.backup + +# gummi +.*.swp + +# KBibTeX +*~[0-9]* + +# TeXnicCenter +*.tps + +# auto folder when using emacs and auctex +./auto/* +*.el + +# expex forward references with \gathertags +*-tags.tex + +# standalone packages +*.sta + +# Makeindex log files +*.lpz diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/ff_patological.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/ff_patological.tex deleted file mode 100644 index 54dab4e41..000000000 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/ff_patological.tex +++ /dev/null @@ -1,99 +0,0 @@ -\chapter{Ford-Fulkerson pathological example} - -\section{Intuizione} - -Sia $r$ tale che $r^2 = 1-r$: -\begin{itemize} - \item le capacità iniziali sono $\{1, r\}$ - \item dopo qualche augmentation, le capacità residuali - diventano $\{1,r,r^2\}$ (dove $r^2$ = $1-r$) - \item dopo altre diventano $\{1,r,r^2, r^3\}$ - (dove $r^3$ = $r-r^2$) - \item dopo altreancora, diventano $\{1,r,r^2, r^3, r^4\}$ - (dove $r^4$ = $r^2-r^3$) -\end{itemize} -$$ -r = \frac{\sqrt{5}-1}{2} \rightarrow r^2 = 1 - r -$$ - -\begin{figure}[H] - \centering - \includegraphics[width=10cm]{Network_flow/imgs/pathological_example.png} -\end{figure} - -Augmenting path 1: $s \to v \to w \to t$. Bottleneck capacity = 1 -(v,w).\\ - -Continuo ad aumentare path che passano per (v,w) e per (w,v) alternati, -quindi aggiungo e tolgo la bottleneck ogni volta. La bottleneck -diminuisce sempre ma va da r a $r^2$ a $r^3$ e cosí via, cosí -l'algoritmo non termina mai: -\begin{itemize} - \item dopo augmenting path 1: $\{ 1 - r^0, 1, r - r^1 \}$ (flow = $1$) - \item dopo dopo augmenting path 5: $\{ 1 - r^2, 1, r - r^3 \}$ (flow = $1 + 2r + 2r^2$) - \item dopo augmenting path 9: $\{ 1 - r^4, 1, r - r^5 \}$ (flow = $1 + 2r + 2r^2 + 2r^3 + 2r^4$)\\ -\end{itemize} -\begin{figure}[H] - \begin{subfigure}{\textwidth} - \centering - \begin{subfigure}{.33\textwidth} - \centering - \includegraphics[width=\linewidth]{Network_flow/imgs/ex1.png} - \end{subfigure}% - \begin{subfigure}{.33\textwidth} - \centering - \includegraphics[width=\linewidth]{Network_flow/imgs/ex2.png} - \end{subfigure}% - \begin{subfigure}{.33\textwidth} - \centering - \includegraphics[width=\linewidth]{Network_flow/imgs/ex3.png} - \end{subfigure}% - \end{subfigure} - \begin{subfigure}{\textwidth} - \centering - \begin{subfigure}{.33\textwidth} - \centering - \includegraphics[width=\linewidth]{Network_flow/imgs/ex4.png} - \end{subfigure}% - \begin{subfigure}{.33\textwidth} - \centering - \includegraphics[width=\linewidth]{Network_flow/imgs/ex5.png} - \end{subfigure}% - \begin{subfigure}{.33\textwidth} - \centering - \includegraphics[width=\linewidth]{Network_flow/imgs/ex6.png} - \end{subfigure}% - \end{subfigure} - \begin{subfigure}{\textwidth} - \centering - \begin{subfigure}{.33\textwidth} - \centering - \includegraphics[width=\linewidth]{Network_flow/imgs/ex7.png} - \end{subfigure}% - \begin{subfigure}{.33\textwidth} - \centering - \includegraphics[width=\linewidth]{Network_flow/imgs/ex8.png} - \end{subfigure}% - \begin{subfigure}{.33\textwidth} - \centering - \includegraphics[width=\linewidth]{Network_flow/imgs/ex9.png} - \end{subfigure} - \end{subfigure} -\end{figure} - -\textbf{Teorema:} -\begin{myblockquote} -L'algoritmo di Ford-Fulkerson -può non terminare e può convergere ad un valore che non è il flusso -massimo. -\end{myblockquote} - -\textbf{Dimostrazione:} Utilizzando la data sequenza di augmenting -paths, dopo $(1+4k)^{th}$ di questi path, il valore del flusso è -uguale a - -$$ -1 + 2 \sum^{2k}_{i=1}r^i \le 1 + 2 \sum^{\infty}_{i=1}r^i = 3 + 2r < 5 -$$ - -($r = \frac{\sqrt{5}-1}{2}$) Valore del flusso massimo = 200 + 1 diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/delta_scaling.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/delta_scaling.tex similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/delta_scaling.tex rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/delta_scaling.tex diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/fat_flow.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/fat_flow.tex similarity index 90% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/fat_flow.tex rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/fat_flow.tex index 410692d62..34c8f6d52 100644 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/fat_flow.tex +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/fat_flow.tex @@ -14,12 +14,15 @@ \subsection{Analisi dell'algoritmo} Ora andremo a dimostrare la terminazione polinomiale dell'algoritmo con le seguenti 2 osservazioni, ma prima ci definiamo $\delta_f(u,v)$ come la distanza del cammino minimo da $u$ a $v$ nel grafo residuale $G_f$, considerando che ogni arco ha distanza unitaria. \begin{myblockquote} - Se l'agloritmo di Edmonds-Karp viene eseguito su una rete di flusso $G = (V, E)$ con sorgente $s$ e pozzo $t$, allora per ogni vertice $v \in V - \{s,t\}$, la distanza de cammino minimo $\delta_f(s,v)$ nella rete residua $G_f$ aumenta monotonicamente per ogni aumento di flusso. + Se l'agloritmo di Edmonds-Karp viene eseguito su una rete di flusso $G = (V, + E)$ con sorgente $s$ e pozzo $t$, allora per ogni vertice $v \in V - + \{s,t\}$, la distanza de cammino minimo $\delta_f(s,v)$ nella rete residua + $G_f$ aumenta \linebreak monotonicamente per ogni aumento di flusso. \end{myblockquote} \textbf{Dimostrazione.} Supponiamo per assurdo che per qualche vertice $v \in V - \{s, t\}$ ci sia un aumento di flusso che provoca una diminuzione della distanza del cammino minimo da $s$ a $v$. Sia $f$ il flusso appena prima del primo aumento che riduce una distanza del cammino minimo; sia $f^{'}$ il flusso subito dopo. Se $v$ è il vertice con il minimo $\delta_{f^{'}}(s,v)$ la cui distanza è stata ridotta dall'aumento, allora $\delta_{f^{'}}(s,v) < \delta_{f}(s,v)$. -Se $p = s \rightsquigarrow u \rightarrow v$ è un cammino minimo da $s$ a $v$ in $G_{f{'}}$, allora +Se $p = s \rightsquigarrow u \rightarrow v$ è un cammino minimo da $s$ a $v$ in $G_{f{'}}$, allora $(u,v) \in E_{f^{'}}$ e: $$ @@ -28,7 +31,7 @@ \subsection{Analisi dell'algoritmo} Per il modo in cui abbiamo scelto $v$, sappiamo che la distanza del vertice $u$ dalla sorgente $s$ non è \textbf{aumentata(?)}, ovvero: $$ - \delta_{f^{'}}(s,u) \ge \delta_{f}(s,u) + \delta_{f^{'}}(s,u) \ge \delta_{f}(s,u) $$ Noi asseriamo che $(u,v) \notin E_f$. \textbf{Perchè?} @@ -39,9 +42,9 @@ \subsection{Analisi dell'algoritmo} \le \delta_{f^{'}}(s,u) -1 \\ = \delta_{f^{'}}(s,v) -2 $$ - Questo contraddice l'ipotesi che $\delta_{f^{'}}(s,v) < \delta_{f}(s,v)$. +Questo contraddice l'ipotesi che $\delta_{f^{'}}(s,v) < \delta_{f}(s,v)$. - Come è possibile avere $(u,v) \notin E_f$ e $(u,v) \in E_f^{'}$? +Come è possibile avere $(u,v) \notin E_f$ e $(u,v) \in E_f^{'}$? L'augment deve avere incrementato il flusso da $v$ a $u$. L'algoritmo di Edmondo-Karp aumenta sempre il flusso lungo tutto i cammini minimi, e quindi il cammino minimo da $s$ a $u$ in $G_f$ ha $(v,u)$ come suo ultimo arco, per tanto si ha: $$ @@ -51,11 +54,14 @@ \subsection{Analisi dell'algoritmo} $$ Questo contraddice l'ipotesi che $\delta_f^{'}(s,v) < \delta_f(s,v)$, quindi l'ipotesi dell'esistenza di un tale vertice $v$ non è corretta.\\ -\\ + +\newpage \textbf{Il prossimo teorema limita il numero di iterazioni dell'algoritmo} \begin{myblockquote} - Se l'algoritmo viene eseguito su una rete di flusso $G = (V, E)$ con sorgente $s$ e pozzo $t$, allora il numero totale di aumenti di glusso effettuati dall'algoritmo è $O(VE)$ + Se l'algoritmo viene eseguito su una rete di flusso $G = (V, E)$ con + sorgente $s$ e pozzo $t$, allora il numero totale di aumenti di flusso + effettuati dall'algoritmo è $O(VE)$. \end{myblockquote} \textbf{Dimostrazione.} Diciamo che un arco $(u,v)$ di una rete residua $G_f$ è \textbf{critico} in un cammino aumentante $p$ se la capacità residua di $p$ è la capacità residua di $(u,v)$. @@ -69,7 +75,7 @@ \subsection{Analisi dell'algoritmo} $$ Una volta che il flusso viene aumentato l'arco $(u,v)$ scompare dalla rete residua e non potrà riapparire successivamente in un altro cammino aumentante fino a che il flusso da $u$ a $v$ non diminuirà, e questo accade solo se $(u,v)$ apppare in un cammino aumentante. -Se consideriamo che $f^{'}$ è il flusso quando si verifica questo evento, allora si ha +Se consideriamo che $f^{'}$ è il flusso quando si verifica questo evento, allora si ha $$ \delta_{f^{'}}(s,u) = \delta_{f^{'}}(s,v) +1 @@ -107,7 +113,7 @@ \subsection{Analisi dell'algoritmo} La dimostrazione precedente implica che aumentando $f$ attraverso il path con il maggior bottleneck in $G_f$ moltiplica il valore del flusso massimo in $G_f$ di un fattore di al massimo $1 - 1/E$. In altre parole il flusso residuale \textit{decade esponenzialmente} all'aumentare delle iterazioni. Dopo $E \cdot \ln{|f^{*}|}$ iterazioni il valore del flusso massimo in $G_f$ sarà al amssimo: $$ -|f^{*}|\cdot(1-1/E)^{E\cdot \ln{|f^{*}|}} < |f^{*}|e^{-\ln{|f^{*}|}} = 1 + |f^{*}|\cdot(1-1/E)^{E\cdot \ln{|f^{*}|}} < |f^{*}|e^{-\ln{|f^{*}|}} = 1 $$ (La $e$ in questione è la costante di Eulero, non l'arco) In particolare, \textit{se tutte le capacità sono interi}, allora dopo $E\cdot \ln{|f^{*}|}$ iterazioni la capacità massima del grafo residuale sarà \textit{zero} e $f$ sarà il flusso massimo.\\ diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/ff_patological.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/ff_patological.tex new file mode 100644 index 000000000..34531853a --- /dev/null +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/ff_patological.tex @@ -0,0 +1,99 @@ +\chapter{Ford-Fulkerson pathological example} + +\section{Intuizione} + +Sia $r$ tale che $r^2 = 1-r$: +\begin{itemize} + \item le capacità iniziali sono $\{1, r\}$ + \item dopo qualche augmentation, le capacità residuali + diventano $\{1,r,r^2\}$ (dove $r^2$ = $1-r$) + \item dopo altre diventano $\{1,r,r^2, r^3\}$ + (dove $r^3$ = $r-r^2$) + \item dopo altreancora, diventano $\{1,r,r^2, r^3, r^4\}$ + (dove $r^4$ = $r^2-r^3$) +\end{itemize} +$$ + r = \frac{\sqrt{5}-1}{2} \rightarrow r^2 = 1 - r +$$ + +\begin{figure}[H] + \centering + \includegraphics[width=10cm]{capitoli/network_flow/imgs/pathological_example.png} +\end{figure} + +Augmenting path 1: $s \to v \to w \to t$. Bottleneck capacity = 1 +(v,w).\\ + +Continuo ad aumentare path che passano per (v,w) e per (w,v) alternati, +quindi aggiungo e tolgo la bottleneck ogni volta. La bottleneck +diminuisce sempre ma va da r a $r^2$ a $r^3$ e cosí via, cosí +l'algoritmo non termina mai: +\begin{itemize} + \item dopo augmenting path 1: $\{ 1 - r^0, 1, r - r^1 \}$ (flow = $1$) + \item dopo dopo augmenting path 5: $\{ 1 - r^2, 1, r - r^3 \}$ (flow = $1 + 2r + 2r^2$) + \item dopo augmenting path 9: $\{ 1 - r^4, 1, r - r^5 \}$ (flow = $1 + 2r + 2r^2 + 2r^3 + 2r^4$)\\ +\end{itemize} +\begin{figure}[H] + \begin{subfigure}{\textwidth} + \centering + \begin{subfigure}{.33\textwidth} + \centering + \includegraphics[width=\linewidth]{capitoli/network_flow/imgs/ex1.png} + \end{subfigure}% + \begin{subfigure}{.33\textwidth} + \centering + \includegraphics[width=\linewidth]{capitoli/network_flow/imgs/ex2.png} + \end{subfigure}% + \begin{subfigure}{.33\textwidth} + \centering + \includegraphics[width=\linewidth]{capitoli/network_flow/imgs/ex3.png} + \end{subfigure}% + \end{subfigure} + \begin{subfigure}{\textwidth} + \centering + \begin{subfigure}{.33\textwidth} + \centering + \includegraphics[width=\linewidth]{capitoli/network_flow/imgs/ex4.png} + \end{subfigure}% + \begin{subfigure}{.33\textwidth} + \centering + \includegraphics[width=\linewidth]{capitoli/network_flow/imgs/ex5.png} + \end{subfigure}% + \begin{subfigure}{.33\textwidth} + \centering + \includegraphics[width=\linewidth]{capitoli/network_flow/imgs/ex6.png} + \end{subfigure}% + \end{subfigure} + \begin{subfigure}{\textwidth} + \centering + \begin{subfigure}{.33\textwidth} + \centering + \includegraphics[width=\linewidth]{capitoli/network_flow/imgs/ex7.png} + \end{subfigure}% + \begin{subfigure}{.33\textwidth} + \centering + \includegraphics[width=\linewidth]{capitoli/network_flow/imgs/ex8.png} + \end{subfigure}% + \begin{subfigure}{.33\textwidth} + \centering + \includegraphics[width=\linewidth]{capitoli/network_flow/imgs/ex9.png} + \end{subfigure} + \end{subfigure} +\end{figure} + +\textbf{Teorema:} +\begin{myblockquote} + L'algoritmo di Ford-Fulkerson + può non terminare e può convergere ad un valore che non è il flusso + massimo. +\end{myblockquote} + +\textbf{Dimostrazione:} Utilizzando la data sequenza di augmenting +paths, dopo $(1+4k)^{th}$ di questi path, il valore del flusso è +uguale a + +$$ + 1 + 2 \sum^{2k}_{i=1}r^i \le 1 + 2 \sum^{\infty}_{i=1}r^i = 3 + 2r < 5 +$$ + +($r = \frac{\sqrt{5}-1}{2}$) Valore del flusso massimo = 200 + 1 diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/ford_fulkerson.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/ford_fulkerson.tex similarity index 68% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/ford_fulkerson.tex rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/ford_fulkerson.tex index f78a77920..20ade971a 100644 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/ford_fulkerson.tex +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/ford_fulkerson.tex @@ -4,25 +4,25 @@ \section{Introduzione} Ricordiamo la struttura dei \textbf{Bipartite Matching Problems}: \begin{myblockquote} - Un grafo bipartito $G = (V , E)$ è un grafo non - orientato il cui insieme di nodi può essere partizionato come - $V = X \cup Y$, con la proprietà che ogni arco $e \in E$ ha un - estremo in $X$ e l'altro estremo in $Y$. + Un grafo bipartito $G = (V , E)$ è un grafo non + orientato il cui insieme di nodi può essere partizionato come + $V = X \cup Y$, con la proprietà che ogni arco $e \in E$ ha un + estremo in $X$ e l'altro estremo in $Y$. \end{myblockquote} Ora, abbiamo già visto la nozione di \textbf{matching}: abbiamo usato il termine per descrivere raccolte di coppie su un insieme, con la proprietà che \textbf{nessun elemento dell'insieme appare in più di una -coppia} (si pensi ai caratteri nel Problema del -\protect\hyperlink{sequence-alignment}{Sequence Alignment}.)\\ + coppia} (si pensi ai caratteri nel Problema del +\protect\autoref{chap:seqal}.)\\ Nel caso di un grafo, gli archi costituiscono coppie di nodi, e di conseguenza diciamo che un \textbf{matching in un grafo $G = (V , E)$ -è un insieme di archi $M \subseteq E$ con la proprietà che ogni nodo -appare al massimo in un arco di $M$}.\\ + è un insieme di archi $M \subseteq E$ con la proprietà che ogni nodo + appare al massimo in un arco di $M$}.\\ \textbf{Un insieme di archi $M$ è un matching perfetto se ogni nodo -appare esattamente in un arco di $M$}.\\ + appare esattamente in un arco di $M$}.\\ I matching nei grafi bipartiti possono modellare situazioni in cui gli oggetti vengono assegnati ad altri oggetti. Un esempio sorge quando i @@ -35,8 +35,8 @@ \section{Introduzione} esattamente un \emph{job}.\\ \textbf{Uno dei problemi più antichi negli algoritmi combinatori è -quello di determinare la dimensione del matching più grande in un grafo -bipartito G}. (Come caso particolare, si noti che $G$ ha un matching + quello di determinare la dimensione del matching più grande in un grafo + bipartito G}. (Come caso particolare, si noti che $G$ ha un matching perfetto se e solo se $|X| = |Y|$ e ha un matching di dimensione $|X|$.)\\ @@ -51,7 +51,7 @@ \section{Introduzione} Sviluppiamo quindi un algoritmo con tempo polinomiale per un problema generale, il problema del \textbf{Flusso Massimo (Maximum-Flow -Problem)}, e mostriamo come questo fornisca un algoritmo efficiente + Problem)}, e mostriamo come questo fornisca un algoritmo efficiente anche per il Bipartite Matching Problem. @@ -67,42 +67,42 @@ \section{The Maximum-Flow Problem and the Ford-Fulkerson Algorithm} modelli di rete di questo tipo hanno diversi ingredienti: \begin{itemize} - \item \textbf{capacità} sugli archi, che indica quanto possono trasportare; - \item \textbf{nodi sorgente} nel grafo, che generano traffico; - \item \textbf{nodi sink (o destinazione)} nel grafo, che possono \emph{``assorbire''} il traffico mano a mano che arriva; - \item il \textbf{traffico}, che viene trasmesso attraverso gli archi. + \item \textbf{capacità} sugli archi, che indica quanto possono trasportare; + \item \textbf{nodi sorgente} nel grafo, che generano traffico; + \item \textbf{nodi sink (o destinazione)} nel grafo, che possono \emph{``assorbire''} il traffico mano a mano che arriva; + \item il \textbf{traffico}, che viene trasmesso attraverso gli archi. \end{itemize} \textbf{Flow Networks}: Prenderemo in considerazione grafi di questa forma e ci riferiamo al \textbf{traffico} come \textbf{flusso}, un'entità \textbf{astratta} che viene \textbf{generata} nei \textbf{nodi -sorgente}, trasmessa attraverso gli archi e assorbita nei \textbf{nodi -sink}.\\ + sorgente}, trasmessa attraverso gli archi e assorbita nei \textbf{nodi + sink}.\\ Formalmente diremo che una Flow Network è un grafo orientato $G = (V , E)$ con le seguenti caratteristiche: \begin{itemize} - \item Associata a ciascun arco $e$ c'è una \textbf{capacità}, che è un numero \textbf{non negativo} che denotiamo $c_e$ . - \item \textbf{Esiste un solo nodo sorgente} $s \in V$. - \item \textbf{C'è \textbf{un solo nodo sink} $t \in V$.} + \item Associata a ciascun arco $e$ c'è una \textbf{capacità}, che è un numero \textbf{non negativo} che denotiamo $c_e$ . + \item \textbf{Esiste un solo nodo sorgente} $s \in V$. + \item \textbf{C'è \textbf{un solo nodo sink} $t \in V$.} \end{itemize} I nodi diversi da $s$ e $t$ saranno chiamati \textbf{nodi interni}.\\ Faremo delle assunzioni sulle reti di flusso di cui ci occupiamo: \begin{enumerate} - \item \textbf{Nessun arco entra nella sorgente $s$ e nessun arco esce dal - sink $t$}; - \item Vi sia almeno un arco per ogni nodo; - \item Tutte le capacità sono numeri interi. + \item \textbf{Nessun arco entra nella sorgente $s$ e nessun arco esce dal + sink $t$}; + \item Vi sia almeno un arco per ogni nodo; + \item Tutte le capacità sono numeri interi. \end{enumerate} \begin{figure}[H] - \centering - \includegraphics[width = 5cm]{Network_flow/imgs/flow1.png} - \caption{Esempio di Flow Network} + \centering + \includegraphics[width = 5cm]{capitoli/network_flow/imgs/flow1.png} + \caption{Esempio di Flow Network} \end{figure} \subsection{Definizione di Flusso} @@ -116,12 +116,12 @@ \subsection{Definizione di Flusso} \\ Un flusso $f$ deve soddisfare le seguenti due proprietà: \begin{enumerate} - \item \textbf{Capacity conditions:} Per ogni $e \in E$, abbiamo - $0 \le f(e) \le c_e$ - \item \textbf{Conservation conditions:} Per ogni nodo $v$ diverso da $s$ e $t$, abbiamo - $$ - \sum_{e \text{ into } v}f(e) = \sum_{e \text{ out of } v}f(e) - $$ + \item \textbf{Capacity conditions:} Per ogni $e \in E$, abbiamo + $0 \le f(e) \le c_e$ + \item \textbf{Conservation conditions:} Per ogni nodo $v$ diverso da $s$ e $t$, abbiamo + $$ + \sum_{e \text{ into } v}f(e) = \sum_{e \text{ out of } v}f(e) + $$ \end{enumerate} @@ -137,26 +137,26 @@ \subsection{Definizione di Flusso} flusso in uscita. \begin{itemize} - \item La sorgente non ha archi entranti (secondo la nostra - assunzione), ma le è consentito avere un flusso uscente; in altre - parole, può generare flusso. - \item Simmetricamente, il sink può avere flusso - in entrata, anche se non ha archi in uscita. + \item La sorgente non ha archi entranti (secondo la nostra + assunzione), ma le è consentito avere un flusso uscente; in altre + parole, può generare flusso. + \item Simmetricamente, il sink può avere flusso + in entrata, anche se non ha archi in uscita. \end{itemize} \textbf{Il valore di un flusso} $f$, indicato con $v(f)$, è definito -come la quantità di flusso generato alla sorgente: +come la quantità di flusso generato alla sorgente: $$ - v(f) = \sum_{e \text{ out of } s}f(e) + v(f) = \sum_{e \text{ out of } s}f(e) $$ Per rendere la notazione più compatta, definiamo: $$ - f^{out}(v) = \sum_{e \text{ out of } v}f(e) + f^{out}(v) = \sum_{e \text{ out of } v}f(e) $$ $$ - f^{in}(v) = \sum_{e \text{ into } v}f(e) + f^{in}(v) = \sum_{e \text{ into } v}f(e) $$ Possiamo estenderlo ad insiemi di vertici; @@ -177,7 +177,7 @@ \section{Descrizione Problema del Maximum-Flow} \subsection{Goal} \textbf{Data una rete di flussi, trovare un flusso di massimo valore -possibile.} + possibile.} È utile considerare come la struttura della rete di flusso pone un \textbf{upper bound} al \textbf{valore massimo} di un flusso $s-t$. @@ -187,12 +187,12 @@ \subsection{Goal} certo punto, e quindi consumare parte della capacità degli archi da $A$ a $B$. Ciò suggerisce che ciascuno di questi ``\textbf{\emph{tagli}}'' del grafo pone un \textbf{limite al massimo -valore di flusso possibile}. L'algoritmo del flusso massimo che + valore di flusso possibile}. L'algoritmo del flusso massimo che svilupperemo, sarà collegato ad una dimostrazione, la quale afferma che: \begin{myblockquote} - \textbf{il valore del flusso massimo è uguale alla - capacità minima di ciascuna di queste divisioni, chiamata taglio minimo} - (\emph{l'algoritmo calcolerà anche il taglio minimo}). + \textbf{il valore del flusso massimo è uguale alla + capacità minima di ciascuna di queste divisioni, chiamata taglio minimo} + (\emph{l'algoritmo calcolerà anche il taglio minimo}). \end{myblockquote} @@ -204,10 +204,10 @@ \section{Implementazione dell'algoritmo} L'algoritmo greedy segue la seguente logica: \begin{itemize} - \item Iniziare con $f(e) = 0$ per ogni arco $e \in E$ - \item Trovare un cammino $s-t$ $P$ in cui ogni arco ha $f(e) < c_e$ - \item Augmentare il flusso lungo il cammino $P$ - \item Ripetere le operazioni precedenti finchè non puoi più proseguire + \item Iniziare con $f(e) = 0$ per ogni arco $e \in E$ + \item Trovare un cammino $s-t$ $P$ in cui ogni arco ha $f(e) < c_e$ + \item Augmentare il flusso lungo il cammino $P$ + \item Ripetere le operazioni precedenti finchè non puoi più proseguire \end{itemize} Come si può vedere nella Figura di seguito, questo approccio fallisce e @@ -218,9 +218,9 @@ \section{Implementazione dell'algoritmo} può più essere decrementato. \begin{figure}[H] - \centering - \includegraphics[width = 12 cm]{Network_flow/imgs/flow2.png} - \caption{Nella figura (a) vediamo il grafo originale e nella (b) la soluzione trovata provando ad utilizzare un approccio greedy. Nella figura (c) vediamo invece quello che sarebbe la soluzione esatta per il problema del massimo flusso.} + \centering + \includegraphics[width = 12 cm]{capitoli/network_flow/imgs/flow2.png} + \caption{Nella figura (a) vediamo il grafo originale e nella (b) la soluzione trovata provando ad utilizzare un approccio greedy. Nella figura (c) vediamo invece quello che sarebbe la soluzione esatta per il problema del massimo flusso.} \end{figure} \subsection{The Residual Graph} @@ -230,16 +230,16 @@ \subsection{The Residual Graph} spinto 20 unità di flusso lungo il percorso $s, u, v, t$.) \begin{myblockquote} -\begin{itemize} - \item L'insieme dei nodi di $G_f$ è uguale a quello di $G$. - \item Per ogni arco $e = (u, v)$ di $G$ su cui - $f(e) < c_e$ , ci sono $c_e - f(e)$ unità di capacità - \emph{``rimanenti''} su cui potremmo provare a spingere il flusso in - avanti. Quindi includiamo l'arco $e = (u, v)$ in $G_f$ , con una - capacità di $c_e - f(e)$. Chiameremo gli archi inclusi in questo modo - \textbf{forward edges}. - \item Per ogni arco $e = (u, v)$ di $G$ su cui $f(e) > 0$, ci sono $f(e)$ unità di flusso che possiamo ``\emph{annullare}'' se vogliamo, spingendo il flusso all'indietro (backward). Quindi includiamo l'arco $e' = (v, u)$ in $G_f$ , con una capacità di $f(e)$. Notare che $e'$ ha le stesse estremità di $e$, ma la sua direzione è \textbf{invertita}; chiameremo gli archi inclusi in questo modo \textbf{backward edges}. -\end{itemize} + \begin{itemize} + \item L'insieme dei nodi di $G_f$ è uguale a quello di $G$. + \item Per ogni arco $e = (u, v)$ di $G$ su cui + $f(e) < c_e$ , ci sono $c_e - f(e)$ unità di capacità + \emph{``rimanenti''} su cui potremmo provare a spingere il flusso in + avanti. Quindi includiamo l'arco $e = (u, v)$ in $G_f$ , con una + capacità di $c_e - f(e)$. Chiameremo gli archi inclusi in questo modo + \textbf{forward edges}. + \item Per ogni arco $e = (u, v)$ di $G$ su cui $f(e) > 0$, ci sono $f(e)$ unità di flusso che possiamo ``\emph{annullare}'' se vogliamo, spingendo il flusso all'indietro (backward). Quindi includiamo l'arco $e' = (v, u)$ in $G_f$ , con una capacità di $f(e)$. Notare che $e'$ ha le stesse estremità di $e$, ma la sua direzione è \textbf{invertita}; chiameremo gli archi inclusi in questo modo \textbf{backward edges}. + \end{itemize} \end{myblockquote} Si noti che ogni arco $e$ in $G$ può dare origine a uno o due archi @@ -247,7 +247,7 @@ \subsection{The Residual Graph} che uno all'indietro siano inclusi in $G_f$ . Quindi $G_f$ ha al massimo il doppio degli archi rispetto a $G$. A volte ci riferiremo alla capacità di un arco nel grafo residuo come \textbf{residual -capacity}, per aiutare a distinguerla dalla capacità dell'arco + capacity}, per aiutare a distinguerla dalla capacità dell'arco corrispondente nella rete di flusso originale $G$. @@ -258,7 +258,7 @@ \subsection{Augmenting Paths in a Residual Graph} path nel grafo residuale viene chiamato \textbf{augmenting path}), cioè $P$ non visita nessun nodo più di una volta. Definiamo \texttt{bottleneck(P,\ f)} come la \textbf{minima capacità residua tra -tutti gli archi di $P$}, rispetto al flusso $f$. Definiamo ora la + tutti gli archi di $P$}, rispetto al flusso $f$. Definiamo ora la seguente operazione \texttt{augment(f\ ,\ P)}, che produce un nuovo flusso $f'$ in $G$.\\ @@ -310,9 +310,9 @@ \subsection{Augmenting Paths in a Residual Graph} ricercatori che lo svilupparono nel 1956. \begin{figure}[H] - \centering - \includegraphics[width = 12 cm]{Network_flow/imgs/flow3.png} - \caption{Esempio di un esecuzione dell'algoritmo di Ford Fulkerson} + \centering + \includegraphics[width = 12 cm]{capitoli/network_flow/imgs/flow3.png} + \caption{Esempio di un esecuzione dell'algoritmo di Ford Fulkerson} \end{figure} L'algoritmo Ford-Fulkerson è davvero molto semplice. Per quanto riguarda @@ -333,8 +333,8 @@ \subsection{Analyzing the Algorithm: Termination and Running Time} interi. \begin{myblockquote} -Ad ogni stadio intermedio dell'algoritmo di Ford-Fulkerson, i valori di -flusso $f(e)$ e le capacità residue in $G_f$ sono interi. + Ad ogni stadio intermedio dell'algoritmo di Ford-Fulkerson, i valori di + flusso $f(e)$ e le capacità residue in $G_f$ sono interi. \end{myblockquote} Possiamo usare questa proprietà per dimostrare che l'algoritmo di @@ -343,9 +343,9 @@ \subsection{Analyzing the Algorithm: Termination and Running Time} \paragraph{DEF 7.3} \begin{myblockquote} - Sia $f$ un flusso in $G$, e sia $P$ un semplice cammino $s-t$ in - $G_f$ . Allora $v(f') = v(f)$ + \texttt{bottleneck(P,\ f)}; e poiché - \texttt{bottleneck(P,\ f)} \textgreater{} 0, abbiamo $v(f') > v(f)$. + Sia $f$ un flusso in $G$, e sia $P$ un semplice cammino $s-t$ in + $G_f$ . Allora $v(f') = v(f)$ + \texttt{bottleneck(P,\ f)}; e poiché + \texttt{bottleneck(P,\ f)} \textgreater{} 0, abbiamo $v(f') > v(f)$. \end{myblockquote} Abbiamo bisogno di un'altra osservazione per dimostrare la terminazione. @@ -353,11 +353,11 @@ \subsection{Analyzing the Algorithm: Termination and Running Time} possibile. Ecco un \textbf{upper bound}: \begin{myblockquote} - Se tutti gli archi al di - fuori di $s$ potessero essere completamente saturati dal flusso, il - valore del flusso sarebbe $\sum_{e \text{ out of }s} c_e$. Sia $C$ - questa somma. Quindi abbiamo $v(f) \le C$ per tutti i flussi $f$ - $s-t$ + Se tutti gli archi al di + fuori di $s$ potessero essere completamente saturati dal flusso, il + valore del flusso sarebbe $\sum_{e \text{ out of }s} c_e$. Sia $C$ + questa somma. Quindi abbiamo $v(f) \le C$ per tutti i flussi $f$ + $s-t$ \end{myblockquote} \textbf{N.B.} @@ -369,10 +369,10 @@ \subsection{Analyzing the Algorithm: Termination and Running Time} Usando l'affermazione (7.3), ora possiamo dimostrare la terminazione: \begin{myblockquote} - Supponiamo, come sopra, che tutte le capacità nella rete - di flusso $G$ siano numeri interi. Quindi l'algoritmo di - Ford-Fulkerson termina al massimo in $C$ iterazioni del ciclo - \texttt{While}. + Supponiamo, come sopra, che tutte le capacità nella rete + di flusso $G$ siano numeri interi. Quindi l'algoritmo di + Ford-Fulkerson termina al massimo in $C$ iterazioni del ciclo + \texttt{While}. \end{myblockquote} @@ -385,9 +385,9 @@ \subsection{Costo} $O(m + n ) = O(m)$ per semplificare i limiti. \begin{myblockquote} -Supponiamo, come sopra, che tutte le capacità nella rete di flusso $G$ -siano numeri interi. Quindi l'algoritmo Ford-Fulkerson può essere -implementato per funzionare in tempo $O(mC)$. + Supponiamo, come sopra, che tutte le capacità nella rete di flusso $G$ + siano numeri interi. Quindi l'algoritmo Ford-Fulkerson può essere + implementato per funzionare in tempo $O(mC)$. \end{myblockquote} Una versione un po' più efficiente dell'algoritmo manterrebbe le linked @@ -408,33 +408,33 @@ \subsection{Analyzing the Algorithm: Flows and Cuts} Per compiere progressi verso questo obiettivo, torniamo ad un problema già descritto: \textbf{il modo in cui la struttura della rete di flusso -pone upper bounds al valore massimo di un flusso $s-t$}. Abbiamo già + pone upper bounds al valore massimo di un flusso $s-t$}. Abbiamo già visto un upper bound: \begin{myblockquote} - il valore $v(f)$ di qualsiasi - flusso $s-t$ $f$ è al massimo - $C = \sum_{e \text{ out of } S} c_e$. A volte questo limite è utile, - ma a volte è molto debole. + il valore $v(f)$ di qualsiasi + flusso $s-t$ $f$ è al massimo + $C = \sum_{e \text{ out of } S} c_e$. A volte questo limite è utile, + ma a volte è molto debole. \end{myblockquote} Usiamo ora la nozione di \textbf{taglio} per sviluppare un metodo molto più generale per porre upper bound al valore del flusso massimo. \begin{myblockquote} - Si consideri la possibilità di dividere i nodi del grafo - in due insiemi, $A$ e $B$, in modo che $s \in A$ e $t \in B$. - - Formalmente diciamo che un \textbf{taglio} $s-t$ è una - partizione $(A, B)$ dell'insieme di vertici $V$, tale che - $s \in A$ e $t \in B$. - - La \textbf{capacità di un taglio} $(A, B)$, che indicheremo con $c(A , B)$, è la somma delle - capacità di tutti gli archi che escono da A: - $ - c(A, B) = \sum_{e \text{ out of } A} c_e. - $\\ - I tagli risultano fornire upper bounds molto naturali sui valori dei flussi. + Si consideri la possibilità di dividere i nodi del grafo + in due insiemi, $A$ e $B$, in modo che $s \in A$ e $t \in B$. + + Formalmente diciamo che un \textbf{taglio} $s-t$ è una + partizione $(A, B)$ dell'insieme di vertici $V$, tale che + $s \in A$ e $t \in B$. + + La \textbf{capacità di un taglio} $(A, B)$, che indicheremo con $c(A , B)$, è la somma delle + capacità di tutti gli archi che escono da A: + $ + c(A, B) = \sum_{e \text{ out of } A} c_e. + $\\ + I tagli risultano fornire upper bounds molto naturali sui valori dei flussi. \end{myblockquote} Lo precisiamo attraverso una sequenza di teoremi e/o definizioni. @@ -442,17 +442,17 @@ \subsection{Analyzing the Algorithm: Flows and Cuts} \paragraph{DEF(7.6)} \begin{myblockquote} - Sia $f$ un flusso $s-t$ qualsiasi, e $(A, B)$ un taglio $s-t$, allora: - $ - v(f) = f^{\text{out}}(A) - f^{\text{in}}(A) - $ + Sia $f$ un flusso $s-t$ qualsiasi, e $(A, B)$ un taglio $s-t$, allora: + $ + v(f) = f^{\text{out}}(A) - f^{\text{in}}(A) + $ \end{myblockquote} Questa affermazione è in realtà molto più forte di un semplice upper bound. Dice che osservando la quantità di flusso che $f$ invia attraverso un taglio, possiamo misurare esattamente il valore del flusso: \textbf{è la quantità totale che lascia A, meno la quantità che -``torna indietro'' in A}.\\ + ``torna indietro'' in A}.\\ Se $A = {s}$, allora $f^{out}(A) = f^{out}(s)$ e $f^{in}(A) = 0$ poiché non ci sono archi che entrano nella sorgente per ipotesi. Quindi @@ -468,10 +468,10 @@ \subsection{Analyzing the Algorithm: Flows and Cuts} \paragraph{DEF(7.7)} \begin{myblockquote} -Sia $f$ un flusso $s-t$ qualsiasi, e $(A, B)$ un taglio $s-t$, allora -$ -v(f) = f^{\text{in}}(B) - f^{\text{out}}(B) -$ + Sia $f$ un flusso $s-t$ qualsiasi, e $(A, B)$ un taglio $s-t$, allora + $ + v(f) = f^{\text{in}}(B) - f^{\text{out}}(B) + $ \end{myblockquote} Se poniamo $A = V - {t}$ e $B = {t}$ nella (7.7), abbiamo @@ -488,18 +488,18 @@ \subsection{Analyzing the Algorithm: Flows and Cuts} \paragraph{DEF(7.8)} \begin{myblockquote} -Sia $f$ un flusso $s-t$ qualsiasi, e $(A, B)$ un taglio $s-t$, allora -$ - v(f) \le c(A, B) -$ + Sia $f$ un flusso $s-t$ qualsiasi, e $(A, B)$ un taglio $s-t$, allora + $ + v(f) \le c(A, B) + $ \end{myblockquote} In un certo senso, la (7.8) sembra più debole della (7.6), poiché è solo una disuguaglianza piuttosto che un'uguaglianza. Tuttavia, ci sarà estremamente utile, poiché il suo lato destro è indipendente da un flusso particolare $f$. Quello che dice la (7.8) è che \textbf{il -valore di ogni flusso è limitato superiormente dalla capacità di ogni -taglio}. In altre parole, se eseguiamo un qualsiasi taglio $s-t$ in + valore di ogni flusso è limitato superiormente dalla capacità di ogni + taglio}. In altre parole, se eseguiamo un qualsiasi taglio $s-t$ in $G$ di un certo valore $c^{*}$, sappiamo immediatamente dalla (7.8) che non può esserci un flusso $s-t$ in $G$ di valore maggiore di $c^{*}$. Al contrario, se valutiamo un qualsiasi flusso $s-t$ in $G$ @@ -518,18 +518,18 @@ \section{Analyzing the Algorithm: Max-Flow Equals Min-Cut} qualsiasi taglio $s-t$.\\ L'algoritmo di Ford-Fulkerson \textbf{termina quando il flusso $f$ non -ha un cammino $s-t$ nel grafo residuale $G_f$}. Questa risulta + ha un cammino $s-t$ nel grafo residuale $G_f$}. Questa risulta essere l'unica proprietà necessaria per dimostrare la sua massimalità.\\ \paragraph{DEF(7.9)} \begin{myblockquote} -Se $f$ è un flusso $s-t$ tale che non esiste un cammino $s-t$ nel -grafo residuale $G_f$ , allora esiste un taglio $s-t$ -$(A^{*} , B^{*})$ in $G$ per cui $v(f) = c(A^{*} , B^{*})$. Di -conseguenza, $f$ ha il valore massimo di qualsiasi flusso in $G$, e -$(A^{*} , B^{*})$ ha la capacità minima di qualsiasi taglio $s-t$ in -$G$. + Se $f$ è un flusso $s-t$ tale che non esiste un cammino $s-t$ nel + grafo residuale $G_f$ , allora esiste un taglio $s-t$ + $(A^{*} , B^{*})$ in $G$ per cui $v(f) = c(A^{*} , B^{*})$. Di + conseguenza, $f$ ha il valore massimo di qualsiasi flusso in $G$, e + $(A^{*} , B^{*})$ ha la capacità minima di qualsiasi taglio $s-t$ in + $G$. \end{myblockquote} @@ -567,35 +567,35 @@ \section{Analyzing the Algorithm: Max-Flow Equals Min-Cut} inutilizzati. Possiamo ora usare la (7.6) per raggiungere la conclusione desiderata: $$ -v(f) = f^{out}(A^{*}) - f^{in}(A^{*}) = \sum_{e \text{ out of }A^{*}} f(e) - \sum_{e \text{ into }A^{*}}f(e) = \sum_{e \text{ out of }A^{*}} c_e - 0 = c(A^{*}, B^{*}) + v(f) = f^{out}(A^{*}) - f^{in}(A^{*}) = \sum_{e \text{ out of }A^{*}} f(e) - \sum_{e \text{ into }A^{*}}f(e) = \sum_{e \text{ out of }A^{*}} c_e - 0 = c(A^{*}, B^{*}) $$ \begin{figure}[H] - \centering - \includegraphics[width = 10 cm]{Network_flow/imgs/flow4.png} - \caption{La dimostrazione della 7.9} + \centering + \includegraphics[width = 10 cm]{capitoli/network_flow/imgs/flow4.png} + \caption{La dimostrazione della 7.9} \end{figure} \paragraph{DEF(7.10)} \begin{myblockquote} -Il flusso $\bar{f}$ restituito dall'algoritmo di Ford-Fulkerson è un -flusso massimo. + Il flusso $\bar{f}$ restituito dall'algoritmo di Ford-Fulkerson è un + flusso massimo. \end{myblockquote} \paragraph{DEF(7.11)} \begin{myblockquote} -Dato un flusso f di valore massimo, possiamo calcolare un taglio $s-t$ -di capacità minima in tempo $O(m)$. + Dato un flusso f di valore massimo, possiamo calcolare un taglio $s-t$ + di capacità minima in tempo $O(m)$. \end{myblockquote} \paragraph{DEF(7.12)} \begin{myblockquote} -In ogni rete di flussi esiste un flusso $f$ e un taglio $(A, B)$ -tale che $v(f) = c(A, B)$. + In ogni rete di flussi esiste un flusso $f$ e un taglio $(A, B)$ + tale che $v(f) = c(A, B)$. \end{myblockquote} Il punto è che $f$ nella (7.12) deve essere un flusso massimo $s-t$; @@ -606,11 +606,11 @@ \section{Analyzing the Algorithm: Max-Flow Equals Min-Cut} fosse un taglio $(A , B)$ di capacità minore, sarebbe minore del valore di $f$ , e anche questo contraddirebbe la (7.8). A causa di queste implicazioni, la (7.12) è spesso chiamata \textbf{teorema del -taglio minimo del flusso massimo} ed è formulata come segue. + taglio minimo del flusso massimo} ed è formulata come segue. \paragraph{Teorema del Taglio Minimo del Flusso Massimo} \begin{myblockquote} -\textbf{In ogni rete di flussi, il valore massimo di un flusso $s-t$ è -uguale alla capacità minima possibile per un taglio $s-t$.} + \textbf{In ogni rete di flussi, il valore massimo di un flusso $s-t$ è + uguale alla capacità minima possibile per un taglio $s-t$.} \end{myblockquote} \ No newline at end of file diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/bipartite1.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/bipartite1.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/bipartite1.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/bipartite1.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/bipartite2.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/bipartite2.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/bipartite2.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/bipartite2.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/bipartite3.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/bipartite3.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/bipartite3.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/bipartite3.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/bipartite4.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/bipartite4.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/bipartite4.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/bipartite4.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/bipartite5.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/bipartite5.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/bipartite5.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/bipartite5.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex1.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex1.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex1.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex1.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex2.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex2.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex2.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex2.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex3.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex3.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex3.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex3.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex4.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex4.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex4.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex4.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex5.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex5.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex5.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex5.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex6.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex6.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex6.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex6.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex7.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex7.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex7.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex7.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex8.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex8.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex8.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex8.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex9.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex9.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/ex9.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/ex9.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/flow1.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/flow1.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/flow1.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/flow1.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/flow2.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/flow2.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/flow2.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/flow2.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/flow3.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/flow3.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/flow3.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/flow3.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/flow4.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/flow4.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/flow4.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/flow4.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/pathological_example.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/pathological_example.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/pathological_example.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/pathological_example.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/preflow1.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/preflow1.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/preflow1.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/preflow1.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/preflow2.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/preflow2.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/imgs/preflow2.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/imgs/preflow2.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/matching_grafi_bipartiti.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/matching_grafi_bipartiti.tex similarity index 63% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/matching_grafi_bipartiti.tex rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/matching_grafi_bipartiti.tex index 5adcf3f1f..337931a30 100644 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/matching_grafi_bipartiti.tex +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/matching_grafi_bipartiti.tex @@ -31,26 +31,26 @@ \section{Designing the Algorithm} seguito:\\ \begin{figure}[H] - \centering - \includegraphics[width = 12cm]{Network_flow/imgs/bipartite1.png} - \caption{Corrispondenza tra grafo bipartito e flow network} + \centering + \includegraphics[width = 12cm]{capitoli/network_flow/imgs/bipartite1.png} + \caption{Corrispondenza tra grafo bipartito e flow network} \end{figure} -Come si ottiene $G'$ ? +Come si ottiene $G'$ ? \begin{itemize} - \item Per prima cosa si direzionano tutti gli archi di $G$ che vanno da $X$ a $Y$ - \item Si aggiunge poi un nodo $s$, e un arco $(s, x)$ da $s$ ad ogni nodo in $X$ - \item Si aggiunge un altro nodo $t$, e un arco $(y, t)$ da ogni nodo in $Y$ verso $t$ - \item Infine, si da una capacità di 1 ad ogni arco in $G'$ + \item Per prima cosa si direzionano tutti gli archi di $G$ che vanno da $X$ a $Y$ + \item Si aggiunge poi un nodo $s$, e un arco $(s, x)$ da $s$ ad ogni nodo in $X$ + \item Si aggiunge un altro nodo $t$, e un arco $(y, t)$ da ogni nodo in $Y$ verso $t$ + \item Infine, si da una capacità di 1 ad ogni arco in $G'$ \end{itemize} Si può ora calcolare il massimo flow $s-t$ nella rete $G'$.\\ Vedremo ora come: \begin{itemize} - \item \textbf{Il valore del massimo flusso di questa rete ($G'$) in - realtà è uguale alla dimensione del massimo matching in $G$.} - \item Inoltre vederemo come ricostruire il matching utilizzando il flusso della rete. + \item \textbf{Il valore del massimo flusso di questa rete ($G'$) in + realtà è uguale alla dimensione del massimo matching in $G$.} + \item Inoltre vederemo come ricostruire il matching utilizzando il flusso della rete. \end{itemize} \paragraph{Dimostrazione del primo punto} @@ -75,9 +75,9 @@ \section{Designing the Algorithm} Ecco 3 semplici fatti sull'insieme $M'$: \begin{itemize} - \item $M'$ contiene $k$ archi - \item Ogni nodo in $X$ è la coda di al massimo un arco in $M'$ - \item Ogni nodo in $Y$ è la testa di al massimo un arco in $M'$ + \item $M'$ contiene $k$ archi + \item Ogni nodo in $X$ è la coda di al massimo un arco in $M'$ + \item Ogni nodo in $Y$ è la testa di al massimo un arco in $M'$ \end{itemize} Combinando questi fatti, vediamo che se consideriamo $M'$ come un @@ -85,9 +85,9 @@ \section{Designing the Algorithm} di dimensione $k$. In sintesi, abbiamo dimostrato il seguente fatto. \begin{myblockquote} -La dimensione del massimo matching in $G$ è uguale al valore del -massimo flusso in $G'$ ; e gli archi in un tale matching in G sono gli -archi che portano il flusso da $X$ a $Y$ in $G'$. + La dimensione del massimo matching in $G$ è uguale al valore del + massimo flusso in $G'$ ; e gli archi in un tale matching in G sono gli + archi che portano il flusso da $X$ a $Y$ in $G'$. \end{myblockquote} \subsection{Costo} @@ -102,8 +102,8 @@ \subsection{Costo} capacità 1 per ogni nodo di $X$. Quindi, utilizzando $O(mC)$ come bound (limite), abbiamo il seguente corollario: \begin{myblockquote} - L'algoritmo di \texttt{Ford-Fulkerson} può essere utilizzato per trovare - un matching massimo in un grafo bipartito in tempo $O(mn)$. + L'algoritmo di \texttt{Ford-Fulkerson} può essere utilizzato per trovare + un matching massimo in un grafo bipartito in tempo $O(mn)$. \end{myblockquote} @@ -113,31 +113,31 @@ \section{Perfect Matching} \textbf{matching perfetto} se ogni vertice $v \in V$ compare in $M$ esattamente una volta. \begin{itemize} - \item Dobbiamo avere \textbar X\textbar{} = \textbar Y\textbar{} + \item Dobbiamo avere \textbar X\textbar{} = \textbar Y\textbar{} \end{itemize} \textbf{Notazione}: Sia $S$ un sottoinsieme dei nodi, e sia $N(S)$ l'insieme dei nodi adiacenti ai nodi in $S$ \begin{myblockquote} -\textbf{Se un grafo bipartito $G = (V, E)$, con i due lati $X$ e -$Y$, ha un perfect matching, allora per ogni $S \subseteq X$ si deve -avere $|N(S)| \ge |S|$.} + \textbf{Se un grafo bipartito $G = (V, E)$, con i due lati $X$ e + $Y$, ha un perfect matching, allora per ogni $S \subseteq X$ si deve + avere $|N(S)| \ge |S|$.} \end{myblockquote} \textbf{Dimostrazione} Ogni nodo in $S$ deve essere matchato a un differente nodo in $N(S)$\\ \begin{figure}[H] - \centering - \includegraphics[width = 10 cm]{Network_flow/imgs/bipartite2.png} - \caption{esempio di assenza di matching perfetto} + \centering + \includegraphics[width = 10 cm]{capitoli/network_flow/imgs/bipartite2.png} + \caption{esempio di assenza di matching perfetto} \end{figure} Con l'affermazione precedente possiamo anche constatare quando un grafo non ha un matching perfetto: \begin{itemize} - \item un insieme $S \subseteq X$ tale per cui $|N(S)| < |S|$ + \item un insieme $S \subseteq X$ tale per cui $|N(S)| < |S|$ \end{itemize} Da qui ne deriva un teorema chiamato \textbf{Hall's Theorem}, la cui @@ -162,17 +162,17 @@ \subsection{Hall's Theorem} $\Leftarrow:$\\ Suppongo che G \textbf{non} abbia perfect matching. \begin{itemize} - \item Lo si formuli come un max-flow problem e sia $(A,B)$ un min-cut di $G'$. - \item Dal max-flow min-cut theorem $cap(A,B) < |X|$. - \item Definisco $X_A = X \cap A$, $X_B = X \cap B$, $Y_A = Y \cap A$ - \item $cap(A,B) = |X_B| + |Y_A| \implies |Y_A| < |X_A|$ - \item min-cut non può usare archi con capacità infinita $\implies N(X_A) \subseteq Y_A$ - \item $|N(X_A)| \le |Y_A| < |X_A|$ - scelgo $S = X_A$. \textbf{Il che è assurdo}. + \item Lo si formuli come un max-flow problem e sia $(A,B)$ un min-cut di $G'$. + \item Dal max-flow min-cut theorem $cap(A,B) < |X|$. + \item Definisco $X_A = X \cap A$, $X_B = X \cap B$, $Y_A = Y \cap A$ + \item $cap(A,B) = |X_B| + |Y_A| \implies |Y_A| < |X_A|$ + \item min-cut non può usare archi con capacità infinita $\implies N(X_A) \subseteq Y_A$ + \item $|N(X_A)| \le |Y_A| < |X_A|$ - scelgo $S = X_A$. \textbf{Il che è assurdo}. \end{itemize} \begin{figure}[H] - \centering - \includegraphics[width = 12 cm]{Network_flow/imgs/bipartite3.png} + \centering + \includegraphics[width = 12 cm]{capitoli/network_flow/imgs/bipartite3.png} \end{figure} Si noti che $X$ corrisponde a $L$ e $Y$ a $R$ nella figura. @@ -198,21 +198,21 @@ \subsection{Max-Flow Formulation} \textbf{Dimostrazione:} $\le:$ \begin{itemize} - \item Suppongo che ci siano $k$ edge-disjoint paths da s a t. - \item Pongo $f(e)=1$ per tutti gli archi che compaiono in questi path, altrimenti pongo $f(e)=0$. - \item Dato che non ci sono archi in comune, $f$ è un flow di valore $k$. + \item Suppongo che ci siano $k$ edge-disjoint paths da s a t. + \item Pongo $f(e)=1$ per tutti gli archi che compaiono in questi path, altrimenti pongo $f(e)=0$. + \item Dato che non ci sono archi in comune, $f$ è un flow di valore $k$. \end{itemize} $\ge:$ \begin{itemize} - \item Suppongo che il max-flow abbia valore $k$. - \item Per l'integrality theorem esiste un flow $0-1$ di valore $k$. - \item Considero gli archi $(s, u)$ con $f(s, u) = 1$. - \begin{itemize} - \item Per la conservazione del flusso esiste un arco $(u,v)$ con $f(u, v) = 1$. - \item Continuo scegliendo sempre nuovi archi fino a raggiungere $t$. - \end{itemize} - \item Produco $k$ edge-disjoint paths. + \item Suppongo che il max-flow abbia valore $k$. + \item Per l'integrality theorem esiste un flow $0-1$ di valore $k$. + \item Considero gli archi $(s, u)$ con $f(s, u) = 1$. + \begin{itemize} + \item Per la conservazione del flusso esiste un arco $(u,v)$ con $f(u, v) = 1$. + \item Continuo scegliendo sempre nuovi archi fino a raggiungere $t$. + \end{itemize} + \item Produco $k$ edge-disjoint paths. \end{itemize} \section{Network Connectivity} @@ -233,26 +233,26 @@ \subsection{Teorema di Menger} \textbf{Dimostrazione:} $\le:$ \begin{itemize} - \item Suppongo che la rimozione di $F \subseteq E$ disconnetta $t$ da $s$ e $|F| = k$. - \item Ogni path $s-t$ passa per almeno un arco di $F$. - \item Quindi il numero di edge-disjoint path è $\le k$ - \item \begin{figure}[H] - \centering - \includegraphics[width = 12cm]{Network_flow/imgs/bipartite4.png} - \end{figure} + \item Suppongo che la rimozione di $F \subseteq E$ disconnetta $t$ da $s$ e $|F| = k$. + \item Ogni path $s-t$ passa per almeno un arco di $F$. + \item Quindi il numero di edge-disjoint path è $\le k$ + \item \begin{figure}[H] + \centering + \includegraphics[width = 12cm]{capitoli/network_flow/imgs/bipartite4.png} + \end{figure} \end{itemize} $\ge :$ \begin{itemize} - \item Suppongo che il massimo numero di edge-disjoint path sia $k$. - \item Allora, il Max-flow value è $k$. - \item Per il max-flow min-cut theorem esiste un cut $(A,B)$ di capacità $k$. - \item Sia $F$ l'insieme di archi che vanno da $A$ a $B$. - \item $|F| = k$ e disconnette $t$ da $s$. - \item \begin{figure}[H] - \centering - \includegraphics[width = 12cm]{Network_flow/imgs/bipartite5.png} - \end{figure} + \item Suppongo che il massimo numero di edge-disjoint path sia $k$. + \item Allora, il Max-flow value è $k$. + \item Per il max-flow min-cut theorem esiste un cut $(A,B)$ di capacità $k$. + \item Sia $F$ l'insieme di archi che vanno da $A$ a $B$. + \item $|F| = k$ e disconnette $t$ da $s$. + \item \begin{figure}[H] + \centering + \includegraphics[width = 12cm]{capitoli/network_flow/imgs/bipartite5.png} + \end{figure} \end{itemize} %\end{document} diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/preflow.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/preflow.tex similarity index 77% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/preflow.tex rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/preflow.tex index a232758b1..d7f9bec01 100644 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Network_flow/preflow.tex +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/network_flow/preflow.tex @@ -10,21 +10,21 @@ \section{Design dell'algoritmo} Solitamente se si usa questo approccio verranno violate le condizioni di conservazione del flusso, quindi per il corretto funzionamento andremo a rilassare la condizione di conservazione introducendo un valore di \textbf{Preflow}. \begin{myblockquote} - Un \textit{$s-t$ preflow } è una funzione $f$ che mappa ogni arco $e$ ad un numero reale non negativo, $f: E \rightarrow \mathbf{R^+}$. + Un \textit{$s-t$ preflow } è una funzione $f$ che mappa ogni arco $e$ ad un numero reale non negativo, $f: E \rightarrow \mathbf{R^+}$. \end{myblockquote} Un \textit{preflow} $f$ deve rispettare la capacity condition, ma al posto della conservetion condition utilizzeremo una condizione meno restrittiva, e dunque avremo quanto segue: \begin{enumerate} - \item \textbf{Capacity}: Per ogni nodo $e \in E$, avremo che $0 \le f(e) \le c_e$ - \item \textbf{Conservation}: Per ogni nodo $v$ al di fuori della source $s$ avremo che: - $$ - \sum_{e \text{ into }v}f(e) \ge \sum_{e \text{ out of }v}f(e). - $$ + \item \textbf{Capacity}: Per ogni nodo $e \in E$, avremo che $0 \le f(e) \le c_e$ + \item \textbf{Conservation}: Per ogni nodo $v$ al di fuori della source $s$ avremo che: + $$ + \sum_{e \text{ into }v}f(e) \ge \sum_{e \text{ out of }v}f(e). + $$ \end{enumerate} Chiameremo la differenza $$ - e_f(v) = \sum_{e \text{ into }v}f(e) - \sum_{e \text{ out of }v}f(e) + e_f(v) = \sum_{e \text{ into }v}f(e) - \sum_{e \text{ out of }v}f(e) $$ l' \textbf{eccesso} del \textbf{preflow} nel nodo $v$.\\ @@ -41,39 +41,39 @@ \subsection{Preflow e Labelings} Ora che abbiamo un idea di come l'algoritmo sfrutta i label possiamo dare una loro definizione più rigorosa. \begin{myblockquote} - Un labeling è una funzione $h: V \rightarrow \mathbf{Z}_{\ge 0}$ che mappa nodi a interi non negativi + Un labeling è una funzione $h: V \rightarrow \mathbf{Z}_{\ge 0}$ che mappa nodi a interi non negativi \end{myblockquote} Il prossimo passo per creare l'algoritmo è quello di definire un labeling \textbf{compatibile}, che si avrà quando saranno rispettate le seguenti condizioni: \begin{enumerate} - \item \textbf{Source and Sink condition}: $h(t) = 0$ e $h(s) = n$, - \item \textbf{Steepness condition}: Per tutti gli archi $(v,w) \in E_f$ nel grafo residuale, avremo che $h(v) \le h(w) + 1$ + \item \textbf{Source and Sink condition}: $h(t) = 0$ e $h(s) = n$, + \item \textbf{Steepness condition}: Per tutti gli archi $(v,w) \in E_f$ nel grafo residuale, avremo che $h(v) \le h(w) + 1$ \end{enumerate} \begin{figure}[H] - \centering - \includegraphics[width = 10 cm]{Network_flow/imgs/preflow1.png} - \caption{Grafo residuale con labeling compatibile} + \centering + \includegraphics[width = 10 cm]{capitoli/network_flow/imgs/preflow1.png} + \caption{Grafo residuale con labeling compatibile} \end{figure} Se il labeling è compatibile allora avremo la seguente proprietà: \begin{myblockquote} - se un \textit{$s-t$ preflow f} è compatibile con un labeling $h$, allora non ci sarà nessun cammino nel grafo residuale $G_f$. + se un \textit{$s-t$ preflow f} è compatibile con un labeling $h$, allora non ci sarà nessun cammino nel grafo residuale $G_f$. \end{myblockquote} e quindi ne segue: \begin{myblockquote} - se un \textit{$s-t$ preflow f} è compatibile con un labeling $h$, allora il flusso $f$ - è un \textbf{flusso di valore massimo} + se un \textit{$s-t$ preflow f} è compatibile con un labeling $h$, allora il flusso $f$ + è un \textbf{flusso di valore massimo} \end{myblockquote} Per iniziare l'algoritmo sarà necessario partire con un labeling compatibile, quindi è importante definire un'\textbf{inizializzazione}: \begin{itemize} - \item $h(v) = 0$ per ogni nodo $v \neq s$, - \item $h(s) = n$ - \item $f(e) = c_e$ per ogni arco $e = (s,v)$ uscente da $s$ - \item $f(e) = 0$ altrimenti + \item $h(v) = 0$ per ogni nodo $v \neq s$, + \item $h(s) = n$ + \item $f(e) = c_e$ per ogni arco $e = (s,v)$ uscente da $s$ + \item $f(e) = 0$ altrimenti \end{itemize} Gli ultimi due punti servono per assicurarsi che non ci siano archi uscenti da $s$ nel grafo residuale, in quanto il preflow e il labeling iniziali devono essere compatibili. @@ -134,40 +134,40 @@ \subsection{Analisi dell'Algoritmo} Come primo passo definiamo questo semplice fatto: \begin{myblockquote} - Sia $f$ un preflow, se il nodo $v$ ha eccesso allora esiste un cammino in $G_f$ da $v$ alla source $s$ + Sia $f$ un preflow, se il nodo $v$ ha eccesso allora esiste un cammino in $G_f$ da $v$ alla source $s$ \end{myblockquote} Detto questo possiamo dimostrare che i label non vengono modificati troppe volte: \begin{myblockquote} - Durante l'algoritmo tutti i nodi hanno $h(v) \le 2n-1$. + Durante l'algoritmo tutti i nodi hanno $h(v) \le 2n-1$. \end{myblockquote} -\textbf{Dimostrazione}. Le labels inziali h(t) = 0 e h(s) = n non cambiano mai durante -l'esecuzione dell'algoritmo. Consideriamo altri nodi $v \neq s, t$. L'algoritmo cambia la -label di $v$ solo quando applica l'oprazione di \textbf{relabel}, quindi siano $f$ e $h$ il -preflow ed il labeling ritornati dalla funzione \textbf{relabel}($f , h, v$). Dalla -definizione precedente a questa esiste un cammino P nel grafo residuale $G_f$ da $v$ a $s$. -Sia $|P|$ il numero di archi in P, e si noti che $|P| \leq n - 1$. La steepness condition -implica che l'altezza dei nodi può diminuire di al massimo 1 lungo ogni arco in $P$, e che +\textbf{Dimostrazione}. Le labels inziali h(t) = 0 e h(s) = n non cambiano mai durante +l'esecuzione dell'algoritmo. Consideriamo altri nodi $v \neq s, t$. L'algoritmo cambia la +label di $v$ solo quando applica l'oprazione di \textbf{relabel}, quindi siano $f$ e $h$ il +preflow ed il labeling ritornati dalla funzione \textbf{relabel}($f , h, v$). Dalla +definizione precedente a questa esiste un cammino P nel grafo residuale $G_f$ da $v$ a $s$. +Sia $|P|$ il numero di archi in P, e si noti che $|P| \leq n - 1$. La steepness condition +implica che l'altezza dei nodi può diminuire di al massimo 1 lungo ogni arco in $P$, e che $h(v) - h(s) \leq |P|$, il che prova l'affermazione di partenza.\\ Dato che i label incrementano in modo \textbf{monotono} durante l'esecuzione dell'algoritmo, questa cosa ci implica un limite immediato al \textbf{numero di operazioni di relabeling}: \begin{myblockquote} - Durante l'algoritmo ogni nodo subisce relabeling al massimo $2n-1$ volte, e il numero totale di operazioni di releabeling serà minore di $2n^2$ + Durante l'algoritmo ogni nodo subisce relabeling al massimo $2n-1$ volte, e il numero totale di operazioni di releabeling serà minore di $2n^2$ \end{myblockquote} Ora cerchiamo un \textbf{bound} per le operazioni di push, per farlo distingueremo \textbf{2 tipi di operazioni push}. \begin{itemize} - \item un $push(f, h, v, w)$ è \textbf{saturante} se o $e = (v, w)$ è un arco forward in $E_f$ e $\delta = c_e - f(e)$, oppure $(v,w)$ è un arco backward con $e = (w,v)$ e $\delta = f(e)$(\textit{in altre parole se dopo il push l'arco $(v,w)$ non è più nel grafo residuale, allora il push è saturante}). - \item il push è \textbf{non saturante} in tutti gli altri casi + \item un $push(f, h, v, w)$ è \textbf{saturante} se o $e = (v, w)$ è un arco forward in $E_f$ e $\delta = c_e - f(e)$, oppure $(v,w)$ è un arco backward con $e = (w,v)$ e $\delta = f(e)$(\textit{in altre parole se dopo il push l'arco $(v,w)$ non è più nel grafo residuale, allora il push è saturante}). + \item il push è \textbf{non saturante} in tutti gli altri casi \end{itemize} \begin{myblockquote} - Il numero massimo di operazioni \textbf{push saturanti} è al massimo $2nm$ + Il numero massimo di operazioni \textbf{push saturanti} è al massimo $2nm$ \end{myblockquote} -\textbf{Dimostrazione.} +\textbf{Dimostrazione.} Consideriamo un arco $(v, w)$ nel grafo residuale. Dopo un push saturante \textbf{push}($f, h, v, w$), abbiamo che $h(v) = h(w) + 1$, e che l'arco $(v, w)$ non è più presente nel grafo residuale $G_f$. Prima di poter fare un'operazione di push in quest'arco dobbiamo prima fare un'operazione di push da $w$ a $v$ per far apparire l'arco @@ -179,12 +179,12 @@ \subsection{Analisi dell'Algoritmo} Per quanto riguarda i push non saturanti, provare un loro upper-bound è la parte più difficile di questa analisi ma anche la più importante perchè ci fornisce un \textbf{bottleneck} per il running time teorico. \begin{myblockquote} - Il numero di operazioni di \textbf{push non saturanti} è al più $2n^2m$ + Il numero di operazioni di \textbf{push non saturanti} è al più $2n^2m$ \end{myblockquote} \textbf{Dimostrazione.} Per questa dimostrazione utilizzaremo una \textbf{funzione potenziale}, definita come segue: $$ - \Phi(f, h) = \sum_{v:e_f(v)>0}h(v) + \Phi(f, h) = \sum_{v:e_f(v)>0}h(v) $$ Sarà la somma delle altezze dei noti con eccesso positivo (è chiamata \textit{potenziale}, perchè assomiglia all'energia potenziale dei nodi con eccesso positivo).\\ @@ -204,5 +204,5 @@ \subsection{Analisi dell'Algoritmo} Con determinati criteri è possibile ridurre il numero di push non saturanti: \begin{myblockquote} - Se ad ogni step scegliamo il nodo con eccesso ad altezza massima, il numero di \textbf{push non saturanti} sarà al massimo $4n^3$ + Se ad ogni step scegliamo il nodo con eccesso ad altezza massima, il numero di \textbf{push non saturanti} sarà al massimo $4n^3$ \end{myblockquote} \ No newline at end of file diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/best_fit.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/best_fit.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/best_fit.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/best_fit.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/hirschberg.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/hirschberg.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/hirschberg.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/hirschberg.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/iter_comp_opt.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/iter_comp_opt.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/iter_comp_opt.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/iter_comp_opt.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/knapsack_opt.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/knapsack_opt.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/knapsack_opt.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/knapsack_opt.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/llsqr_funzionamento.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/llsqr_funzionamento.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/llsqr_funzionamento.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/llsqr_funzionamento.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/matrix1.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/matrix1.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/matrix1.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/matrix1.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/matrix2.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/matrix2.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/matrix2.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/matrix2.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/pole1.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/pole1.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/pole1.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/pole1.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/pole2.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/pole2.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/pole2.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/pole2.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/pole3.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/pole3.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/pole3.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/pole3.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/pole4.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/pole4.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/pole4.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/pole4.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/rna1.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/rna1.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/rna1.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/rna1.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/rna2.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/rna2.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/rna2.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/rna2.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/rna3.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/rna3.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/rna3.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/rna3.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/rna4.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/rna4.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/rna4.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/rna4.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/sa.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/sa.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/sa.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/sa.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/seg_llsqr.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/seg_llsqr.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/seg_llsqr.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/seg_llsqr.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/seq_align_recurrence.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/seq_align_recurrence.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/seq_align_recurrence.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/seq_align_recurrence.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/seqalignmatrix.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/seqalignmatrix.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/seqalignmatrix.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/seqalignmatrix.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/weigted_interval_scheduling.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/weigted_interval_scheduling.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/weigted_interval_scheduling.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/weigted_interval_scheduling.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/wis_instance.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/wis_instance.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/wis_instance.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/wis_instance.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/wis_subproblem_tree.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/wis_subproblem_tree.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/wis_subproblem_tree.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/wis_subproblem_tree.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/zaino1.png b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/zaino1.png similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/imgs/zaino1.png rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/imgs/zaino1.png diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/introduzione.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/introduzione.tex similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/introduzione.tex rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/introduzione.tex diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/knapsack_problem.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/knapsack_problem.tex similarity index 95% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/knapsack_problem.tex rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/knapsack_problem.tex index 91ae5fdcd..2cafeba15 100644 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/knapsack_problem.tex +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/knapsack_problem.tex @@ -52,9 +52,9 @@ \section{Dynamic Version} otteniamo la seguente ricorsione: \begin{myblockquote} \begin{itemize} - \item se: $W < w_i$ allora: + \item se: $W < w_i$ allora: $OPT(i, W) = OPT(i-1,W)$ - \item altrimenti: + \item altrimenti: $OPT(i, W) = \max(OPT(i-1, W), w_i + OPT(i-1, W-w_i))$ \end{itemize} \end{myblockquote} @@ -90,7 +90,7 @@ \section{Dynamic Version} \end{lstlisting} \begin{figure}[H] \centering - \includegraphics[width = 15cm, keepaspectratio]{Programmazione_dinamica/imgs/knapsack_opt.png} + \includegraphics[width = 15cm, keepaspectratio]{capitoli/programmazione_dinamica/imgs/knapsack_opt.png} \caption{La tabella bidimensionale dei valori di $OPT$. La colonna più a sinistra e l'ultima riga sono sempre 0. L'entry per $OPT(i, w)$ si calcola come indicato dalle frecce.} @@ -134,9 +134,9 @@ \subsection{Costi} \hline \textbf{Funzione} & \textbf{Costo in tempo} & \textbf{Costo in spazio} \\ \hline - Subset-Sum & $\Theta(nW)$ & $\Theta(nW)$ \\ + Subset-Sum & $\Theta(nW)$ & $\Theta(nW)$ \\ \hline - Find-Solution & $O(n)$ & \\ + Find-Solution & $O(n)$ & \\ \hline \end{tabular} \end{center} @@ -162,7 +162,7 @@ \subsection{Osservazioni} pseudopolinomiale, perchè dipende da due variabili). \begin{figure}[H] - \includegraphics[width = 15cm]{Programmazione_dinamica/imgs/zaino1.png} + \includegraphics[width = 15cm]{capitoli/programmazione_dinamica/imgs/zaino1.png} \centering \caption{In questa immagine si può vedere come è possibile ricostruire la soluzione salvata nell'array bidimensionale di memoization} @@ -184,7 +184,7 @@ \subsection{Osservazioni} \begin{myblockquote} \begin{itemize} \item se $W < w_i$ allora $OPT(i, W) = OPT(i-1,W)$ - \item altrimenti $OPT(i, W) = max(OPT(i-1, W), v_i + OPT(i-1, W-w_i))$ + \item altrimenti \linebreak $OPT(i, W) = max(OPT(i-1, W), v_i + OPT(i-1, W-w_i))$ \end{itemize} \end{myblockquote} diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/matrix_chain_parenthesization.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/matrix_chain_parenthesization.tex similarity index 96% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/matrix_chain_parenthesization.tex rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/matrix_chain_parenthesization.tex index 18f46a756..adaf29ee6 100644 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/matrix_chain_parenthesization.tex +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/matrix_chain_parenthesization.tex @@ -126,10 +126,10 @@ \subsection{Goal} Quindi otteniamo la seguente ricorrenza \begin{figure}[H] -\centering - \includegraphics[width=10cm, keepaspectratio]{Programmazione_dinamica/imgs/matrix1.png} + \centering + \includegraphics[width=10cm, keepaspectratio]{capitoli/programmazione_dinamica/imgs/matrix1.png} \caption{Sequenza: 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, -$\ldots$} + $\ldots$} \end{figure} \begin{itemize} @@ -177,7 +177,7 @@ \subsubsection{Defininizione della sottostruttura} \begin{myblockquote} Supponiamo che una parentesizzazione ottima $A_i A_{i+1} \ldots A_j$ - suddivida il prodotto fra $A_k$ e $A_{k+1}$. Allora la + suddivida \linebreak il prodotto fra $A_k$ e $A_{k+1}$. Allora la parentesizzazione della prima sottosequenza $A_i A_{i+1} \ldots A_k$ all'interno di questa parentesizzazione ottima di $A_i A_{i+1} \ldots A_j$, deve essere una parentesizzazione ottima di @@ -225,8 +225,8 @@ \subsection{Soluzione in modo ricorsivo} parentesizzazione del prodotto $A_i A_{i+1} \ldots A_j$ diventa \begin{figure}[H] -\centering - \includegraphics[width=15cm, keepaspectratio]{Programmazione_dinamica/imgs/matrix2.png} + \centering + \includegraphics[width=15cm, keepaspectratio]{capitoli/programmazione_dinamica/imgs/matrix2.png} \end{figure} I valori \texttt{m[i,\ j]} sono i costi delle soluzioni ottime dei @@ -333,16 +333,16 @@ \subsection{Costo} \section{Costruire una soluzione ottima} -La procedura \texttt{Matrix-Chain-Order}, determina il numero ottimo di -prodotti scalari richiesti per moltiplciare una sequenza di matrici, ma -non mostra direttamente come moltiplicare le matrici. La tabella +La procedura \texttt{Matrix-Chain-Order}, determina il numero ottimo di prodotti +scalari richiesti per moltiplciare una sequenza di matrici, ma non mostra +direttamente come moltiplicare le matrici. La tabella \texttt{s{[}1,..n,1,..n{]}} ci fornisce le informazioni per farlo. Ogni -posizione \texttt{s{[}i,j{]}} registra quel valore di $k$ per il quale -la parentesizzazione ottima di $A_i A_{i+1}\ldots A_j$ suddivide il -prodotto fra $A_k$ e $A_{k+1}$.\\ +posizione \texttt{s{[}i,j{]}} registra quel valore di $k$ per il quale la +parentesizzazione ottima di $A_i A_{i+1}\ldots A_j$ suddivide il prodotto fra +$A_k$ e $A_{k+1}$.\\ Quindi, sappiamo che il prodotto finale delle matrici nel calcolo di -$A_{1..n}$ è $A_{1..s[1,n]} A_{s[1,n]+1..n}$. I prodotti precedenti +$A_{1..n}$ è \linebreak $A_{1..s[1,n]} A_{s[1,n]+1..n}$. I prodotti precedenti possono essere calcolati ricorsivamente perchè \texttt{s{[}i,\ s{[}i,n{]}{]}} determina l'ultimo prodotto nel calcolo di $A_{s[1,n]+1..n}$. La seguente procedura ricorsiva produce una diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/opt_binary_search_tree.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/opt_binary_search_tree.tex similarity index 96% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/opt_binary_search_tree.tex rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/opt_binary_search_tree.tex index 913cceb55..2e89d3f7e 100644 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/opt_binary_search_tree.tex +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/opt_binary_search_tree.tex @@ -41,8 +41,8 @@ \section{Descrizione del problema} \begin{itemize} - \item dove $\text{profondità}_T$ indica la \textbf{profondità} di un nodo - nell'albero $T$. + \item dove $\text{profondità}_T$ indica la \textbf{profondità} di un nodo + nell'albero $T$. \end{itemize} @@ -73,11 +73,11 @@ \section{La struttura di un albero binario di ricerca ottimo} $d_{i-1}, ..., d_j$. Adesso possiamo definire la \textbf{sottostruttura ottima}: \begin{myblockquote} - se un albero - binario di ricerca ottimo $T$ ha un sottoalbero $T'$ che contiene le - chiavi $k_i, ..., k_j$, allora questo sottoalberto $T'$ deve essere - ottimo anche per il sottoproblema con chiavi $k_i, ..., k_j$ e chiavi - fittizie $d_{i-1}, ..., d_j$. + se un albero + binario di ricerca ottimo $T$ ha un sottoalbero $T'$ che contiene le + chiavi $k_i, ..., k_j$, allora questo sottoalberto $T'$ deve essere + ottimo anche per il sottoproblema con chiavi $k_i, ..., k_j$ e chiavi + fittizie $d_{i-1}, ..., d_j$. \end{myblockquote} Date le chiavi $k_i, ..., k_j$, una di queste chiavi, per esempio $k_r$ ($i \le r \le j$), sarà la radice di un sottoalbero ottimo che @@ -146,13 +146,15 @@ \section{Una soluzione ricorsiva} e[i,j] = e[i, r-1] + e[r+1, j] + w(i,j) $$ Otteniamo quindi la seguente formula ricorsiva finale: -$$ + +\begin{equation*} e[i,j] = \begin{cases} q_{i-1}, & j = i-1 \\ \min_{i \le r \le j} \{e[i, r-1] + e[r+1, j] + w(i,j)\} & i \le j \end{cases} -$$ +\end{equation*} + I valori $e[i,j]$ rappresentano i costi attesi di ricerca negli alberi binari di ricerca ottimi. Per tenere traccia della struttura degli alberi binari di ricerca ottimi, definiamo $root[i,j]$, per diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/pole_cutting.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/pole_cutting.tex similarity index 95% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/pole_cutting.tex rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/pole_cutting.tex index ecad187b0..3aae0d2d3 100644 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/pole_cutting.tex +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/pole_cutting.tex @@ -15,15 +15,15 @@ \section{Descrizione del problema} \end{myblockquote} \begin{figure}[H] -\centering - \includegraphics[width=10cm, keepaspectratio]{Programmazione_dinamica/imgs/pole1.png} + \centering + \includegraphics[width=10cm, keepaspectratio]{capitoli/programmazione_dinamica/imgs/pole1.png} \caption{La figura mostra un esempio di problema Pole Cutting.} \end{figure} \begin{figure}[H] \centering - \includegraphics[width=10cm, keepaspectratio]{Programmazione_dinamica/imgs/pole2.png} + \includegraphics[width=10cm, keepaspectratio]{capitoli/programmazione_dinamica/imgs/pole2.png} \caption{La figura sopra invece, mostra tutti i modi in cui può essere tagliata un'asta lunga 4 pollici.} \end{figure} @@ -41,8 +41,8 @@ \section{Descrizione del problema} $r_m = p_{i_1} + p_{i_2} + \ldots + p_{i_k}$ \begin{figure}[H] -\centering - \includegraphics[width=10cm, keepaspectratio]{Programmazione_dinamica/imgs/pole3.png} + \centering + \includegraphics[width=10cm, keepaspectratio]{capitoli/programmazione_dinamica/imgs/pole3.png} \caption{Esempio di valori possibili ottenuti tagliando l'asta in vari pezzi} \end{figure} @@ -132,8 +132,8 @@ \subsection{Costo} ricorsivo con gli stessi valori dei parametri, ovverro \textbf{risolve ripetutamente gli stessi sottoproblemi}. \begin{figure}[H] -\centering - \includegraphics[width=10cm, keepaspectratio]{Programmazione_dinamica/imgs/pole4.png} + \centering + \includegraphics[width=10cm, keepaspectratio]{capitoli/programmazione_dinamica/imgs/pole4.png} \caption{Albero delle soluzioni ottenuto da una solizione trovata con 5 tagli} \end{figure} diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/rna_secondary_structure.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/rna_secondary_structure.tex similarity index 85% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/rna_secondary_structure.tex rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/rna_secondary_structure.tex index eaa622eb1..d4df00781 100644 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/rna_secondary_structure.tex +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/rna_secondary_structure.tex @@ -1,4 +1,5 @@ \chapter{RNA Secondary Stucture Problem} +\label{chap:rna} La ricerca della struttura secondaria dell'RNA è un problema a 2 variabili risolvibile tramite il paradigma della programmazione @@ -19,7 +20,7 @@ \chapter{RNA Secondary Stucture Problem} \begin{figure}[H] \centering - \includegraphics[width=10cm, keepaspectratio]{Programmazione_dinamica/imgs/rna1.png} + \includegraphics[width=10cm, keepaspectratio]{capitoli/programmazione_dinamica/imgs/rna1.png} \caption{Un possibile ripiegamento dell' \textbf{RNA}} \end{figure} @@ -56,7 +57,7 @@ \section{Descrizione del Problema} \end{enumerate} \begin{figure}[H] - \includegraphics[width=15cm, keepaspectratio]{Programmazione_dinamica/imgs/rna2.png} + \includegraphics[width=15cm, keepaspectratio]{capitoli/programmazione_dinamica/imgs/rna2.png} \centering \caption{La figura $(a)$ rappresenta un esempio di Sharp Turn, mentre la figura $(b)$ mostra una Crossing Condition dove il filo blu non dovrebbe @@ -73,22 +74,22 @@ \section{Funzionamento} Per mappare il problema sul paradigma della programmazione dinamica, come prima idea, potremmo basarci sul seguente sotto-problema: \begin{myblockquote} - \begin{itemize} - \item Affermiamo che $OPT(j)$ è il massimo numero di coppie - di basi sulla struttura secondaria $b_1 b_2 \ldots b_j$ - \item per la Non Sharp Turn Condition sappiamo che - $OPT(j) = 0$ per $j \leq 5$ - \item e sappiamo anche che - $OPT(n)$ è la soluzione che vogliamo trovare. - \end{itemize} + \begin{itemize} + \item Affermiamo che $OPT(j)$ è il massimo numero di coppie + di basi sulla struttura secondaria $b_1 b_2 \ldots b_j$ + \item per la Non Sharp Turn Condition sappiamo che + $OPT(j) = 0$ per $j \leq 5$ + \item e sappiamo anche che + $OPT(n)$ è la soluzione che vogliamo trovare. + \end{itemize} \end{myblockquote} Il problema sta nell'esprimere $OPT(j)$ ricorsivamente. Possiamo parzialmente farlo sfruttando le seguenti scelte: \begin{enumerate} - \item $j$ non appartiene ad una coppia - \item $j$ si accoppia con $t$ per qualche $t \leq j - 4$ + \item $j$ non appartiene ad una coppia + \item $j$ si accoppia con $t$ per qualche $t \leq j - 4$ \end{enumerate} \begin{itemize} \item @@ -111,8 +112,8 @@ \section{Funzionamento} \begin{figure}[H] -\centering - \includegraphics[width=15cm, keepaspectratio]{Programmazione_dinamica/imgs/rna3.png} + \centering + \includegraphics[width=15cm, keepaspectratio]{capitoli/programmazione_dinamica/imgs/rna3.png} \centering \end{figure} @@ -149,8 +150,8 @@ \section{Funzionamento} Possiamo esprimere formalmente la ricorsione come segue: \\ \begin{myblockquote} - $OPT(i, j) = \max(OPT(i, j-1), \max_t(1+OPT(i, t-1)+OPT(t+1, j-1)))$,\\ -dove il massimo è calcolato su $t$ tale che $b_t$ e + $OPT(i, j) = \max(OPT(i, j-1), \max_t(1+OPT(i, t-1)+OPT(t+1, j-1)))$,\\ + dove il massimo è calcolato su $t$ tale che $b_t$ e $b_j$ siano una coppia di basi consentita (sotto le condizioni (1) e (2) dalla definizione di struttura secondaria). \end{myblockquote} @@ -158,7 +159,7 @@ \section{Funzionamento} \begin{figure}[H] - \includegraphics[width=12cm, keepaspectratio]{Programmazione_dinamica/imgs/rna4.png} + \includegraphics[width=12cm, keepaspectratio]{capitoli/programmazione_dinamica/imgs/rna4.png} \centering \caption{Iterazioni dell'algoritmo su un campione del problema in questione $(ACCGGUAGU)$} diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/segmented_least_squares_problem.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/segmented_least_squares_problem.tex similarity index 93% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/segmented_least_squares_problem.tex rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/segmented_least_squares_problem.tex index bf8e9d58f..346e3a988 100644 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/segmented_least_squares_problem.tex +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/segmented_least_squares_problem.tex @@ -10,21 +10,23 @@ \chapter{Linear Least Square} \section{Descrizione del Problema} \begin{myblockquote} - Dato un insieme $P$ composto di $n$ punti sul piano denotati con + Dato un insieme $P$ composto di $n$ punti sul piano denotati con \linebreak $(x_1, y_1), (x_2, y_2), \ldots, (x_n, y_n)$ e supponiamo che $x_1 < x_2 < \ldots < x_n$ (sono strettamente crescenti). Data una linea $L$ definita dall'equazione $y = ax + b$, definiamo l'\emph{errore} di $L$ in funzione di $P$ come la somma delle distanze al quadrato della linea rispetto ai punti in $P$.\\ - - Formalmente:\\ - $Error(L, P) = \sum_{i=1}^{n} (y_i - ax_i - b)^2$ + + Formalmente: + \begin{equation*} + Error(L, P) = \sum_{i=1}^{n} (y_i - ax_i - b)^2 + \end{equation*} \end{myblockquote} \begin{figure}[H] -\centering -\includegraphics[width = 10cm, keepaspectratio]{Programmazione_dinamica/imgs/best_fit.png} -\caption{Esempio di linea con errore minimo} + \centering + \includegraphics[width = 10cm, keepaspectratio]{capitoli/programmazione_dinamica/imgs/best_fit.png} + \caption{Esempio di linea con errore minimo} \end{figure} \subsection{Goal} @@ -51,8 +53,8 @@ \section{Segmented Least Squares} circostanze. \begin{figure}[H] -\centering - \includegraphics[width = 10cm, keepaspectratio]{Programmazione_dinamica/imgs/seg_llsqr.png} + \centering + \includegraphics[width = 10cm, keepaspectratio]{capitoli/programmazione_dinamica/imgs/seg_llsqr.png} \caption{Esempio di insieme di punti non approssimabile con una sola retta} \end{figure} @@ -106,8 +108,8 @@ \section{Funzionamento} possiamo togliere questi punti dal totale per ottenete un sotto-problema più piccolo. \begin{figure}[H] -\centering - \includegraphics[width = 10cm, keepaspectratio]{Programmazione_dinamica/imgs/llsqr_funzionamento.png} + \centering + \includegraphics[width = 10cm, keepaspectratio]{capitoli/programmazione_dinamica/imgs/llsqr_funzionamento.png} \centering \caption{Una soluzione possibile per il fit digli ultimi punti da $p_i$ a $p_n$, e poi la soluzione $OPT(i-1)$ trovata nei punti rimanenti $p_1, \ldotp, p_{i-1}$} diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/sequence_alignment.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/sequence_alignment.tex similarity index 73% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/sequence_alignment.tex rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/sequence_alignment.tex index 8ccef4042..4ba48ddf7 100644 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/sequence_alignment.tex +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/sequence_alignment.tex @@ -1,4 +1,5 @@ \chapter{Sequence Alignment} +\label{chap:seqal} Il problema del Sequence Alignment consiste nel riuscire a comparare delle stringhe, come per esempio quando si effettua un @@ -16,8 +17,8 @@ \section{Descrizione del Problema} Come prima definizione di \textbf{\emph{similarità}} possiamo dire che: \begin{myblockquote} - \textbf{minore è il numero di caratteri che non - corrispondono, maggiore è la similarità tra le parole}. + \textbf{minore è il numero di caratteri che non + corrispondono, maggiore è la similarità tra le parole}. \end{myblockquote} Questa problematica è anche un tema centrale della biologia molecolare, @@ -27,23 +28,23 @@ \section{Descrizione del Problema} Prima di dare una definizione similarità dobbiamo però darne una di \textbf{allineamento}: \begin{myblockquote} - Supponiamo di avere due stringhe - $X$ e $Y$, che consistono rispettivamente della sequenza di simboli - $x_1 x_2 \ldots x_m$ e $y_1 y_2 \ldots y_n$. - Consideriamo gli insiemi $\{1,2,\ldots ,m\}$ e $\{1,2,\ldots ,n\}$ - che rappresentano le varie posizioni nelle stringhe $X$ e $Y$, e - consideriamo un \textbf{Matching} di questi due insiemi (un matching è - stato definito \protect\hyperlink{rna-secondary-stucture-problem}{qui} - $\rightarrow$ si tratta di un insieme di coppie ordinate con la - proprietà che ogni oggetto si trova al più in una sola coppia). - Diciamo ora che \textbf{un matching $M$ di questi due - insiemi è un \emph{allineamento} se gli elementi di varie coppie non si - incrociano}: - \begin{itemize} - \item se $(i,j),(i^{\prime},j^{\prime}) \in M$ - \item e $i < i^{\prime}$, - \item allora $j < j^{\prime}$. - \end{itemize} + Supponiamo di avere due stringhe + $X$ e $Y$, che consistono rispettivamente della sequenza di simboli + $x_1 x_2 \ldots x_m$ e $y_1 y_2 \ldots y_n$. + Consideriamo gli insiemi $\{1,2,\ldots ,m\}$ e $\{1,2,\ldots ,n\}$ + che rappresentano le varie posizioni nelle stringhe $X$ e $Y$, e + consideriamo un \textbf{Matching} di questi due insiemi (un matching è + stato definito nel \autoref{chap:rna} + $\rightarrow$ si tratta di un insieme di coppie ordinate con la + proprietà che ogni oggetto si trova al più in una sola coppia). + Diciamo ora che \textbf{un matching $M$ di questi due + insiemi è un \emph{allineamento} se gli elementi di varie coppie non si + incrociano}: + \begin{itemize} + \item se $(i,j),(i^{\prime},j^{\prime}) \in M$ + \item e $i < i^{\prime}$, + \item allora $j < j^{\prime}$. + \end{itemize} \end{myblockquote} Intuitivamente, un \textbf{\emph{alignment}} fornisce un modo per @@ -58,18 +59,18 @@ \section{Descrizione del Problema} corrisponde all'alignment \texttt{\{(2,\ 1),\ (3,\ 2),\ (4,\ 3)\}}.\\ Ora la nostra definizione di similarità si baserà sul \textbf{trovare il - miglior allineamento}, seguendo questi criteri:\\ + miglior allineamento}, seguendo questi criteri:\\ Supponiamo che $M$ sia un dato allineamento tra $X$ e $Y$. \begin{itemize} - \item - C'è un parametro $\delta>0$ che definisce la \textbf{gap penalty}, - che viene sostenuta ogni volta che un carattere di $X$ o $Y$ non è - in un matching (ovvero non ha una corrispondenza). Nell'allignment il - ``\textbf{\emph{gap}}'' viene posto con il simbolo `\texttt{-}', - necessario al fine di allineare le due stringhe (avere uguale - \emph{lunghezza}). + \item + C'è un parametro $\delta>0$ che definisce la \textbf{gap penalty}, + che viene sostenuta ogni volta che un carattere di $X$ o $Y$ non è + in un matching (ovvero non ha una corrispondenza). Nell'allignment il + ``\textbf{\emph{gap}}'' viene posto con il simbolo `\texttt{-}', + necessario al fine di allineare le due stringhe (avere uguale + \emph{lunghezza}). \end{itemize} \begin{verbatim} @@ -78,10 +79,10 @@ \section{Descrizione del Problema} \end{verbatim} \begin{itemize} - \item - Per ogni coppia di lettere $p,q$ del nostro alfabeto, se c'è un - accoppiamento errato si paga il corrispondente \textbf{mismatch cost} - $a_{(p,q)}$. + \item + Per ogni coppia di lettere $p,q$ del nostro alfabeto, se c'è un + accoppiamento errato si paga il corrispondente \textbf{mismatch cost} + $a_{(p,q)}$. \end{itemize} \begin{verbatim} @@ -90,9 +91,9 @@ \section{Descrizione del Problema} \end{verbatim} \begin{itemize} - \item - Il costo di $M$ è la somma del suo gap e mismatch cost, e - l'\textbf{obiettivo sarà quello di minimizzarlo}. + \item + Il costo di $M$ è la somma del suo gap e mismatch cost, e + l'\textbf{obiettivo sarà quello di minimizzarlo}. \end{itemize} \textbf{N.B.} Le quantità $\delta$ e $a_{(p,q)}$ sono parametri @@ -121,8 +122,8 @@ \subsection{Goal} \end{verbatim} Possiamo notare che nel primo abbiamo \textbf{1 gap} e \textbf{1 - mismatch} mentre nel secondo abbiamo \textbf{3 gap} ma \textbf{nessun - mismatch}.\\ + mismatch} mentre nel secondo abbiamo \textbf{3 gap} ma \textbf{nessun + mismatch}.\\ Vogliamo quindi determinare quale dei due sia il migliore. @@ -135,48 +136,47 @@ \section{Implementazione dell'algoritmo} visti, una \textbf{scelta binaria}.\\ Dato l'allineamento ottimale $M$, allora: \begin{itemize} - \item $(m,n) \in M$ (quindi gli ultimi due simboli delle due - stringhe \textbf{sono in un matching}) - \item $(m,n) \notin M$ (gli ultimi - simboli delle due stringhe \textbf{\emph{non} sono in un matching}) + \item $(m,n) \in M$ (quindi gli ultimi due simboli delle due + stringhe \textbf{sono in un matching}) + \item $(m,n) \notin M$ (gli ultimi + simboli delle due stringhe \textbf{\emph{non} sono in un matching}) \end{itemize} Tuttavia questa semplice distinzione \textbf{non è sufficiente}, quindi supponiamo di aggiungere anche il seguente concetto elementare: \begin{myblockquote} - Sia $M$ un qualsiasi allineamento di $X$ e $Y$.\\ - se $(m,n) \notin M$,\\ - allora, o l'$m$-esima posizione di $X$ o l' $n$-esima posizione di $Y$ - \textbf{non è in un matching di $M$}. + Sia $M$ un qualsiasi allineamento di $X$ e $Y$. Se $(m,n) \notin M$, allora, + o l'$m$-esima posizione di $X$ o l' $n$-esima posizione di $Y$ \textbf{non è + in un matching di $M$}. \end{myblockquote} Dire questo, equivale a riscrivere le due condizioni sopra come tre, dunque \textbf{in un allineamento ottimo $M$ almeno una deve essere - vera}: + vera}: \begin{enumerate} - \item $(m,n) \in M$ - \item l' $m-esima$ posizione di $X$ non è nel matching; o - \item l' $n-esima$ posizione di $Y$ non è nel matching + \item $(m,n) \in M$ + \item l' $m-esima$ posizione di $X$ non è nel matching; o + \item l' $n-esima$ posizione di $Y$ non è nel matching \end{enumerate} Ora definiamo la funzione di costo minimo $OPT(i,j)$ come costo dell'alignment tra $x_1 x_2 \ldots x_i$ e $y_1 y_2 \ldots y_j$. \begin{itemize} - \item - \texttt{Nel\ caso\ 1}, abbiamo un costo di $a_{x_m y_n}$ e poi si - allinea $x_1 x_2 \ldots x_{m-1}$ nel miglior modo possibile con - $y_1 y_2 \ldots y_{n-1}$. Si ha quindi che - $OPT(m,n) = a_{x_m y_n} + OPT(m-1,n-1)$. - \item - \texttt{Nel\ caso\ 2}, si paga un gap cost $\delta$ dato che la - $m^{th}$ posizione di $X$ non è in matching, e poi si allinea - $x_1 x_2 \ldots x_{m-1}$ nel miglior modo possibile con - $y_1 y_2 \ldots y_{n}$. Si ha quindi che - $OPT(m,n) = \delta + OPT(m-1,n)$. - \item - Similmente per \texttt{il\ caso\ 3}, abbiamo - $OPT(m,n) = \delta + OPT(m,n-1)$. + \item + \texttt{Nel\ caso\ 1}, abbiamo un costo di $a_{x_m y_n}$ e poi si + allinea $x_1 x_2 \ldots x_{m-1}$ nel miglior modo possibile con + $y_1 y_2 \ldots y_{n-1}$. Si ha quindi che + $OPT(m,n) = a_{x_m y_n} + OPT(m-1,n-1)$. + \item + \texttt{Nel\ caso\ 2}, si paga un gap cost $\delta$ dato che la + $m^{th}$ posizione di $X$ non è in matching, e poi si allinea + $x_1 x_2 \ldots x_{m-1}$ nel miglior modo possibile con + $y_1 y_2 \ldots y_{n}$. Si ha quindi che + $OPT(m,n) = \delta + OPT(m-1,n)$. + \item + Similmente per \texttt{il\ caso\ 3}, abbiamo + $OPT(m,n) = \delta + OPT(m,n-1)$. \end{itemize} Utilizzando dunque gli stessi argomenti per i sottoproblemi, per @@ -184,9 +184,9 @@ \section{Implementazione dell'algoritmo} definizione generale di $OPT(i,j)$: \begin{myblockquote} - L'allineamento di costo minimo soddisfa la seguente ricorsione per - $i \geq 1$ e $j \geq 1$:\\ - $OPT(i,j) = min[a_{(x_i y_j)} + OPT(i-1, j-1), \delta + OPT(i-1, j), \delta + OPT(i, j-1)]$ + L'allineamento di costo minimo soddisfa la seguente ricorsione per + $i \geq 1$ e $j \geq 1$:\\ + $OPT(i,j) = min[a_{(x_i y_j)} + OPT(i-1, j-1), \delta + OPT(i-1, j), \delta + OPT(i, j-1)]$ \end{myblockquote} Dunque così abbiamo ottenuto la nostra funzione di ricorsione e possiamo @@ -212,11 +212,11 @@ \subsection{Bottom-Up} \subsection{Costo} \begin{itemize} - \item - Il running time è di $O(mn)$, poiché l'array $A$ ha $O(mn)$ voci - e nel peggiore dei casi trascorriamo un tempo costante su ciascuna. - \item - Costo spaziale è di $O(mn)$ + \item + Il running time è di $O(mn)$, poiché l'array $A$ ha $O(mn)$ voci + e nel peggiore dei casi trascorriamo un tempo costante su ciascuna. + \item + Costo spaziale è di $O(mn)$ \end{itemize} C'è un modo pittorico accattivante in cui le persone pensano a questo @@ -231,17 +231,17 @@ \subsection{Costo} \centering \begin{subfigure}{.5\textwidth} \centering - \includegraphics[width=\linewidth, keepaspectratio]{Programmazione_dinamica/imgs/sa.png} + \includegraphics[width=\linewidth, keepaspectratio]{capitoli/programmazione_dinamica/imgs/sa.png} \end{subfigure}% \begin{subfigure}{.5\textwidth} \centering - \includegraphics[width=\linewidth, keepaspectratio]{Programmazione_dinamica/imgs/seqalignmatrix.png} + \includegraphics[width=\linewidth, keepaspectratio]{capitoli/programmazione_dinamica/imgs/seqalignmatrix.png} \end{subfigure}% \end{subfigure} \end{figure} \emph{Nell'esempio il matching tra \texttt{name} e \texttt{mean}, con i - parametri scelti per questo esempio sarà:} + parametri scelti per questo esempio sarà:} \begin{verbatim} mean- @@ -257,12 +257,12 @@ \subsection{Costo} diagonale da \texttt{(i\ -\ 1,\ j\ -\ 1)} a \texttt{(i,\ j)} è $a_{x_i y_i}$.\\ Lo scopo di questa immagine emerge ora: la ricorrenza definita precedentemente per $OPT(i, j)$ \textbf{è precisamente la - ricorrenza che si ottiene per il percorso di costo minimo in $G_{XY}$ - da \texttt{(0,\ 0)} a \texttt{(i,\ j)}}. Così possiamo mostrare che: + ricorrenza che si ottiene per il percorso di costo minimo in $G_{XY}$ + da \texttt{(0,\ 0)} a \texttt{(i,\ j)}}. Così possiamo mostrare che: \begin{myblockquote} - Sia $f(i, j)$ il costo minimo di un cammino da - \texttt{(0,\ 0)} a \texttt{(i,\ j)} in $G_{XY}$ . Allora per ogni - $i$, $j$, abbiamo $f(i, j) = OPT(i, j)$. + Sia $f(i, j)$ il costo minimo di un cammino da + \texttt{(0,\ 0)} a \texttt{(i,\ j)} in $G_{XY}$ . Allora per ogni + $i$, $j$, abbiamo $f(i, j) = OPT(i, j)$. \end{myblockquote} Quindi il valore dell'allineamento ottimale è la lunghezza dello @@ -280,27 +280,27 @@ \subsection{Costo} \section{Riepilogo} \begin{itemize} - \item - Trovare il numero di operazioni da fare per allineare due sequenze - \item - $OPT[i,j] = min\{ \alpha_{ij} + OPT[i-1,j-1], \delta + OPT[i, j-1], \delta + OPT[i-1, j] \}$ - \item - Ho bisogno di una matrice $i \times j$ \textbf{TEMPO =} $O(nm)$ - (nella versione base dell'algoritmo) - \item - Per ogni sottoproblema faccio solo un controllo. Posso anche - utilizzare una matrice con sole due righe o sole due colonne - \textbf{SPAZIO =} $O(nm)$ (nella versione base dell'algoritmo) - \item - \textbf{Per costrure la soluzione} ho bisogno di una matrice dove - salvo le operazioni fatte, posso risalire in diagonale. - - \begin{itemize} - \item - \textbf{SPAZIO =} $O(nm)$ - \item - \textbf{TEMPO =} $O(n+m)$ - \end{itemize} + \item + Trovare il numero di operazioni da fare per allineare due sequenze + \item + $OPT[i,j] = min\{ \alpha_{ij} + OPT[i-1,j-1], \delta + OPT[i, j-1], \delta + OPT[i-1, j] \}$ + \item + Ho bisogno di una matrice $i \times j$ \textbf{TEMPO =} $O(nm)$ + (nella versione base dell'algoritmo) + \item + Per ogni sottoproblema faccio solo un controllo. Posso anche + utilizzare una matrice con sole due righe o sole due colonne + \textbf{SPAZIO =} $O(nm)$ (nella versione base dell'algoritmo) + \item + \textbf{Per costrure la soluzione} ho bisogno di una matrice dove + salvo le operazioni fatte, posso risalire in diagonale. + + \begin{itemize} + \item + \textbf{SPAZIO =} $O(nm)$ + \item + \textbf{TEMPO =} $O(n+m)$ + \end{itemize} \end{itemize} \section{Hirschberg's algorithm} @@ -323,10 +323,10 @@ \subsection{Sequence Alignment in Spazio Lineare utilizzando la Dividi et Impera in un allineamento ottimale, possiamo equivalentemente chiedere gli archi in un percorso \emph{angolo-angolo} più breve in $G_{XY}$. L'algoritmo stesso sarà una bella applicazione delle idee \emph{divide - et impera}. Il punto cruciale della tecnica è l'osservazione che, + et impera}. Il punto cruciale della tecnica è l'osservazione che, \textbf{se dividiamo il problema in più chiamate ricorsive, allora lo - spazio necessario per il calcolo può essere riutilizzato da una chiamata - all'altra}. Il modo in cui questa idea viene utilizzata, tuttavia, è + spazio necessario per il calcolo può essere riutilizzato da una chiamata + all'altra}. Il modo in cui questa idea viene utilizzata, tuttavia, è abbastanza sottile. \subsection{Implementazione dell'algoritmo} @@ -338,8 +338,8 @@ \subsection{Implementazione dell'algoritmo} precedente di quella che si sta analizzando, dunque basterà caricarsi in memoria una matrice $m$ x $2$, riducendo così il costo spaziale ad $m$. Tuttavia utilizzando questo metodo \textbf{non è possibile - ricavare l'alignment effettivo} perché \textbf{non si hanno informazioni - sufficienti}.\\ + ricavare l'alignment effettivo} perché \textbf{non si hanno informazioni + sufficienti}.\\ Lo pseudo-codice dell'algoritmo appena definito è il seguente: @@ -382,7 +382,7 @@ \subsection{Implementazione dell'algoritmo} Per stretta analogia con la ricorrenza precedente, abbiamo la seguente ricorrenza per $g$: \begin{myblockquote} Per $i < m$ e $j < n$ abbiamo\\ - $g(i, j) = min[a_{x_{i+1} y_{i+1}} + g(i + 1, j + 1), \delta + g(i, j + 1), \delta + g (i + 1, j)]$. + $g(i, j) = min[a_{x_{i+1} y_{i+1}} + g(i + 1, j + 1), \delta + g(i, j + 1), \delta + g (i + 1, j)]$. \end{myblockquote} Questa è solo la ricorrenza che si ottiene prendendo il grafo $G_{XY}$ @@ -404,21 +404,21 @@ \subsection{Implementazione dell'algoritmo} fatti fondamentali che riassumono alcune relazioni tra le funzioni $f$ e $g$. \begin{myblockquote} - La lunghezza del cammino \emph{angolo-angolo} - più corto in $G_{XY}$ che passa per \texttt{(i, j)} è - $f(i, j) + g(i, j)$. + La lunghezza del cammino \emph{angolo-angolo} + più corto in $G_{XY}$ che passa per \texttt{(i, j)} è + $f(i, j) + g(i, j)$. \end{myblockquote} \begin{myblockquote} - Sia k un qualsiasi numero in ${0, . . . , n}$, e sia $q$ un indice - che minimizza la quantità $f(q, k) + g(q, k)$. Poi c'è un percorso - \emph{angolo-angolo} di lunghezza minima che passa attraverso il nodo \texttt{(q, k)}. + Sia k un qualsiasi numero in ${0, . . . , n}$, e sia $q$ un indice + che minimizza la quantità $f(q, k) + g(q, k)$. Poi c'è un percorso + \emph{angolo-angolo} di lunghezza minima che passa attraverso il nodo \texttt{(q, k)}. \end{myblockquote} Possiamo sfruttare questo fatto per provare ad utilizzare lo \texttt{Space\ Efficient\ Sequence\ Alignment\ Algorithm} combinato ad un approccio \emph{\textbf{divide et impera}} e \textbf{un array di - supporto $P$ per riuscire a calcolare il Sequence Alignment in spazio - lineare}, aumentando solo di una costatane la complessità temporale. + supporto $P$ per riuscire a calcolare il Sequence Alignment in spazio + lineare}, aumentando solo di una costatane la complessità temporale. \subsection{Lemma e Dimostrazione} @@ -426,16 +426,16 @@ \subsection{Lemma e Dimostrazione} $(i,j) = OPT(i,j)$\\ \textbf{Dimostrazione} per induzione \begin{itemize} - \item caso base: - $f(0,0) = OPT(0,0) = 0$ - \item ipotesi induttiva: assum vero per ogni - $(i', j')$ con $i'+j' < i+j$ - \item l'ultimo arco nello shortest path - verso $(i,j)$ è $(i-1, j-1)$, $(i, j-1)$ o $(i-1, j)$ - \item quindi - $f(i,j) = min\{ \alpha_{x_i y_j} + f(i-1, j-1), \delta + f(i-1, j), \delta +f(i, j-1)\} =$ - $= min\{ \alpha_{x_i y_j} + OPT(i-1, j-1), \delta + OPT(i-1, j), \delta + OPT(i, j-1)\} =$ - $= OPT(i,j)$ + \item caso base: + $f(0,0) = OPT(0,0) = 0$ + \item ipotesi induttiva: assum vero per ogni + $(i', j')$ con $i'+j' < i+j$ + \item l'ultimo arco nello shortest path + verso $(i,j)$ è $(i-1, j-1)$, $(i, j-1)$ o $(i-1, j)$ + \item quindi + $f(i,j) = min\{ \alpha_{x_i y_j} + f(i-1, j-1), \delta + f(i-1, j), \delta +f(i, j-1)\} =$ + $= min\{ \alpha_{x_i y_j} + OPT(i-1, j-1), \delta + OPT(i-1, j), \delta + OPT(i, j-1)\} =$ + $= OPT(i,j)$ \end{itemize} Per calcolare lo shortest path da un $(i,j)$ a $(m,n)$ posso @@ -448,15 +448,15 @@ \subsection{Lemma e Dimostrazione} Nel cammino incontrerò per forza la colonna $n/2$ ma non so per quale vertice (riga $q$): \begin{itemize} - \item voglio trovare $q$.\\ - Divido quindi il problema in 2:\\ - $f((0,0)(q,n/2)) + f((q,n/2)(m,n))$ - \begin{itemize} - \item e posso quindi renderlo ricorsivo, - \begin{itemize} - \item in ogni ricorsione mi ricordo solo $q$. - \end{itemize} - \end{itemize} + \item voglio trovare $q$.\\ + Divido quindi il problema in 2:\\ + $f((0,0)(q,n/2)) + f((q,n/2)(m,n))$ + \begin{itemize} + \item e posso quindi renderlo ricorsivo, + \begin{itemize} + \item in ogni ricorsione mi ricordo solo $q$. + \end{itemize} + \end{itemize} \end{itemize} \subsection{Funzionamento Algoritmo} @@ -517,8 +517,8 @@ \subsection{Funzionamento Algoritmo} \end{lstlisting} \begin{figure}[H] -\centering - \includegraphics[width=10cm, keepaspectratio]{Programmazione_dinamica/imgs/seq_align_recurrence.png} + \centering + \includegraphics[width=10cm, keepaspectratio]{capitoli/programmazione_dinamica/imgs/seq_align_recurrence.png} \end{figure} \subsection{Costo} @@ -528,8 +528,8 @@ \subsection{Costo} $(q, n/2) + (m-q, n/2)$ \begin{figure}[H] -\centering - \includegraphics[width=12cm, keepaspectratio]{Programmazione_dinamica/imgs/hirschberg.png} + \centering + \includegraphics[width=12cm, keepaspectratio]{capitoli/programmazione_dinamica/imgs/hirschberg.png} \end{figure} Quindi, il tempo di esecuzione dell'aligment \emph{divide et impera} su @@ -547,11 +547,11 @@ \subsection{Descrizione del Problema} sequenza stessa alla quale sono stati tolti zero o più elementi. Formalmente: \begin{myblockquote} - Data una sequenza $X$ = - $x_1, x_2, ..., x_m$, un'altra sequenza $Z$ = $z_1, z_2, ..., z_k$ - è una \textbf{sottosequenza} di $X$ se esiste una sequenza - strettamente crescente $i_2, i_2, ..., i_k$ di indici di $X$ tale - che per ogni $j = 1, 2, ..., k$, si ha $x_{i_j} = z_j$. + Data una sequenza $X$ = + $x_1, x_2, ..., x_m$, un'altra sequenza $Z$ = $z_1, z_2, ..., z_k$ + è una \textbf{sottosequenza} di $X$ se esiste una sequenza + strettamente crescente $i_2, i_2, ..., i_k$ di indici di $X$ tale + che per ogni $j = 1, 2, ..., k$, si ha $x_{i_j} = z_j$. \end{myblockquote} @@ -599,12 +599,12 @@ \subsection{Caratterizzare la più lunga sottosequenza comune} $Y$. \begin{enumerate} - \item Se $x_m = y_n$, allora $z_k = x_m = y_n$ e $Z_{k-1}$ è - una LCS di $X_{m-1}$ e $Y_{n-1}$ - \item Se $x_m \ne y_n$, allora - $z_k \ne x_m$ implica che $Z$ è una LCS di $X_{m-1}$ e $Y$. - \item Se $x_m \ne y_n$, allora $z_k \ne y_n$ implica che $Z$ è una LCS - di $X$ e $Y_{n-1}$. + \item Se $x_m = y_n$, allora $z_k = x_m = y_n$ e $Z_{k-1}$ è + una LCS di $X_{m-1}$ e $Y_{n-1}$ + \item Se $x_m \ne y_n$, allora + $z_k \ne x_m$ implica che $Z$ è una LCS di $X_{m-1}$ e $Y$. + \item Se $x_m \ne y_n$, allora $z_k \ne y_n$ implica che $Z$ è una LCS + di $X$ e $Y_{n-1}$. \end{enumerate} @@ -634,11 +634,11 @@ \subsection{Soluzione Ricorsiva} ottima del problema della LCS consente di scrivere la formula ricorsiva\\ $$ - c[i,j]= \begin{cases} - 0, & i = 0 \vee j = 0\\ - c[i-1, j-1] + 1, & i, j > 0 \wedge x_i = y_i\\ - max(c[i, j-1], c[i-1, j]), & i,j > 0 \wedge x_i \neq y_j - \end{cases} + c[i,j]= \begin{cases} + 0, & i = 0 \vee j = 0 \\ + c[i-1, j-1] + 1, & i, j > 0 \wedge x_i = y_i \\ + max(c[i, j-1], c[i-1, j]), & i,j > 0 \wedge x_i \neq y_j + \end{cases} $$ \subsection{Calcolare la lunghezza di una LCS} diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/weighted_interval_scheduling.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/weighted_interval_scheduling.tex similarity index 67% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/weighted_interval_scheduling.tex rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/weighted_interval_scheduling.tex index 5ea946f72..63dda9005 100644 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/Programmazione_dinamica/weighted_interval_scheduling.tex +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/capitoli/programmazione_dinamica/weighted_interval_scheduling.tex @@ -21,49 +21,49 @@ \chapter{Weighted Interval Scheduling \begin{figure}[H] - \includegraphics[width=\textwidth]{Programmazione_dinamica/imgs/weigted_interval_scheduling.png} - \centering - \caption{Un esempio di weighted interval scheduling} - \label{fig:wis} + \includegraphics[width=\textwidth]{capitoli/programmazione_dinamica/imgs/weigted_interval_scheduling.png} + \centering + \caption{Un esempio di weighted interval scheduling} + %\label{fig:wis} \end{figure} \section{Descrizione del problema} \begin{itemize} - \item - $n$: un intero che rappresenta l'indice dell'intervallo (job) - \item - $s_i$: tempo di inizio dell'intervallo $i$ - \item - $f_i$: tempo di fine dell'intervallo $i$ - \item - $v_i$: peso dell'intervallo $i$ - \item - Due job sono \textbf{compatibili} se non si sovrappongono. - \item - $p(j)$: ritorna l'indice più grande $i$, con $i < j$, del primo - intervallo compatibile con l'intervallo $j$, considerando il fatto - che gli intervalli sono ordinati in ordine non decrescente in base a - $f_i$ - \item - $\mathcal{O}_j$: rappresenta la soluzione ottima al problema - calcolato sull'insieme $\{1, \ldots, j\}$ - \item - $OPT(j)$: rappresenta il valore della soluzione ottima - $\mathcal{O}_j$ + \item + $n$: un intero che rappresenta l'indice dell'intervallo (job) + \item + $s_i$: tempo di inizio dell'intervallo $i$ + \item + $f_i$: tempo di fine dell'intervallo $i$ + \item + $v_i$: peso dell'intervallo $i$ + \item + Due job sono \textbf{compatibili} se non si sovrappongono. + \item + $p(j)$: ritorna l'indice più grande $i$, con $i < j$, del primo + intervallo compatibile con l'intervallo $j$, considerando il fatto + che gli intervalli sono ordinati in ordine non decrescente in base a + $f_i$ + \item + $\mathcal{O}_j$: rappresenta la soluzione ottima al problema + calcolato sull'insieme $\{1, \ldots, j\}$ + \item + $OPT(j)$: rappresenta il valore della soluzione ottima + $\mathcal{O}_j$ \end{itemize} \begin{figure}[H] - \centering - \includegraphics[width=15cm, keepaspectratio]{Programmazione_dinamica/imgs/wis_instance.png} - \caption{Si può vedere come funziona effettivamente la funzione $p(i)$} + \centering + \includegraphics[width=15cm, keepaspectratio]{capitoli/programmazione_dinamica/imgs/wis_instance.png} + \caption{Si può vedere come funziona effettivamente la funzione $p(i)$} \end{figure} \subsection{Goal:} \begin{itemize} - \item L'obiettivo del problema attuale è quello di trovare un sottoinsieme + \item L'obiettivo del problema attuale è quello di trovare un sottoinsieme $S \subseteq \{1, \ldots, n\}$ di intervalli mutualmente compatibili che vanno a massimizzare la somma dei pesi degli intervalli selezionati $\sum_{i \in S} v_i$. @@ -87,13 +87,13 @@ \section{Dynamic Version} a $f_i$): $$ - OPT(j) = max(v_j + OPT(p(j)), \ \ OPT(j-1)) + OPT(j) = max(v_j + OPT(p(j)), \ \ OPT(j-1)) $$ Questo può essere anche visto come una \textbf{disequazione}: $$ - v_j + OPT(p(j)) \geq OPT(j-1) + v_j + OPT(p(j)) \geq OPT(j-1) $$ che \textbf{se vera}, includerà $j$ nella soluzione ottimale. @@ -123,9 +123,9 @@ \section{Brute Force} ricorsive cresce come la \textbf{sequenza di fibonacci}. \begin{figure}[H] -\centering - \includegraphics[width=10cm]{Programmazione_dinamica/imgs/wis_subproblem_tree.png} - \caption{L'albero dei sottoproblemi chiamati da \texttt{Compute-Opt}} + \centering + \includegraphics[width=10cm]{capitoli/programmazione_dinamica/imgs/wis_subproblem_tree.png} + \caption{L'albero dei sottoproblemi chiamati da \texttt{Compute-Opt}} \end{figure} Una soluzione è quella di utilizzare la tecnica della @@ -159,13 +159,13 @@ \section{Memoization} \textbf{Costo computazionale} = $O(n\log{n})$: \begin{itemize} - \item - Sort: $O(n\log{n})$ - \item - Computazione di $p[i]$: $O(n\log{n})$ - \item - \texttt{M-Compute-Opt(i)}: $O(1)$ ogni iterazione, al massimo $2n$ - ricorsioni = $O(n)$ + \item + Sort: $O(n\log{n})$ + \item + Computazione di $p[i]$: $O(n\log{n})$ + \item + \texttt{M-Compute-Opt(i)}: $O(1)$ ogni iterazione, al massimo $2n$ + ricorsioni = $O(n)$ \end{itemize} Se i job sono già \textbf{ordinati} = $O(n)$ @@ -203,24 +203,24 @@ \subsection{Bottom-Up (iterative way)} della programmazione dinamica, e anche per offrire una prospettiva diversa che sarà fondamentale per il resto delle spiegazioni: \textbf{\emph{iterare su sottoproblemi, piuttosto che calcolare - soluzioni in modo ricorsivo}}. + soluzioni in modo ricorsivo}}. \begin{figure}[H] - \includegraphics[width = \textwidth]{Programmazione_dinamica/imgs/iter_comp_opt.png} - \caption{Figura che mostra le iterazioni per recuperare i valori di OPT} + \includegraphics[width = \textwidth]{capitoli/programmazione_dinamica/imgs/iter_comp_opt.png} + \caption{Figura che mostra le iterazioni per recuperare i valori di OPT} \end{figure} Nella sezione precedente, abbiamo sviluppato una soluzione in tempo polinomiale al problema, progettando: prima un \textbf{algoritmo - ricorsivo in tempo esponenziale} e poi \textbf{convertendolo (tramite - memoization) in un algoritmo ricorsivo efficiente} che consultava un + ricorsivo in tempo esponenziale} e poi \textbf{convertendolo (tramite + memoization) in un algoritmo ricorsivo efficiente} che consultava un array globale M di soluzioni ottimali per sottoproblemi. Per capire davvero i concetti della programmazione dinamica, è utile formulare una versione essenzialmente equivalente dell'algoritmo. \textbf{È questa - nuova formulazione che cattura in modo più esplicito l'essenza della - tecnica di programmazione dinamica e servirà come modello generale per - gli algoritmi che svilupperemo nelle sezioni successive}. + nuova formulazione che cattura in modo più esplicito l'essenza della + tecnica di programmazione dinamica e servirà come modello generale per + gli algoritmi che svilupperemo nelle sezioni successive}. \begin{lstlisting}[language=Python, mathescape=true] Sort jobs by finish time so that f1 $\le$ f2 $\le$ ... $\le$ fn. @@ -244,19 +244,19 @@ \subsection{Bottom-Up (iterative way)} \section{Riepilogo} \begin{itemize} - \item - $OPT[j] = \max_{v_j}+OPT[p_j],OPT[j-1]$ - \item - Per ogni $j$ scelgo se prenderlo o meno - \item - Alcuni sottoproblemi vengono scartati (quelli che si sovrappongono al - $j$ scelto) - \item - Per ogni scelta ho due possibilità: \textbf{TEMPO =} $O(n \log n)$ - \item - Lo spazio è un vettore di $OPT[j]$: \textbf{SPAZIO =} $O(n)$ - \item - Per ricostruire la soluzione uso un vettore dove per ogni $j$ ho un - valore booleano che indica se il job fa parte della soluzione: - \textbf{SPAZIO\_S =} $O(n)$ + \item + $OPT[j] = \max_{v_j}+OPT[p_j],OPT[j-1]$ + \item + Per ogni $j$ scelgo se prenderlo o meno + \item + Alcuni sottoproblemi vengono scartati (quelli che si sovrappongono al + $j$ scelto) + \item + Per ogni scelta ho due possibilità: \textbf{TEMPO =} $O(n \log n)$ + \item + Lo spazio è un vettore di $OPT[j]$: \textbf{SPAZIO =} $O(n)$ + \item + Per ricostruire la soluzione uso un vettore dove per ogni $j$ ho un + valore booleano che indica se il job fa parte della soluzione: + \textbf{SPAZIO\_S =} $O(n)$ \end{itemize} diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/img/logoDMI.jpg b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/frontmatter/imgs/logoDMI.jpg similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/img/logoDMI.jpg rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/frontmatter/imgs/logoDMI.jpg diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/img/logoUniPg.jpg b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/frontmatter/imgs/logoUniPg.jpg similarity index 100% rename from magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/img/logoUniPg.jpg rename to magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/frontmatter/imgs/logoUniPg.jpg diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/frontmatter/main.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/frontmatter/main.tex new file mode 100644 index 000000000..f92fc9fe7 --- /dev/null +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/frontmatter/main.tex @@ -0,0 +1,32 @@ +% Thesis frontmatter -------------------------------------------- + +\thispagestyle{empty} %suppress page number + +\noindent % just to prevent indentation narrowing the line width for this line +\includegraphics[width=0.15\textwidth]{frontmatter/imgs/logoUniPg.jpg} +\begin{minipage}[b]{0.7\textwidth} + \centering + {\Large \textsc{Universit{\`a} di Perugia}}\\ + \vspace{0.4 em} + {\large Dipartimento di Matematica e Informatica} + \vspace{0.6 em} +\end{minipage}% +\includegraphics[width=0.15\textwidth]{frontmatter/imgs/logoDMI.jpg} + +\vspace{8 em} + +\begin{center} + {\Huge Appunti \textit{Inserisci Nome}}\\ + \vspace{5 em} + {\Huge \textbf{Testo}}\\ + + \vfill + + \rule{380pt}{.4pt}\\ + \vspace{1.2 em} + \large{Anno Accademico 2021-2022}\\ %% MODIFICARE + \vspace{.9 em} + \small{\textit{Last Update: \today{}}} +\end{center} + +% ------------------------------------------------------------------ \ No newline at end of file diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/macros.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/macros.tex deleted file mode 100644 index 5d0c0a177..000000000 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/macros.tex +++ /dev/null @@ -1,5 +0,0 @@ -%% Compila questi campi !! -\newcommand{\esame}{Algoritmi Avanzati e Distribuiti} -\newcommand{\titolo}{Appunti Modulo Pinotti} -\newcommand{\prof}{Nome Cognome} -\newcommand{\studente}{Nome Cognome} \ No newline at end of file diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/main.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/main.tex index cc1a596c8..b15796fba 100644 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/main.tex +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/main.tex @@ -1,34 +1,136 @@ -\input{macros} +\documentclass[a4paper,12 pt]{report} +\usepackage[T1]{fontenc} +\usepackage[utf8]{inputenc} +\usepackage[italian]{babel} +\usepackage{lmodern} +\usepackage{listings} +\usepackage{latexsym} +\usepackage{graphicx} +\usepackage{float} +\usepackage{subcaption} +\usepackage{hyperref} +\usepackage{wrapfig} +\usepackage{fancyhdr} +\usepackage{amsthm} +\usepackage{amsmath} +\usepackage{amssymb} +\usepackage{amsfonts} -\documentclass[answers, 14 pt]{report} +%\usepackage[user]{zref} -\input{settings/prelude} +% forza le footnote a stare il più in basso possibile +\usepackage[bottom]{footmisc} + + +%% STILE LISTINGS + +\usepackage{xcolor} + +\definecolor{codegreen}{rgb}{0,0.6,0} +\definecolor{codegray}{rgb}{0.5,0.5,0.5} +\definecolor{codepurple}{rgb}{0.58,0,0.82} +\definecolor{backcolour}{rgb}{0.95,0.95,0.92} + +\lstdefinestyle{mystyle}{ + backgroundcolor=\color{backcolour}, + commentstyle=\color{codegreen}, + keywordstyle=\color{magenta}, + numberstyle=\tiny\color{codegray}, + stringstyle=\color{codepurple}, + basicstyle=\ttfamily\footnotesize, + breakatwhitespace=false, + breaklines=true, + captionpos=b, + keepspaces=true, + numbers=left, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + tabsize=2 +} + +\lstset{style=mystyle} + +\definecolor{lightgray}{RGB}{249,249,249} +\definecolor{darkgray}{RGB}{204,204,204} + +%\usepackage[framemethod=tikz]{mdframed} +\usepackage{mdframed} +\usepackage{geometry} +\newmdenv[ + linecolor=darkgray, + backgroundcolor=lightgray, + linewidth=5pt, + leftline=true, + rightline=false, + topline=false, + bottomline=false, + %skipabove=\topsep, + %skipbelow=\topsep, + innertopmargin=\dimexpr\topsep\relax, + innerbottommargin=\dimexpr\topsep\relax, + %innerleftmargin=1em, + %innerrightmargin=1em, +]{myblockquote} +% \usepackage{tcolorbox} +% \newtcolorbox{myblockquote}{colback=red!5!white, colframe=red!75!black} +% % redefine the 'quote' environment to use this 'myquote' environment +% \renewenvironment{quote}{\begin{myblockquote}}{\end{myblockquote}} + +%\usepackage{bookmark} +%% ----- + +% mostra le subsubsection nell'indice +\setcounter{tocdepth}{3} +\setcounter{secnumdepth}{3} + +% Resetta la numerazione dei chapter quando +% una nuova part viene creata +\makeatletter +\@addtoreset{chapter}{part} +\makeatother + +% Rimuove l'indentazione quando si crea un nuovo paragrafo +\setlength{\parindent}{0pt} + +% footer +\pagestyle{fancyplain} +% rimuove la riga nell'header +\fancyhf{} % sets both header and footer to nothing +\renewcommand{\headrulewidth}{0pt} +\fancyfoot[L]{\href{https://github.com/Typing-Monkeys/AppuntiUniversita}{Typing Monkeys}} +\fancyfoot[C]{\emoji{gorilla}} +\fancyfoot[R]{\thepage} + +% configurazione emoji +\usepackage{fontspec} +\usepackage{emoji} +\setemojifont{NotoColorEmoji.ttf}[Path=/usr/share/fonts/truetype/noto/] \begin{document} +\include{frontmatter/main.tex} + +\tableofcontents + +\include{quote/main.tex} + +\include{capitoli/programmazione_dinamica/weighted_interval_scheduling} +\include{capitoli/programmazione_dinamica/segmented_least_squares_problem} +\include{capitoli/programmazione_dinamica/knapsack_problem} +\include{capitoli/programmazione_dinamica/rna_secondary_structure} +\include{capitoli/programmazione_dinamica/pole_cutting} +\include{capitoli/programmazione_dinamica/matrix_chain_parenthesization} +\include{capitoli/programmazione_dinamica/opt_binary_search_tree} +\include{capitoli/programmazione_dinamica/sequence_alignment} + + +\include{capitoli/network_flow/ford_fulkerson} +\include{capitoli/network_flow/ff_patological} +\include{capitoli/network_flow/fat_flow} +\include{capitoli/network_flow/delta_scaling} +\include{capitoli/network_flow/preflow} +\include{capitoli/network_flow/matching_grafi_bipartiti} - \input{settings/frontmatter} - \newpage - - \tableofcontents - \newpage - \newgeometry{top=2cm, bottom=2cm, left=2.5cm, right=2.5cm} - %\input{content} - \include{Programmazione_dinamica/introduzione} - \include{Programmazione_dinamica/weighted_interval_scheduling} - \include{Programmazione_dinamica/segmented_least_squares_problem} - \include{Programmazione_dinamica/knapsack_problem} - \include{Programmazione_dinamica/rna_secondary_structure} - \include{Programmazione_dinamica/pole_cutting} - \include{Programmazione_dinamica/matrix_chain_parenthesization} - \include{Programmazione_dinamica/opt_binary_search_tree} - \include{Programmazione_dinamica/sequence_alignment} - - - \include{Network_flow/ford_fulkerson} - \include{Network_flow/ff_patological} - \include{Network_flow/fat_flow} - \include{Network_flow/delta_scaling} - \include{Network_flow/preflow} - \include{Network_flow/matching_grafi_bipartiti} \end{document} \ No newline at end of file diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/main_old.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/main_old.tex deleted file mode 100644 index 0c0c1b665..000000000 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/main_old.tex +++ /dev/null @@ -1,183 +0,0 @@ -% Options for packages loaded elsewhere -\PassOptionsToPackage{unicode}{hyperref} -\PassOptionsToPackage{hyphens}{url} -% -\documentclass[15pt]{article} -\usepackage{amsmath,amssymb} -\usepackage{lmodern} -\usepackage{iftex} -\ifPDFTeX - \usepackage[T1]{fontenc} - \usepackage[utf8]{inputenc} - \usepackage{textcomp} % provide euro and other symbols -\else % if luatex or xetex - \usepackage{unicode-math} - \defaultfontfeatures{Scale=MatchLowercase} - \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1} -\fi -% Use upquote if available, for straight quotes in verbatim environments -\IfFileExists{upquote.sty}{\usepackage{upquote}}{} -\IfFileExists{microtype.sty}{% use microtype if available - \usepackage[]{microtype} - \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts -}{} -\makeatletter -\@ifundefined{KOMAClassName}{% if non-KOMA class - \IfFileExists{parskip.sty}{% - \usepackage{parskip} - }{% else - \setlength{\parindent}{0pt} - \setlength{\parskip}{6pt plus 2pt minus 1pt}} -}{% if KOMA class - \KOMAoptions{parskip=half}} -\makeatother -\usepackage{xcolor} -\usepackage{color} -\usepackage{fancyvrb} -\newcommand{\VerbBar}{|} -\newcommand{\VERB}{\Verb[commandchars=\\\{\}]} -\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}} -% Add ',fontsize=\small' for more characters per line -\newenvironment{Shaded}{}{} -\newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{#1}}} -\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{#1}}}} -\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.49,0.56,0.16}{#1}} -\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{#1}} -\newcommand{\BuiltInTok}[1]{\textcolor[rgb]{0.00,0.50,0.00}{#1}} -\newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{#1}} -\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{#1}}} -\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{#1}}}} -\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.53,0.00,0.00}{#1}} -\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{#1}}} -\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{#1}} -\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{#1}} -\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.73,0.13,0.13}{\textit{#1}}} -\newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{#1}}} -\newcommand{\ExtensionTok}[1]{#1} -\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{#1}} -\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{#1}} -\newcommand{\ImportTok}[1]{\textcolor[rgb]{0.00,0.50,0.00}{\textbf{#1}}} -\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{#1}}}} -\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{#1}}} -\newcommand{\NormalTok}[1]{#1} -\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}} -\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{#1}} -\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.74,0.48,0.00}{#1}} -\newcommand{\RegionMarkerTok}[1]{#1} -\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{#1}} -\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.73,0.40,0.53}{#1}} -\newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{#1}} -\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.10,0.09,0.49}{#1}} -\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{#1}} -\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{#1}}}} -\usepackage{longtable,booktabs,array} -\usepackage{graphicx} -\usepackage{float} -\usepackage{calc} % for calculating minipage widths -% Correct order of tables after \paragraph or \subparagraph -\usepackage{etoolbox} -\makeatletter -\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{} -\makeatother -% Allow footnotes in longtable head/foot -\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}} -\makesavenoteenv{longtable} -\setlength{\emergencystretch}{3em} % prevent overfull lines -\providecommand{\tightlist}{% - \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} -\setcounter{secnumdepth}{-\maxdimen} % remove section numbering -\ifLuaTeX - \usepackage{selnolig} % disable illegal ligatures -\fi -\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}} -\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available -\urlstyle{same} % disable monospaced font for URLs -\hypersetup{ - hidelinks, - pdfcreator={LaTeX via pandoc}} - -\author{} -\date{} - -\begin{document} - -\hypertarget{advanced-and-distributed-algorithms---modulo-2}{% -\section{Advanced and Distributed Algorithms - Modulo -2}\label{advanced-and-distributed-algorithms---modulo-2}} - -\hypertarget{indice}{% -\subsection{Indice}\label{indice}} - -\begin{itemize} -\tightlist -\item - \protect\hyperlink{dynamic-programming}{Dynamic Programming} - - \begin{itemize} - \tightlist - \item - \protect\hyperlink{introduzione}{Introduzione} - \item - \protect\hyperlink{weighted-interval-scheduling-problem}{Weighted - Interval Scheduling Problem} - \item - \protect\hyperlink{segmented-least-squares-problem}{Segmented Least - Squares Problem} - \item - \protect\hyperlink{knapsack-problem}{Knapsack Problem} - \item - \protect\hyperlink{rna-secondary-stucture-problem}{RNA Secondary - Stucture} - \item - \protect\hyperlink{pole-cutting-problem}{Pole Cutting Problem} - \item - \protect\hyperlink{matrix-chain-parenthesization}{Matrix Chain - Parentesizathion} - \item - \protect\hyperlink{optimal-binary-search-tree}{Optimal Binary Search - Tree} - \item - \protect\hyperlink{sequence-alignment}{Sequence Alignment Problem} - - \begin{itemize} - \tightlist - \item - \protect\hyperlink{sequence-alignment-in-spazio-lineare-utilizzando-la-dividi-et-impera}{Hirschberg's - Algorithm} - \item - \protect\hyperlink{longest-common-subsequence}{Longest Common - Subsequence (LCS)} - \end{itemize} - \end{itemize} -\item - \protect\hyperlink{network-flow}{Network Flow} - - \begin{itemize} - \tightlist - \item - \protect\hyperlink{introduzione-1}{Introduzione} - \item - \protect\hyperlink{the-maximum-flow-problem-and-the-ford-fulkerson-algorithm}{The - Max-Flow Problem and the Ford-Fulkerson Algorithm} - \item - \protect\hyperlink{maximum-flows-and-minimum-cuts-in-a-network}{Maximum - Flows and Minimum Cuts in a Network} - \item - \protect\hyperlink{capacity-scaling-algorithm-choosing-good-augmenting-paths}{Capacity - Scaling Algorithm} - \item - \protect\hyperlink{ford-fulkerson-pathological-example}{Ford-Fulkerson - pathological example} - \item - \protect\hyperlink{matching-su-grafi-bipartiti}{Matching su Grafi - Bipartiti} - \item - \protect\hyperlink{disjoint-paths}{Disjoint Paths} - \item - \protect\hyperlink{network-connectivity}{Network Connectivity} - \end{itemize} -\end{itemize} - - - -\end{document} \ No newline at end of file diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/quote/main.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/quote/main.tex new file mode 100644 index 000000000..e379d17b6 --- /dev/null +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/quote/main.tex @@ -0,0 +1,23 @@ +\newlength\longest + +\clearpage + +\thispagestyle{empty} +\null\vfill + +\settowidth\longest{\huge\itshape just as his inclination leads him;} +\begin{center} + \parbox{\longest}{% + \raggedright{\LARGE\itshape% + "Oi, con quanto sentimento\\ + defeco sul tuo naso,\\ + così che ti coli sul mento."\par\bigskip + } + \raggedleft\Large{Wolfgang Amadeus Mozart}\par% + } +\end{center} + + +\vfill\vfill + +\clearpage \ No newline at end of file diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/requirements.txt b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/requirements.txt new file mode 100644 index 000000000..ea0064046 --- /dev/null +++ b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/requirements.txt @@ -0,0 +1,4 @@ +mdframed +etoolbox +zref +needspace \ No newline at end of file diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/settings/frontmatter.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/settings/frontmatter.tex deleted file mode 100644 index 53f8f18f4..000000000 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/settings/frontmatter.tex +++ /dev/null @@ -1,42 +0,0 @@ -% Thesis frontmatter -------------------------------------------- - -\thispagestyle{empty} %suppress page number - - \noindent % just to prevent indentation narrowing the line width for this line - \includegraphics[width=0.15\textwidth]{img/logoUniPg} - \begin{minipage}[b]{0.7\textwidth} - \centering - {\Large {\textsc{Universit{\`a} di Perugia}}}\\ - \vspace{0.4 em} - {\large {Dipartimento di Matematica e Informatica}} - \vspace{0.6 em} - \end{minipage}% - \includegraphics[width=0.15\textwidth]{img/logoDMI} - - \vspace{5 em} - - \begin{center} - - {\large {\textsc{\esame}}} %% scrivere qui il nome dell'esame - \vspace{8 em} - - {\Huge {\titolo}} %% scrivere qui il titolo dell'esercitazione - \vspace{10 em} - - %% modificare il nome e il cognome del prof e dello studente - \makebox[380pt][c]{{\textit{Professore} \hfill \textit{Studente}}} - \makebox[380pt][c]{{\textbf{Prof. \prof \hfill \studente}}} - - \vspace{6 em} - \vfill - - {\rule{380pt}{.4pt}}\\ - \vspace{1.2 em} - \large{{Anno Accademico 2021-2022}} %% modificare anno accademico - - - - - \end{center} - -% ------------------------------------------------------------------ \ No newline at end of file diff --git a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/settings/prelude.tex b/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/settings/prelude.tex deleted file mode 100644 index 525e37de9..000000000 --- a/magistrale/Anno 1/Advanced and Distributed Algorithms/Pinotti/latex/settings/prelude.tex +++ /dev/null @@ -1,111 +0,0 @@ -\usepackage[italian]{babel} -\usepackage{graphicx} -\usepackage[utf8]{inputenc} -%% links -\usepackage{hyperref} -\hypersetup{ - colorlinks=true, - linkcolor=blue, - filecolor=magenta, - urlcolor=cyan, - pdftitle={\titolo}, - pdfpagemode=FullScreen, -} - -\graphicspath{ {./img/} } - - - -%% configurazione per i listing di codice -\usepackage{xcolor} -\usepackage{float} -\usepackage{caption} -\usepackage{subcaption} -\usepackage{amsmath} -\usepackage{csquotes} -\usepackage{amssymb} -\usepackage{listings} -\colorlet{mycoolgray}{gray!40} - -\lstdefinestyle{output}{ - numbers=none, % where to put the line-numbers - numberstyle=\tiny, % the size of the fonts that are used for the line-numbers - backgroundcolor=\color{darkgray}, - basicstyle=\ttfamily\color{white}, - captionpos=b, % sets the caption-position to bottom - breaklines=true, % sets automatic line breaking - breakatwhitespace=false, -} - -\lstdefinestyle{cmd}{ - numbers=none, % where to put the line-numbers - numberstyle=\tiny, % the size of the fonts that are used for the line-numbers - backgroundcolor=\color{mycoolgray}, - basicstyle=\ttfamily\color{black}, - captionpos=b, % sets the caption-position to bottom - breaklines=true, % sets automatic line breaking - breakatwhitespace=false, -} - - -\usepackage{xcolor} - -\definecolor{codegreen}{rgb}{0,0.6,0} -\definecolor{codegray}{rgb}{0.5,0.5,0.5} -\definecolor{codepurple}{rgb}{0.58,0,0.82} -\definecolor{backcolour}{rgb}{0.95,0.95,0.92} - -\lstdefinestyle{mystyle}{ - backgroundcolor=\color{backcolour}, - commentstyle=\color{codegreen}, - keywordstyle=\color{magenta}, - numberstyle=\tiny\color{codegray}, - stringstyle=\color{codepurple}, - basicstyle=\ttfamily\footnotesize, - breakatwhitespace=false, - breaklines=true, - captionpos=b, - keepspaces=true, - numbers=left, - numbersep=5pt, - showspaces=false, - showstringspaces=false, - showtabs=false, - tabsize=2 -} - -\lstset{style=mystyle} - -\setlength\parindent{0pt} -\usepackage{tocloft} -\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}} - -\newcommand{\Color}[1]{\hypersetup{linkcolor=#1}\color{#1}} -\renewcommand{\cftsecfont}{\Color{black}\large\bfseries} -\renewcommand{\cftsubsecfont}{\Color{black}\large\bfseries} -\renewcommand{\cftsubsubsecfont}{\Color{black}\large\bfseries} - - - -\definecolor{lightgray}{RGB}{249,249,249} -\definecolor{darkgray}{RGB}{204,204,204} - -\usepackage{mdframed} - -\newmdenv[ - linecolor=darkgray, - backgroundcolor=lightgray, - linewidth=5pt, - leftline=true, - rightline=false, - topline=false, - bottomline=false, - %skipabove=\topsep, - %skipbelow=\topsep, - innertopmargin=\dimexpr\topsep\relax, - innerbottommargin=\dimexpr\topsep\relax, - innerleftmargin=1em, - innerrightmargin=1em, -]{myblockquote} - -\usepackage{geometry}