Exemple #1
0
        public void ComputeCriticalPath <TVertex, TEdge>(
            IVertexListGraph <TVertex, TEdge> g)
            where TEdge : IEdge <TVertex>
        {
            // is this a dag ?
            bool isDag = g.IsDirectedAcyclicGraph();

            var relaxer  = DistanceRelaxers.CriticalDistance;
            var vertices = new List <TVertex>(g.Vertices);

            foreach (var root in vertices)
            {
                if (isDag)
                {
                    Search(g, root, relaxer);
                }
                else
                {
                    try
                    {
                        Search(g, root, relaxer);
                        Assert.Fail("should have found the acyclic graph");
                    }
                    catch (NonAcyclicGraphException)
                    {
                        Console.WriteLine("NonAcyclicGraphException caught (as expected)");
                    }
                }
            }
        }
        private static void Compute <TVertex, TEdge>([NotNull] IVertexListGraph <TVertex, TEdge> graph)
            where TEdge : IEdge <TVertex>
        {
            // Is this a dag?
            bool             isDag   = graph.IsDirectedAcyclicGraph();
            IDistanceRelaxer relaxer = DistanceRelaxers.ShortestDistance;
            var vertices             = new List <TVertex>(graph.Vertices);

            foreach (TVertex root in vertices)
            {
                if (isDag)
                {
                    Search(graph, root, relaxer);
                }
                else
                {
                    Assert.Throws <NonAcyclicGraphException>(() => Search(graph, root, relaxer));
                }
            }
        }
Exemple #3
0
        private static void DagAlgorithm_Test <TVertex, TEdge>(
            [NotNull] IVertexListGraph <TVertex, TEdge> graph,
            [NotNull] IDistanceRelaxer relaxer)
            where TEdge : IEdge <TVertex>
        {
            // Is this a dag?
            bool isDag = graph.IsDirectedAcyclicGraph();

            TVertex[] vertices = graph.Vertices.ToArray();
            foreach (TVertex root in vertices)
            {
                if (isDag)
                {
                    RunDagShortestPathAndCheck(graph, root, relaxer);
                }
                else
                {
                    Assert.Throws <NonAcyclicGraphException>(() => RunDagShortestPathAndCheck(graph, root, relaxer));
                }
            }
        }
Exemple #4
0
 private bool HasCycles(IVertexListGraph <IBuilder, EquatableEdge <IBuilder> > graph)
 {
     return(!graph.IsDirectedAcyclicGraph());
 }
Exemple #5
0
 private bool HasCycles(IVertexListGraph<IBuilder, EquatableEdge<IBuilder>> graph)
 {
     return !graph.IsDirectedAcyclicGraph();
 }