Exemple #1
0
        /**
         * {@inheritDoc}
         */
        public GraphPath <V, E> getPath(V targetVertex)
        {
            if (source.Equals(targetVertex))
            {
                return(GraphWalk <V, E> .singletonWalk(g, source, 0d));
            }

            List <E> edgeList = new List <E>();

            V cur = targetVertex;
            KeyValuePair <Double, E> p;
            bool find = map.TryGetValue(cur, out p);

            if (!find || p.Key.Equals(Double.PositiveInfinity))
            {
                return(null);
            }

            double weight = 0d;

            while (find && !p.Equals(source))
            {
                E e = p.Value;
                if (e == null)
                {
                    break;
                }
                edgeList.Insert(0, e);
                weight += g.getEdgeWeight(e);
                cur     = Graphs.getOppositeVertex(g, e, cur);
                find    = map.TryGetValue(cur, out p);
            }

            return(new GraphWalk <V, E>(g, source, targetVertex, null, edgeList, weight));
        }
 /**
  * Create an empty path. Returns null if the source vertex is different than the target vertex.
  *
  * @param source the source vertex
  * @param sink the sink vertex
  * @return an empty path or null null if the source vertex is different than the target vertex
  */
 protected GraphPath <V, E> createEmptyPath(V source, V sink)
 {
     if (source.Equals(sink))
     {
         return(GraphWalk <V, E> .singletonWalk(graph, source, 0d));
     }
     else
     {
         return(null);
     }
 }
Exemple #3
0
        /**
         * {@inheritDoc}
         */
        public GraphPath <V, E> getPath(V targetVertex)
        {
            GraphPath <V, E> p = paths[targetVertex];

            if (p == null)
            {
                if (source.Equals(targetVertex))
                {
                    return(GraphWalk <V, E> .singletonWalk(graph, source, 0d));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(p);
            }
        }