chiark / gitweb /
strategy: define W in Notation
[topbloke-formulae.git] / ranking.tex
1 \section{Ranking phase}
2
3 We run the following algorithm:
4 \begin{enumerate}
5 \item Set $\allpatches = \{ \}$.
6 \item Repeatedly:
7 \begin{enumerate}
8 \item Clear out the graph $\hasdirdep$ so it has no edges.
9 \item Execute $\alg{Rank-Recurse}(\pc_0)$
10 \item Until $\allpatches$ remains unchanged.
11 \end{enumerate}
12 \end{enumerate}
13
14 $\alg{Rank-Recurse}(\pc)$ is:
15 \begin{enumerate}
16
17 \item If we have already done $\alg{Rank-Recurse}(\pc)$ in this
18 ranking iteration, do nothing.  Otherwise:
19
20 \item Add $\pc$ to $\allpatches$ if it is not there already.
21 If it was added, recalculate $\allsrcs$ accordingly.
22
23 \item Set
24 $$
25   \set S \iassign h(\pcn)
26      \cup
27          \{ \baseof{E} \; | \; E \in \pendsof{\allsrcs}{\pcy} \}
28 $$
29
30 and $W \iassign w(\pcn)$
31
32 \item While $\exists_{S \in \set S} S \ge W$,
33 update $W \assign S$ and $\set S \assign \set S \, \backslash \{ S \}$
34
35 (This will often remove $W$ from $\set S$.  Afterwards, $\set S$
36 is a collection of heads to be merged into $W$.)
37
38 \item Choose an ordering of $\set S$, $S_i$ for $i=1 \ldots n$.
39
40 \item For each $S_i$ in turn, choose a corresponding $M_i$
41 such that $$
42    M_i \le S_i \land \left[
43    M_i \le W \lor \bigexists_{j<i} M_i \le S_j
44    \right]
45 $$
46
47 \item Set $\Gamma \iassign \depsreqof{W}$.
48
49 If there are multiple candidates we prefer $M_i \in \pcn$
50 if available.
51
52 \item For each $i \ldots 1..n$, update our putative direct
53 dependencies:
54 $$
55 \Gamma \assign \setmergeof{
56     \Gamma
57   }{
58     \begin{cases}
59      M_i \in \pcn :     & \depsreqof{M_i} \\
60      M_i \not\in \pcn : & \{ \}
61     \end{cases}
62   }{
63     \depsreqof{S_i}
64   }
65 $$
66
67 \item Finalise our putative direct dependencies
68 $
69 \Gamma \assign g(\pc, \Gamma)
70 $
71
72 \item For each direct dependency $\pd \in \Gamma$,
73
74 \begin{enumerate}
75 \item Add an edge $\pc \hasdirdep \pd$ to the digraph (adding nodes
76 as necessary).
77 If this results in a cycle, abort entirely (as the function $g$ is
78 inappropriate; a different $g$ could work).
79 \item Run $\alg{Rank-Recurse}(\pd)$.
80 \end{enumerate}
81
82 \end{enumerate}
83
84 \subsection{Results of the ranking phase}
85
86 By the end of the ranking phase, we have recorded the following
87 information:
88
89 \begin{itemize}
90 \item
91 $ \allpatches, \hasdirdep $ and hence the completion of $\hasdirdep$
92 into the partial order $\hasdep$.
93
94 \item
95 For each $\pc \in \allpatches$,
96 the base branch starting point commit $W^{\pcn} = W$.
97
98 \item
99 For each $\pc$,
100 the direct dependencies $\Gamma^{\pc} = \Gamma$.
101
102 \item
103 For each $\pc$,
104 the ordered set of base branch sources $\set S^{\pcn} = \set S,
105 S^{\pcn}_i = S_i$
106 and corresponding merge bases $M^{\pcn}_i = M_i$.
107
108 \end{itemize}
109
110 \subsection{Proof of termination}
111
112 $\alg{Rank-Recurse}(\pc)$ recurses but only downwards through the
113 finite graph $\hasdirdep$, so it must terminate.  
114
115 The whole ranking algorithm iterates but each iteration involves
116 adding one or more patches to $\allpatches$.  Since there are
117 finitely many patches and we never remove anything from $\allpatches$
118 this must complete eventually.
119
120 $\qed$
121