public void ReducePathDistance(IVertexDistanceMatrix distances, IVertex source, IVertex target, IVertex intermediate)
 {
     if (distances.Distance(source, target) == 0.0)
     {
         distances.SetDistance(source, target, Convert.ToDouble((distances.Distance(source, intermediate) != 0.0) && (distances.Distance(intermediate, target) != 0.0)));
     }
 }
 public void ReducePathDistance(IVertexDistanceMatrix distances, IVertex source, IVertex target, IVertex intermediate)
 {
     if ((source == target) && (distances.Distance(source, target) < 0.0))
     {
         throw new Exception("Negative cycle");
     }
 }
Exemple #3
0
 public void ReducePathDistance(
     IVertexDistanceMatrix distances,
     IVertex source,
     IVertex target,
     IVertex intermediate
     )
 {
     if (source == target && distances.Distance(source, target) < 0)
     {
         throw new Exception(@"Negative cycle");
     }
 }
 public void ReducePathDistance(
     IVertexDistanceMatrix distances,
     IVertex source,
     IVertex target,
     IVertex intermediate
     )
 {
     distances.SetDistance(source,target,
         distances.Distance(source,intermediate)
         + distances.Distance(intermediate,target)
         );
 }
 public void ReducePathDistance(
     IVertexDistanceMatrix distances,
     IVertex source,
     IVertex target,
     IVertex intermediate
     )
 {
     distances.SetDistance(source, target,
                           distances.Distance(source, intermediate)
                           + distances.Distance(intermediate, target)
                           );
 }
Exemple #6
0
 public bool TestDistance(
     IVertexDistanceMatrix distances,
     IVertex source,
     IVertex target,
     IVertex intermediate
     )
 {
     return
         (distances.Distance(source, intermediate)
          + distances.Distance(intermediate, target)
          < distances.Distance(source, target));
 }
 public FloydWarshallDistanceTester(IVertexDistanceMatrix distances, IFloydWarshallDistanceTester tester)
 {
     if (distances == null)
     {
         throw new ArgumentNullException("distances");
     }
     if (tester == null)
     {
         throw new ArgumentNullException("tester");
     }
     this.distances = distances;
     this.tester = tester;
 }
 public void ReducePathDistance(
     IVertexDistanceMatrix distances,
     IVertex source,
     IVertex target,
     IVertex intermediate
     )
 {
     if (distances.Distance(source, target) == 0)
     {
         distances.SetDistance(source, target,
                               Convert.ToDouble(
                                   (distances.Distance(source, intermediate) != 0) &&
                                   (distances.Distance(intermediate, target) != 0)
                                   )
                               );
     }
 }
        public FloydWarshallDistanceTester(
            IVertexDistanceMatrix distances,
            IFloydWarshallDistanceTester tester
            )
        {
            if (distances == null)
            {
                throw new ArgumentNullException(@"distances");
            }
            if (tester == null)
            {
                throw new ArgumentNullException(@"tester");
            }

            this.distances = distances;
            this.tester    = tester;
        }
        /// <summary>
        /// Checks the graph for connectivity and negative cycles
        /// </summary>
        /// <param name="costs">cost distionary</param>
        /// <exception cref="NegativeCycleException">graph has negatice cycle.</exception>
        /// <exception cref="GraphNotStronglyConnectedException">graph is not strongly connected</exception>
        public void CheckConnectivityAndNegativeCycles(IVertexDistanceMatrix costs)
        {
            foreach (IVertex u in VisitedGraph.Vertices)
            {
                if (costs != null && costs.Distance(u, u) < 0)
                {
                    throw new NegativeCycleException("Graph has negative cycle");
                }

                foreach (IVertex v in VisitedGraph.Vertices)
                {
                    if (!DefinedPaths.Contains(new VertexPair(u, v)))
                    {
                        throw new Exception("Graph is not strongly connected");
                    }
                }
            }
        }
 public void CheckConnectivityAndNegativeCycles(IVertexDistanceMatrix costs)
 {
     IVertexEnumerator enumerator = this.VisitedGraph.get_Vertices().GetEnumerator();
     while (enumerator.MoveNext())
     {
         IVertex vertex = enumerator.get_Current();
         if ((costs != null) && (costs.Distance(vertex, vertex) < 0.0))
         {
             throw new NegativeCycleException("Graph has negative cycle");
         }
         IVertexEnumerator enumerator2 = this.VisitedGraph.get_Vertices().GetEnumerator();
         while (enumerator2.MoveNext())
         {
             IVertex vertex2 = enumerator2.get_Current();
             if (!this.DefinedPaths.Contains(new VertexPair(vertex, vertex2)))
             {
                 throw new Exception("Graph is not strongly connected");
             }
         }
     }
 }
        /// <summary>
        /// Checks the graph for connectivity and negative cycles
        /// </summary>
        /// <param name="costs">cost distionary</param>
        /// <exception cref="NegativeCycleException">graph has negatice cycle.</exception>
        /// <exception cref="GraphNotStronglyConnectedException">graph is not strongly connected</exception>
        public void CheckConnectivityAndNegativeCycles(IVertexDistanceMatrix costs)
        {
            foreach(IVertex u in VisitedGraph.Vertices)
            {
                if( costs!=null && costs.Distance(u,u) < 0 )
                    throw new NegativeCycleException("Graph has negative cycle");

                foreach(IVertex v in VisitedGraph.Vertices)
                    if(!DefinedPaths.Contains(new VertexPair(u,v)))
                        throw new Exception("Graph is not strongly connected");
            }
        }
 public bool TestDistance(IVertexDistanceMatrix distances, IVertex source, IVertex target, IVertex intermediate)
 {
     return ((distances.Distance(source, intermediate) + distances.Distance(intermediate, target)) < distances.Distance(source, target));
 }