/// <summary> /// Get the time span when route must start to satisfy first break. /// </summary> /// <param name="startTimeRange">TimeRange in which route can left start location.</param> /// <param name="firstBreak">TimeWindowBreak.</param> /// <param name="tripMaxDuration">Max trip duration.</param> /// <returns>TimeSpan?.</returns> private TimeSpan?_GetRealStart(TimeRange startTimeRange, TimeWindowBreak firstBreak, TimeSpan tripMaxDuration) { // Calculate trip possible time range. var tripPossibleTimeRange = startTimeRange.Clone() as TimeRange; tripPossibleTimeRange.To += tripMaxDuration; // Get finishTimeRange of trip and break time ranges. var intersection = tripPossibleTimeRange.Intersection( new TimeRange(firstBreak.EffectiveFrom, firstBreak.EffectiveFrom)); // If they intersects - calculate trip start. if (intersection != null) { return(_MinTimeSpan(startTimeRange.To, intersection.To)); } else { return(null); } }
/// <summary> /// Return trip time range, which will allow to visit finish location. /// </summary> /// <param name="tripTimeRange">TimeRange.</param> /// <param name="endLocationTimeWindow">TimeWindow.</param> /// <param name="tripDuration">Trip max duration.</param> /// <returns>Trip time range if it was found, null otherwise.</returns> private TimeRange _GetTripTimeRangeOptimalForEndlLocation( TimeRange tripTimeRange, TimeWindow endLocationTimeWindow, TimeSpan tripDuration) { TimeRange result = null; // Calculate time window in which trip can be finished. var tripFinishTimeRange = tripTimeRange.Clone() as TimeRange; tripFinishTimeRange.To += tripDuration; // If after finishing trip end location can be visited - calculate trip time window. var finishTimeRange = tripFinishTimeRange.Intersection( new TimeRange(endLocationTimeWindow)); if (finishTimeRange != null && finishTimeRange.Length.TotalMinutes > _route.TimeAtEnd) { var tripStart = tripTimeRange.From > finishTimeRange.From ? tripTimeRange.From : finishTimeRange.From; result = new TimeRange(tripStart, tripStart + tripDuration); } return(result); }