Example #1
0
 public Path(SparseGraph <TNode, TEdge> graph, TVal distance, IEnumerable <TEdge> pathEdges)
 {
     Graph     = graph;
     Distance  = distance;
     PathEdges = pathEdges.ToArray();
     if (!IsEmpty)
     {
         From         = PathEdges[0].From;
         To           = PathEdges[PathEdges.Length - 1].To;
         PathNodes    = new TNode[PathEdges.Length + 1];
         PathNodes[0] = PathEdges[0].From;
         for (var i = 0; i < PathEdges.Length; i++)
         {
             PathNodes[i + 1] = PathEdges[i].To;
         }
     }
 }
Example #2
0
        /// <summary>
        /// Creates a graph snapshot with old instances of nodes and new instances of edges
        /// </summary>
        /// <returns>Graph snapshot</returns>
        public SparseGraph <TNode, TNewEdge> GetSnapshot <TNewEdge>(Func <TEdge, TNewEdge> converter) where TNewEdge : Edge <TNode>
        {
            var snapshot = new SparseGraph <TNode, TNewEdge>();

            snapshot._nodes.AddRange(_nodes);
            for (var i = 0; i < NodesCnt; i++)
            {
                snapshot._nodeInEdges.Add(new List <TNewEdge>());
                snapshot._nodeOutEdges.Add(new List <TNewEdge>());
            }
            foreach (var edge in Edges)
            {
                var newEdge = converter(edge);
                if (newEdge != null)
                {
                    snapshot.AddEdge(newEdge);
                }
            }

            return(snapshot);
        }