1\par 2\section{Prototypes and descriptions of {\tt BKL} methods} 3\label{section:BKL:proto} 4\par 5This section contains brief descriptions including prototypes 6of all methods that belong to the {\tt BKL} object. 7\par 8\section{Basic methods} 9\label{subsection:BKL:proto:basics} 10\par 11As usual, there are four basic methods to support object creation, 12setting default fields, clearing any allocated data, and free'ing 13the object. 14\par 15%======================================================================= 16\begin{enumerate} 17%----------------------------------------------------------------------- 18\item 19\begin{verbatim} 20BKL * BKL_new ( void ) ; 21\end{verbatim} 22\index{BKL_new@{\tt BKL\_new()}} 23This method simply allocates storage for the {\tt BKL} structure 24and then sets the default fields by a call to 25{\tt BKL\_setDefaultFields()}. 26%----------------------------------------------------------------------- 27\item 28\begin{verbatim} 29void BKL_setDefaultFields ( BKL *bkl ) ; 30\end{verbatim} 31\index{BKL_setDefaultFields@{\tt BKL\_setDefaultFields()}} 32This method sets the fields of the structure to their default 33values: 34{\tt bpg}, {\tt colors} and {\tt regwghts} are set to {\tt NULL}, 35the {\tt int} parameters are set to zero, 36and the {\tt cweights} vector is filled with zeros. 37\par \noindent {\it Error checking:} 38If {\tt bkl} is {\tt NULL}, 39an error message is printed and the program exits. 40%----------------------------------------------------------------------- 41\item 42\begin{verbatim} 43void BKL_clearData ( BKL *bkl ) ; 44\end{verbatim} 45\index{BKL_clearData@{\tt BKL\_clearData()}} 46This method clears any data allocated by the object, 47namely the {\tt colors} and {\tt regwghts} vectors. 48It then fills the structure's fields with default values 49with a call to {\tt BKL\_setDefaultFields()}. 50\par \noindent {\it Error checking:} 51If {\tt bkl} is {\tt NULL}, 52an error message is printed and the program exits. 53%----------------------------------------------------------------------- 54\item 55\begin{verbatim} 56void BKL_free ( BKL *bkl ) ; 57\end{verbatim} 58\index{BKL_free@{\tt BKL\_free()}} 59This method releases any storage by a call to 60{\tt BKL\_clearData()} then free's the storage for the 61structure with a call to {\tt free()}. 62\par \noindent {\it Error checking:} 63If {\tt bkl} is {\tt NULL}, 64an error message is printed and the program exits. 65%----------------------------------------------------------------------- 66\end{enumerate} 67\par 68\subsection{Initializer methods} 69\label{subsection:BKL:proto:initializers} 70\par 71%======================================================================= 72\begin{enumerate} 73%----------------------------------------------------------------------- 74\item 75\begin{verbatim} 76void BKL_init ( BKL *bkl, BPG *bpg, float alpha ) ; 77\end{verbatim} 78\index{BKL_init@{\tt BKL\_init()}} 79This method initializes the {\tt BKL} object given a bipartite 80graph object and cost function parameter as input. 81Any previous data is cleared with a call to {\tt BKL\_clearData()}. 82The {\tt ndom}, {\tt nseg} and {\tt nreg} scalars are set, 83the {\tt regwghts[]} vector allocated and filled, 84and 85the {\tt colors[]} vector allocated and filled with zeros. 86\par \noindent {\it Error checking:} 87If {\tt bkl} or {\tt bpg} is {\tt NULL}, 88an error message is printed and the program exits. 89%----------------------------------------------------------------------- 90\end{enumerate} 91\par 92\subsection{Utility methods} 93\label{subsection:BKL:proto:utilities} 94\par 95%======================================================================= 96\begin{enumerate} 97%----------------------------------------------------------------------- 98\item 99\begin{verbatim} 100void BKL_setRandomColors ( BKL *bkl, int seed ) ; 101\end{verbatim} 102\index{BKL_setRandomColors@{\tt BKL\_setRandomColors()}} 103If {\tt seed > 0} 104a random number generator is set using {\tt seed}. 105The domains are then colored {\tt 1} or {\tt 2} randomly 106and {\tt BKL\_setColorWeights()} is called to set the segment 107weights. 108\par \noindent {\it Error checking:} 109If {\tt bkl} or {\tt bkl->bpg} is {\tt NULL}, 110an error message is printed and the program exits. 111%----------------------------------------------------------------------- 112\item 113\begin{verbatim} 114void BKL_setColorWeights ( BKL *bkl ) ; 115\end{verbatim} 116\index{BKL_setColorWeights@{\tt BKL\_setColorWeights()}} 117This method sets the color weights for the region. 118It assumes that all domains are colored {\tt 1} or {\tt 2}. 119The segments are then colored. 120If a segment is adjacent only to domains of one color, its color is 121that color, otherwise its color is {\tt 0}. 122\par \noindent {\it Error checking:} 123If {\tt bkl} or {\tt bkl->bpg} is {\tt NULL}, 124an error message is printed and the program exits. 125The colors of the domains are checked to ensure they are {\tt 1} or 126{\tt 2}. 127%----------------------------------------------------------------------- 128\item 129\begin{verbatim} 130int BKL_segColor ( BKL *bkl, int iseg ) ; 131\end{verbatim} 132\index{BKL_segColor@{\tt BKL\_segColor()}} 133This method returns the color of segment {\tt iseg}. 134\par \noindent {\it Error checking:} 135If {\tt bkl} is {\tt NULL}, 136or if {\tt iseg} is not in {\tt [bkl->ndom, bkl->nreg)}, 137an error message is printed and the program exits. 138%----------------------------------------------------------------------- 139\item 140\begin{verbatim} 141void BKL_flipDomain ( BKL *bkl, int idom ) ; 142\end{verbatim} 143\index{BKL_flipDomain@{\tt BKL\_flipDomain()}} 144This method flips the color of domain {\tt idom}, 145adjusts the colors of neighboring segments 146and the {\tt cweights[]} vector. 147\par \noindent {\it Error checking:} 148If {\tt bkl} is {\tt NULL}, 149or if {\tt idom} is not in {\tt [0,bkl->ndom)}, 150an error message is printed and the program exits. 151%----------------------------------------------------------------------- 152\item 153\begin{verbatim} 154int BKL_greyCodeDomain ( BKL *bkl, int count ) ; 155\end{verbatim} 156\index{BKL_greyCodeDomain@{\tt BKL\_greyCodeDomain()}} 157This method returns the next domain id in a grey code sequence, 158used to exhaustively search of a subspace of partitions 159defined by set of candidate domains to flip. 160The value {\tt count} ranges from {\tt 1} to $2^{\mbox{\tt ndom}}$. 161\par \noindent {\it Error checking:} 162If {\tt bkl} is {\tt NULL}, 163an error message is printed and the program exits. 164%----------------------------------------------------------------------- 165\item 166\begin{verbatim} 167float BKL_setInitPart ( BKL *bkl, int flag, int seed, int domcolors[] ) ; 168\end{verbatim} 169\index{BKL_setInitPart@{\tt BKL\_setInitPart()}} 170This method sets the initial partition 171by coloring the domains and segments. 172The {\tt flag} parameter has the following values. 173\begin{itemize} 174\item 175{\tt flag = 1} $\longrightarrow$ 176random coloring of the domains 177\item 178{\tt flag = 2} $\longrightarrow$ 179one black domain, ({\tt seed} \% {\tt ndom}), rest are white 180\item 181{\tt flag = 3} $\longrightarrow$ 182one black pseudoperipheral domain, found using 183domain ({\tt seed} \% {\tt ndom}) as root, rest are white 184\item 185{\tt flag = 4} $\longrightarrow$ 186roughly half-half split, breadth first search 187of domains, ({\tt seed} \% {\tt ndom}) as root 188\item 189{\tt flag = 5} $\longrightarrow$ 190roughly half-half split, breadth first search 191of domains, ({\tt seed} \% {\tt ndom}) as root to find 192a pseudoperipheral domain as root 193\item 194{\tt flag = 6} $\longrightarrow$ 195use {\tt domcolors[]} to seed the {\tt colors[]} array 196\end{itemize} 197The {\tt seed} input parameter is for a random number generator. 198The {\tt domcolors[]} input array is used only for {\tt flag = 6}. 199\par \noindent {\it Error checking:} 200If {\tt bkl} is {\tt NULL}, 201or if {\tt flag = 6} and {\tt domcolors} is {\tt NULL}, 202or if {\tt flag} is not in {\tt [1,6]}, 203an error message is printed and the program exits. 204%----------------------------------------------------------------------- 205\item 206\begin{verbatim} 207int BKL_domAdjToSep ( BKL *bkl, int dom ) ; 208\end{verbatim} 209\index{BKL_domAdjToSep@{\tt BKL\_domAdjToSep()}} 210This method returns {\tt 1} 211if domain {\tt dom} is adjacent to the separator 212and {\tt 0} otherwise. 213\par \noindent {\it Error checking:} 214If {\tt bkl} is {\tt NULL}, 215or if {\tt dom} is not in {\tt [0,ndom)}, 216an error message is printed and the program exits. 217%----------------------------------------------------------------------- 218\end{enumerate} 219\par 220\subsection{Partition evaluation methods} 221\label{subsection:BKL:proto:evaluation} 222\par 223There are three functions that evaluate the cost of a partition. 224\par 225%======================================================================= 226\begin{enumerate} 227%----------------------------------------------------------------------- 228\item 229\begin{verbatim} 230void BKL_evalgain ( BKL *bkl, int dom, int *pdeltaS, int *pdeltaB, int *pdeltaW ) ; 231\end{verbatim} 232\index{BKL_evalgain@{\tt BKL\_evalgain()}} 233This method evaluates the change in the components 234$\Delta S$, $\Delta B$ and $\Delta W$ 235that would occur if domain {\tt dom} were to be flipped. 236These {\it gain} values are put into the storage pointed to by 237{\tt pdeltaS}, {\tt pdeltaB} and {\tt pdeltaW}. 238The method checks that {\tt bkl}, {\tt pdeltaS}, {\tt pdeltaB} 239and {\tt pdeltaW} are not {\tt NULL} 240and that {\tt idom} is in {\tt [0,bkl->ndom)}. 241\par \noindent {\it Error checking:} 242If {\tt bkl}, {\tt pdeltaS}, {\tt pdeltaB} or {\tt pdeltaW} 243is {\tt NULL}, 244or if {\tt dom} is not in {\tt [0,ndom)}, 245an error message is printed and the program exits. 246%----------------------------------------------------------------------- 247\item 248\begin{verbatim} 249float BKL_evalfcn ( BKL *bkl ) ; 250\end{verbatim} 251\index{BKL_evalfcn@{\tt BKL\_evalfcn()}} 252The $|S|$, $|B|$ and $|W|$ values are taken from the {\tt 253cweights[]} vector. 254If $\min(|B|,|W|) > 0$, this function returns 255$$ 256|S|\left(1 + \alpha * \frac{\max(|B|,|W|)}{\min(|B|,|W|)} \right), 257$$ 258otherwise it returns $(|S| + |B| + |W|)^2$. 259\par \noindent {\it Error checking:} 260If {\tt bkl} is {\tt NULL}, 261an error message is printed and the program exits. 262%----------------------------------------------------------------------- 263\item 264\begin{verbatim} 265float BKL_eval ( BKL *bkl, int Sweight, int Bweight, int Wweight ) ; 266\end{verbatim} 267\index{BKL_eval@{\tt BKL\_eval()}} 268The $|S|$, $|B|$ and $|W|$ values are taken from the {\tt 269Sweight}, {\tt Bweight} and {\tt Wweight} parameters. 270If $\min(|B|,|W|) > 0$, this function returns 271$$ 272|S|\left(1 + \alpha * \frac{\max(|B|,|W|)}{\min(|B|,|W|)} \right), 273$$ 274otherwise it returns $(|S| + |B| + |W|)^2$. 275The method checks that {\tt bkl} is not {\tt NULL}. 276\par \noindent {\it Error checking:} 277If {\tt bkl} is {\tt NULL}, 278an error message is printed and the program exits. 279%----------------------------------------------------------------------- 280\end{enumerate} 281\par 282\subsection{Partition improvement methods} 283\label{subsection:BKL:proto:improve} 284\par 285There are two functions that take a given partition and some input 286parameters and return a (hopefully) improved partition. 287\par 288%======================================================================= 289\begin{enumerate} 290%----------------------------------------------------------------------- 291\item 292\begin{verbatim} 293float BKL_exhSearch ( BKL *bkl, int mdom, int domids[], int tcolors[] ) ; 294\end{verbatim} 295\index{BKL_exhSearch@{\tt BKL\_exhSearch()}} 296This method performs an exhaustive search of a subspace of 297partitions and returns the best partition. 298The starting partition is given by the {\tt BKL} object's {\tt 299colors[]} vector. 300The subspace of domains to flip is defined by the {\tt 301domids[mdom]} vector. 302The {\tt tcolors[]} vector is a work vector. 303There are $2^{\mbox{\tt mdom}}$ distinct partitions in the subspace 304to be explored. 305We flip the domains using a grey code sequence so a total of 306$2^{\mbox{\tt mdom}}$ domain flips are performed. 307The {\tt bkl->colors[]} vector is filled with the colors of 308the best partition and its cost is returned. 309\par \noindent {\it Error checking:} 310If {\tt bkl}, {\tt domids} or {\tt tcolors} is {\tt NULL}, 311or if {\tt mdom < 1}, 312an error message is printed and the program exits. 313%----------------------------------------------------------------------- 314\item 315\begin{verbatim} 316float BKL_fidmat ( BKL *bkl ) ; 317\end{verbatim} 318\index{BKL_fidmat@{\tt BKL\_fidmat()}} 319If the number of domains is eight or less, an exhaustive search is 320made. 321Otherwise, this method finds a good partition using a variant of the 322Fiduccia-Mattheyes algorithm. 323At any step, only the domains that are adjacent to the separator 324are eligible to be flipped. 325For each eligible domain, 326we maintain 327$\Delta S$, $\Delta B$ and $\Delta W$, 328the change in the three component weights 329if this domain were to be flipped. 330These values must be updated whenever a neighboring domain has been 331flipped, and so is {\it local} information. 332The cost of the partition that would result if a domain were to be 333flipped is a function of the local information 334$\Delta S$, $\Delta B$ and $\Delta W$, 335as well as the present weights of the components 336(global information). 337At each step we evaluate the cost of the resulting partition for each 338domain that is eligible to be flipped. 339This is relatively expensive when compared to using a heap to contain 340$\Delta S$ for each domain, but we have found the resulting 341partitions to be better. 342The eligible domains are kept on a doubly linked list to allow easy 343insertions and deletions. 344\par \noindent {\it Error checking:} 345If {\tt bkl} is {\tt NULL}, 346an error message is printed and the program exits. 347%----------------------------------------------------------------------- 348\end{enumerate} 349