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); }
public int CalculateConnectionTime(StopConnection waitingConnection) { var travelStartTime = waitingConnection.StartDateTime; var travelEndTime = waitingConnection.EndDateTime; return((int)Math.Abs((travelEndTime - travelStartTime).TotalMinutes)); }
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 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)); }
private DescriptionRow WriteTransfer(StopConnection connection) { return(new DescriptionRow { First = DescriptionResources.Transfer, }); }
private IEnumerable <DescriptionRow> WriteLine(StopConnection connection) { var descriptionRows = new List <DescriptionRow>(); var departureRow = new DescriptionRow { First = connection.StartDateTime.ToString(HOUR_FILTER), Second = connection.SourceStop.Stop.Name }; var lineRow = new DescriptionRow { First = $"{connection.Line.LineType} {connection.Line.Name}", Second = $"{DescriptionResources.Direction}: {_lineDirectionService.GetDirectionStop(connection.Line).Name}", Third = $"{_timeCalculator.CalculateConnectionTime(connection).ToString()} " + $"{DescriptionResources.Minutes}" }; var arrivalRow = new DescriptionRow { First = connection.EndDateTime.ToString(HOUR_FILTER), Second = connection.DestinationStop.Stop.Name }; descriptionRows.Add(departureRow); descriptionRows.Add(lineRow); descriptionRows.Add(arrivalRow); return(descriptionRows); }
public StopConnection GetDestinationStopFastestConnection( IEnumerable <StopConnection> vertexFastestConnections, StopConnection stopConnection) { return(vertexFastestConnections .First(p => p.DestinationStop.Stop.Id == stopConnection.DestinationStop.Stop.Id)); }
public void ReplaceWithNewFastestConnection( StopConnection currentFastestStopConnection, StopConnection newFastestConnection) { currentFastestStopConnection.Line = newFastestConnection.Line; currentFastestStopConnection.StartDateTime = newFastestConnection.StartDateTime; currentFastestStopConnection.SourceStop = newFastestConnection.SourceStop; currentFastestStopConnection.EndDateTime = newFastestConnection.EndDateTime; }
public StopConnection CloneFrom(StopConnection stopConnection) { return(new StopConnection { DestinationStop = stopConnection.DestinationStop, EndDateTime = stopConnection.EndDateTime, IsTransfer = stopConnection.IsTransfer, Line = stopConnection.Line, SourceStop = stopConnection.SourceStop, StartDateTime = stopConnection.StartDateTime }); }
public StopConnection GetStopConnectionFromPreviousVertex( IEnumerable <StopConnection> vertexFastestConnections, StopConnection stopConnection) { if (stopConnection.SourceStop == null) { return(null); } return(vertexFastestConnections .FirstOrNull(p => p.DestinationStop != null && p.DestinationStop.Stop.Id == stopConnection.SourceStop.Stop.Id)); }
public StopConnection GenerateWaitingAsStopConnection (SearchInput search, StopConnection firstConnection) { return(new StopConnection() { SourceStop = firstConnection.SourceStop, DestinationStop = firstConnection.SourceStop, StartDateTime = search.StartFullDate, EndDateTime = firstConnection.StartDateTime, Line = null, IsTransfer = true, }); }
public StopConnection GenerateTransferAsStopConnection (StopConnection sourceConnection, StopConnection nextConnection) { return(new StopConnection() { SourceStop = sourceConnection.DestinationStop, DestinationStop = sourceConnection.DestinationStop, StartDateTime = sourceConnection.EndDateTime, EndDateTime = nextConnection.StartDateTime, Line = null, IsTransfer = true, }); }
public bool IsAlreadyTransfer(StopConnection currentConnection) { return(currentConnection.IsTransfer); }
public bool ShouldBeWaitingOnFirstStop (SearchInput search, StopConnection firstConnection) { return(search.StartFullDate != firstConnection.StartDateTime); }
public bool ShouldBeTransfer (StopConnection sourceConnection, StopConnection nextConnection) { return(sourceConnection.Line.Id != nextConnection.Line.Id); }
public bool IsConnectionEmpty(StopConnection stopConnection) { return(stopConnection == null || stopConnection.SourceStop == null); }