lemon/floyd_warshall.h
changeset 1741 7a98fe2ed989
parent 1723 fb4f801dd692
child 1754 4bf5ceb49023
     1.1 --- a/lemon/floyd_warshall.h	Mon Oct 24 17:03:02 2005 +0000
     1.2 +++ b/lemon/floyd_warshall.h	Wed Oct 26 10:50:47 2005 +0000
     1.3 @@ -392,9 +392,9 @@
     1.4        for (NodeIt it(*graph); it != INVALID; ++it) {
     1.5  	for (NodeIt jt(*graph); jt != INVALID; ++jt) {
     1.6  	  _pred->set(it, jt, INVALID);
     1.7 -	  _dist->set(it, jt, it == jt ? 
     1.8 -		     OperationTraits::zero() : OperationTraits::infinity());
     1.9 +	  _dist->set(it, jt, OperationTraits::infinity());
    1.10  	}
    1.11 +	_dist->set(it, it, OperationTraits::zero());
    1.12        }
    1.13        for (EdgeIt it(*graph); it != INVALID; ++it) {
    1.14  	Node source = graph->source(it);
    1.15 @@ -427,6 +427,24 @@
    1.16  	}
    1.17        }
    1.18      }
    1.19 +
    1.20 +    /// \brief Executes the algorithm and checks the negative circles.
    1.21 +    ///
    1.22 +    /// This method runs the %FloydWarshall algorithm in order to compute 
    1.23 +    /// the shortest path to each node pairs. If there is a negative circle 
    1.24 +    /// in the graph it gives back false. 
    1.25 +    /// The algorithm computes 
    1.26 +    /// - The shortest path tree for each node.
    1.27 +    /// - The distance between each node pairs.
    1.28 +    bool checkedStart() {
    1.29 +      start();
    1.30 +      for (NodeIt it(*graph); it != INVALID; ++it) {
    1.31 +	if (OperationTraits::less((*dist)(it, it), OperationTraits::zero())) {
    1.32 +	  return false;
    1.33 +	}
    1.34 +      }
    1.35 +      return true;
    1.36 +    }
    1.37      
    1.38      /// \brief Runs %FloydWarshall algorithm.
    1.39      ///