public bool Calculate(GraphTable graph, int fromNode, int toNode) { //_dNodes.Add(new Node(fromNode, 0.0)); Node startNode = _dNodes.ByIdOrAdd(fromNode); if (double.IsNaN(startNode.Dist)) { startNode.Dist = 0.0; } if (_barrierNodeIds != null && _barrierNodeIds.BinarySearch(fromNode) >= 0) { return(true); } bool found = false; int nodeId = fromNode; DistanceNodeStack distStack = new DistanceNodeStack(); distStack.Add(startNode); #region Progress ProgressReport report = new ProgressReport(); report.Message = "Network Calculations..."; report.featureMax = 1000; report.featurePos = 0; #endregion while (true) { //Node minDistNode = _dNodes.MinDistNode(); Node minDistNode = distStack.Pop(); if (minDistNode == null) // Keine Knoten mehr -> Ziel ist nicht ereichbar! { break; } if (minDistNode.Id == toNode) // Ziel mit kürzesten Weg erreicht! { found = true; break; } minDistNode.Used = true; if (minDistNode.Dist >= _maxDistance) { continue; } GraphTableRows graphRows = graph.QueryN1(minDistNode.Id); foreach (GraphTableRow graphRow in graphRows) { if (_applySwitchState && graph.SwitchState(graphRow.N1) == false) { continue; } if (_targetNodeFcIds != null && graphRow.N1 != fromNode && _targetNodeFcIds.Contains(graph.GetNodeFcid(graphRow.N1))) { if (_targetNodeType != null) { NetworkNodeType nodeType = graph.GetNodeType(graphRow.N1); if (nodeType == (NetworkNodeType)_targetNodeType) { continue; } } else { continue; } } if (_allowedNodeIds != null && _allowedNodeIds.BinarySearch(graphRow.N2) < 0) { continue; } if (_forbiddenTargetNodeIds != null && _forbiddenTargetNodeIds.BinarySearch(graphRow.N2) >= 0) { continue; } if (_forbiddenEdgeIds != null && _forbiddenEdgeIds.BinarySearch(graphRow.EID) >= 0) { continue; } if (_forbiddenStartNodeEdgeIds != null && graphRow.N1 == fromNode && _forbiddenStartNodeEdgeIds.BinarySearch(graphRow.EID) >= 0) { continue; } if (_barrierNodeIds != null && _barrierNodeIds.BinarySearch(graphRow.N2) >= 0) { continue; } Node n = _dNodes.ByIdOrAdd(graphRow.N2); double length = graphRow.LENGTH; if (_weight != null) { double weight = graph.QueryEdgeWeight(_weight.Guid, graphRow.EID); switch (_weightApplying) { case WeightApplying.Weight: length /= weight; break; case WeightApplying.ActualCosts: length = weight; break; } } double dist = minDistNode.Dist + length; double geodist = minDistNode.GeoDist + graphRow.LENGTH; if (double.IsNaN(n.Dist) || n.Dist > dist) { if (!double.IsNaN(n.Dist)) { distStack.Remove(n); } n.Dist = dist; n.GeoDist = geodist; n.Pre = minDistNode.Id; n.EId = graphRow.EID; n.Used = false; distStack.Add(n); } } if (_cancelTracker != null && _cancelTracker.Continue == false) { return(false); } if (reportProgress != null && _dNodes.Count % 20 == 0) { report.featurePos += 20; if (report.featurePos > report.featureMax) { // report.featurePos = 0; report.featureMax += 1000; } reportProgress(report); } } return(found); }
public bool Calculate(GraphTable graph, int fromNode) { return(Calculate(graph, fromNode, -1)); }