public bool ShouldConnectionBeReplaced( SearchInput searchInput, StopConnection stopConnectionFromPreviousVertex, StopConnection destinationStopCurrentFastestConnection, StopConnection maybeNewFastestConnection) { bool isDestinationVertexMarkedAsVisited = destinationStopCurrentFastestConnection .DestinationStop.IsVisited; bool isCurrentFastestConnectionEmpty = _dijkstraStopConnectionsService .IsConnectionEmpty(destinationStopCurrentFastestConnection); bool isPreviousVertexFastestConnectionEmpty = _dijkstraStopConnectionsService .IsConnectionEmpty(stopConnectionFromPreviousVertex); bool canMaybeNewFastestConnectionExist = searchInput.StartFullDate <= maybeNewFastestConnection.StartDateTime && (isPreviousVertexFastestConnectionEmpty || stopConnectionFromPreviousVertex.EndDateTime <= maybeNewFastestConnection.StartDateTime); bool isMaybeNewFastestConnectionFaster = maybeNewFastestConnection.EndDateTime < destinationStopCurrentFastestConnection.EndDateTime; if (isDestinationVertexMarkedAsVisited) { return(false); } return(canMaybeNewFastestConnectionExist && (isCurrentFastestConnectionEmpty || isMaybeNewFastestConnectionFaster)); }
public StopVertex GetNextVertex(StopGraph graph, IEnumerable <StopConnection> vertexFastestConnections) { StopConnection fastestConnection = null; foreach (var maybeNewFastestConnection in vertexFastestConnections) { if (!_dijkstraStopConnectionsService.IsConnectionEmpty(maybeNewFastestConnection)) { if (!maybeNewFastestConnection.DestinationStop.IsVisited) { if (fastestConnection == null || fastestConnection.EndDateTime > maybeNewFastestConnection.EndDateTime) { fastestConnection = maybeNewFastestConnection; } } } } if (fastestConnection == null) { return(null); } return(fastestConnection.DestinationStop); }