public IEnumerable <StopConnection> Create(StopGraph graph, SearchInput search)
        {
            var vertexFastestConnections = new List <StopConnection>();
            var startingVertex           = graph
                                           .StopVertices
                                           .First(p => p.Stop.Id == search.StartStop.Id);
            var startingConnection = new StopConnection()
            {
                DestinationStop = startingVertex,
                SourceStop      = startingVertex,
                Line            = null,
                StartDateTime   = search.StartFullDate,
                EndDateTime     = search.StartFullDate,
            };

            vertexFastestConnections.Add(startingConnection);
            foreach (var vertex in graph.StopVertices)
            {
                if (vertex.Stop.Id != search.StartStop.Id)
                {
                    vertexFastestConnections.Add(new StopConnection()
                    {
                        DestinationStop = vertex,
                        SourceStop      = null,
                        Line            = null,
                        StartDateTime   = DateTime.MinValue,
                        EndDateTime     = DateTime.MinValue,
                    });
                }
            }
            return(vertexFastestConnections);
        }
Beispiel #2
0
        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);
        }
        public IEnumerable <StopConnection> SearchConnections(SearchInput search, StopGraph graph)
        {
            var vertexFastestConnections = _dijkstraEmptyFastestConnectionsFactory
                                           .Create(graph, search);
            var currentVertex = _dijkstraNextVertexResolver.GetFirstVertex(graph, search.StartStop);

            vertexFastestConnections = _dijkstraStopGraphService.SetTransferConnectionsToSimilarVertices(
                vertexFastestConnections, currentVertex, currentVertex.SimilarStopVertices);
            while (ShouldSearchingContinue(search, currentVertex))
            {
                var allStopConnections = _dijkstraStopGraphService.GetConnectionsFromSimilarVertices
                                             (currentVertex, currentVertex.SimilarStopVertices);
                foreach (var stopConnection in allStopConnections)
                {
                    var destinationStopFastestConnection = _dijkstraStopConnectionsService
                                                           .GetDestinationStopFastestConnection(vertexFastestConnections, stopConnection);
                    var stopConnectionFromPreviousVertex = _dijkstraStopConnectionsService
                                                           .GetStopConnectionFromPreviousVertex(vertexFastestConnections, stopConnection);
                    if (_dijkstraFastestConnectionReplacer
                        .ShouldConnectionBeReplaced(search, stopConnectionFromPreviousVertex,
                                                    destinationStopFastestConnection, stopConnection))
                    {
                        _dijkstraFastestConnectionReplacer
                        .ReplaceWithNewFastestConnection(destinationStopFastestConnection, stopConnection);
                    }
                }
                _dijkstraStopGraphService.MarkVertexAsVisited(currentVertex);
                currentVertex = _dijkstraNextVertexResolver.GetNextVertex(graph, vertexFastestConnections);
                if (currentVertex == null)
                {
                    throw new DijkstraNoFastestPathExistsException();
                }
                vertexFastestConnections = _dijkstraStopGraphService.SetTransferConnectionsToSimilarVertices(
                    vertexFastestConnections, currentVertex, currentVertex.SimilarStopVertices);
            }
            return(vertexFastestConnections);
        }
Beispiel #4
0
 public StopVertex GetFirstVertex(StopGraph graph, Stop startingStop)
 {
     return(_dijkstraStopGraphService
            .GetStopVertexByStop(graph, startingStop));
 }
Beispiel #5
0
 public StopVertex GetStopVertexByStop(StopGraph graph, Stop stop)
 {
     return(graph
            .StopVertices
            .First(p => p.Stop.Id == stop.Id));
 }