private void FinalizeAuxTrips(ITashaHousehold household) { var persons = household.Persons; var pLength = persons.Length; for (int i = 0; i < pLength; i++) { var aux = persons[i].AuxTripChains; var auxLength = aux.Count; for (int j = 0; j < auxLength; j++) { ITrip connectingTripChain = aux[j]["ConnectingChain"] as ITrip; Activity purpose = (Activity)aux[j]["Purpose"]; ITrip facilitatedTrip = aux[j]["FacilitateTrip"] as ITrip; ISharedMode facilitatedTripMode = aux[j]["SharedMode"] as ISharedMode; facilitatedTrip.Mode = facilitatedTripMode; var trips = aux[j].Trips; var tripsLength = trips.Count; var associatedMode = facilitatedTripMode.AssociatedMode; for (int t = 0; t < tripsLength; t++) { trips[t].Mode = associatedMode; } } } }
/// <summary> /// Calculates the U of the facilitated trip /// </summary> /// <param name="tripChain"></param> /// <param name="oldU"></param> /// <param name="newU"></param> public void CalculateU(ITripChain tripChain, out double oldU, out double newU) { ITrip facilitatedTrip = (ITrip)tripChain["FacilitateTrip"]; ISharedMode facilitatedTripMode = (ISharedMode)tripChain["SharedMode"]; ITrip connectingTrip = tripChain["ConnectingChain"] as ITrip; //the mode data for the facilitated trip ModeData facilitatedTripData = ModeData.Get(facilitatedTrip); int indexOfPass = TashaRuntime.GetIndexOfMode(facilitatedTripMode); double UofAuxiliaryTrip = CalculateUofAuxTrip(tripChain); facilitatedTripData.V[indexOfPass] = facilitatedTripMode.CalculateV(facilitatedTrip); newU = facilitatedTripData.U(indexOfPass) + UofAuxiliaryTrip; if (facilitatedTrip.Mode == null) { // if there is no other way oldU = float.NegativeInfinity; } else { if (connectingTrip == null) { oldU = facilitatedTripData.U(TashaRuntime.GetIndexOfMode(facilitatedTrip.Mode)); } else { ModeData connectingTripData = ModeData.Get(connectingTrip); oldU = facilitatedTripData.U(TashaRuntime.GetIndexOfMode(facilitatedTrip.Mode)) + connectingTripData.U(TashaRuntime.GetIndexOfMode(connectingTrip.Mode)); } } }
private void ChangeFacilitatedTripMode(ITripChain auxTrip) { ITrip facilitatedTrip = auxTrip["FacilitateTrip"] as ITrip; ISharedMode facilitatedTripMode = auxTrip["FacilitateTripMode"] as ISharedMode; facilitatedTrip.Mode = facilitatedTripMode; facilitatedTrip.SharedModeDriver = auxTrip.Person; }
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); }
public bool RuntimeValidation(ref string error) { if (!string.IsNullOrWhiteSpace(RideshareModeName)) { bool found = false; foreach (var sharedMode in Root.SharedModes) { if (sharedMode.ModeName == RideshareModeName) { Rideshare = sharedMode; found = true; break; } } if (!found) { error = "In '" + Name + "' we were unable to find a shared mode called '" + RideshareModeName + "' to use for rideshare"; return(false); } found = false; foreach (var nonSharedMode in Root.NonSharedModes) { if (nonSharedMode.ModeName == AutoModeName) { AutoMode = nonSharedMode; found = true; break; } } if (!found) { error = "In '" + Name + "' we were unable to find a non shared mode called '" + AutoModeName + "' to use replace with rideshare"; return(false); } } if (!string.IsNullOrWhiteSpace(PassengerModeName)) { foreach (var sharedMode in Root.SharedModes) { if (sharedMode.ModeName == PassengerModeName) { PassengerMode = sharedMode as ITashaPassenger; break; } } if (PassengerMode == null) { error = "In '" + Name + "' we were unable to find a shared mode called '" + PassengerModeName + "' to use for passenger"; return(false); } } return(true); }
private bool OffsetActivityStartTime(ITrip driverTrip, ITrip passengerTrip, ISharedMode sharedMode, bool pickUp, int driverWaitThreshold, int passengerWaitThreshold, AdjustmentType adjustmentType, out Time newDriverStartTime, out Time newPassengerStartTime) { newPassengerStartTime = Time.Zero; newDriverStartTime = Time.Zero; if (adjustmentType == AdjustmentType.Driver) { Time startTime = passengerTrip.ActivityStartTime; newDriverStartTime = startTime + driverTrip.Mode.TravelTime(passengerTrip.DestinationZone, driverTrip.DestinationZone, driverTrip.TripStartTime); newPassengerStartTime = startTime; return(WithinWaitThreshold(newDriverStartTime, driverTrip.ActivityStartTime, driverWaitThreshold)); } else if (adjustmentType == AdjustmentType.Passenger) { Time toIntermediatefTime; Time toDestinationfTime; //determining travel times given whether its a pickup or drop-off trip if (pickUp) { toIntermediatefTime = driverTrip.Mode.TravelTime(driverTrip.OriginalZone, passengerTrip.OriginalZone, passengerTrip.TripStartTime); toDestinationfTime = sharedMode.TravelTime(passengerTrip.OriginalZone, passengerTrip.DestinationZone, passengerTrip.TripStartTime); } else { toIntermediatefTime = sharedMode.TravelTime(driverTrip.OriginalZone, passengerTrip.DestinationZone, passengerTrip.TripStartTime); toDestinationfTime = driverTrip.Mode.TravelTime(passengerTrip.DestinationZone, driverTrip.DestinationZone, driverTrip.TripStartTime); } Time toIntermediateTime = toIntermediatefTime; Time toDestinationTime = toDestinationfTime; newPassengerStartTime = driverTrip.ActivityStartTime - toDestinationTime; newDriverStartTime = driverTrip.ActivityStartTime; return(WithinWaitThreshold(newPassengerStartTime, passengerTrip.ActivityStartTime, passengerWaitThreshold)); } else if (adjustmentType == AdjustmentType.Compromise) { throw new NotImplementedException("AdjustmentType.Compromise not implemented"); } return(false); }
/// <summary> /// Gets all the trip chains of a Person /// The Auxiliary connecting trips are combined to (Non-Auxiliary) Trip chains /// The Regular trip chains (non-auxiliary) are therefore copied to not /// interfere with the next household iteration /// </summary> /// <param name="person"></param> /// <returns></returns> public static List <ITripChain> GetAllTripChains(this ITashaPerson person) { List <ITripChain> allTripChains = new List <ITripChain>(); List <ITripChain> addedChains = new List <ITripChain>(); //adding all auxiliary trip chains foreach (var auxTripChain in person.AuxTripChains) { ITrip connectingTripChain = auxTripChain["ConnectingChain"] as ITrip; Activity purpose = (Activity)auxTripChain["Purpose"]; ITrip facilitatedTrip = auxTripChain["FacilitateTrip"] as ITrip; ISharedMode facilitatedTripMode = auxTripChain["SharedMode"] as ISharedMode; if (connectingTripChain == null) { allTripChains.Add(auxTripChain); } else { ITripChain clonedChain = connectingTripChain.TripChain.DeepClone(); if (purpose == Activity.Dropoff) { clonedChain.Trips.RemoveAt(0); } else if (purpose == Activity.Pickup) { clonedChain.Trips.RemoveAt(clonedChain.Trips.Count - 1); } clonedChain.Trips.AddRange(auxTripChain.Trips); clonedChain.Trips.Sort(TripComparer); addedChains.Add(connectingTripChain.TripChain); allTripChains.Add(clonedChain); } } //adding all regular trip chains foreach (ITripChain chain in person.TripChains) { if (!addedChains.Contains(chain)) { allTripChains.Add(chain.DeepClone()); } } return(allTripChains); }
public double CalculateU(ITripChain tripChain) { ITrip facilitatedTrip = tripChain["FacilitateTrip"] as ITrip; ISharedMode facilitatedTripMode = (ISharedMode)tripChain["SharedMode"]; //the mode data for the facilitated trip ModeData facilitatedTripData = ModeData.Get(facilitatedTrip); if (facilitatedTripData == null) { throw new XTMFRuntimeException(null, "There was no facilitated Trip Data!"); } if (TashaRuntime == null) { throw new XTMFRuntimeException(null, "Tasha runtime was null!"); } double passengersU = facilitatedTripData.U(facilitatedTripMode.ModeChoiceArrIndex); double driversU = CalculateUofAuxTrip(tripChain); return(passengersU + driversU); }
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); }
public bool AssignPossibleDrivers(ITrip trip, ISharedMode mode) { //if not a joint trip determine if its a pick up or drop off if (!trip.TripChain.JointTrip) { bool dropOff; ITripChain auxiliaryTripChain; bool success; //if this trip is a pick up ... then create the appropriate trip chain (and go back home trip) if (isPickUpTrip(trip)) { auxiliaryTripChain = CreatePickUpTrip(trip, mode, out success); dropOff = false; }//if this is a drop off trip ... then create the appropriate trip chain (and go back home trip) else if (isDropOffTrip(trip)) { auxiliaryTripChain = CreateDropOffTrip(trip, mode, out success); dropOff = true; } else { return(false); } if (!success) { return(false); } success = false; if (dropOff) { if (AssignFacilitateAndContinueTripChains(trip.TripChain.Person.Household, mode, trip, ((Time)trip.GetVariable("MaxDriverTimeThreshold")).Minutes)) { success = true; } } else { if (AssignPickUpAndReturnTripChains(trip.TripChain.Person.Household, mode, trip, ((Time)trip.GetVariable("MaxDriverTimeThreshold")).Minutes)) { success = true; } } if (AssignGoToAndReturnTripChains(auxiliaryTripChain, trip.TripChain.Person.Household, mode.RequiresVehicle, trip, mode)) { success = true; } return(success); } else { //is a joint trip var jointTripChains = trip.TripChain.JointTripChains; for (int i = 0; i < jointTripChains.Count; i++) { for (int j = 0; j < jointTripChains[i].Trips.Count; j++) { var t = jointTripChains[i].Trips[j]; if (t.Mode.NonPersonalVehicle == false) { //this is a possible driver //save the rideshare data trip.SharedModeDriver = t.TripChain.Person; return(true); } } } } return(false); }
private bool AssignGoToAndReturnTripChains(ITripChain auxiliaryTripChain, ITashaHousehold household, IVehicleType vehicleType, ITrip trip, ISharedMode mode) { if (numVehiclesAvailable(vehicleType, auxiliaryTripChain.StartTime, auxiliaryTripChain.EndTime, household) == 0) { return(false); } bool success = false; bool conflict; foreach (var p in household.Persons) { if (!vehicleType.CanUse(p)) { continue; } conflict = false; foreach (var tc in p.TripChains) { if (tc.StartTime <= auxiliaryTripChain.EndTime && tc.EndTime >= auxiliaryTripChain.StartTime) { conflict = true; break; // go onto next person } } if (!conflict) { //this person has no conflict so give him an aux trip chain AddAuxTripChain(p, trip.TripChain.Person, copyTrip(auxiliaryTripChain.Trips[0]), copyTrip(auxiliaryTripChain.Trips[1]), trip, mode, isDropOffTrip(trip), null); success = true; } } return(success); }
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; }
private bool AssignGoToAndReturnTripChains(ITripChain auxiliaryTripChain, ITashaHousehold household, IVehicleType vehicleType, ITrip trip, ISharedMode mode) { if ( numVehiclesAvailable( vehicleType, auxiliaryTripChain.StartTime, auxiliaryTripChain.EndTime, household ) == 0 ) return false; bool success = false; bool conflict; foreach ( var p in household.Persons ) { if ( !vehicleType.CanUse( p ) ) { continue; } conflict = false; foreach ( var tc in p.TripChains ) { if ( tc.StartTime <= auxiliaryTripChain.EndTime && tc.EndTime >= auxiliaryTripChain.StartTime ) { conflict = true; break; // go onto next person } } if ( !conflict ) { //this person has no conflict so give him an aux trip chain AddAuxTripChain( p, trip.TripChain.Person, copyTrip( auxiliaryTripChain.Trips[0] ), copyTrip( auxiliaryTripChain.Trips[1] ), trip, mode, isDropOffTrip( trip ), null ); success = true; } } return success; }
public bool RuntimeValidation(ref string error) { if ( !string.IsNullOrWhiteSpace( RideshareModeName ) ) { bool found = false; foreach ( var sharedMode in Root.SharedModes ) { if ( sharedMode.ModeName == RideshareModeName ) { Rideshare = sharedMode; found = true; break; } } if ( !found ) { error = "In '" + Name + "' we were unable to find a shared mode called '" + RideshareModeName + "' to use for rideshare"; return false; } found = false; foreach ( var nonSharedMode in Root.NonSharedModes ) { if ( nonSharedMode.ModeName == AutoModeName ) { AutoMode = nonSharedMode; found = true; break; } } if ( !found ) { error = "In '" + Name + "' we were unable to find a non shared mode called '" + AutoModeName + "' to use replace with rideshare"; return false; } } if ( !string.IsNullOrWhiteSpace( PassengerModeName ) ) { foreach ( var sharedMode in Root.SharedModes ) { if ( sharedMode.ModeName == PassengerModeName ) { PassengerMode = sharedMode as ITashaPassenger; break; } } if ( PassengerMode == null ) { error = "In '" + Name + "' we were unable to find a shared mode called '" + PassengerModeName + "' to use for passenger"; return false; } } return true; }
public bool AssignPossibleDrivers(ITrip trip, ISharedMode mode) { //if not a joint trip determine if its a pick up or drop off if ( !trip.TripChain.JointTrip ) { bool dropOff; ITripChain auxiliaryTripChain; bool success; //if this trip is a pick up ... then create the appropriate trip chain (and go back home trip) if ( isPickUpTrip( trip ) ) { auxiliaryTripChain = CreatePickUpTrip( trip, mode, out success ); dropOff = false; }//if this is a drop off trip ... then create the appropriate trip chain (and go back home trip) else if ( isDropOffTrip( trip ) ) { auxiliaryTripChain = CreateDropOffTrip( trip, mode, out success ); dropOff = true; } else { return false; } if ( !success ) { return false; } success = false; if ( dropOff ) { if ( AssignFacilitateAndContinueTripChains( trip.TripChain.Person.Household, mode, trip, ( (Time)trip.GetVariable( "MaxDriverTimeThreshold" ) ).Minutes ) ) { success = true; } } else { if ( AssignPickUpAndReturnTripChains( trip.TripChain.Person.Household, mode, trip, ( (Time)trip.GetVariable( "MaxDriverTimeThreshold" ) ).Minutes ) ) { success = true; } } if ( AssignGoToAndReturnTripChains( auxiliaryTripChain, trip.TripChain.Person.Household, mode.RequiresVehicle, trip, mode ) ) { success = true; } return success; } else { //is a joint trip var jointTripChains = trip.TripChain.JointTripChains; for ( int i = 0; i < jointTripChains.Count; i++ ) { for ( int j = 0; j < jointTripChains[i].Trips.Count; j++ ) { var t = jointTripChains[i].Trips[j]; if ( t.Mode.NonPersonalVehicle == false ) { //this is a possible driver //save the rideshare data trip.SharedModeDriver = t.TripChain.Person; return true; } } } } return false; }
private bool OffsetActivityStartTime(ITrip driverTrip, ITrip passengerTrip, ISharedMode sharedMode, bool pickUp, int driverWaitThreshold, int passengerWaitThreshold, AdjustmentType adjustmentType, out Time newDriverStartTime, out Time newPassengerStartTime) { newPassengerStartTime = Time.Zero; newDriverStartTime = Time.Zero; if ( adjustmentType == AdjustmentType.Driver ) { Time startTime = passengerTrip.ActivityStartTime; newDriverStartTime = startTime + driverTrip.Mode.TravelTime( passengerTrip.DestinationZone, driverTrip.DestinationZone, driverTrip.TripStartTime ); newPassengerStartTime = startTime; return WithinWaitThreshold( newDriverStartTime, driverTrip.ActivityStartTime, driverWaitThreshold ); } else if ( adjustmentType == AdjustmentType.Passenger ) { Time toIntermediatefTime; Time toDestinationfTime; //determining travel times given whether its a pickup or drop-off trip if ( pickUp ) { toIntermediatefTime = driverTrip.Mode.TravelTime( driverTrip.OriginalZone, passengerTrip.OriginalZone, passengerTrip.TripStartTime ); toDestinationfTime = sharedMode.TravelTime( passengerTrip.OriginalZone, passengerTrip.DestinationZone, passengerTrip.TripStartTime ); } else { toIntermediatefTime = sharedMode.TravelTime( driverTrip.OriginalZone, passengerTrip.DestinationZone, passengerTrip.TripStartTime ); toDestinationfTime = driverTrip.Mode.TravelTime( passengerTrip.DestinationZone, driverTrip.DestinationZone, driverTrip.TripStartTime ); } Time toIntermediateTime = toIntermediatefTime; Time toDestinationTime = toDestinationfTime; newPassengerStartTime = driverTrip.ActivityStartTime - toDestinationTime; newDriverStartTime = driverTrip.ActivityStartTime; return WithinWaitThreshold( newPassengerStartTime, passengerTrip.ActivityStartTime, passengerWaitThreshold ); } else if ( adjustmentType == AdjustmentType.Compromise ) { throw new NotImplementedException( "AdjustmentType.Compromise not implemented" ); } return false; }
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 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> /// Adds the auxiliary trip chain to the person if its Utility is greater than not including it /// </summary> /// <param name="driver">the driver</param> /// <param name="passenger">the passenger</param> /// <param name="trip1">aux trip 1</param> /// <param name="trip2">aux trip 2</param> /// <param name="facilitateTrip">the trip being facilitated</param> /// <param name="mode">the shared mode to assign</param> /// <param name="dropoff">is this a dropoff or pickup aux trip chain?</param> /// <param name="connectingTrip">what is the chain this aux trip chain connects to if any?</param> private void AddAuxTripChain(ITashaPerson driver, ITashaPerson passenger, ITrip trip1, ITrip trip2, ITrip facilitateTrip, ISharedMode mode, bool dropoff, ITrip connectingTrip) { ITripChain auxTripChain = new AuxiliaryTripChain(); auxTripChain.Attach("SharedMode", mode); auxTripChain.Attach("FacilitateTrip", facilitateTrip); trip1.TripChain = auxTripChain; trip2.TripChain = auxTripChain; auxTripChain.Trips.Add(trip1); auxTripChain.Trips.Add(trip2); auxTripChain.Person = driver; facilitateTrip.Attach("isDriver", false); if (dropoff) { trip1.Passengers.Add(passenger); trip1.Attach("isDriver", true); } else { trip2.Passengers.Add(passenger); trip2.Attach("isDriver", true); } if (connectingTrip != null) { auxTripChain.Attach("ConnectingChain", connectingTrip); } if (dropoff) { if (connectingTrip == null) { auxTripChain.Attach("Purpose", Activity.DropoffAndReturn); trip1.Purpose = Activity.FacilitatePassenger; trip2.Purpose = Activity.Home; } else if (connectingTrip != null) { auxTripChain.Attach("Purpose", Activity.Dropoff); auxTripChain.Attach("OriginalPurpose", connectingTrip.Purpose); trip1.Purpose = Activity.FacilitatePassenger; trip2.Purpose = connectingTrip.Purpose; //transfering feasible transit stations and such foreach (var key in connectingTrip.Keys) { trip1.Attach(key, connectingTrip[key]); } } } else { if (connectingTrip == null) { auxTripChain.Attach("Purpose", Activity.PickupAndReturn); trip1.Purpose = Activity.FacilitatePassenger; trip2.Purpose = Activity.Home; } else if (connectingTrip != null) { ///TODO: Look into this again auxTripChain.Attach("Purpose", Activity.Pickup); auxTripChain.Attach("OriginalPurpose", connectingTrip.Purpose); trip1.Purpose = Activity.FacilitatePassenger; trip2.Purpose = Activity.Home; //transfering feasible transit stations and such foreach (var key in connectingTrip.Keys) { trip2.Attach(key, connectingTrip[key]); } } } double oldU, newU; CalculateU(auxTripChain, out oldU, out newU); if (double.IsNegativeInfinity(oldU) | (newU > oldU)) { driver.AuxTripChains.Add(auxTripChain); auxTripChain.Attach("FacilitateTripMode", mode); } }
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); }
/// <summary> /// This is called before the start method as a way to pre-check that all of the parameters that are selected /// are in fact valid for this module. /// </summary> /// <param name="error">A string that should be assigned a detailed error</param> /// <returns>If the validation was successful or if there was a problem</returns> public bool RuntimeValidation(ref string error) { JointTripGenerator.ObsMode = ObservedMode; var ibd = Root.InputBaseDirectory; if (ibd == null) { error = "The model system's input base directory was null!"; return(false); } AutoType = Root.AutoType; if (SecondVehicleColumnNumber >= 0) { if (Root.VehicleTypes == null) { error = "In '" + Name + "' we were unable to get the alternative vehicle types for the secondary vehicle!"; return(false); } foreach (var vt in Root.VehicleTypes) { if (vt.VehicleName == SecondaryVehicleTypeName) { SecondaryType = vt; break; } } if (SecondaryType == null) { error = "Could not find vehicle type '" + SecondaryVehicleTypeName + "'."; return(false); } } if (CalculateJointTrips && !string.IsNullOrWhiteSpace(RideshareModeName)) { bool found = false; if (Root.SharedModes == null) { error = "In '" + Name + "' we were unable to access any Shared Modes inside of '" + Root.Name + "' Please either turn off rideshare's mode swap or fix the model system!"; return(false); } foreach (var sharedMode in Root.SharedModes) { if (sharedMode.ModeName == RideshareModeName) { Rideshare = sharedMode; found = true; break; } } if (!found) { error = "In '" + Name + "' we were unable to find a shared mode called '" + RideshareModeName + "' to use for rideshare"; return(false); } found = false; foreach (var nonSharedMode in Root.NonSharedModes) { if (nonSharedMode.ModeName == AutoModeName) { AutoMode = nonSharedMode; found = true; break; } } if (!found) { error = "In '" + Name + "' we were unable to find a non shared mode called '" + AutoModeName + "' to use replace with rideshare"; return(false); } found = false; foreach (var nonSharedMode in Root.AllModes) { if (nonSharedMode.ModeName == PassengerModeName) { PassengerMode = nonSharedMode; found = true; break; } } if (!found) { error = "In '" + Name + "' we were unable to find a non shared mode called '" + PassengerModeName + "' to use replace with rideshare"; return(false); } } return(true); }
/// <summary> /// Adds the auxiliary trip chain to the person if its Utility is greater than not including it /// </summary> /// <param name="driver">the driver</param> /// <param name="passenger">the passenger</param> /// <param name="trip1">aux trip 1</param> /// <param name="trip2">aux trip 2</param> /// <param name="facilitateTrip">the trip being facilitated</param> /// <param name="mode">the shared mode to assign</param> /// <param name="dropoff">is this a dropoff or pickup aux trip chain?</param> /// <param name="connectingTrip">what is the chain this aux trip chain connects to if any?</param> private void AddAuxTripChain(ITashaPerson driver, ITashaPerson passenger, ITrip trip1, ITrip trip2, ITrip facilitateTrip, ISharedMode mode, bool dropoff, ITrip connectingTrip) { ITripChain auxTripChain = new AuxiliaryTripChain(); auxTripChain.Attach( "SharedMode", mode ); auxTripChain.Attach( "FacilitateTrip", facilitateTrip ); trip1.TripChain = auxTripChain; trip2.TripChain = auxTripChain; auxTripChain.Trips.Add( trip1 ); auxTripChain.Trips.Add( trip2 ); auxTripChain.Person = driver; facilitateTrip.Attach( "isDriver", false ); if ( dropoff ) { trip1.Passengers.Add( passenger ); trip1.Attach( "isDriver", true ); } else { trip2.Passengers.Add( passenger ); trip2.Attach( "isDriver", true ); } if ( connectingTrip != null ) { auxTripChain.Attach( "ConnectingChain", connectingTrip ); } if ( dropoff ) { if ( connectingTrip == null ) { auxTripChain.Attach( "Purpose", Activity.DropoffAndReturn ); trip1.Purpose = Activity.FacilitatePassenger; trip2.Purpose = Activity.Home; } else if ( connectingTrip != null ) { auxTripChain.Attach( "Purpose", Activity.Dropoff ); auxTripChain.Attach( "OriginalPurpose", connectingTrip.Purpose ); trip1.Purpose = Activity.FacilitatePassenger; trip2.Purpose = connectingTrip.Purpose; //transfering feasible transit stations and such foreach ( var key in connectingTrip.Keys ) { trip1.Attach( key, connectingTrip[key] ); } } } else { if ( connectingTrip == null ) { auxTripChain.Attach( "Purpose", Activity.PickupAndReturn ); trip1.Purpose = Activity.FacilitatePassenger; trip2.Purpose = Activity.Home; } else if ( connectingTrip != null ) { ///TODO: Look into this again auxTripChain.Attach( "Purpose", Activity.Pickup ); auxTripChain.Attach( "OriginalPurpose", connectingTrip.Purpose ); trip1.Purpose = Activity.FacilitatePassenger; trip2.Purpose = Activity.Home; //transfering feasible transit stations and such foreach ( var key in connectingTrip.Keys ) { trip2.Attach( key, connectingTrip[key] ); } } } double oldU, newU; CalculateU( auxTripChain, out oldU, out newU ); if ( double.IsNegativeInfinity( oldU ) | ( newU > oldU ) ) { driver.AuxTripChains.Add( auxTripChain ); auxTripChain.Attach( "FacilitateTripMode", mode ); } }