Exemple #1
0
 /// <summary>
 /// Adds the auxiliary trip chain to the person if enough vehicles are available
 /// </summary>
 /// <param name="household"></param>
 /// <param name="optimalSets"></param>
 private void AddPassengerTrips(ITashaHousehold household, Dictionary <ITashaPerson, List <ITripChain> > optimalSets)
 {
     foreach (var optSet in optimalSets)
     {
         ITashaPerson      person     = optSet.Key;
         List <ITripChain> optimalSet = optSet.Value;
         if (person.AuxTripChains == null)
         {
             person.AuxTripChains = new List <ITripChain>(5);
         }
         else
         {
             person.AuxTripChains.Clear();
         }
         var length = optimalSet.Count;
         for (int i = 0; i < length; i++)
         {
             var vehicles       = optimalSet[i].RequiresVehicle;
             var vehiclesLength = vehicles.Count;
             for (int j = 0; j < vehiclesLength; j++)
             {
                 if (household.NumberOfVehicleAvailable(new TashaTimeSpan(optimalSet[i].StartTime, optimalSet[i].EndTime), vehicles[j], true) > 0)
                 {
                     person.AuxTripChains.Add(optimalSet[i]);
                 }
             }
         }
     }
 }
        public static void AssignJointTours(ITashaHousehold household)
        {
            Dictionary <int, List <ITripChain> > JointTours = household.JointTours;
            ITashaMode rideShare      = null;
            int        rideShareIndex = -1;
            var        allModes       = TashaRuntime.AllModes;
            var        numberOfModes  = allModes.Count;

            for (int i = 0; i < numberOfModes; i++)
            {
                if ((allModes[i] is ISharedMode) && allModes[i].ModeName == "RideShare")
                {
                    rideShare      = allModes[i];
                    rideShareIndex = i;
                }
            }
            //no rideshare mode?
            if (rideShare == null)
            {
                return;
            }
            //go through each joint tour and assign identical modes for each tripchain in a tour if possible
            foreach (var element in JointTours)
            {
                List <ITripChain> tripChains = element.Value;
                //does a non vehicle tour exist
                bool nonVehicleTour = BestNonVehicleModeSetForTour(tripChains, out IList <ITashaMode> nonVehicleModesChosen, out double nonVehicleU);
                //the potential driver in this tour
                ITashaPerson potentialDriver = null;
                //finding potential driver who already has the car
                foreach (var tripChain in tripChains)
                {
                    if (tripChain.RequiresVehicle.Contains(rideShare.RequiresVehicle))
                    {
                        potentialDriver = tripChain.Person;
                        break;
                    }
                }
                //if no one has the car check if one is available
                if (potentialDriver == null)
                {
                    if (household.NumberOfVehicleAvailable(
                            new TashaTimeSpan(tripChains[0].StartTime, tripChains[0].EndTime), rideShare.RequiresVehicle, false) > 0)
                    {
                        foreach (var tc in tripChains)
                        {
                            if (rideShare.RequiresVehicle.CanUse(tc.Person))
                            {
                                potentialDriver = tc.Person;
                                break;
                            }
                        }
                    }
                }
                //No potential driver and no nonVehicle tour means that ppl in this tour have to take different modes which shouldnt happen
                if ((potentialDriver == null) & (!nonVehicleTour))
                {
                    continue;
                }
                double oldU = Double.MinValue;
                if (nonVehicleTour)
                {
                    oldU = nonVehicleU;
                }
                //no driver, go to next tour
                if (potentialDriver == null)
                {
                    continue;
                }
                double newU    = 0.0;
                bool   success = true;

                /*
                 * Now we assign the rideshare mode and if the total U of everyone using rideshare is less than that
                 * of a non personal vehicle mode, everyone uses rideshare
                 *
                 */
                foreach (var tripChain in tripChains)
                {
                    foreach (var trip in tripChain.Trips)
                    {
                        ModeData md = (ModeData)trip.GetVariable("MD");
                        trip.Mode = rideShare;
                        trip.CalculateVTrip();
                        newU += md.U(rideShareIndex);
                    }
                    if (!tripChain.Feasible())
                    {
                        success = false;
                        break;
                    }
                }
                //reset modes
                if ((!success || newU <= oldU) & (nonVehicleTour))
                {
                    SetModes(tripChains, nonVehicleModesChosen);
                    //go to next joint trip
                }
            }
        }
 /// <summary>
 /// Gets if the requested vehicle is available (Excluding auxiliary trips)
 /// </summary>
 /// <param name="veqType"></param>
 /// <param name="start"></param>
 /// <param name="end"></param>
 /// <param name="hh"></param>
 /// <returns></returns>
 public int numVehiclesAvailable(IVehicleType veqType, Time start, Time end, ITashaHousehold hh)
 {
     return ( hh.NumberOfVehicleAvailable( new TashaTimeSpan( start, end ), veqType, false ) );
 }
 /// <summary>
 /// Gets if the requested vehicle is available (Excluding auxiliary trips)
 /// </summary>
 /// <param name="veqType"></param>
 /// <param name="start"></param>
 /// <param name="end"></param>
 /// <param name="hh"></param>
 /// <returns></returns>
 public int numVehiclesAvailable(IVehicleType veqType, Time start, Time end, ITashaHousehold hh)
 {
     return(hh.NumberOfVehicleAvailable(new TashaTimeSpan(start, end), veqType, false));
 }
 public void AssignJointTours(ITashaHousehold household)
 {
     ITashaMode rideShare = null;
     int rideShareIndex = -1;
     var allModes = this.Root.AllModes;
     var numberOfModes = allModes.Count;
     for ( int i = 0; i < numberOfModes; i++ )
     {
         if ( ( allModes[i] is ISharedMode ) && allModes[i].ModeName == "RideShare" )
         {
             rideShare = allModes[i];
             rideShareIndex = i;
         }
     }
     //no rideshare mode?
     if ( rideShare == null )
     {
         return;
     }
     //go through each joint tour and assign identical modes for each tripchain in a tour if possible
     foreach ( var element in household.JointTours )
     {
         List<ITripChain> tripChains = element.Value;
         IList<ITashaMode> nonVehicleModesChosen;
         double nonVehicleU;
         //does a non vehicle tour exist
         bool nonVehicleTour = BestNonVehicleModeSetForTour( tripChains, out nonVehicleModesChosen, out nonVehicleU );
         //the potential driver in this tour
         ITashaPerson potentialDriver = null;
         //finding potential driver who already has the car
         foreach ( var tripChain in tripChains )
         {
             if ( tripChain.requiresVehicle.Contains( rideShare.RequiresVehicle ) )
             {
                 potentialDriver = tripChain.Person;
                 break;
             }
         }
         //if no one has the car check if one is available
         if ( potentialDriver == null )
         {
             if ( household.NumberOfVehicleAvailable(
                 new TashaTimeSpan( tripChains[0].StartTime, tripChains[0].EndTime ), rideShare.RequiresVehicle, false ) > 0 )
             {
                 foreach ( var tc in tripChains )
                 {
                     if ( rideShare.RequiresVehicle.CanUse( tc.Person ) )
                     {
                         potentialDriver = tc.Person;
                         break;
                     }
                 }
             }
         }
         //No potential driver and no nonVehicle tour means that ppl in this tour have to take different modes which shouldnt happen
         if ( ( potentialDriver == null ) & ( !nonVehicleTour ) )
         {
             continue;
         }
         double oldU = Double.MinValue;
         if ( nonVehicleTour )
         {
             oldU = nonVehicleU;
         }
         //no driver, go to next tour
         if ( potentialDriver == null )
         {
             continue;
         }
         double newU = 0.0;
         bool success = true;
         /*
          * Now we assign the rideshare mode and if the total U of everyone using rideshare is less than that
          * of a non personal vehicle mode, everyone uses rideshare
          *
          */
         foreach ( var tripChain in tripChains )
         {
             foreach ( var trip in tripChain.Trips )
             {
                 ModeData md = (ModeData)trip.GetVariable( "MD" );
                 trip.Mode = rideShare;
                 trip.CalculateVTrip();
                 newU += md.U( rideShareIndex );
             }
             if ( !tripChain.Feasible() )
             {
                 success = false;
                 break;
             }
         }
         //reset modes
         if ( ( !success || newU <= oldU ) & ( nonVehicleTour ) )
         {
             SetModes( tripChains, nonVehicleModesChosen );
             //go to next joint trip
             continue;
         }
     }
 }