# HG changeset patch
# User Peter Kovacs <kpeter@inf.elte.hu>
# Date 1249302938 -7200
# Node ID d66ff32624e2cec102cedea55dca5e9f67ce1931
# Parent b31e130db13dc0fb04aa077d61de09785b55fe43
Simplify the interface of MinMeanCycle (#179)
Remove init() and reset(), and move their content into findMinMean().
diff --git a/lemon/min_mean_cycle.h b/lemon/min_mean_cycle.h
a
|
b
|
|
122 | 122 | /// found cycle. |
123 | 123 | /// |
124 | 124 | /// If you don't call this function before calling \ref run() or |
125 | | /// \ref init(), it will allocate a local \ref Path "path" |
| 125 | /// \ref findMinMean(), it will allocate a local \ref Path "path" |
126 | 126 | /// structure. The destuctor deallocates this automatically |
127 | 127 | /// allocated object, of course. |
128 | 128 | /// |
… |
… |
|
144 | 144 | /// \name Execution control |
145 | 145 | /// The simplest way to execute the algorithm is to call the \ref run() |
146 | 146 | /// function.\n |
147 | | /// If you only need the minimum mean length, you may call \ref init() |
148 | | /// and \ref findMinMean(). |
149 | | /// If you would like to run the algorithm again (e.g. the underlying |
150 | | /// digraph and/or the arc lengths has been modified), you may not |
151 | | /// create a new instance of the class, rather call \ref reset(), |
152 | | /// \ref findMinMean() and \ref findCycle() instead. |
| 147 | /// If you only need the minimum mean length, you may call |
| 148 | /// \ref findMinMean(). |
153 | 149 | |
154 | 150 | /// @{ |
155 | 151 | |
156 | 152 | /// \brief Run the algorithm. |
157 | 153 | /// |
158 | 154 | /// This function runs the algorithm. |
| 155 | /// It can be called more than once (e.g. if the underlying digraph |
| 156 | /// and/or the arc lengths have been modified). |
159 | 157 | /// |
160 | 158 | /// \return \c true if a directed cycle exists in the digraph. |
161 | 159 | /// |
162 | | /// \note Apart from the return value, <tt>mmc.run()</tt> is just a |
163 | | /// shortcut of the following code. |
| 160 | /// \note <tt>mmc.run()</tt> is just a shortcut of the following code. |
164 | 161 | /// \code |
165 | | /// mmc.init(); |
166 | | /// mmc.findMinMean(); |
167 | | /// mmc.findCycle(); |
| 162 | /// return mmc.findMinMean() && mmc.findCycle(); |
168 | 163 | /// \endcode |
169 | 164 | bool run() { |
170 | | init(); |
171 | 165 | return findMinMean() && findCycle(); |
172 | 166 | } |
173 | 167 | |
174 | | /// \brief Initialize the internal data structures. |
| 168 | /// \brief Find the minimum cycle mean. |
175 | 169 | /// |
176 | | /// This function initializes the internal data structures. |
| 170 | /// This function finds the minimum mean length of the directed |
| 171 | /// cycles in the digraph. |
177 | 172 | /// |
178 | | /// \sa reset() |
179 | | void init() { |
| 173 | /// \return \c true if a directed cycle exists in the digraph. |
| 174 | bool findMinMean() { |
| 175 | // Initialize |
180 | 176 | _tol.epsilon(1e-6); |
181 | 177 | if (!_cycle_path) { |
182 | 178 | _local_path = true; |
183 | 179 | _cycle_path = new Path; |
184 | 180 | } |
| 181 | _cycle_path->clear(); |
185 | 182 | _cycle_found = false; |
| 183 | |
| 184 | // Find the minimum cycle mean in the components |
186 | 185 | _comp_num = stronglyConnectedComponents(_gr, _comp); |
187 | | } |
188 | | |
189 | | /// \brief Reset the internal data structures. |
190 | | /// |
191 | | /// This function resets the internal data structures so that |
192 | | /// findMinMean() and findCycle() can be called again (e.g. when the |
193 | | /// underlying digraph and/or the arc lengths has been modified). |
194 | | /// |
195 | | /// \sa init() |
196 | | void reset() { |
197 | | if (_cycle_path) _cycle_path->clear(); |
198 | | _cycle_found = false; |
199 | | _comp_num = stronglyConnectedComponents(_gr, _comp); |
200 | | } |
201 | | |
202 | | /// \brief Find the minimum cycle mean. |
203 | | /// |
204 | | /// This function computes all the required data and finds the |
205 | | /// minimum mean length of the directed cycles in the digraph. |
206 | | /// |
207 | | /// \return \c true if a directed cycle exists in the digraph. |
208 | | /// |
209 | | /// \pre \ref init() must be called before using this function. |
210 | | bool findMinMean() { |
211 | | // Find the minimum cycle mean in the components |
212 | 186 | for (int comp = 0; comp < _comp_num; ++comp) { |
213 | 187 | if (!initCurrentComponent(comp)) continue; |
214 | 188 | while (true) { |
… |
… |
|
227 | 201 | /// |
228 | 202 | /// \return \c true if a directed cycle exists in the digraph. |
229 | 203 | /// |
230 | | /// \pre \ref init() and \ref findMinMean() must be called before |
231 | | /// using this function. |
| 204 | /// \pre \ref findMinMean() must be called before using this function. |
232 | 205 | bool findCycle() { |
233 | 206 | if (!_cycle_found) return false; |
234 | 207 | _cycle_path->addBack(_policy[_cycle_node]); |
… |
… |
|
242 | 215 | /// @} |
243 | 216 | |
244 | 217 | /// \name Query Functions |
245 | | /// The result of the algorithm can be obtained using these |
| 218 | /// The results of the algorithm can be obtained using these |
246 | 219 | /// functions.\n |
247 | 220 | /// The algorithm should be executed before using them. |
248 | 221 | |