private bool AssignPickUpAndReturnTripChains(ITashaHousehold h, ISharedMode mode, ITrip facilitateTrip, int maxWaitThreshold) { bool success = false; for (int i = 0; i < h.Persons.Length; i++) { var p = h.Persons[i]; if (p == facilitateTrip.TripChain.Person || !mode.RequiresVehicle.CanUse(p)) { continue; } foreach (var tc in p.TripChains) { if (tc.requiresVehicle.Contains(mode.RequiresVehicle) && tc.Trips[tc.Trips.Count - 1].TripStartTime < facilitateTrip.ActivityStartTime) { ITrip lastTrip = tc.Trips[tc.Trips.Count - 1]; ITrip originToIntermediatePoint = AuxiliaryTrip.MakeAuxiliaryTrip(lastTrip.OriginalZone, facilitateTrip.OriginalZone, lastTrip.Mode, lastTrip.ActivityStartTime); originToIntermediatePoint.TripChain = tc; ITrip intermediateToDestination = AuxiliaryTrip.MakeAuxiliaryTrip(facilitateTrip.OriginalZone, facilitateTrip.DestinationZone, mode, facilitateTrip.ActivityStartTime); intermediateToDestination.TripChain = tc; Time newEndTime = facilitateTrip.TripStartTime + intermediateToDestination.TravelTime; if (!WithinWaitThreshold(newEndTime, tc.EndTime, maxWaitThreshold)) { continue; } //not the last trip: check for overlap with next tc if (!(p.TripChains[p.TripChains.Count - 1] == tc)) { //last chain if (newEndTime > p.TripChains[p.TripChains.IndexOf(tc) + 1].StartTime) { continue; } } //check feasibility if (!originToIntermediatePoint.Mode.Feasible(originToIntermediatePoint)) { continue; } //adding aux chain AddAuxTripChain(p, facilitateTrip.TripChain.Person, originToIntermediatePoint, intermediateToDestination, facilitateTrip, mode, false, lastTrip); success = true; } } } return(success); }
/// <summary> /// Create a temporary auxiliary trip with minimum information /// </summary> /// <param name="origin"></param> /// <param name="destination"></param> /// <param name="modeChoice"></param> /// <param name="startTime"></param> public static AuxiliaryTrip MakeAuxiliaryTrip(IZone origin, IZone destination, ITashaMode modeChoice, Time startTime) { AuxiliaryTrip aux; //if ( !AuxiliaryTrip.Trips.TryTake( out aux ) ) //{ aux = new AuxiliaryTrip(); aux.Passengers = new List <ITashaPerson>(); //} aux.OriginalZone = origin; aux.DestinationZone = destination; aux.Mode = modeChoice; aux.ActivityStartTime = startTime; return(aux); }
private ITripChain CreatePickUpTrip(ITrip trip, ISharedMode mode, out bool success) { ITripChain auxTripChain = new AuxiliaryTripChain(); //go to trip ITrip goToTrip = AuxiliaryTrip.MakeAuxiliaryTrip(trip.OriginalZone, trip.TripChain.Person.Household.HomeZone, mode.AssociatedMode, trip.ActivityStartTime); //End Time of return trip Time travelTimeToHome = mode.TravelTime(trip.OriginalZone, trip.TripChain.Person.Household.HomeZone, trip.TripStartTime); Time tripEndTime = trip.ActivityStartTime + travelTimeToHome; //return home trip ITrip returnHomeTrip = AuxiliaryTrip.MakeAuxiliaryTrip(trip.TripChain.Person.Household.HomeZone, trip.OriginalZone, mode, tripEndTime); //travel times generated success = returnHomeTrip.TravelTime > Time.Zero && goToTrip.TravelTime > Time.Zero; auxTripChain.Trips.Add(goToTrip); auxTripChain.Trips.Add(returnHomeTrip); return(auxTripChain); }
private ITrip copyTrip(ITrip trip) { return(AuxiliaryTrip.MakeAuxiliaryTrip(trip.OriginalZone, trip.DestinationZone, trip.Mode, trip.ActivityStartTime)); }
private bool AssignFacilitateAndContinueTripChains(ITashaHousehold h, ISharedMode mode, ITrip facilitateTrip, int maxWaitThreshold) { bool success = false; for (int pIt = 0; pIt < h.Persons.Length; pIt++) { var p = h.Persons[pIt]; //is this person the same person as the trip we are looking to facilitate? //can this person use the specified vehicle? if (p == facilitateTrip.TripChain.Person || !mode.RequiresVehicle.CanUse(p)) { continue; } var numberOfTripChains = p.TripChains.Count; for (int i = 0; i < numberOfTripChains; i++) { ITrip originToIntermediatePoint; ITrip intermediateToDestination; //if this trip chain is part of a joint trip chain then it can't be used if (p.TripChains[i].JointTrip) { continue; } //look for the first trip chain with a start time after the passengers start time //determine if it is feasible if (p.TripChains[i].Trips[0].ActivityStartTime >= facilitateTrip.ActivityStartTime) { if (i == 0) // first trip of the day... { //trip uses vehicle needed for specified shared mode if (p.TripChains[i].requiresVehicle.Contains(mode.RequiresVehicle)) { originToIntermediatePoint = AuxiliaryTrip.MakeAuxiliaryTrip(h.HomeZone, facilitateTrip.DestinationZone, mode, facilitateTrip.ActivityStartTime); //travel time from the facilitated trips destination to the trips destination Time travelTime = p.TripChains[i].Trips[0].Mode.TravelTime(facilitateTrip.DestinationZone, p.TripChains[i].Trips[0].DestinationZone, p.TripChains[i].Trips[0].TripStartTime); //new start time is drop offs start time plus additional time to get to destination Time newStartTime = travelTime + originToIntermediatePoint.ActivityStartTime; intermediateToDestination = AuxiliaryTrip.MakeAuxiliaryTrip(facilitateTrip.DestinationZone, p.TripChains[i].Trips[0].DestinationZone, p.TripChains[i].Trips[0].Mode, newStartTime); intermediateToDestination.TripChain = p.TripChains[i]; //if time between drop off and first trip is too long it is invalid if (!intermediateToDestination.Mode.Feasible(intermediateToDestination) || !WithinWaitThreshold(intermediateToDestination.ActivityStartTime, p.TripChains[i].Trips[0].ActivityStartTime, maxWaitThreshold)) { continue; } AddAuxTripChain(p, facilitateTrip.TripChain.Person, originToIntermediatePoint, intermediateToDestination, facilitateTrip, mode, true, p.TripChains[i].Trips[0]); success = true; } } else { if (p.TripChains[i].TripChainRequiresPV) { //determine if they have been at home enough long enough //to allow for total driving time and to get to their destination Time homeTime = p.TripChains[i - 1].EndTime; originToIntermediatePoint = AuxiliaryTrip.MakeAuxiliaryTrip(h.HomeZone, facilitateTrip.DestinationZone, mode, facilitateTrip.ActivityStartTime); Time travelTime = p.TripChains[i].Trips[0].Mode.TravelTime(facilitateTrip.DestinationZone, p.TripChains[i].Trips[0].DestinationZone, p.TripChains[i].Trips[0].TripStartTime); Time newStartTime = travelTime + originToIntermediatePoint.ActivityStartTime; intermediateToDestination = AuxiliaryTrip.MakeAuxiliaryTrip(facilitateTrip.DestinationZone, p.TripChains[i].Trips[0].DestinationZone, p.TripChains[i].Trips[0].Mode, newStartTime); intermediateToDestination.TripChain = p.TripChains[i]; if (intermediateToDestination.TravelTime.ToFloat() == 0f || originToIntermediatePoint.TravelTime.ToFloat() == 0f) { continue; //travel times do not exist; skip } if (originToIntermediatePoint.TripStartTime > (homeTime) && WithinWaitThreshold(intermediateToDestination.ActivityStartTime, p.TripChains[i].Trips[0].ActivityStartTime, maxWaitThreshold)) { if (!intermediateToDestination.Mode.Feasible(intermediateToDestination)) { continue; } //adding aux trip chain to driver AddAuxTripChain(p, facilitateTrip.TripChain.Person, originToIntermediatePoint, intermediateToDestination, facilitateTrip, mode, true, p.TripChains[i].Trips[0]); success = true; } } else { //cant drive.. since no personal vehicle break; } } } } } return(success); }