Ejemplo n.º 1
0
        private static void AssignFeasibility(ITashaHousehold household)
        {
            //loop through each trip in the household and assign all possible auxiliary trips
            var modes          = TashaRuntime.SharedModes;
            var nonSharedModes = TashaRuntime.NonSharedModes.Count;
            var modesLength    = modes.Count;
            // clear out all of the aux trip chains to begin with
            var persons = household.Persons;

            for (int i = 0; i < persons.Length; i++)
            {
                persons[i].AuxTripChains.Clear();
            }
            for (int i = 0; i < persons.Length; i++)
            {
                var tripChains = persons[i].TripChains;
                for (int j = 0; j < tripChains.Count; j++)
                {
                    var trips = tripChains[j].Trips;
                    for (int k = 0; k < trips.Count; k++)
                    {
                        ModeData md = ModeData.Get(trips[k]);   //get the mode data saved on the object
                        for (int l = 0; l < modesLength; l++)
                        {
                            if (!(md.Feasible[l + nonSharedModes] = modes[l].Feasible(trips[k])))
                            {
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        internal void RecalculateU()
        {
            int    tripPlace     = 0;
            double NewU          = 0;
            var    numberOfModes = ModeChoice.NonSharedModes.Count;

            if (this.Chain == null || this.Chain.Trips == null)
            {
                return;
            }
            foreach (var trip in this.Chain.Trips)
            {
                var data = ModeData.Get(trip);
                for (int mode = 0; mode < numberOfModes; mode++)
                {
                    if (ModeChoice.NonSharedModes[mode] == this.ChosenMode[tripPlace])
                    {
                        NewU += data.U(mode);
                        break;
                    }
                }
                tripPlace++;
            }
            this.U = NewU;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generates all feasible sets of modes for the trip chain
        /// </summary>
        /// <param name="chain">The chain to operate on</param>
        public static void GenerateModeSets(this ITripChain chain)
        {
            //initiates the mode set
            ModeSet.InitModeSets(chain);
            ModeData[] data = new ModeData[chain.Trips.Count];
            // Generate the random terms
            var trips = chain.Trips;

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = ModeData.Get(trips[i]);
                if (data[i] != null)
                {
                    data[i].GenerateError();
                }
            }
            ModeSet set = ModeSet.Make(chain);

            // launch the recursive version to explore all sets
            GenerateModeSets(chain, data, set);

            //clear temp var 'mode' that was used in generate mode set algo
            foreach (var trip in chain.Trips)
            {
                trip.Mode = null;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Calculate the non random part of the utility for the trip
        /// For each mode
        /// </summary>
        /// <param name="trip">The trip to work on</param>
        public static bool CalculateVTrip(this ITrip trip)
        {
            ModeData data = ModeData.MakeModeData();

            //initializes mode set
            data.Store(trip);
            bool feasible      = false;
            var  modes         = TashaRuntime.NonSharedModes;
            int  numberOfModes = modes.Count;

            for (int i = 0; i < numberOfModes; i++)
            {
                // start processing the next mode number
                if (!(data.Feasible[i] = modes[i].Feasible(trip)))
                {
                    continue;
                }
                feasible  = true;
                data.V[i] = modes[i].CalculateV(trip);
            }
            // This will generate the error for all of the modes
            // including the shared modes
            data.GenerateError();
            return(feasible);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Goes through the data and regenerates the random components for utility
 /// </summary>
 /// <param name="household"></param>
 public static void UpdateUtilities(this ITashaHousehold household)
 {
     foreach (var p in household.Persons)
     {
         foreach (var chain in p.TripChains)
         {
             foreach (var trip in chain.Trips)
             {
                 ModeData.Get(trip).GenerateError();
             }
             foreach (var modeSet in ModeSet.GetModeSets(chain))
             {
                 modeSet.RecalculateU();
             }
             chain.SelectBestPerVehicleType();
         }
     }
 }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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
                }
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Get all of the V's for this trip, one for each mode.
 /// </summary>
 /// <param name="trip">The trip to get this from</param>
 /// <returns>An array of V's for each mode</returns>
 public static double[] GetV(this ITrip trip)
 {
     return(ModeData.Get(trip).V);
 }