Exemplo n.º 1
0
        private static int MinRoutes(IBidirectionalIncidenceGraph <Node, Edge <Node> > grpah, Node source, Node target, IEdge <Node> edge,
                                     int depth = 0)
        {
            Node other;

            if (edge.Target == source)
            {
                other = edge.Source;
            }
            else if (edge.Source == source)
            {
                other = edge.Target;
            }
            else
            {
                throw new InvalidOperationException();
            }
            if (other == target)
            {
                return(++depth);
            }
            if (other == source)
            {
                return(int.MaxValue);
            }
            var lst = new List <Edge <Node> >();

            lst.AddRange(grpah.InEdges(other));
            lst.AddRange(grpah.OutEdges(other));
            return(lst.Min(o => MinRoutes(grpah, other, target, o, ++depth)));
        }
Exemplo n.º 2
0
        private int Routes(IBidirectionalIncidenceGraph <Node, Edge <Node> > grpah, Node a, IEdge <Node> be, int depth = 0)
        {
            var other = be.Target == a ? be.Source : be.Target;
            var lst   = new List <KeyValuePair <int, Edge <Node> > >();

            foreach (var c in grpah.InEdges(a))
            {
                if (c.Source == other)
                {
                    return(++depth);
                }
                lst.Add(new KeyValuePair <int, Edge <Node> >(Routes(grpah, c.Source, c, depth), c));
            }

            foreach (var c in grpah.OutEdges(a))
            {
                if (c.Target == other)
                {
                    return(++depth);
                }
                lst.Add(new KeyValuePair <int, Edge <Node> >(Routes(grpah, c.Target, c, depth), c));
            }

            return(lst.Select(o => o.Key).Min());
        }