示例#1
0
        private LinkedList <WeightedAdjacencyNode <T> > MakePath(Graph <T> graph, WeightedAdjacencyNode <T> startingPoint)
        {
            var path        = new LinkedList <WeightedAdjacencyNode <T> >(new [] { startingPoint });
            var currentNode = startingPoint.Vertex;

            while (true)
            {
                var nextVertexAdjancencyNode = GetNextVertex(graph, currentNode);
                if (nextVertexAdjancencyNode == null)
                {
                    break;
                }

                path.AddLast(new WeightedAdjacencyNode <T>(nextVertexAdjancencyNode.Vertex, nextVertexAdjancencyNode.Distance, 0, nextVertexAdjancencyNode.MustHit));
                graph.ReduceEdgeCardinality(nextVertexAdjancencyNode.Vertex, currentNode);
                currentNode = nextVertexAdjancencyNode.Vertex;
            }

            if (!path.First.Value.Vertex.Equals(path.Last.Value.Vertex))
            {
                throw new InvalidOperationException(
                          "Found a path that didn't start/end at same time. This implies that there are vertices with odd edge counts.");
            }

            return(path);
        }
示例#2
0
        /// <summary>
        /// Follow available paths until one returns to the starting point, using each edge at most as many
        /// times as its cardinality.
        /// </summary>
        /// <param name="graph"></param>
        /// <param name="startingPoint"></param>
        /// <returns></returns>
        private LinkedList <WeightedAdjacencyNode <T> > MakePath(Graph <T> graph, T startingPoint)
        {
            var wan = new WeightedAdjacencyNode <T>(startingPoint, 0, 0, true);

            return(MakePath(graph, wan));
        }