throwing an exception if s=t
authorjacint
Fri, 04 Nov 2005 13:53:22 +0000
changeset 17623915867b6975
parent 1761 896464fe9fbb
child 1763 49045f2d28d4
throwing an exception if s=t
lemon/preflow.h
     1.1 --- a/lemon/preflow.h	Fri Nov 04 13:20:24 2005 +0000
     1.2 +++ b/lemon/preflow.h	Fri Nov 04 13:53:22 2005 +0000
     1.3 @@ -20,6 +20,7 @@
     1.4  #include <vector>
     1.5  #include <queue>
     1.6  
     1.7 +#include <lemon/error.h>
     1.8  #include <lemon/invalid.h>
     1.9  #include <lemon/maps.h>
    1.10  #include <lemon/graph_utils.h>
    1.11 @@ -88,10 +89,21 @@
    1.12      static const int H0=20;
    1.13      static const int H1=1;
    1.14  
    1.15 +  public:
    1.16 +
    1.17 +    ///\ref Exception for the case when s=t.
    1.18 +
    1.19 +    ///\ref Exception for the case when the source equals the target.
    1.20 +    class InvalidArgument : public lemon::LogicError {
    1.21      public:
    1.22 -
    1.23 +      virtual const char* exceptionName() const {
    1.24 +	return "lemon::Preflow::InvalidArgument";
    1.25 +      }
    1.26 +    };
    1.27 +    
    1.28 +    
    1.29      ///Indicates the property of the starting flow map.
    1.30 -
    1.31 +    
    1.32      ///Indicates the property of the starting flow map.
    1.33      ///The meanings are as follows:
    1.34      ///- \c ZERO_FLOW: constant zero flow
    1.35 @@ -126,8 +138,8 @@
    1.36        AFTER_PREFLOW_PHASE_2
    1.37      };
    1.38      
    1.39 -    protected: 
    1.40 -      FlowEnum flow_prop;
    1.41 +  protected: 
    1.42 +    FlowEnum flow_prop;
    1.43      StatusEnum status; // Do not needle this flag only if necessary.
    1.44      
    1.45    public: 
    1.46 @@ -146,8 +158,11 @@
    1.47  	      const CapacityMap& _cap, FlowMap& _f) :
    1.48  	_g(&_gr), _source(_s), _target(_t), _capacity(&_cap),
    1.49  	_flow(&_f), _node_num(countNodes(_gr)), level(_gr), excess(_gr,0), 
    1.50 -	flow_prop(NO_FLOW), status(AFTER_NOTHING) { }
    1.51 -
    1.52 +	flow_prop(NO_FLOW), status(AFTER_NOTHING) { 
    1.53 +	if ( _source==_target )
    1.54 +	  throw InvalidArgument();
    1.55 +      }
    1.56 +    
    1.57  
    1.58                                                                                
    1.59      ///Runs the preflow algorithm.