Exemplo n.º 1
0
 public UnAssignedModeSet(ITripChain chain, ModeSet mSet, IVehicleType vehicleType)
     : this()
 {
     Chain       = chain;
     Set         = mSet;
     VehicleType = vehicleType;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Calculates and stores the best trip chain for
        /// each type of vehicle (and NPV)
        /// </summary>
        /// <param name="chain">The chain to calculate</param>
        public static void SelectBestPerVehicleType(this ITripChain chain)
        {
            ModeSet[] best = chain["BestForVehicle"] as ModeSet[];
            var       sets = ModeSet.GetModeSets(chain);

            if (best == null)
            {
                best = new ModeSet[TashaRuntime.VehicleTypes.Count + 1];
                chain.Attach("BestForVehicle", best);
            }
            for (int i = 0; i < best.Length; i++)
            {
                best[i] = null;
            }
            foreach (var set in sets)
            {
                IVehicleType type = null;
                foreach (var mode in set.ChosenMode)
                {
                    if (mode.RequiresVehicle != null)
                    {
                        type = mode.RequiresVehicle;
                        break;
                    }
                }
                int index = TashaRuntime.VehicleTypes.IndexOf(type);
                best[index + 1] = (best[index + 1] == null || best[index + 1].U < set.U) ? set : best[index + 1];
            }
        }
Exemplo n.º 3
0
 public void Recycle()
 {
     this.VehicleType = null;
     this.Release();
     if (Vehicles.Count < 100)
     {
         Vehicle.Vehicles.Add(this);
     }
 }
Exemplo n.º 4
0
 public static Vehicle MakeVehicle(IVehicleType type)
 {
     if (Vehicles.TryTake(out Vehicle v))
     {
         v.VehicleType = type;
         return(v);
     }
     return(new Vehicle(type));
 }
Exemplo n.º 5
0
        /// <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)
        {
            var householdFile = System.IO.Path.Combine(this.TashaRuntime.InputBaseDirectory, this.FileName);

            this.AutoType = this.TashaRuntime.AutoType;
            try
            {
                if (!System.IO.File.Exists(householdFile))
                {
                    error = String.Concat("The file ", householdFile, " does not exist!");
                    return(false);
                }
            }
            catch
            {
                error = String.Concat("We were unable to access ", householdFile, " the path may be invalid or unavailable at this time.");
                return(false);
            }
            if (this.FilterPassenger)
            {
                try
                {
                    foreach (var mode in this.TashaRuntime.AllModes)
                    {
                        if (mode.ModeName == this.PassengerName)
                        {
                            this.Passenger = mode;
                            return(true);
                        }
                    }
                }
                catch
                {
                    foreach (var mode in this.TashaRuntime.SharedModes)
                    {
                        if (mode.ModeName == this.PassengerName)
                        {
                            this.Passenger = mode;
                            return(true);
                        }
                    }
                }
                error = "We did not find any shared mode named " + this.PassengerName + " to filter with!";
                return(false);
            }
            return(true);
        }
Exemplo n.º 6
0
 private void FirstPass(ITashaPerson person, IVehicleType primaryVehicle, int[] eventCount)
 {
     foreach (var tripChain in person.TripChains)
     {
         if (tripChain.JointTrip)
         {
             foreach (var trip in tripChain.Trips)
             {
                 int id = -1;
                 if (((trip.Purpose == Activity.JointOther) | (trip.Purpose == Activity.JointMarket)) & tripChain.JointTripRep)
                 {
                     id = Distribution.GetDistributionID(person.Household, trip.Purpose);
                 }
                 else if (tripChain.JointTripRep || !((trip.Purpose == Activity.JointOther) | (trip.Purpose == Activity.JointMarket)))
                 {
                     id = Distribution.GetDistributionID(person, trip.Purpose);
                 }
                 if (id != -1)
                 {
                     CheckForZero(person, id, trip.Purpose);
                     eventCount[id]++;
                 }
             }
         }
         else
         {
             foreach (var trip in tripChain.Trips)
             {
                 if (!IsWorkTrip(trip.Purpose))
                 {
                     var id = Distribution.GetDistributionID(person, trip.Purpose);
                     if (id != -1)
                     {
                         CheckForZero(person, id, trip.Purpose);
                         eventCount[id]++;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
 /// <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)
 {
     this.AutoType = this.TashaRuntime.AutoType;
     return true;
 }
Exemplo n.º 8
0
 private Vehicle(IVehicleType type)
 {
     this.VehicleType = type;
 }
Exemplo n.º 9
0
        public static void FindPossibleAssignments(List <Pair <IVehicleType[], double> > possibleAssignments,
                                                   List <ITripChain> chains,
                                                   List <IVehicle> vehicles,
                                                   int position,
                                                   List <UnAssignedModeSet> currentChains,
                                                   IVehicleType[] currentAssignment,
                                                   double currentU)
        {
            ModeSet[] sets = (ModeSet[])chains[position]["BestForVehicle"];
            if (sets == null)
            {
                return;
            }
            var numberOfVehicleTypes = ModeChoice.VehicleTypes.Count + 1;

            for (int j = 0; j < numberOfVehicleTypes; j++)  //take into account NPV
            {
                ModeSet set = sets[j];
                //if this vehicle cannot be used for this set skip it since we are already considering NPV
                if ((set != null) && (set.ChosenMode != null))
                {
                    //a Personal vehicle mode
                    if (j > 0)
                    {
                        UnAssignedModeSet        newUms = new UnAssignedModeSet(chains[position], set, set.ChosenMode[0].RequiresVehicle);
                        List <UnAssignedModeSet> allChainsWithSameVehicle = currentChains.FindAll(n => n.VehicleType == newUms.VehicleType);
                        List <ITripChain>        sameVehicleChains        = new List <ITripChain>();
                        foreach (var ums in allChainsWithSameVehicle)
                        {
                            sameVehicleChains.Add(ums.GetChainWithAssignedModes());
                        }
                        int count          = vehicles.Count(n => n.VehicleType.Equals(newUms.VehicleType));
                        var availabilities = HouseholdExtender.FindVehicleAvailabilites(sameVehicleChains, count);
                        foreach (var ums in allChainsWithSameVehicle)
                        {
                            ums.ResetChain();
                        }
                        ITripChain curChain = newUms.GetChainWithAssignedModes();
                        var        span     = new TashaTimeSpan(curChain.StartTime, curChain.EndTime);
                        newUms.ResetChain();
                        if (HouseholdExtender.VehicleAvailableInTimeSpan(availabilities, span, count))
                        {
                            currentAssignment[position] = newUms.VehicleType;
                            currentChains.Add(newUms);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    double newU = currentU + set.U;
                    if (position + 1 == chains.Count)
                    {   //end of the line
                        IVehicleType[] nextAssignment = new IVehicleType[chains.Count];
                        currentAssignment.CopyTo(nextAssignment, 0);
                        possibleAssignments.Add(new Pair <IVehicleType[], double>(nextAssignment, newU));
                    }
                    else
                    {
                        IVehicleType[] nextAssignment = new IVehicleType[chains.Count];
                        currentAssignment.CopyTo(nextAssignment, 0);
                        FindPossibleAssignments(possibleAssignments, chains, vehicles, position + 1, new List <UnAssignedModeSet>(currentChains), nextAssignment, newU);
                    }
                }
            }
        }
Exemplo n.º 10
0
 /// <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 ) );
 }
Exemplo n.º 11
0
        /// <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);
        }
Exemplo n.º 12
0
        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;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Gets all the trip chains and auxiliary trip chains that use the specified vehicle
        /// </summary>
        /// <param name="household"></param>
        /// <param name="vehicle"></param>
        /// <returns></returns>
        public static List <ITripChain> AllTripChainsWithAuxThatUseVehicle(this ITashaHousehold household, IVehicleType vehicle)
        {
            List <ITripChain> trips = new List <ITripChain>();

            //flatten households trips
            foreach (var p in household.Persons)
            {
                foreach (var tc in p.TripChains)
                {
                    if (tc.requiresVehicle.Contains(vehicle))
                    {
                        trips.Add(tc);
                    }
                }
                foreach (var tc in p.AuxTripChains)
                {
                    if (tc.requiresVehicle.Contains(vehicle))
                    {
                        trips.Add(tc);
                    }
                }
            }

            return(trips);
        }
Exemplo n.º 14
0
 /// <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));
 }
Exemplo n.º 15
0
 /// <summary>
 /// Returns a dictionary of time spans indicating at which time the # of vehicles not in use
 /// </summary>
 /// <param name="h"></param>
 /// <param name="vehicleType"></param>
 /// <returns></returns>
 public static Dictionary <TashaTimeSpan, int> FindVehicleAvailabilites(this ITashaHousehold h, IVehicleType vehicleType, bool includeAuxTripChains)
 {
     return(FindVehicleAvailabilitesHelper(h, vehicleType, includeAuxTripChains));
 }
Exemplo n.º 16
0
        public static int NumberOfVehicleAvailable(List <ITripChain> tripChains, int numVehicles, IVehicleType vehicleType, TashaTimeSpan span)
        {
            Dictionary <TashaTimeSpan, int> availabilities = FindVehicleAvailabilites(tripChains, numVehicles);
            int available = numVehicles;

            foreach (var a in availabilities)
            {
                if ((a.Key.Start < span.End) && (a.Key.End > span.Start))
                {
                    if (a.Value < available)
                    {
                        available = a.Value;
                    }
                }
            }
            return(available);
        }
Exemplo n.º 17
0
 private Vehicle(IVehicleType type)
 {
     VehicleType = type;
 }
Exemplo n.º 18
0
 private Vehicle(IVehicleType type)
 {
     this.VehicleType = type;
 }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 20
0
 public static Vehicle MakeVehicle(IVehicleType type)
 {
     Vehicle v;
     if ( Vehicle.Vehicles.TryTake( out v ) )
     {
         v.VehicleType = type;
         return v;
     }
     return new Vehicle( type );
 }
Exemplo n.º 21
0
 public static TashaVehicle MakeVehicle(IVehicleType type)
 {
     return new TashaVehicle( type );
 }
Exemplo n.º 22
0
 public void Recycle()
 {
     this.VehicleType = null;
     this.Release();
     if(Vehicles.Count < 100)
     {
         Vehicle.Vehicles.Add(this);
     }
 }
Exemplo n.º 23
0
Arquivo: Auto.cs Projeto: Cocotus/XTMF
        /// <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)
        {
            // if our deep ancestor is in fact a tasha runtime
            this.TashaRuntime = this.Root as ITashaRuntime;
            IList<INetworkData> networks;
            if(this.TashaRuntime == null)
            {
                // check for a 4Step model system template
                var tdm = this.Root as ITravelDemandModel;
                // if it isn't report the error
                if(tdm == null)
                {
                    error = "The Tasha.Modes.Auto Module only works with ITashaRuntime's and ITravelDemandModel's!";
                    return false;
                }
                networks = tdm.NetworkData;
            }
            else
            {
                if(String.IsNullOrWhiteSpace(this.VehicleTypeName))
                {
                    this.AutoType = this.TashaRuntime.AutoType;
                }
                else
                {
                    if(this.TashaRuntime.VehicleTypes != null)
                    {
                        foreach(var v in this.TashaRuntime.VehicleTypes)
                        {
                            if(v.VehicleName == this.VehicleTypeName)
                            {
                                this.AutoType = v;
                                break;
                            }
                        }
                    }
                }
                if(AutoType == null)
                {
                    error = "We were unable to find an vehicle type to use for '" + this.ModeName + "'!";
                    return false;
                }
                networks = this.TashaRuntime.NetworkData;
            }
            if(String.IsNullOrWhiteSpace(this.NetworkType))
            {
                error = "There was no network type selected for the " + (String.IsNullOrWhiteSpace(this.ModeName) ? "Auto" : this.ModeName) + " mode!";
                return false;
            }
            if(networks == null)
            {
                error = "There was no Auto Network loaded for the Auto Mode!";
                return false;
            }
            bool found = false;
            foreach(var network in networks)
            {
                if(network.NetworkType == this.NetworkType)
                {
                    this.AutoData = network;
                    found = true;
                    break;
                }
            }
            if(!found)
            {
                error = "In '" + Name + "' we were unable to find the network data with the name \"" + this.NetworkType + "\" in this Model System!";
                return false;
            }

            return true;
        }
Exemplo n.º 24
0
        /// <summary>
        /// Gets the number of vehicles available in the household for the given timespan
        /// </summary>
        /// <param name="h"></param>
        /// <param name="span"></param>
        /// <param name="vehicleType"></param>
        /// <param name="includeAuxTripChains"></param>
        /// <returns></returns>
        public static int NumberOfVehicleAvailable(this ITashaHousehold h, TashaTimeSpan span, IVehicleType vehicleType, bool includeAuxTripChains)
        {
            Dictionary <TashaTimeSpan, int> availabilities = h.FindVehicleAvailabilites(vehicleType, includeAuxTripChains);
            var vehicles  = h.Vehicles;
            int available = 0;

            for (int i = 0; i < vehicles.Length; i++)
            {
                if (vehicles[i].VehicleType == vehicleType)
                {
                    available++;
                }
            }
            foreach (var a in availabilities)
            {
                if ((a.Key.Start < span.End) && (a.Key.End > span.Start))
                {
                    // this is strictly less than since we want the min of the vehicles
                    if (a.Value < available)
                    {
                        available = a.Value;
                    }
                }
            }
            return(available);
        }
Exemplo n.º 25
0
 private TashaVehicle(IVehicleType type)
 {
     VehicleType = type;
 }
Exemplo n.º 26
0
        /// <summary>
        /// Returns a list of Timespans and the associated number of vehicles in that time span
        /// </summary>
        /// <param name="h"></param>
        /// <param name="vehicleType"></param>
        /// <param name="aux"></param>
        /// <returns></returns>
        private static Dictionary <TashaTimeSpan, int> FindVehicleAvailabilitesHelper(ITashaHousehold h, IVehicleType vehicleType, bool aux)
        {
            Dictionary <TashaTimeSpan, int> availabilities = new Dictionary <TashaTimeSpan, int>();
            List <ITripChain> allTripChains;

            if (aux)
            {
                allTripChains = h.AllTripChainsWithAuxThatUseVehicle(vehicleType);
            }
            else
            {
                allTripChains = h.AllTripChainsThatUseVehicle(vehicleType);
            }
            int vehiclesAvailable = 0;
            var vehicles          = h.Vehicles;

            for (int i = 0; i < vehicles.Length; i++)
            {
                if (vehicles[i].VehicleType == vehicleType)
                {
                    vehiclesAvailable++;
                }
            }
            return(FindVehicleAvailabilites(allTripChains, vehiclesAvailable));
        }
Exemplo n.º 27
0
 /// <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)
 {
     this.AutoType = this.TashaRuntime.AutoType;
     return(true);
 }
Exemplo n.º 28
0
 private TashaVehicle(IVehicleType type)
 {
     this.VehicleType = type;
 }
Exemplo n.º 29
0
 private TashaVehicle(IVehicleType type)
 {
     this.VehicleType = type;
 }
Exemplo n.º 30
0
        /// <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)
        {
            // if our deep ancestor is in fact a tasha runtime
            this.TashaRuntime = this.Root as ITashaRuntime;
            IList <INetworkData> networks;

            if (this.TashaRuntime == null)
            {
                // check for a 4Step model system template
                var tdm = this.Root as ITravelDemandModel;
                // if it isn't report the error
                if (tdm == null)
                {
                    error = "The Tasha.Modes.Auto Module only works with ITashaRuntime's and ITravelDemandModel's!";
                    return(false);
                }
                networks = tdm.NetworkData;
            }
            else
            {
                if (String.IsNullOrWhiteSpace(this.VehicleTypeName))
                {
                    this.AutoType = this.TashaRuntime.AutoType;
                }
                else
                {
                    if (this.TashaRuntime.VehicleTypes != null)
                    {
                        foreach (var v in this.TashaRuntime.VehicleTypes)
                        {
                            if (v.VehicleName == this.VehicleTypeName)
                            {
                                this.AutoType = v;
                                break;
                            }
                        }
                    }
                }
                if (AutoType == null)
                {
                    error = "We were unable to find an vehicle type to use for '" + this.ModeName + "'!";
                    return(false);
                }
                networks = this.TashaRuntime.NetworkData;
            }
            if (String.IsNullOrWhiteSpace(this.NetworkType))
            {
                error = "There was no network type selected for the " + (String.IsNullOrWhiteSpace(this.ModeName) ? "Auto" : this.ModeName) + " mode!";
                return(false);
            }
            if (networks == null)
            {
                error = "There was no Auto Network loaded for the Auto Mode!";
                return(false);
            }
            bool found = false;

            foreach (var network in networks)
            {
                if (network.NetworkType == this.NetworkType)
                {
                    this.AutoData = network;
                    found         = true;
                    break;
                }
            }
            if (!found)
            {
                error = "In '" + Name + "' we were unable to find the network data with the name \"" + this.NetworkType + "\" in this Model System!";
                return(false);
            }

            return(true);
        }
Exemplo n.º 31
0
 public static TashaVehicle MakeVehicle(IVehicleType type)
 {
     return(new TashaVehicle(type));
 }
Exemplo n.º 32
0
 /// <summary>
 /// Assigns the best mode to each trip in the trip chain for use in pass 3. (Conflict Vers.)
 /// </summary>
 /// <param name="household">Household to work on</param>
 /// <param name="bestAssignment">The current (after pass 2) best vehicle assignment</param>
 private void AssignBestMode(ITashaHousehold household, IVehicleType[] bestAssignment)
 {
     int i = 0;
     foreach ( var person in household.Persons )
     {
         foreach ( var tripChain in person.TripChains )
         {
             ModeSet[] sets = (ModeSet[])tripChain["BestForVehicle"];
             ModeSet set = sets[this.VehicleTypes.IndexOf( bestAssignment[i++] ) + 1];
             if ( set != null )
             {
                 var numberOfTrips = tripChain.Trips.Count;
                 for ( int j = 0; j < numberOfTrips; j++ )
                 {
                     tripChain.Trips[j].Mode = set.ChosenMode[j];
                 }
             }
         }
     }
 }
Exemplo n.º 33
0
        private RentalReceipt RentItem_CheckArguments(RentalRequest rentalRequest, IVehicleType vehicleType)
        {
            if (vehicleType == null)
            {
                return new RentalReceipt()
                {
                    Status = ERentalRequestStatus.NotOk,
                    Message = string.Format("The vehicle type {0} does not exist.", rentalRequest.VehicleTypeName)
                };
            }

            if (string.IsNullOrEmpty(rentalRequest.RegNo))
            {
                return new RentalReceipt()
                {
                    Status = ERentalRequestStatus.NotOk,
                    Message = "RegNo can not be empty."
                };
            }

            if (string.IsNullOrEmpty(rentalRequest.CustomerInfo.PersonNummer))
            {
                return new RentalReceipt()
                {
                    Status = ERentalRequestStatus.NotOk,
                    Message = "PersonNummer can not be empty."
                };
            }

            if (rentalRequest.CurrentMilageKm < 0)
            {
                return new RentalReceipt()
                {
                    Status = ERentalRequestStatus.NotOk,
                    Message = "Milage can not be < 0 km."
                };
            }

            if (_rentalsRepository.VehicleIsOutForRent(rentalRequest.RegNo))
            {
                return new RentalReceipt()
                {
                    Status = ERentalRequestStatus.NotOk,
                    Message = string.Format("Vehicle with RegNo {0} can not be rented as it is already out for rent.", rentalRequest.RegNo)
                };
            }

            return new RentalReceipt() { Status = ERentalRequestStatus.Ok };
        }