public void Run(ITourWrapper subtour) { if (subtour == null) { throw new ArgumentNullException("subtour"); } TourTime.InitializeTourTimes(); subtour.PersonDay.ResetRandom(50 + subtour.Sequence - 1); if (subtour == null) { throw new ArgumentNullException("subtour"); } if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return; } } ChoiceProbabilityCalculator choiceProbabilityCalculator = _helpers[ParallelUtility.threadLocalAssignedIndex.Value].GetChoiceProbabilityCalculator(subtour.Id); if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode) { if (subtour.DestinationParcel == null || subtour.OriginParcel == null || subtour.Mode <= Global.Settings.Modes.None || subtour.Mode >= Global.Settings.Modes.ParkAndRide) { return; } RunModel(choiceProbabilityCalculator, subtour, new TourTime(subtour.DestinationArrivalTime, subtour.DestinationDepartureTime)); choiceProbabilityCalculator.WriteObservation(); } else { RunModel(choiceProbabilityCalculator, subtour); ChoiceProbabilityCalculator.Alternative chosenAlternative = choiceProbabilityCalculator.SimulateChoice(subtour.Household.RandomUtility); if (chosenAlternative == null) { Global.PrintFile.WriteNoAlternativesAvailableWarning(CHOICE_MODEL_NAME, "Run", subtour.PersonDay.Id); subtour.PersonDay.IsValid = false; return; } TourTime choice = (TourTime)chosenAlternative.Choice; IMinuteSpan destinationTimes = choice.GetDestinationTimes(subtour); subtour.DestinationArrivalTime = destinationTimes.Start; subtour.DestinationDepartureTime = destinationTimes.End; } }
public IMinuteSpan AdjacentAvailableWindowAfter(int minute) { IMinuteSpan span = (from availableMinute in _availableMinutes where minute.IsBetween(availableMinute.Start, availableMinute.End) select availableMinute).FirstOrDefault(); span.Start = minute; return(span); }
public bool Equals(IMinuteSpan other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(other.Start == Start && other.End == End); }
private List <IMinuteSpan> GetAvailableMinutes() { var availableMinutes = new List <IMinuteSpan>(); if (_busyMinutes.Count == 0) { availableMinutes.Add(new MinuteSpan(1, Global.Settings.Times.MinutesInADay)); } IMinuteSpan lastBusyMinute = null; foreach (var busyMinute in _busyMinutes) { if (busyMinute.Start > 1) { var start = lastBusyMinute == null ? 1 : lastBusyMinute.End + 1; availableMinutes.Add(new MinuteSpan(start, busyMinute.Start - 1)); } lastBusyMinute = busyMinute; } if (lastBusyMinute != null && lastBusyMinute.End < Global.Settings.Times.MinutesInADay) { availableMinutes.Add(new MinuteSpan(lastBusyMinute.End + 1, Global.Settings.Times.MinutesInADay)); } _availableMinutes = availableMinutes; if (ValidTimeWindow() == false) { bool testBreak = true; } return(availableMinutes); }
public IMinuteSpan LongestAvailableFeasibleWindow(int apEnd, int dpStart, double timeTo, double timeFrom, int mad) //find the longest window that starts at least timeTo before apEnd and ends at least timeFrom after dpStart, and has total // duration of at least timeTo + mad + timeFrom (used in HTourModeTime) { IMinuteSpan span = null; var maxDuration = 0; foreach (var availableMinute in _availableMinutes.Where(availableMinute => availableMinute.Start + timeTo <= apEnd && availableMinute.End - timeFrom >= dpStart && availableMinute.End - availableMinute.Start >= timeTo + mad + timeFrom)) { if (availableMinute.End - availableMinute.Start > maxDuration) { span = availableMinute; maxDuration = span.End - span.Start; } } return(span); }