1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
|
\par
\section{Prototypes and descriptions of {\tt Network} methods}
\label{section:Network:proto}
\par
This section contains brief descriptions including prototypes
of all methods that belong to the {\tt Network} object.
\par
\subsection{Basic methods}
\label{subsection:Network:proto:basics}
\par
As usual, there are four basic methods to support object creation,
setting default fields, clearing any allocated data, and free'ing
the object.
\par
%=======================================================================
\begin{enumerate}
%-----------------------------------------------------------------------
\item
\begin{verbatim}
Network * Network_new ( void ) ;
\end{verbatim}
\index{Network_new@{\tt Network\_new()}}
This method simply allocates storage for the {\tt Network} structure
and then sets the default fields by a call to
{\tt Network\_setDefaultFields()}.
%-----------------------------------------------------------------------
\item
\begin{verbatim}
void Network_setDefaultFields ( Network *network ) ;
\end{verbatim}
\index{Network_setDefaultFields@{\tt Network\_setDefaultFields()}}
This method sets the structure's fields to default values.
\par \noindent {\it Error checking:}
If {\tt network} is {\tt NULL},
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\item
\begin{verbatim}
void Network_clearData ( Network *network ) ;
\end{verbatim}
\index{Network_clearData@{\tt Network\_clearData()}}
This method releases any storage held by the object,
e.g., it free's the {\tt inheads} and {\tt outheads} vectors
and one by one it releases the storage held in the list of {\tt
ArcChunk} structures.
It then sets the structure's default fields
with a call to {\tt Network\_setDefaultFields()}.
\par \noindent {\it Error checking:}
If {\tt network} is {\tt NULL},
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\item
\begin{verbatim}
void Network_free ( Network *network ) ;
\end{verbatim}
\index{Network_free@{\tt Network\_free()}}
Thismethod releases any storage by a call to
{\tt Network\_clearData()} then free's the storage for the
structure with a call to {\tt free()}.
\par \noindent {\it Error checking:}
If {\tt network} is {\tt NULL},
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\end{enumerate}
\par
\subsection{Initializer methods}
\label{subsection:Network:proto:initializers}
\par
There are three initializer methods.
\par
%=======================================================================
\begin{enumerate}
%-----------------------------------------------------------------------
\item
\begin{verbatim}
void Network_init ( Network *network, int nnode, int narc ) ;
\end{verbatim}\
\index{Network_init@{\tt Network\_init()}}
This method initializes an {\tt Network} object given the number of
nodes and number of arcs.
(The latter may be zero since we allow the storage for the arcs to
grow dynamically.)
\par \noindent {\it Error checking:}
If {\tt network} is {\tt NULL},
or if ${\tt nnode} \le 2$,
or if ${\tt narc} < 0$,
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\item
\begin{verbatim}
void Network_setMessageInfo ( Network *network, int msglvl, FILE *msgFile) ;
\end{verbatim}
\index{Network_setMessageInfo@{\tt Network\_setMessageInfo()}}
This method sets the message level and message file pointer for the
object.
\par \noindent {\it Error checking:}
If {\tt network} is {\tt NULL},
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\item
\begin{verbatim}
void Network_addArc ( Network *network, int firstNode, secondNode,
int capacity, int flow ) ;
\end{verbatim}
\index{Network_addArc@{\tt Network\_addArc()}}
This method adds an arc from {\tt firstNode} to {\tt secondNode}
with flow {\tt flow} and capacity {\tt capacity}.
The arc is inserted in the out-list for {\tt firstNode} and the
in-list for {\tt secondNode}.
\par \noindent {\it Error checking:}
If {\tt network} is {\tt NULL},
or if ${\tt nnode} \le 0$,
or if ${\tt firstNode} \le 0$,
or if ${\tt nnode} \le {\tt firstNode}$,
or if ${\tt secondNode} \le 0$,
or if ${\tt nnode} \le {\tt secondNode}$,
or if ${\tt capacity} \le 0$,
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\end{enumerate}
\par
%=======================================================================
\subsection{Utility methods}
\label{subsection:Network:proto:utilities}
\par
%=======================================================================
\begin{enumerate}
%-----------------------------------------------------------------------
\item
\begin{verbatim}
void Network_findMaxFlow ( Network *network ) ;
\end{verbatim}
\index{Network_findMaxFlow@{\tt Network\_findMaxFlow()}}
This method finds a maximum flow over the network by repeatedly
calling the method to find an augmenting path and then the method
to augment the path.
It uses an {\tt Ideq} object to maintain a priority dequeue.
\par \noindent {\it Error checking:}
If {\tt network} is {\tt NULL},
or if ${\tt nnode} \le 0$,
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\item
\begin{verbatim}
int Network_findAugmentingPath ( Network *network, int node, int delta,
int tag, Ideq *deq, int tags[], int deltas[], int pres[] ) ;
\end{verbatim}
\index{Network_findAugmentingPath@{\tt Network\_findAugmentingPath()}}
This methods tries to find an augmenting path.
If successful, the return value is the additional flow that can
flow down the path.
The start node is {\tt node}, adjacent to the source and for which
the edge {\tt (source, node)} is not saturated.
The input parameter {\tt delta} is the difference between the
capacity and the flow along this initial edge.
The {\tt Ideq} object holds the priority dequeue to store the nodes
ids that are visited during the search.
The {\tt tags[]} vector is used to tag nodes that have been
visited --- if {\tt tags[v] = tag}, then {\tt v} has been visited.
The {\tt deltas[v]} value maintains the largest admissible flow in
the path from the source to {\tt v}.
The {\tt pred[]} vector holds the tree links for the nodes.
\par \noindent {\it Error checking:}
If {\tt network}, {\tt deq}, {\tt tags}, {\tt deltas} or
{\tt pred} is {\tt NULL},
or if ${\tt nnode} \le 0$,
or if ${\tt node} \le 0$,
or if ${\tt nnode - 1} \le {\tt node}$,
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\item
\begin{verbatim}
void Network_augmentPath ( Network *network, int delta, int pred[] ) ;
\end{verbatim}
\index{Network_augmentPath@{\tt Network\_augmentPath()}}
This method augments the flow along the path defined by the {\tt
pred[]} vector by {\tt delta} units.
\par \noindent {\it Error checking:}
If {\tt network} or {\tt pred} is {\tt NULL},
or if ${\tt nnode} \le 0$,
or if ${\tt delta} \le 0$,
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\item
\begin{verbatim}
void Network_findMincutFromSource ( Network *network, Ideq deq, int mark[]) ;
\end{verbatim}
\index{Network_findMincutFromSource@{\tt Network\_findMincutFromSource()}}
This method finds the min-cut closest to the source by traversing a
tree of flow-alternating paths from the source.
On return, {\tt mark[v] = 1} if the node {\tt v} is in the
component that contains the source.
If the node {\tt v} is in the component that contains the sink,
then {\tt mark[v] = 2}.
\par \noindent {\it Error checking:}
If {\tt network}, {\tt deq} or {\tt mark} is {\tt NULL},
or if ${\tt nnode} \le 0$,
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\item
\begin{verbatim}
void Network_findMincutFromSink ( Network *network, Ideq deq, int mark[]) ;
\end{verbatim}
\index{Network_findMincutFromSink@{\tt Network\_findMincutFromSink()}}
This method finds the min-cut closest to the sink by traversing a
tree of flow-alternating paths into the sink.
On return, {\tt mark[v] = 1} if the node {\tt v} is in the
component that contains the source.
If the node {\tt v} is in the component that contains the sink,
then {\tt mark[v] = 2}.
\par \noindent {\it Error checking:}
If {\tt network}, {\tt deq} or {\tt mark} is {\tt NULL},
or if ${\tt nnode} \le 0$,
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\end{enumerate}
\par
\subsection{IO methods}
\label{subsection:Network:proto:IO}
\par
There are two IO routines for debugging purposes.
\par
%=======================================================================
\begin{enumerate}
%-----------------------------------------------------------------------
\item
\begin{verbatim}
void Network_writeForHumanEye ( Network *network, FILE *fp ) ;
\end{verbatim}
\index{Network_writeForHumanEye@{\tt Network\_writeForHumanEye()}}
\par
This method writes the network to a file in a human readable format.
The method {\tt Network\_writeStats()}
is called to write out the
header and statistics.
Then the in-list and out-lists for the nodes in the network are
printed.
\par \noindent {\it Error checking:}
If {\tt network} or {\tt fp} is {\tt NULL},
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\item
\begin{verbatim}
void Network_writeStats ( Network *network, FILE *fp ) ;
\end{verbatim}
\index{Network_writeStats@{\tt Network\_writeStats()}}
\par
This method writes a header and statistics to a file.
\par \noindent {\it Error checking:}
If {\tt network} or {\tt fp} is {\tt NULL},
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\end{enumerate}
|