[404] | 1 | /* -*- mode: C++; indent-tabs-mode: nil; -*- |
---|
| 2 | * |
---|
| 3 | * This file is a part of LEMON, a generic C++ optimization library. |
---|
| 4 | * |
---|
[463] | 5 | * Copyright (C) 2003-2009 |
---|
[404] | 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
| 8 | * |
---|
| 9 | * Permission to use, modify and distribute this software is granted |
---|
| 10 | * provided that this copyright notice appears in all copies. For |
---|
| 11 | * precise terms see the accompanying LICENSE file. |
---|
| 12 | * |
---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 14 | * express or implied, and with no claim as to its suitability for any |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #ifndef LEMON_PREFLOW_H |
---|
| 20 | #define LEMON_PREFLOW_H |
---|
| 21 | |
---|
| 22 | #include <lemon/tolerance.h> |
---|
| 23 | #include <lemon/elevator.h> |
---|
| 24 | |
---|
| 25 | /// \file |
---|
| 26 | /// \ingroup max_flow |
---|
| 27 | /// \brief Implementation of the preflow algorithm. |
---|
| 28 | |
---|
| 29 | namespace lemon { |
---|
| 30 | |
---|
| 31 | /// \brief Default traits class of Preflow class. |
---|
| 32 | /// |
---|
| 33 | /// Default traits class of Preflow class. |
---|
[525] | 34 | /// \tparam GR Digraph type. |
---|
[606] | 35 | /// \tparam CAP Capacity map type. |
---|
| 36 | template <typename GR, typename CAP> |
---|
[404] | 37 | struct PreflowDefaultTraits { |
---|
| 38 | |
---|
[408] | 39 | /// \brief The type of the digraph the algorithm runs on. |
---|
[525] | 40 | typedef GR Digraph; |
---|
[404] | 41 | |
---|
| 42 | /// \brief The type of the map that stores the arc capacities. |
---|
| 43 | /// |
---|
| 44 | /// The type of the map that stores the arc capacities. |
---|
| 45 | /// It must meet the \ref concepts::ReadMap "ReadMap" concept. |
---|
[606] | 46 | typedef CAP CapacityMap; |
---|
[404] | 47 | |
---|
[408] | 48 | /// \brief The type of the flow values. |
---|
[688] | 49 | typedef typename CapacityMap::Value Value; |
---|
[404] | 50 | |
---|
[408] | 51 | /// \brief The type of the map that stores the flow values. |
---|
[404] | 52 | /// |
---|
[408] | 53 | /// The type of the map that stores the flow values. |
---|
[404] | 54 | /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
---|
[688] | 55 | typedef typename Digraph::template ArcMap<Value> FlowMap; |
---|
[404] | 56 | |
---|
| 57 | /// \brief Instantiates a FlowMap. |
---|
| 58 | /// |
---|
| 59 | /// This function instantiates a \ref FlowMap. |
---|
[657] | 60 | /// \param digraph The digraph for which we would like to define |
---|
[404] | 61 | /// the flow map. |
---|
| 62 | static FlowMap* createFlowMap(const Digraph& digraph) { |
---|
| 63 | return new FlowMap(digraph); |
---|
| 64 | } |
---|
| 65 | |
---|
[408] | 66 | /// \brief The elevator type used by Preflow algorithm. |
---|
[404] | 67 | /// |
---|
| 68 | /// The elevator type used by Preflow algorithm. |
---|
| 69 | /// |
---|
| 70 | /// \sa Elevator |
---|
| 71 | /// \sa LinkedElevator |
---|
| 72 | typedef LinkedElevator<Digraph, typename Digraph::Node> Elevator; |
---|
| 73 | |
---|
| 74 | /// \brief Instantiates an Elevator. |
---|
| 75 | /// |
---|
[408] | 76 | /// This function instantiates an \ref Elevator. |
---|
[657] | 77 | /// \param digraph The digraph for which we would like to define |
---|
[404] | 78 | /// the elevator. |
---|
| 79 | /// \param max_level The maximum level of the elevator. |
---|
| 80 | static Elevator* createElevator(const Digraph& digraph, int max_level) { |
---|
| 81 | return new Elevator(digraph, max_level); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | /// \brief The tolerance used by the algorithm |
---|
| 85 | /// |
---|
| 86 | /// The tolerance used by the algorithm to handle inexact computation. |
---|
[688] | 87 | typedef lemon::Tolerance<Value> Tolerance; |
---|
[404] | 88 | |
---|
| 89 | }; |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | /// \ingroup max_flow |
---|
| 93 | /// |
---|
[408] | 94 | /// \brief %Preflow algorithm class. |
---|
[404] | 95 | /// |
---|
[408] | 96 | /// This class provides an implementation of Goldberg-Tarjan's \e preflow |
---|
[606] | 97 | /// \e push-relabel algorithm producing a \ref max_flow |
---|
| 98 | /// "flow of maximum value" in a digraph. |
---|
| 99 | /// The preflow algorithms are the fastest known maximum |
---|
[736] | 100 | /// flow algorithms. The current implementation uses a mixture of the |
---|
[404] | 101 | /// \e "highest label" and the \e "bound decrease" heuristics. |
---|
| 102 | /// The worst case time complexity of the algorithm is \f$O(n^2\sqrt{e})\f$. |
---|
| 103 | /// |
---|
[408] | 104 | /// The algorithm consists of two phases. After the first phase |
---|
| 105 | /// the maximum flow value and the minimum cut is obtained. The |
---|
| 106 | /// second phase constructs a feasible maximum flow on each arc. |
---|
[404] | 107 | /// |
---|
[525] | 108 | /// \tparam GR The type of the digraph the algorithm runs on. |
---|
[606] | 109 | /// \tparam CAP The type of the capacity map. The default map |
---|
[525] | 110 | /// type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". |
---|
[404] | 111 | #ifdef DOXYGEN |
---|
[606] | 112 | template <typename GR, typename CAP, typename TR> |
---|
[404] | 113 | #else |
---|
[525] | 114 | template <typename GR, |
---|
[606] | 115 | typename CAP = typename GR::template ArcMap<int>, |
---|
| 116 | typename TR = PreflowDefaultTraits<GR, CAP> > |
---|
[404] | 117 | #endif |
---|
| 118 | class Preflow { |
---|
| 119 | public: |
---|
| 120 | |
---|
[408] | 121 | ///The \ref PreflowDefaultTraits "traits class" of the algorithm. |
---|
[525] | 122 | typedef TR Traits; |
---|
[408] | 123 | ///The type of the digraph the algorithm runs on. |
---|
[404] | 124 | typedef typename Traits::Digraph Digraph; |
---|
[408] | 125 | ///The type of the capacity map. |
---|
[404] | 126 | typedef typename Traits::CapacityMap CapacityMap; |
---|
[408] | 127 | ///The type of the flow values. |
---|
[688] | 128 | typedef typename Traits::Value Value; |
---|
[404] | 129 | |
---|
[408] | 130 | ///The type of the flow map. |
---|
[404] | 131 | typedef typename Traits::FlowMap FlowMap; |
---|
[408] | 132 | ///The type of the elevator. |
---|
[404] | 133 | typedef typename Traits::Elevator Elevator; |
---|
[408] | 134 | ///The type of the tolerance. |
---|
[404] | 135 | typedef typename Traits::Tolerance Tolerance; |
---|
| 136 | |
---|
| 137 | private: |
---|
| 138 | |
---|
| 139 | TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
---|
| 140 | |
---|
| 141 | const Digraph& _graph; |
---|
| 142 | const CapacityMap* _capacity; |
---|
| 143 | |
---|
| 144 | int _node_num; |
---|
| 145 | |
---|
| 146 | Node _source, _target; |
---|
| 147 | |
---|
| 148 | FlowMap* _flow; |
---|
| 149 | bool _local_flow; |
---|
| 150 | |
---|
| 151 | Elevator* _level; |
---|
| 152 | bool _local_level; |
---|
| 153 | |
---|
[688] | 154 | typedef typename Digraph::template NodeMap<Value> ExcessMap; |
---|
[404] | 155 | ExcessMap* _excess; |
---|
| 156 | |
---|
| 157 | Tolerance _tolerance; |
---|
| 158 | |
---|
| 159 | bool _phase; |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | void createStructures() { |
---|
| 163 | _node_num = countNodes(_graph); |
---|
| 164 | |
---|
| 165 | if (!_flow) { |
---|
| 166 | _flow = Traits::createFlowMap(_graph); |
---|
| 167 | _local_flow = true; |
---|
| 168 | } |
---|
| 169 | if (!_level) { |
---|
| 170 | _level = Traits::createElevator(_graph, _node_num); |
---|
| 171 | _local_level = true; |
---|
| 172 | } |
---|
| 173 | if (!_excess) { |
---|
| 174 | _excess = new ExcessMap(_graph); |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | void destroyStructures() { |
---|
| 179 | if (_local_flow) { |
---|
| 180 | delete _flow; |
---|
| 181 | } |
---|
| 182 | if (_local_level) { |
---|
| 183 | delete _level; |
---|
| 184 | } |
---|
| 185 | if (_excess) { |
---|
| 186 | delete _excess; |
---|
| 187 | } |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | public: |
---|
| 191 | |
---|
| 192 | typedef Preflow Create; |
---|
| 193 | |
---|
[408] | 194 | ///\name Named Template Parameters |
---|
[404] | 195 | |
---|
| 196 | ///@{ |
---|
| 197 | |
---|
[606] | 198 | template <typename T> |
---|
[406] | 199 | struct SetFlowMapTraits : public Traits { |
---|
[606] | 200 | typedef T FlowMap; |
---|
[404] | 201 | static FlowMap *createFlowMap(const Digraph&) { |
---|
[405] | 202 | LEMON_ASSERT(false, "FlowMap is not initialized"); |
---|
| 203 | return 0; // ignore warnings |
---|
[404] | 204 | } |
---|
| 205 | }; |
---|
| 206 | |
---|
| 207 | /// \brief \ref named-templ-param "Named parameter" for setting |
---|
| 208 | /// FlowMap type |
---|
| 209 | /// |
---|
| 210 | /// \ref named-templ-param "Named parameter" for setting FlowMap |
---|
[408] | 211 | /// type. |
---|
[606] | 212 | template <typename T> |
---|
[406] | 213 | struct SetFlowMap |
---|
[606] | 214 | : public Preflow<Digraph, CapacityMap, SetFlowMapTraits<T> > { |
---|
[404] | 215 | typedef Preflow<Digraph, CapacityMap, |
---|
[606] | 216 | SetFlowMapTraits<T> > Create; |
---|
[404] | 217 | }; |
---|
| 218 | |
---|
[606] | 219 | template <typename T> |
---|
[406] | 220 | struct SetElevatorTraits : public Traits { |
---|
[606] | 221 | typedef T Elevator; |
---|
[404] | 222 | static Elevator *createElevator(const Digraph&, int) { |
---|
[405] | 223 | LEMON_ASSERT(false, "Elevator is not initialized"); |
---|
| 224 | return 0; // ignore warnings |
---|
[404] | 225 | } |
---|
| 226 | }; |
---|
| 227 | |
---|
| 228 | /// \brief \ref named-templ-param "Named parameter" for setting |
---|
| 229 | /// Elevator type |
---|
| 230 | /// |
---|
| 231 | /// \ref named-templ-param "Named parameter" for setting Elevator |
---|
[408] | 232 | /// type. If this named parameter is used, then an external |
---|
| 233 | /// elevator object must be passed to the algorithm using the |
---|
| 234 | /// \ref elevator(Elevator&) "elevator()" function before calling |
---|
| 235 | /// \ref run() or \ref init(). |
---|
| 236 | /// \sa SetStandardElevator |
---|
[606] | 237 | template <typename T> |
---|
[406] | 238 | struct SetElevator |
---|
[606] | 239 | : public Preflow<Digraph, CapacityMap, SetElevatorTraits<T> > { |
---|
[404] | 240 | typedef Preflow<Digraph, CapacityMap, |
---|
[606] | 241 | SetElevatorTraits<T> > Create; |
---|
[404] | 242 | }; |
---|
| 243 | |
---|
[606] | 244 | template <typename T> |
---|
[406] | 245 | struct SetStandardElevatorTraits : public Traits { |
---|
[606] | 246 | typedef T Elevator; |
---|
[404] | 247 | static Elevator *createElevator(const Digraph& digraph, int max_level) { |
---|
| 248 | return new Elevator(digraph, max_level); |
---|
| 249 | } |
---|
| 250 | }; |
---|
| 251 | |
---|
| 252 | /// \brief \ref named-templ-param "Named parameter" for setting |
---|
[408] | 253 | /// Elevator type with automatic allocation |
---|
[404] | 254 | /// |
---|
| 255 | /// \ref named-templ-param "Named parameter" for setting Elevator |
---|
[408] | 256 | /// type with automatic allocation. |
---|
| 257 | /// The Elevator should have standard constructor interface to be |
---|
| 258 | /// able to automatically created by the algorithm (i.e. the |
---|
| 259 | /// digraph and the maximum level should be passed to it). |
---|
| 260 | /// However an external elevator object could also be passed to the |
---|
| 261 | /// algorithm with the \ref elevator(Elevator&) "elevator()" function |
---|
| 262 | /// before calling \ref run() or \ref init(). |
---|
| 263 | /// \sa SetElevator |
---|
[606] | 264 | template <typename T> |
---|
[406] | 265 | struct SetStandardElevator |
---|
[404] | 266 | : public Preflow<Digraph, CapacityMap, |
---|
[606] | 267 | SetStandardElevatorTraits<T> > { |
---|
[404] | 268 | typedef Preflow<Digraph, CapacityMap, |
---|
[606] | 269 | SetStandardElevatorTraits<T> > Create; |
---|
[404] | 270 | }; |
---|
| 271 | |
---|
| 272 | /// @} |
---|
| 273 | |
---|
| 274 | protected: |
---|
| 275 | |
---|
| 276 | Preflow() {} |
---|
| 277 | |
---|
| 278 | public: |
---|
| 279 | |
---|
| 280 | |
---|
| 281 | /// \brief The constructor of the class. |
---|
| 282 | /// |
---|
| 283 | /// The constructor of the class. |
---|
| 284 | /// \param digraph The digraph the algorithm runs on. |
---|
| 285 | /// \param capacity The capacity of the arcs. |
---|
| 286 | /// \param source The source node. |
---|
| 287 | /// \param target The target node. |
---|
| 288 | Preflow(const Digraph& digraph, const CapacityMap& capacity, |
---|
[408] | 289 | Node source, Node target) |
---|
[404] | 290 | : _graph(digraph), _capacity(&capacity), |
---|
| 291 | _node_num(0), _source(source), _target(target), |
---|
| 292 | _flow(0), _local_flow(false), |
---|
| 293 | _level(0), _local_level(false), |
---|
| 294 | _excess(0), _tolerance(), _phase() {} |
---|
| 295 | |
---|
[408] | 296 | /// \brief Destructor. |
---|
[404] | 297 | /// |
---|
| 298 | /// Destructor. |
---|
| 299 | ~Preflow() { |
---|
| 300 | destroyStructures(); |
---|
| 301 | } |
---|
| 302 | |
---|
| 303 | /// \brief Sets the capacity map. |
---|
| 304 | /// |
---|
| 305 | /// Sets the capacity map. |
---|
[408] | 306 | /// \return <tt>(*this)</tt> |
---|
[404] | 307 | Preflow& capacityMap(const CapacityMap& map) { |
---|
| 308 | _capacity = ↦ |
---|
| 309 | return *this; |
---|
| 310 | } |
---|
| 311 | |
---|
| 312 | /// \brief Sets the flow map. |
---|
| 313 | /// |
---|
| 314 | /// Sets the flow map. |
---|
[408] | 315 | /// If you don't use this function before calling \ref run() or |
---|
| 316 | /// \ref init(), an instance will be allocated automatically. |
---|
| 317 | /// The destructor deallocates this automatically allocated map, |
---|
| 318 | /// of course. |
---|
| 319 | /// \return <tt>(*this)</tt> |
---|
[404] | 320 | Preflow& flowMap(FlowMap& map) { |
---|
| 321 | if (_local_flow) { |
---|
| 322 | delete _flow; |
---|
| 323 | _local_flow = false; |
---|
| 324 | } |
---|
| 325 | _flow = ↦ |
---|
| 326 | return *this; |
---|
| 327 | } |
---|
| 328 | |
---|
[408] | 329 | /// \brief Sets the source node. |
---|
[404] | 330 | /// |
---|
[408] | 331 | /// Sets the source node. |
---|
| 332 | /// \return <tt>(*this)</tt> |
---|
| 333 | Preflow& source(const Node& node) { |
---|
| 334 | _source = node; |
---|
| 335 | return *this; |
---|
[404] | 336 | } |
---|
| 337 | |
---|
[408] | 338 | /// \brief Sets the target node. |
---|
[404] | 339 | /// |
---|
[408] | 340 | /// Sets the target node. |
---|
| 341 | /// \return <tt>(*this)</tt> |
---|
| 342 | Preflow& target(const Node& node) { |
---|
| 343 | _target = node; |
---|
| 344 | return *this; |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | /// \brief Sets the elevator used by algorithm. |
---|
| 348 | /// |
---|
| 349 | /// Sets the elevator used by algorithm. |
---|
| 350 | /// If you don't use this function before calling \ref run() or |
---|
| 351 | /// \ref init(), an instance will be allocated automatically. |
---|
| 352 | /// The destructor deallocates this automatically allocated elevator, |
---|
| 353 | /// of course. |
---|
| 354 | /// \return <tt>(*this)</tt> |
---|
[404] | 355 | Preflow& elevator(Elevator& elevator) { |
---|
| 356 | if (_local_level) { |
---|
| 357 | delete _level; |
---|
| 358 | _local_level = false; |
---|
| 359 | } |
---|
| 360 | _level = &elevator; |
---|
| 361 | return *this; |
---|
| 362 | } |
---|
| 363 | |
---|
[408] | 364 | /// \brief Returns a const reference to the elevator. |
---|
[404] | 365 | /// |
---|
[408] | 366 | /// Returns a const reference to the elevator. |
---|
| 367 | /// |
---|
| 368 | /// \pre Either \ref run() or \ref init() must be called before |
---|
| 369 | /// using this function. |
---|
[437] | 370 | const Elevator& elevator() const { |
---|
[404] | 371 | return *_level; |
---|
| 372 | } |
---|
| 373 | |
---|
[736] | 374 | /// \brief Sets the tolerance used by the algorithm. |
---|
[404] | 375 | /// |
---|
[736] | 376 | /// Sets the tolerance object used by the algorithm. |
---|
| 377 | /// \return <tt>(*this)</tt> |
---|
[735] | 378 | Preflow& tolerance(const Tolerance& tolerance) { |
---|
[404] | 379 | _tolerance = tolerance; |
---|
| 380 | return *this; |
---|
| 381 | } |
---|
| 382 | |
---|
[408] | 383 | /// \brief Returns a const reference to the tolerance. |
---|
[404] | 384 | /// |
---|
[736] | 385 | /// Returns a const reference to the tolerance object used by |
---|
| 386 | /// the algorithm. |
---|
[404] | 387 | const Tolerance& tolerance() const { |
---|
[735] | 388 | return _tolerance; |
---|
[404] | 389 | } |
---|
| 390 | |
---|
[408] | 391 | /// \name Execution Control |
---|
| 392 | /// The simplest way to execute the preflow algorithm is to use |
---|
| 393 | /// \ref run() or \ref runMinCut().\n |
---|
| 394 | /// If you need more control on the initial solution or the execution, |
---|
| 395 | /// first you have to call one of the \ref init() functions, then |
---|
| 396 | /// \ref startFirstPhase() and if you need it \ref startSecondPhase(). |
---|
[404] | 397 | |
---|
| 398 | ///@{ |
---|
| 399 | |
---|
| 400 | /// \brief Initializes the internal data structures. |
---|
| 401 | /// |
---|
[408] | 402 | /// Initializes the internal data structures and sets the initial |
---|
| 403 | /// flow to zero on each arc. |
---|
[404] | 404 | void init() { |
---|
| 405 | createStructures(); |
---|
| 406 | |
---|
| 407 | _phase = true; |
---|
| 408 | for (NodeIt n(_graph); n != INVALID; ++n) { |
---|
[628] | 409 | (*_excess)[n] = 0; |
---|
[404] | 410 | } |
---|
| 411 | |
---|
| 412 | for (ArcIt e(_graph); e != INVALID; ++e) { |
---|
| 413 | _flow->set(e, 0); |
---|
| 414 | } |
---|
| 415 | |
---|
| 416 | typename Digraph::template NodeMap<bool> reached(_graph, false); |
---|
| 417 | |
---|
| 418 | _level->initStart(); |
---|
| 419 | _level->initAddItem(_target); |
---|
| 420 | |
---|
| 421 | std::vector<Node> queue; |
---|
[628] | 422 | reached[_source] = true; |
---|
[404] | 423 | |
---|
| 424 | queue.push_back(_target); |
---|
[628] | 425 | reached[_target] = true; |
---|
[404] | 426 | while (!queue.empty()) { |
---|
| 427 | _level->initNewLevel(); |
---|
| 428 | std::vector<Node> nqueue; |
---|
| 429 | for (int i = 0; i < int(queue.size()); ++i) { |
---|
| 430 | Node n = queue[i]; |
---|
| 431 | for (InArcIt e(_graph, n); e != INVALID; ++e) { |
---|
| 432 | Node u = _graph.source(e); |
---|
| 433 | if (!reached[u] && _tolerance.positive((*_capacity)[e])) { |
---|
[628] | 434 | reached[u] = true; |
---|
[404] | 435 | _level->initAddItem(u); |
---|
| 436 | nqueue.push_back(u); |
---|
| 437 | } |
---|
| 438 | } |
---|
| 439 | } |
---|
| 440 | queue.swap(nqueue); |
---|
| 441 | } |
---|
| 442 | _level->initFinish(); |
---|
| 443 | |
---|
| 444 | for (OutArcIt e(_graph, _source); e != INVALID; ++e) { |
---|
| 445 | if (_tolerance.positive((*_capacity)[e])) { |
---|
| 446 | Node u = _graph.target(e); |
---|
| 447 | if ((*_level)[u] == _level->maxLevel()) continue; |
---|
| 448 | _flow->set(e, (*_capacity)[e]); |
---|
[628] | 449 | (*_excess)[u] += (*_capacity)[e]; |
---|
[404] | 450 | if (u != _target && !_level->active(u)) { |
---|
| 451 | _level->activate(u); |
---|
| 452 | } |
---|
| 453 | } |
---|
| 454 | } |
---|
| 455 | } |
---|
| 456 | |
---|
[408] | 457 | /// \brief Initializes the internal data structures using the |
---|
| 458 | /// given flow map. |
---|
[404] | 459 | /// |
---|
| 460 | /// Initializes the internal data structures and sets the initial |
---|
| 461 | /// flow to the given \c flowMap. The \c flowMap should contain a |
---|
[408] | 462 | /// flow or at least a preflow, i.e. at each node excluding the |
---|
| 463 | /// source node the incoming flow should greater or equal to the |
---|
[404] | 464 | /// outgoing flow. |
---|
[408] | 465 | /// \return \c false if the given \c flowMap is not a preflow. |
---|
[404] | 466 | template <typename FlowMap> |
---|
[407] | 467 | bool init(const FlowMap& flowMap) { |
---|
[404] | 468 | createStructures(); |
---|
| 469 | |
---|
| 470 | for (ArcIt e(_graph); e != INVALID; ++e) { |
---|
| 471 | _flow->set(e, flowMap[e]); |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | for (NodeIt n(_graph); n != INVALID; ++n) { |
---|
[688] | 475 | Value excess = 0; |
---|
[404] | 476 | for (InArcIt e(_graph, n); e != INVALID; ++e) { |
---|
| 477 | excess += (*_flow)[e]; |
---|
| 478 | } |
---|
| 479 | for (OutArcIt e(_graph, n); e != INVALID; ++e) { |
---|
| 480 | excess -= (*_flow)[e]; |
---|
| 481 | } |
---|
| 482 | if (excess < 0 && n != _source) return false; |
---|
[628] | 483 | (*_excess)[n] = excess; |
---|
[404] | 484 | } |
---|
| 485 | |
---|
| 486 | typename Digraph::template NodeMap<bool> reached(_graph, false); |
---|
| 487 | |
---|
| 488 | _level->initStart(); |
---|
| 489 | _level->initAddItem(_target); |
---|
| 490 | |
---|
| 491 | std::vector<Node> queue; |
---|
[628] | 492 | reached[_source] = true; |
---|
[404] | 493 | |
---|
| 494 | queue.push_back(_target); |
---|
[628] | 495 | reached[_target] = true; |
---|
[404] | 496 | while (!queue.empty()) { |
---|
| 497 | _level->initNewLevel(); |
---|
| 498 | std::vector<Node> nqueue; |
---|
| 499 | for (int i = 0; i < int(queue.size()); ++i) { |
---|
| 500 | Node n = queue[i]; |
---|
| 501 | for (InArcIt e(_graph, n); e != INVALID; ++e) { |
---|
| 502 | Node u = _graph.source(e); |
---|
| 503 | if (!reached[u] && |
---|
| 504 | _tolerance.positive((*_capacity)[e] - (*_flow)[e])) { |
---|
[628] | 505 | reached[u] = true; |
---|
[404] | 506 | _level->initAddItem(u); |
---|
| 507 | nqueue.push_back(u); |
---|
| 508 | } |
---|
| 509 | } |
---|
| 510 | for (OutArcIt e(_graph, n); e != INVALID; ++e) { |
---|
| 511 | Node v = _graph.target(e); |
---|
| 512 | if (!reached[v] && _tolerance.positive((*_flow)[e])) { |
---|
[628] | 513 | reached[v] = true; |
---|
[404] | 514 | _level->initAddItem(v); |
---|
| 515 | nqueue.push_back(v); |
---|
| 516 | } |
---|
| 517 | } |
---|
| 518 | } |
---|
| 519 | queue.swap(nqueue); |
---|
| 520 | } |
---|
| 521 | _level->initFinish(); |
---|
| 522 | |
---|
| 523 | for (OutArcIt e(_graph, _source); e != INVALID; ++e) { |
---|
[688] | 524 | Value rem = (*_capacity)[e] - (*_flow)[e]; |
---|
[404] | 525 | if (_tolerance.positive(rem)) { |
---|
| 526 | Node u = _graph.target(e); |
---|
| 527 | if ((*_level)[u] == _level->maxLevel()) continue; |
---|
| 528 | _flow->set(e, (*_capacity)[e]); |
---|
[628] | 529 | (*_excess)[u] += rem; |
---|
[404] | 530 | if (u != _target && !_level->active(u)) { |
---|
| 531 | _level->activate(u); |
---|
| 532 | } |
---|
| 533 | } |
---|
| 534 | } |
---|
| 535 | for (InArcIt e(_graph, _source); e != INVALID; ++e) { |
---|
[688] | 536 | Value rem = (*_flow)[e]; |
---|
[404] | 537 | if (_tolerance.positive(rem)) { |
---|
| 538 | Node v = _graph.source(e); |
---|
| 539 | if ((*_level)[v] == _level->maxLevel()) continue; |
---|
| 540 | _flow->set(e, 0); |
---|
[628] | 541 | (*_excess)[v] += rem; |
---|
[404] | 542 | if (v != _target && !_level->active(v)) { |
---|
| 543 | _level->activate(v); |
---|
| 544 | } |
---|
| 545 | } |
---|
| 546 | } |
---|
| 547 | return true; |
---|
| 548 | } |
---|
| 549 | |
---|
| 550 | /// \brief Starts the first phase of the preflow algorithm. |
---|
| 551 | /// |
---|
| 552 | /// The preflow algorithm consists of two phases, this method runs |
---|
| 553 | /// the first phase. After the first phase the maximum flow value |
---|
| 554 | /// and a minimum value cut can already be computed, although a |
---|
| 555 | /// maximum flow is not yet obtained. So after calling this method |
---|
| 556 | /// \ref flowValue() returns the value of a maximum flow and \ref |
---|
| 557 | /// minCut() returns a minimum cut. |
---|
[408] | 558 | /// \pre One of the \ref init() functions must be called before |
---|
| 559 | /// using this function. |
---|
[404] | 560 | void startFirstPhase() { |
---|
| 561 | _phase = true; |
---|
| 562 | |
---|
| 563 | Node n = _level->highestActive(); |
---|
| 564 | int level = _level->highestActiveLevel(); |
---|
| 565 | while (n != INVALID) { |
---|
| 566 | int num = _node_num; |
---|
| 567 | |
---|
| 568 | while (num > 0 && n != INVALID) { |
---|
[688] | 569 | Value excess = (*_excess)[n]; |
---|
[404] | 570 | int new_level = _level->maxLevel(); |
---|
| 571 | |
---|
| 572 | for (OutArcIt e(_graph, n); e != INVALID; ++e) { |
---|
[688] | 573 | Value rem = (*_capacity)[e] - (*_flow)[e]; |
---|
[404] | 574 | if (!_tolerance.positive(rem)) continue; |
---|
| 575 | Node v = _graph.target(e); |
---|
| 576 | if ((*_level)[v] < level) { |
---|
| 577 | if (!_level->active(v) && v != _target) { |
---|
| 578 | _level->activate(v); |
---|
| 579 | } |
---|
| 580 | if (!_tolerance.less(rem, excess)) { |
---|
| 581 | _flow->set(e, (*_flow)[e] + excess); |
---|
[628] | 582 | (*_excess)[v] += excess; |
---|
[404] | 583 | excess = 0; |
---|
| 584 | goto no_more_push_1; |
---|
| 585 | } else { |
---|
| 586 | excess -= rem; |
---|
[628] | 587 | (*_excess)[v] += rem; |
---|
[404] | 588 | _flow->set(e, (*_capacity)[e]); |
---|
| 589 | } |
---|
| 590 | } else if (new_level > (*_level)[v]) { |
---|
| 591 | new_level = (*_level)[v]; |
---|
| 592 | } |
---|
| 593 | } |
---|
| 594 | |
---|
| 595 | for (InArcIt e(_graph, n); e != INVALID; ++e) { |
---|
[688] | 596 | Value rem = (*_flow)[e]; |
---|
[404] | 597 | if (!_tolerance.positive(rem)) continue; |
---|
| 598 | Node v = _graph.source(e); |
---|
| 599 | if ((*_level)[v] < level) { |
---|
| 600 | if (!_level->active(v) && v != _target) { |
---|
| 601 | _level->activate(v); |
---|
| 602 | } |
---|
| 603 | if (!_tolerance.less(rem, excess)) { |
---|
| 604 | _flow->set(e, (*_flow)[e] - excess); |
---|
[628] | 605 | (*_excess)[v] += excess; |
---|
[404] | 606 | excess = 0; |
---|
| 607 | goto no_more_push_1; |
---|
| 608 | } else { |
---|
| 609 | excess -= rem; |
---|
[628] | 610 | (*_excess)[v] += rem; |
---|
[404] | 611 | _flow->set(e, 0); |
---|
| 612 | } |
---|
| 613 | } else if (new_level > (*_level)[v]) { |
---|
| 614 | new_level = (*_level)[v]; |
---|
| 615 | } |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | no_more_push_1: |
---|
| 619 | |
---|
[628] | 620 | (*_excess)[n] = excess; |
---|
[404] | 621 | |
---|
| 622 | if (excess != 0) { |
---|
| 623 | if (new_level + 1 < _level->maxLevel()) { |
---|
| 624 | _level->liftHighestActive(new_level + 1); |
---|
| 625 | } else { |
---|
| 626 | _level->liftHighestActiveToTop(); |
---|
| 627 | } |
---|
| 628 | if (_level->emptyLevel(level)) { |
---|
| 629 | _level->liftToTop(level); |
---|
| 630 | } |
---|
| 631 | } else { |
---|
| 632 | _level->deactivate(n); |
---|
| 633 | } |
---|
| 634 | |
---|
| 635 | n = _level->highestActive(); |
---|
| 636 | level = _level->highestActiveLevel(); |
---|
| 637 | --num; |
---|
| 638 | } |
---|
| 639 | |
---|
| 640 | num = _node_num * 20; |
---|
| 641 | while (num > 0 && n != INVALID) { |
---|
[688] | 642 | Value excess = (*_excess)[n]; |
---|
[404] | 643 | int new_level = _level->maxLevel(); |
---|
| 644 | |
---|
| 645 | for (OutArcIt e(_graph, n); e != INVALID; ++e) { |
---|
[688] | 646 | Value rem = (*_capacity)[e] - (*_flow)[e]; |
---|
[404] | 647 | if (!_tolerance.positive(rem)) continue; |
---|
| 648 | Node v = _graph.target(e); |
---|
| 649 | if ((*_level)[v] < level) { |
---|
| 650 | if (!_level->active(v) && v != _target) { |
---|
| 651 | _level->activate(v); |
---|
| 652 | } |
---|
| 653 | if (!_tolerance.less(rem, excess)) { |
---|
| 654 | _flow->set(e, (*_flow)[e] + excess); |
---|
[628] | 655 | (*_excess)[v] += excess; |
---|
[404] | 656 | excess = 0; |
---|
| 657 | goto no_more_push_2; |
---|
| 658 | } else { |
---|
| 659 | excess -= rem; |
---|
[628] | 660 | (*_excess)[v] += rem; |
---|
[404] | 661 | _flow->set(e, (*_capacity)[e]); |
---|
| 662 | } |
---|
| 663 | } else if (new_level > (*_level)[v]) { |
---|
| 664 | new_level = (*_level)[v]; |
---|
| 665 | } |
---|
| 666 | } |
---|
| 667 | |
---|
| 668 | for (InArcIt e(_graph, n); e != INVALID; ++e) { |
---|
[688] | 669 | Value rem = (*_flow)[e]; |
---|
[404] | 670 | if (!_tolerance.positive(rem)) continue; |
---|
| 671 | Node v = _graph.source(e); |
---|
| 672 | if ((*_level)[v] < level) { |
---|
| 673 | if (!_level->active(v) && v != _target) { |
---|
| 674 | _level->activate(v); |
---|
| 675 | } |
---|
| 676 | if (!_tolerance.less(rem, excess)) { |
---|
| 677 | _flow->set(e, (*_flow)[e] - excess); |
---|
[628] | 678 | (*_excess)[v] += excess; |
---|
[404] | 679 | excess = 0; |
---|
| 680 | goto no_more_push_2; |
---|
| 681 | } else { |
---|
| 682 | excess -= rem; |
---|
[628] | 683 | (*_excess)[v] += rem; |
---|
[404] | 684 | _flow->set(e, 0); |
---|
| 685 | } |
---|
| 686 | } else if (new_level > (*_level)[v]) { |
---|
| 687 | new_level = (*_level)[v]; |
---|
| 688 | } |
---|
| 689 | } |
---|
| 690 | |
---|
| 691 | no_more_push_2: |
---|
| 692 | |
---|
[628] | 693 | (*_excess)[n] = excess; |
---|
[404] | 694 | |
---|
| 695 | if (excess != 0) { |
---|
| 696 | if (new_level + 1 < _level->maxLevel()) { |
---|
| 697 | _level->liftActiveOn(level, new_level + 1); |
---|
| 698 | } else { |
---|
| 699 | _level->liftActiveToTop(level); |
---|
| 700 | } |
---|
| 701 | if (_level->emptyLevel(level)) { |
---|
| 702 | _level->liftToTop(level); |
---|
| 703 | } |
---|
| 704 | } else { |
---|
| 705 | _level->deactivate(n); |
---|
| 706 | } |
---|
| 707 | |
---|
| 708 | while (level >= 0 && _level->activeFree(level)) { |
---|
| 709 | --level; |
---|
| 710 | } |
---|
| 711 | if (level == -1) { |
---|
| 712 | n = _level->highestActive(); |
---|
| 713 | level = _level->highestActiveLevel(); |
---|
| 714 | } else { |
---|
| 715 | n = _level->activeOn(level); |
---|
| 716 | } |
---|
| 717 | --num; |
---|
| 718 | } |
---|
| 719 | } |
---|
| 720 | } |
---|
| 721 | |
---|
| 722 | /// \brief Starts the second phase of the preflow algorithm. |
---|
| 723 | /// |
---|
| 724 | /// The preflow algorithm consists of two phases, this method runs |
---|
[408] | 725 | /// the second phase. After calling one of the \ref init() functions |
---|
| 726 | /// and \ref startFirstPhase() and then \ref startSecondPhase(), |
---|
| 727 | /// \ref flowMap() returns a maximum flow, \ref flowValue() returns the |
---|
[404] | 728 | /// value of a maximum flow, \ref minCut() returns a minimum cut |
---|
[408] | 729 | /// \pre One of the \ref init() functions and \ref startFirstPhase() |
---|
| 730 | /// must be called before using this function. |
---|
[404] | 731 | void startSecondPhase() { |
---|
| 732 | _phase = false; |
---|
| 733 | |
---|
| 734 | typename Digraph::template NodeMap<bool> reached(_graph); |
---|
| 735 | for (NodeIt n(_graph); n != INVALID; ++n) { |
---|
[628] | 736 | reached[n] = (*_level)[n] < _level->maxLevel(); |
---|
[404] | 737 | } |
---|
| 738 | |
---|
| 739 | _level->initStart(); |
---|
| 740 | _level->initAddItem(_source); |
---|
| 741 | |
---|
| 742 | std::vector<Node> queue; |
---|
| 743 | queue.push_back(_source); |
---|
[628] | 744 | reached[_source] = true; |
---|
[404] | 745 | |
---|
| 746 | while (!queue.empty()) { |
---|
| 747 | _level->initNewLevel(); |
---|
| 748 | std::vector<Node> nqueue; |
---|
| 749 | for (int i = 0; i < int(queue.size()); ++i) { |
---|
| 750 | Node n = queue[i]; |
---|
| 751 | for (OutArcIt e(_graph, n); e != INVALID; ++e) { |
---|
| 752 | Node v = _graph.target(e); |
---|
| 753 | if (!reached[v] && _tolerance.positive((*_flow)[e])) { |
---|
[628] | 754 | reached[v] = true; |
---|
[404] | 755 | _level->initAddItem(v); |
---|
| 756 | nqueue.push_back(v); |
---|
| 757 | } |
---|
| 758 | } |
---|
| 759 | for (InArcIt e(_graph, n); e != INVALID; ++e) { |
---|
| 760 | Node u = _graph.source(e); |
---|
| 761 | if (!reached[u] && |
---|
| 762 | _tolerance.positive((*_capacity)[e] - (*_flow)[e])) { |
---|
[628] | 763 | reached[u] = true; |
---|
[404] | 764 | _level->initAddItem(u); |
---|
| 765 | nqueue.push_back(u); |
---|
| 766 | } |
---|
| 767 | } |
---|
| 768 | } |
---|
| 769 | queue.swap(nqueue); |
---|
| 770 | } |
---|
| 771 | _level->initFinish(); |
---|
| 772 | |
---|
| 773 | for (NodeIt n(_graph); n != INVALID; ++n) { |
---|
| 774 | if (!reached[n]) { |
---|
| 775 | _level->dirtyTopButOne(n); |
---|
| 776 | } else if ((*_excess)[n] > 0 && _target != n) { |
---|
| 777 | _level->activate(n); |
---|
| 778 | } |
---|
| 779 | } |
---|
| 780 | |
---|
| 781 | Node n; |
---|
| 782 | while ((n = _level->highestActive()) != INVALID) { |
---|
[688] | 783 | Value excess = (*_excess)[n]; |
---|
[404] | 784 | int level = _level->highestActiveLevel(); |
---|
| 785 | int new_level = _level->maxLevel(); |
---|
| 786 | |
---|
| 787 | for (OutArcIt e(_graph, n); e != INVALID; ++e) { |
---|
[688] | 788 | Value rem = (*_capacity)[e] - (*_flow)[e]; |
---|
[404] | 789 | if (!_tolerance.positive(rem)) continue; |
---|
| 790 | Node v = _graph.target(e); |
---|
| 791 | if ((*_level)[v] < level) { |
---|
| 792 | if (!_level->active(v) && v != _source) { |
---|
| 793 | _level->activate(v); |
---|
| 794 | } |
---|
| 795 | if (!_tolerance.less(rem, excess)) { |
---|
| 796 | _flow->set(e, (*_flow)[e] + excess); |
---|
[628] | 797 | (*_excess)[v] += excess; |
---|
[404] | 798 | excess = 0; |
---|
| 799 | goto no_more_push; |
---|
| 800 | } else { |
---|
| 801 | excess -= rem; |
---|
[628] | 802 | (*_excess)[v] += rem; |
---|
[404] | 803 | _flow->set(e, (*_capacity)[e]); |
---|
| 804 | } |
---|
| 805 | } else if (new_level > (*_level)[v]) { |
---|
| 806 | new_level = (*_level)[v]; |
---|
| 807 | } |
---|
| 808 | } |
---|
| 809 | |
---|
| 810 | for (InArcIt e(_graph, n); e != INVALID; ++e) { |
---|
[688] | 811 | Value rem = (*_flow)[e]; |
---|
[404] | 812 | if (!_tolerance.positive(rem)) continue; |
---|
| 813 | Node v = _graph.source(e); |
---|
| 814 | if ((*_level)[v] < level) { |
---|
| 815 | if (!_level->active(v) && v != _source) { |
---|
| 816 | _level->activate(v); |
---|
| 817 | } |
---|
| 818 | if (!_tolerance.less(rem, excess)) { |
---|
| 819 | _flow->set(e, (*_flow)[e] - excess); |
---|
[628] | 820 | (*_excess)[v] += excess; |
---|
[404] | 821 | excess = 0; |
---|
| 822 | goto no_more_push; |
---|
| 823 | } else { |
---|
| 824 | excess -= rem; |
---|
[628] | 825 | (*_excess)[v] += rem; |
---|
[404] | 826 | _flow->set(e, 0); |
---|
| 827 | } |
---|
| 828 | } else if (new_level > (*_level)[v]) { |
---|
| 829 | new_level = (*_level)[v]; |
---|
| 830 | } |
---|
| 831 | } |
---|
| 832 | |
---|
| 833 | no_more_push: |
---|
| 834 | |
---|
[628] | 835 | (*_excess)[n] = excess; |
---|
[404] | 836 | |
---|
| 837 | if (excess != 0) { |
---|
| 838 | if (new_level + 1 < _level->maxLevel()) { |
---|
| 839 | _level->liftHighestActive(new_level + 1); |
---|
| 840 | } else { |
---|
| 841 | // Calculation error |
---|
| 842 | _level->liftHighestActiveToTop(); |
---|
| 843 | } |
---|
| 844 | if (_level->emptyLevel(level)) { |
---|
| 845 | // Calculation error |
---|
| 846 | _level->liftToTop(level); |
---|
| 847 | } |
---|
| 848 | } else { |
---|
| 849 | _level->deactivate(n); |
---|
| 850 | } |
---|
| 851 | |
---|
| 852 | } |
---|
| 853 | } |
---|
| 854 | |
---|
| 855 | /// \brief Runs the preflow algorithm. |
---|
| 856 | /// |
---|
| 857 | /// Runs the preflow algorithm. |
---|
| 858 | /// \note pf.run() is just a shortcut of the following code. |
---|
| 859 | /// \code |
---|
| 860 | /// pf.init(); |
---|
| 861 | /// pf.startFirstPhase(); |
---|
| 862 | /// pf.startSecondPhase(); |
---|
| 863 | /// \endcode |
---|
| 864 | void run() { |
---|
| 865 | init(); |
---|
| 866 | startFirstPhase(); |
---|
| 867 | startSecondPhase(); |
---|
| 868 | } |
---|
| 869 | |
---|
| 870 | /// \brief Runs the preflow algorithm to compute the minimum cut. |
---|
| 871 | /// |
---|
| 872 | /// Runs the preflow algorithm to compute the minimum cut. |
---|
| 873 | /// \note pf.runMinCut() is just a shortcut of the following code. |
---|
| 874 | /// \code |
---|
| 875 | /// pf.init(); |
---|
| 876 | /// pf.startFirstPhase(); |
---|
| 877 | /// \endcode |
---|
| 878 | void runMinCut() { |
---|
| 879 | init(); |
---|
| 880 | startFirstPhase(); |
---|
| 881 | } |
---|
| 882 | |
---|
| 883 | /// @} |
---|
| 884 | |
---|
| 885 | /// \name Query Functions |
---|
[408] | 886 | /// The results of the preflow algorithm can be obtained using these |
---|
[404] | 887 | /// functions.\n |
---|
[408] | 888 | /// Either one of the \ref run() "run*()" functions or one of the |
---|
| 889 | /// \ref startFirstPhase() "start*()" functions should be called |
---|
| 890 | /// before using them. |
---|
[404] | 891 | |
---|
| 892 | ///@{ |
---|
| 893 | |
---|
| 894 | /// \brief Returns the value of the maximum flow. |
---|
| 895 | /// |
---|
| 896 | /// Returns the value of the maximum flow by returning the excess |
---|
[408] | 897 | /// of the target node. This value equals to the value of |
---|
| 898 | /// the maximum flow already after the first phase of the algorithm. |
---|
| 899 | /// |
---|
| 900 | /// \pre Either \ref run() or \ref init() must be called before |
---|
| 901 | /// using this function. |
---|
[688] | 902 | Value flowValue() const { |
---|
[404] | 903 | return (*_excess)[_target]; |
---|
| 904 | } |
---|
| 905 | |
---|
[688] | 906 | /// \brief Returns the flow value on the given arc. |
---|
[404] | 907 | /// |
---|
[688] | 908 | /// Returns the flow value on the given arc. This method can |
---|
[408] | 909 | /// be called after the second phase of the algorithm. |
---|
| 910 | /// |
---|
| 911 | /// \pre Either \ref run() or \ref init() must be called before |
---|
| 912 | /// using this function. |
---|
[688] | 913 | Value flow(const Arc& arc) const { |
---|
[408] | 914 | return (*_flow)[arc]; |
---|
| 915 | } |
---|
| 916 | |
---|
| 917 | /// \brief Returns a const reference to the flow map. |
---|
| 918 | /// |
---|
| 919 | /// Returns a const reference to the arc map storing the found flow. |
---|
| 920 | /// This method can be called after the second phase of the algorithm. |
---|
| 921 | /// |
---|
| 922 | /// \pre Either \ref run() or \ref init() must be called before |
---|
| 923 | /// using this function. |
---|
[437] | 924 | const FlowMap& flowMap() const { |
---|
[408] | 925 | return *_flow; |
---|
| 926 | } |
---|
| 927 | |
---|
| 928 | /// \brief Returns \c true when the node is on the source side of the |
---|
| 929 | /// minimum cut. |
---|
| 930 | /// |
---|
| 931 | /// Returns true when the node is on the source side of the found |
---|
| 932 | /// minimum cut. This method can be called both after running \ref |
---|
[404] | 933 | /// startFirstPhase() and \ref startSecondPhase(). |
---|
[408] | 934 | /// |
---|
| 935 | /// \pre Either \ref run() or \ref init() must be called before |
---|
| 936 | /// using this function. |
---|
[404] | 937 | bool minCut(const Node& node) const { |
---|
| 938 | return ((*_level)[node] == _level->maxLevel()) == _phase; |
---|
| 939 | } |
---|
| 940 | |
---|
[408] | 941 | /// \brief Gives back a minimum value cut. |
---|
[404] | 942 | /// |
---|
[408] | 943 | /// Sets \c cutMap to the characteristic vector of a minimum value |
---|
| 944 | /// cut. \c cutMap should be a \ref concepts::WriteMap "writable" |
---|
| 945 | /// node map with \c bool (or convertible) value type. |
---|
| 946 | /// |
---|
| 947 | /// This method can be called both after running \ref startFirstPhase() |
---|
| 948 | /// and \ref startSecondPhase(). The result after the second phase |
---|
| 949 | /// could be slightly different if inexact computation is used. |
---|
| 950 | /// |
---|
| 951 | /// \note This function calls \ref minCut() for each node, so it runs in |
---|
[606] | 952 | /// O(n) time. |
---|
[408] | 953 | /// |
---|
| 954 | /// \pre Either \ref run() or \ref init() must be called before |
---|
| 955 | /// using this function. |
---|
[404] | 956 | template <typename CutMap> |
---|
| 957 | void minCutMap(CutMap& cutMap) const { |
---|
| 958 | for (NodeIt n(_graph); n != INVALID; ++n) { |
---|
| 959 | cutMap.set(n, minCut(n)); |
---|
| 960 | } |
---|
| 961 | } |
---|
| 962 | |
---|
| 963 | /// @} |
---|
| 964 | }; |
---|
| 965 | } |
---|
| 966 | |
---|
| 967 | #endif |
---|