gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Small improvements for NetworkSimplex (#298)
0 1 0
default
1 file changed with 2 insertions and 15 deletions:
↑ Collapse diff ↑
Ignore white space 24 line context
... ...
@@ -152,26 +152,24 @@
152 152

	
153 153
      /// The Altering Candidate List pivot rule.
154 154
      /// It is a modified version of the Candidate List method.
155 155
      /// It keeps only the several best eligible arcs from the former
156 156
      /// candidate list and extends this list in every iteration.
157 157
      ALTERING_LIST
158 158
    };
159 159
    
160 160
  private:
161 161

	
162 162
    TEMPLATE_DIGRAPH_TYPEDEFS(GR);
163 163

	
164
    typedef std::vector<Arc> ArcVector;
165
    typedef std::vector<Node> NodeVector;
166 164
    typedef std::vector<int> IntVector;
167 165
    typedef std::vector<bool> BoolVector;
168 166
    typedef std::vector<Value> ValueVector;
169 167
    typedef std::vector<Cost> CostVector;
170 168

	
171 169
    // State constants for arcs
172 170
    enum ArcStateEnum {
173 171
      STATE_UPPER = -1,
174 172
      STATE_TREE  =  0,
175 173
      STATE_LOWER =  1
176 174
    };
177 175

	
... ...
@@ -676,35 +674,26 @@
676 674
      for (NodeIt n(_graph); n != INVALID; ++n, ++i) {
677 675
        _node_id[n] = i;
678 676
      }
679 677
      int k = std::max(int(std::sqrt(double(_arc_num))), 10);
680 678
      i = 0;
681 679
      for (ArcIt a(_graph); a != INVALID; ++a) {
682 680
        _arc_id[a] = i;
683 681
        _source[i] = _node_id[_graph.source(a)];
684 682
        _target[i] = _node_id[_graph.target(a)];
685 683
        if ((i += k) >= _arc_num) i = (i % k) + 1;
686 684
      }
687 685
      
688
      // Initialize maps
689
      for (int i = 0; i != _node_num; ++i) {
690
        _supply[i] = 0;
691
      }
692
      for (int i = 0; i != _arc_num; ++i) {
693
        _lower[i] = 0;
694
        _upper[i] = INF;
695
        _cost[i] = 1;
696
      }
697
      _have_lower = false;
698
      _stype = GEQ;
686
      // Reset parameters
687
      reset();
699 688
    }
700 689

	
701 690
    /// \name Parameters
702 691
    /// The parameters of the algorithm can be specified using these
703 692
    /// functions.
704 693

	
705 694
    /// @{
706 695

	
707 696
    /// \brief Set the lower bounds on the arcs.
708 697
    ///
709 698
    /// This function sets the lower bounds on the arcs.
710 699
    /// If it is not used before calling \ref run(), the lower bounds
... ...
@@ -759,46 +748,44 @@
759 748
    NetworkSimplex& costMap(const CostMap& map) {
760 749
      for (ArcIt a(_graph); a != INVALID; ++a) {
761 750
        _cost[_arc_id[a]] = map[a];
762 751
      }
763 752
      return *this;
764 753
    }
765 754

	
766 755
    /// \brief Set the supply values of the nodes.
767 756
    ///
768 757
    /// This function sets the supply values of the nodes.
769 758
    /// If neither this function nor \ref stSupply() is used before
770 759
    /// calling \ref run(), the supply of each node will be set to zero.
771
    /// (It makes sense only if non-zero lower bounds are given.)
772 760
    ///
773 761
    /// \param map A node map storing the supply values.
774 762
    /// Its \c Value type must be convertible to the \c Value type
775 763
    /// of the algorithm.
776 764
    ///
777 765
    /// \return <tt>(*this)</tt>
778 766
    template<typename SupplyMap>
779 767
    NetworkSimplex& supplyMap(const SupplyMap& map) {
780 768
      for (NodeIt n(_graph); n != INVALID; ++n) {
781 769
        _supply[_node_id[n]] = map[n];
782 770
      }
783 771
      return *this;
784 772
    }
785 773

	
786 774
    /// \brief Set single source and target nodes and a supply value.
787 775
    ///
788 776
    /// This function sets a single source node and a single target node
789 777
    /// and the required flow value.
790 778
    /// If neither this function nor \ref supplyMap() is used before
791 779
    /// calling \ref run(), the supply of each node will be set to zero.
792
    /// (It makes sense only if non-zero lower bounds are given.)
793 780
    ///
794 781
    /// Using this function has the same effect as using \ref supplyMap()
795 782
    /// with such a map in which \c k is assigned to \c s, \c -k is
796 783
    /// assigned to \c t and all other nodes have zero supply value.
797 784
    ///
798 785
    /// \param s The source node.
799 786
    /// \param t The target node.
800 787
    /// \param k The required amount of flow from node \c s to node \c t
801 788
    /// (i.e. the supply of \c s and the demand of \c t).
802 789
    ///
803 790
    /// \return <tt>(*this)</tt>
804 791
    NetworkSimplex& stSupply(const Node& s, const Node& t, Value k) {
0 comments (0 inline)