private void ReportCycle(TNode node, AbstractDiGraph <TNode> graph) { var cycle = new GraphPath <TNode>(); _allcycles.Add(cycle); cycle.SourceNode = node; cycle.DestinationNode = node; cycle.Path = new List <TNode>(); List <TNode> stacklist = _vStack.ToList(); int i = 0; while (!stacklist[i].Equals(node)) { i++; } for (; i >= 0; i--) { cycle.Path.Add(stacklist[i]); } cycle.Path.Add(node); cycle.PathWeight = 0; for (int j = 1; j < cycle.Path.Count; j++) { cycle.PathWeight += graph.GetEdgeWeight(cycle.Path[j - 1], cycle.Path[j]); } }
private void Reportpath(TNode node, TNode dnode, AbstractDiGraph <TNode> graph) { var path = new GraphPath <TNode>(); _allpaths.Add(path); path.SourceNode = node; path.DestinationNode = dnode; path.Path = new List <TNode>(); List <TNode> stacklist = _vStack.ToList(); int i = 0; while (!stacklist[i].Equals(node)) { i++; } for (; i >= 0; i--) { path.Path.Add(stacklist[i]); } path.Path.Add(dnode); path.PathWeight = 0; for (int j = 1; j < path.Path.Count; j++) { path.PathWeight += graph.GetEdgeWeight(path.Path[j - 1], path.Path[j]); } }
public List <AbstractGraphPath <TNode> > FindCycles(List <DepthFirstSearchEdge <TNode> > depthFirstSearchEdges, TNode sourceVertex, int maxStops) { var cycles = new List <AbstractGraphPath <TNode> >(); foreach ( var allDFSBackEdges in depthFirstSearchEdges.Where(x => x.EdgeType == DepthFirstSearchEdgeType.BackEdge) ) { var sourceNode = allDFSBackEdges.DestinationNode; foreach ( var backEdge in depthFirstSearchEdges.Where( x => x.EdgeType == DepthFirstSearchEdgeType.BackEdge && x.DestinationNode.Equals(sourceNode)) ) { var cycle = new GraphPath <TNode>() { SourceNode = sourceNode, DestinationNode = sourceNode }; cycle.Path = new List <TNode>() { sourceNode }; cycle.PathWeight = 0; var treeEdges = depthFirstSearchEdges.Where(x => x.EdgeType == DepthFirstSearchEdgeType.TreeEdge); var treeEdge = treeEdges.Single(x => x.SourceNode.Equals(sourceNode)); int nodeCounter = 2; while (!treeEdge.DestinationNode.Equals(backEdge.SourceNode) && !IsMaxNodeLimitReached(maxStops, nodeCounter)) { cycle.PathWeight += treeEdge.EdgeWeight; cycle.Path.Add(treeEdge.DestinationNode) ; treeEdge = treeEdges.Single(x => x.SourceNode.Equals(treeEdge.DestinationNode)); } cycle.Path.Add(backEdge.SourceNode); cycle.Path.Add(backEdge.DestinationNode); cycle.PathWeight += backEdge.EdgeWeight; if (!IsMaxNodeLimitReached(maxStops, nodeCounter)) { cycles.Add(cycle); } } } return(cycles); }
private void Initialise(AbstractDiGraph <TNode> graph, TNode sourceNode) { foreach (var node in graph.AllNodes.Where(x => !x.Equals(sourceNode))) { var shortestPathNode = new GraphPath <TNode>(); shortestPathNode.DestinationNode = node; shortestPathNode.PathWeight = Infinity; shortestPathNode.SourceNode = sourceNode; _estimatedDistances.Add(node, shortestPathNode); _shortestPathUnKnownNodesQueue.Add(shortestPathNode); } //Source Node Initialise _estimatedDistances.Add(sourceNode, new GraphPath <TNode>() { DestinationNode = sourceNode, SourceNode = sourceNode }); _estimatedDistances[sourceNode].PathWeight = 0; _shortestPathKnownNodes.Add(sourceNode); }