Beispiel #1
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);
        }
        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
                }
            }
        }