lemon/cycle_canceling.h
changeset 1103 c0c2f5c87aa6
parent 1102 330264b171cf
child 1104 a78e5b779b69
equal deleted inserted replaced
21:65e912e7d80a 22:156fe9e2a87f
   193     int _res_node_num;
   193     int _res_node_num;
   194     int _res_arc_num;
   194     int _res_arc_num;
   195     int _root;
   195     int _root;
   196 
   196 
   197     // Parameters of the problem
   197     // Parameters of the problem
   198     bool _have_lower;
   198     bool _has_lower;
   199     Value _sum_supply;
   199     Value _sum_supply;
   200 
   200 
   201     // Data structures for storing the digraph
   201     // Data structures for storing the digraph
   202     IntNodeMap _node_id;
   202     IntNodeMap _node_id;
   203     IntArcMap _arc_idf;
   203     IntArcMap _arc_idf;
   276     /// of the algorithm.
   276     /// of the algorithm.
   277     ///
   277     ///
   278     /// \return <tt>(*this)</tt>
   278     /// \return <tt>(*this)</tt>
   279     template <typename LowerMap>
   279     template <typename LowerMap>
   280     CycleCanceling& lowerMap(const LowerMap& map) {
   280     CycleCanceling& lowerMap(const LowerMap& map) {
   281       _have_lower = true;
   281       _has_lower = true;
   282       for (ArcIt a(_graph); a != INVALID; ++a) {
   282       for (ArcIt a(_graph); a != INVALID; ++a) {
   283         _lower[_arc_idf[a]] = map[a];
   283         _lower[_arc_idf[a]] = map[a];
   284       }
   284       }
   285       return *this;
   285       return *this;
   286     }
   286     }
   468         _lower[j] = 0;
   468         _lower[j] = 0;
   469         _upper[j] = INF;
   469         _upper[j] = INF;
   470         _cost[j] = 0;
   470         _cost[j] = 0;
   471         _cost[_reverse[j]] = 0;
   471         _cost[_reverse[j]] = 0;
   472       }
   472       }
   473       _have_lower = false;
   473       _has_lower = false;
   474       return *this;
   474       return *this;
   475     }
   475     }
   476 
   476 
   477     /// \brief Reset the internal data structures and all the parameters
   477     /// \brief Reset the internal data structures and all the parameters
   478     /// that have been given before.
   478     /// that have been given before.
   681       ValueVector excess(_supply);
   681       ValueVector excess(_supply);
   682 
   682 
   683       // Remove infinite upper bounds and check negative arcs
   683       // Remove infinite upper bounds and check negative arcs
   684       const Value MAX = std::numeric_limits<Value>::max();
   684       const Value MAX = std::numeric_limits<Value>::max();
   685       int last_out;
   685       int last_out;
   686       if (_have_lower) {
   686       if (_has_lower) {
   687         for (int i = 0; i != _root; ++i) {
   687         for (int i = 0; i != _root; ++i) {
   688           last_out = _first_out[i+1];
   688           last_out = _first_out[i+1];
   689           for (int j = _first_out[i]; j != last_out; ++j) {
   689           for (int j = _first_out[i]; j != last_out; ++j) {
   690             if (_forward[j]) {
   690             if (_forward[j]) {
   691               Value c = _cost[j] < 0 ? _upper[j] : _lower[j];
   691               Value c = _cost[j] < 0 ? _upper[j] : _lower[j];
   724       ValueArcMap cap(_graph), flow(_graph);
   724       ValueArcMap cap(_graph), flow(_graph);
   725       ValueNodeMap sup(_graph);
   725       ValueNodeMap sup(_graph);
   726       for (NodeIt n(_graph); n != INVALID; ++n) {
   726       for (NodeIt n(_graph); n != INVALID; ++n) {
   727         sup[n] = _supply[_node_id[n]];
   727         sup[n] = _supply[_node_id[n]];
   728       }
   728       }
   729       if (_have_lower) {
   729       if (_has_lower) {
   730         for (ArcIt a(_graph); a != INVALID; ++a) {
   730         for (ArcIt a(_graph); a != INVALID; ++a) {
   731           int j = _arc_idf[a];
   731           int j = _arc_idf[a];
   732           Value c = _lower[j];
   732           Value c = _lower[j];
   733           cap[a] = _upper[j] - c;
   733           cap[a] = _upper[j] - c;
   734           sup[_graph.source(a)] -= c;
   734           sup[_graph.source(a)] -= c;
   832         bf.init(0);
   832         bf.init(0);
   833         bf.start();
   833         bf.start();
   834       }
   834       }
   835 
   835 
   836       // Handle non-zero lower bounds
   836       // Handle non-zero lower bounds
   837       if (_have_lower) {
   837       if (_has_lower) {
   838         int limit = _first_out[_root];
   838         int limit = _first_out[_root];
   839         for (int j = 0; j != limit; ++j) {
   839         for (int j = 0; j != limit; ++j) {
   840           if (_forward[j]) _res_cap[_reverse[j]] += _lower[j];
   840           if (_forward[j]) _res_cap[_reverse[j]] += _lower[j];
   841         }
   841         }
   842       }
   842       }