示例#1
0
 public bool RuntimeValidation(ref string error)
 {
     if (!BaseYearTrips.CheckResourceType <List <ITripChain> >())
     {
         error = "In '" + this.Name + "' the resource for Base Year Trips was not of type List<ITripChain>!";
         return(false);
     }
     if (!BaseYearPopulation.CheckResourceType <SparseArray <float> >())
     {
         error = "In '" + this.Name + "' the resource for Base Year Population was not of type SparseArray<float>!";
         return(false);
     }
     ExternalTransit = new HashSet <ITashaMode>();
     foreach (var mode in this.Root.AllModes)
     {
         var modeName = mode.ModeName;
         if (ModeName == modeName)
         {
             PrimaryMode = mode;
         }
         if (ExternalTransitMode.Contains(modeName))
         {
             ExternalTransit.Add(mode);
         }
     }
     if (PrimaryMode == null)
     {
         error = "In '" + this.Name + "' we were unable to find a mode with the name '" + ModeName + "'!";
         return(false);
     }
     return(true);
 }
示例#2
0
 public bool RuntimeValidation(ref string error)
 {
     if (!BaseYearTrips.CheckResourceType <List <ITripChain> >())
     {
         error = "In '" + this.Name + "' the resource for Base Year Trips was not of type List<ITripChain>!";
         return(false);
     }
     if (!BaseYearPopulation.CheckResourceType <SparseArray <float> >())
     {
         error = "In '" + this.Name + "' the resource for Base Year Population was not of type SparseArray<float>!";
         return(false);
     }
     foreach (var mode in this.Root.AllModes)
     {
         if (ModeName == mode.ModeName)
         {
             Mode = mode;
         }
     }
     if (Mode == null)
     {
         error = "In '" + this.Name + "' we were unable to find a mode with the name '" + ModeName + "'!";
         return(false);
     }
     return(true);
 }
示例#3
0
 private ModeSet(ModeSet copyMe, double u)
 {
     Chain      = copyMe.Chain;
     Length     = copyMe.Length;
     ChosenMode = new ITashaMode[Length];
     Array.Copy(copyMe.ChosenMode, ChosenMode, copyMe.Length);
     U = u;
 }
示例#4
0
        private string GetVariableName(string modeName, string parameterName)
        {
            ITashaMode selectedMode = null;

            foreach (var mode in AllModes)
            {
                if (mode.ModeName == modeName)
                {
                    selectedMode = mode;
                    break;
                }
            }
            if (selectedMode == null)
            {
                throw new XTMFRuntimeException(this, "We were unable to find a mode with the name " + modeName + " while trying to load the parameters to estimate!");
            }
            // Search for a field or property that has an attribute with this name
            var modeType = selectedMode.GetType();

            foreach (var f in modeType.GetProperties())
            {
                // search the attributes
                var attributes = f.GetCustomAttributes(true);
                foreach (var at in attributes)
                {
                    // if we find an attribute from XTMF
                    ParameterAttribute parameter;
                    if ((parameter = (at as ParameterAttribute)) != null)
                    {
                        // Check to see if this is our parameter
                        if (parameter.Name == parameterName)
                        {
                            return(f.Name);
                        }
                    }
                }
            }
            foreach (var f in modeType.GetFields())
            {
                // search the attributes
                var attributes = f.GetCustomAttributes(true);
                foreach (var at in attributes)
                {
                    // if we find an attribute from XTMF
                    ParameterAttribute parameter;
                    if ((parameter = (at as ParameterAttribute)) != null)
                    {
                        // Check to see if this is our parameter
                        if (parameter.Name == parameterName)
                        {
                            return(f.Name);
                        }
                    }
                }
            }
            // If we get here then we did not find it!
            throw new XTMFRuntimeException(this, "We were unable to find a parameter with the name \"" + parameterName + "\" in the mode " + modeName);
        }
示例#5
0
        public void LoadData()
        {
            foreach (var mode in Root.AllModes)
            {
                if (mode.ModeName == TripModeName)
                {
                    this.TripMode = mode;
                    break;
                }
            }
            if (TripMode == null)
            {
                throw new XTMFRuntimeException("In '" + Name + "' we were unable to find a mode with the name '" + TripModeName + "'.");
            }
            // if the data has already been loaded we are done
            if (this.Data != null)
            {
                return;
            }
            var zones = this.Root.ZoneSystem.ZoneArray;
            List <AccessTourData> tours = new List <AccessTourData>();

            // we only need to load the data once so lets do that now
            using (CsvReader reader = new CsvReader(FileLocation))
            {
                //burn the header
                reader.LoadLine();
                // after that read in the rest of the lines
                int columns;
                while (reader.LoadLine(out columns))
                {
                    // if they have less than the number of columns we need, skip them
                    if (columns < 7)
                    {
                        continue;
                    }

                    tours.Add(new AccessTourData(
                                  // first origin
                                  GetZoneFromColumn(zones, reader, 0),
                                  // first destination
                                  GetZoneFromColumn(zones, reader, 1),
                                  // the time for the first trip
                                  GetTimeFromColumn(reader, 2),
                                  // second origin
                                  GetZoneFromColumn(zones, reader, 3),
                                  // second destination
                                  GetZoneFromColumn(zones, reader, 4),
                                  // the time for the second trip
                                  GetTimeFromColumn(reader, 5),
                                  // access station
                                  GetZoneFromColumn(zones, reader, 6)));
                }
            }
            this.Data = ConvertToursToTripChains(tours);
        }
示例#6
0
        private void AddToDictionary(Dictionary <ITashaMode, float> modeDictionary, ITashaMode mode, float toAdd)
        {
            float initialValue;

            if (!modeDictionary.TryGetValue(mode, out initialValue))
            {
                initialValue = 0;
            }
            modeDictionary[mode] = toAdd + initialValue;
        }
示例#7
0
 /// <summary>
 /// check to see if the mode being used for this trip is one that we are interested in.
 /// </summary>
 /// <returns></returns>
 private bool IsThisModeOneWeShouldCount(ITashaMode mode)
 {
     for (int i = 0; i < Modes.Length; i++)
     {
         if (Modes[i].Mode == mode)
         {
             return(true);
         }
     }
     return(false);
 }
示例#8
0
 private int UsesAccessMode(ITashaMode mode)
 {
     for (int i = 0; i < AccessModes.Length; i++)
     {
         if (AccessModes[i].Mode == mode)
         {
             return(i);
         }
     }
     return(-1);
 }
示例#9
0
 private int GetTripModeIndex(ITashaMode mode)
 {
     for (int i = 0; i < Modes.Length; i++)
     {
         if (mode == Modes[i])
         {
             return(i);
         }
     }
     return(-1);
 }
示例#10
0
 private int GetIndex(ITashaMode mode)
 {
     for (int i = 0; i < Modes.Length; i++)
     {
         if (Modes[i] == mode)
         {
             return(i);
         }
     }
     throw new XTMFRuntimeException(this, "In '" + Name + "' we were unable to find a mode called '" + mode.ModeName + "'");
 }
示例#11
0
文件: Trip.cs 项目: Cocotus/XTMF
 public Trip(ITripChain chain, IZone origin, IZone destination, Activity purpose, Time startTime, int householdIterations)
 {
     TripChain = chain;
     TripStartTime = startTime;
     OriginalZone = origin;
     DestinationZone = destination;
     Purpose = purpose;
     IntermediateZone = null;
     Passengers = new List<ITashaPerson>();
     ModesChosen = new ITashaMode[householdIterations];
 }
示例#12
0
文件: Trip.cs 项目: lunaxi7/XTMF
 public Trip(ITripChain chain, IZone origin, IZone destination, Activity purpose, Time startTime, int householdIterations)
 {
     TripChain        = chain;
     TripStartTime    = startTime;
     OriginalZone     = origin;
     DestinationZone  = destination;
     Purpose          = purpose;
     IntermediateZone = null;
     Passengers       = new List <ITashaPerson>();
     ModesChosen      = new ITashaMode[householdIterations];
 }
示例#13
0
        public static PurePassengerTrip MakeDriverTrip(IZone homeZone, ITashaMode mode, Time startTime, Time endTime)
        {
            PurePassengerTrip driverTrip = new PurePassengerTrip();

            driverTrip.Purpose           = Activity.FacilitatePassenger;
            driverTrip.OriginalZone      = driverTrip.DestinationZone = homeZone;
            driverTrip.Mode              = mode;
            driverTrip.ActivityStartTime = endTime;
            driverTrip.TripStartTime     = startTime;
            return(driverTrip);
        }
示例#14
0
 private bool UsesAccessMode(ITashaMode mode)
 {
     for (int i = 0; i < AccessModes.Length; i++)
     {
         if (AccessModes[i].Mode == mode)
         {
             return(true);
         }
     }
     return(false);
 }
示例#15
0
        public static PurePassengerTrip MakeDriverTrip(IZone HomeZone, ITashaMode mode, Time StartTime, Time EndTime)
        {
            PurePassengerTrip DriverTrip = new PurePassengerTrip();

            DriverTrip.Purpose           = Activity.FacilitatePassenger;
            DriverTrip.OriginalZone      = DriverTrip.DestinationZone = HomeZone;
            DriverTrip.Mode              = mode;
            DriverTrip.ActivityStartTime = EndTime;
            DriverTrip.TripStartTime     = StartTime;
            return(DriverTrip);
        }
示例#16
0
 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);
 }
示例#17
0
 private void LoadMode()
 {
     foreach (var mode in Root.AllModes)
     {
         if (mode.ModeName == OurModeName)
         {
             OurMode = mode;
             return;
         }
     }
     throw new XTMFRuntimeException("In '" + Name + "' we were unable to find a mode named '" + OurModeName + "'.");
 }
示例#18
0
 public bool RuntimeValidation(ref string error)
 {
     foreach (var mode in Root.AllModes)
     {
         if (mode.ModeName == ModeName)
         {
             Mode = mode;
             return(true);
         }
     }
     error = "In '" + Name + "' we were unable to find a mode called '" + ModeName + "'";
     return(false);
 }
示例#19
0
 public void IterationStarting(int iteration, int totalIterations)
 {
     WriteThisIteration = iteration == totalIterations - 1;
     if (WriteThisIteration)
     {
         ZoneSystem    = Root.ZoneSystem.ZoneArray;
         ZoneDistances = Root.ZoneSystem.Distances;
         AllModes      = Root.AllModes.ToArray();
         DAT           = AllModes.First(m => m.Name == DATName);
         Writer        = new StreamWriter(SaveTo);
         WriteHeader();
     }
 }
        public int GetIndexOfMode(ITashaMode mode)
        {
            var numberOfModes = AllModes.Count;

            for (int i = 0; i < numberOfModes; i++)
            {
                if (AllModes[i] == mode)
                {
                    return(i);
                }
            }
            return(-1);
        }
示例#21
0
        private bool UsesModeToCheck(ITashaMode mode)
        {
            var modes = ModesToCheck;

            for (int i = 0; i < modes.Length; i++)
            {
                if (modes[i].Mode == mode)
                {
                    return(true);
                }
            }
            return(false);
        }
 public bool RuntimeValidation(ref string error)
 {
     foreach (var network in Root.NetworkData)
     {
         if (network.NetworkType == AutoNetworkName)
         {
             _autoNetwork = network as INetworkData;
         }
         else if (network.NetworkType == TransitNetworkName)
         {
             _transitNetwork = network as ITripComponentData;
         }
     }
     if (_autoNetwork == null)
     {
         error = "In '" + Name + "' we were unable to find an auto network called '" + AutoNetworkName + "'";
         return(false);
     }
     if (_transitNetwork == null)
     {
         error = "In '" + Name + "' we were unable to find a transit network called '" + TransitNetworkName + "'";
         return(false);
     }
     foreach (var mode in Root.AllModes)
     {
         if (mode.ModeName == DATModeName)
         {
             _dat = mode;
             break;
         }
     }
     foreach (var mode in Root.AllModes)
     {
         if (mode.ModeName == PassengerModeName)
         {
             _passenger = mode;
             break;
         }
     }
     if (_dat == null)
     {
         error = "In '" + Name + "' we were unable to find a DAT mode called '" + DATModeName + "'";
         return(false);
     }
     if (_passenger == null)
     {
         error = "In '" + Name + "' we were unable to find a Passenger mode called '" + DATModeName + "'";
         return(false);
     }
     return(true);
 }
示例#23
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);
        }
示例#24
0
 public bool RuntimeValidation(ref string error)
 {
     foreach (var mode in Root.AllModes)
     {
         if (mode.ModeName == ModeName)
         {
             Mode = mode;
             break;
         }
     }
     if (Mode == null)
     {
         error = "In '" + Name + "' the mode named '" + ModeName + "' could not be found!";
         return(false);
     }
     return(true);
 }
示例#25
0
        public int GetIndexOfMode(ITashaMode mode)
        {
            if (AllModes == null)
            {
                return(-1);
            }
            var length = AllModes.Count;

            for (int i = 0; i < length; i++)
            {
                if (AllModes[i] == mode)
                {
                    return(i);
                }
            }
            return(-1);
        }
        private void AssignParameter(ITashaMode mode, string parameter, float value)
        {
            parameter = GetVariableName(mode, parameter);
            Type modeType  = mode.GetType();
            var  fieldInfo = modeType.GetField(parameter);

            if (fieldInfo != null)
            {
                fieldInfo.SetValue(mode, value);
                return;
            }
            var propertyInfo = modeType.GetProperty(parameter);

            if (propertyInfo != null)
            {
                propertyInfo.SetValue(mode, value, null);
            }
        }
示例#27
0
        private void CreateData(ITashaHousehold[] hhlds, ITashaMode mode, SparseTwinIndex <float> am, SparseTwinIndex <float> pm, SparseTwinIndex <float> ff)
        {
            var length = (float)hhlds.Length;

            Progress = 0;
            int count = 0;

            foreach (var household in hhlds)
            {
                foreach (var person in household.Persons)
                {
                    foreach (var tripChain in person.TripChains)
                    {
                        foreach (var trip in tripChain.Trips)
                        {
                            if (trip[ObservedModeAttachment] as IMode == mode)
                            {
                                var origin      = trip.OriginalZone.ZoneNumber;
                                var destination = trip.DestinationZone.ZoneNumber;

                                if (trip.TripStartTime < AMRushEnd && trip.TripStartTime > AMRushStart)
                                {
                                    am[origin, destination] += household.ExpansionFactor;
                                }
                                else if (trip.TripStartTime < PMRushEnd && trip.TripStartTime > PMRushStart)
                                {
                                    pm[origin, destination] += household.ExpansionFactor;
                                }
                                else
                                {
                                    ff[origin, destination] += household.ExpansionFactor;
                                }
                            }
                        }
                    }
                }
                Progress = count++ / length;
            }
        }
示例#28
0
        private void CreateData(ITashaHousehold[] hhlds, ITashaMode mode, SparseTwinIndex <float> AM, SparseTwinIndex <float> PM, SparseTwinIndex <float> FF)
        {
            var length = (float)hhlds.Length;

            this.Progress = 0;
            int count = 0;

            foreach (var household in hhlds)
            {
                foreach (var person in household.Persons)
                {
                    foreach (var TripChain in person.TripChains)
                    {
                        foreach (var Trip in TripChain.Trips)
                        {
                            if (Trip[ObservedModeAttachment] as IMode == mode)
                            {
                                var Origin      = Trip.OriginalZone.ZoneNumber;
                                var Destination = Trip.DestinationZone.ZoneNumber;

                                if (Trip.TripStartTime < AMRushEnd && Trip.TripStartTime > AMRushStart)
                                {
                                    AM[Origin, Destination] += household.ExpansionFactor;
                                }
                                else if (Trip.TripStartTime < PMRushEnd && Trip.TripStartTime > PMRushStart)
                                {
                                    PM[Origin, Destination] += household.ExpansionFactor;
                                }
                                else
                                {
                                    FF[Origin, Destination] += household.ExpansionFactor;
                                }
                            }
                        }
                    }
                }
                this.Progress = count++ / length;
            }
        }
            internal void AddTourData(ITashaMode dat, ITripChain chain, int replication, IZone accessStationZone,
                                      INetworkData autoNetwork, ITripComponentData transitNetwork, SparseArray <IZone> _zones)
            {
                bool first         = true;
                var  stnZoneNumber = accessStationZone.ZoneNumber;
                var  stnIndex      = _zones.GetFlatIndex(accessStationZone.ZoneNumber);

                foreach (var trip in chain.Trips)
                {
                    if (trip.Mode == dat)
                    {
                        if (!_tripData.TryGetValue(trip, out TripData data))
                        {
                            data = new TripData();
                        }
                        data.Add(first, stnZoneNumber, CalculateDATTime(_zones, autoNetwork, transitNetwork,
                                                                        (trip.Purpose == Activity.Home ? trip.TripStartTime : trip.ActivityStartTime)
                                                                        , trip.OriginalZone, stnIndex, trip.DestinationZone, first));
                        _tripData[trip] = data;
                        first           = false;
                    }
                }
            }
示例#30
0
        public void Execute(ITashaHousehold household, int iteration)
        {
            StringBuilder builder = Builder;

            if (builder == null)
            {
                Builder = builder = new StringBuilder();
            }
            foreach (var person in household.Persons)
            {
                float expansionFactor = person.ExpansionFactor;
                int   age             = person.Age;
                foreach (var tripChain in person.TripChains)
                {
                    for (int j = 0; j < tripChain.Trips.Count; j++)
                    {
                        var trip     = tripChain.Trips[j];
                        var nextTrip = j < tripChain.Trips.Count - 1 ? tripChain.Trips[j + 1] : null;
                        if (trip.ActivityStartTime > Time.EndOfDay && trip.Purpose != Activity.Home)
                        {
                            throw new XTMFRuntimeException(this, "PAST END OF DAY! " + trip.ActivityStartTime + "\r\n " + trip.Purpose + "\r\n " + "household ID is " + household.HouseholdId + " person ID is " + person.Id);
                        }
                        var householdIterations = (trip.ModesChosen == null || trip.ModesChosen.Length == 0) ? 1 : trip.ModesChosen.Length;
                        for (int i = 0; i < householdIterations; i++)
                        {
                            ITashaMode mode = (ITashaMode)trip[ObservedMode];
                            builder.Append(trip.TripChain.Person.Household.HouseholdId);
                            builder.Append(',');
                            builder.Append(trip.TripChain.Person.Id);
                            builder.Append(',');
                            builder.Append(trip.TripNumber);
                            builder.Append(',');
                            builder.Append(trip.TripStartTime);
                            builder.Append(',');
                            builder.Append(trip.ActivityStartTime);
                            builder.Append(',');
                            builder.Append((nextTrip != null ? nextTrip.TripStartTime - trip.ActivityStartTime : Time.Zero));
                            builder.Append(',');
                            builder.Append(trip.Purpose);
                            builder.Append(',');
                            builder.Append(age);
                            builder.Append(',');
                            builder.Append(trip.OriginalZone.ZoneNumber);
                            builder.Append(',');
                            builder.Append(trip.DestinationZone.ZoneNumber);
                            builder.Append(',');
                            builder.Append(IsObserved ? mode.ModeName : (trip.Mode?.ModeName));
                            builder.Append(',');
                            builder.Append((trip.ModesChosen == null || trip.ModesChosen.Length <= i || trip.ModesChosen[i] == null) ? "NONE" : trip.ModesChosen[i].ModeName);
                            builder.Append(',');
                            builder.Append(expansionFactor);
                            builder.Append(',');
                            builder.Append((trip.TripStartTime.Hours * 100 + (trip.TripStartTime.Minutes / 30) * 30));
                            builder.Append(',');
                            builder.Append(StraightLineDistance(trip.OriginalZone, trip.DestinationZone));
                            builder.Append(',');
                            builder.Append(ManhattanDistance(trip.OriginalZone, trip.DestinationZone));
                            builder.AppendLine();
                        }
                    }
                }
            }
            if (builder.Length > 0)
            {
                var  builderData = builder.ToString();
                bool taken       = false;
                lock (ModesChosen)
                {
                    WriteLock.Enter(ref taken);
                    ModesChosen.Write(builderData);
                    if (taken)
                    {
                        WriteLock.Exit(false);
                    }
                }
                builder.Clear();
            }
        }
示例#31
0
 private SchedulerTrip(int householdIterations)
 {
     Mode = null;
     ModesChosen = new ITashaMode[householdIterations];
 }
示例#32
0
 public static PurePassengerTrip MakeDriverTrip(IZone HomeZone, ITashaMode mode, Time StartTime, Time EndTime)
 {
     PurePassengerTrip DriverTrip = new PurePassengerTrip();
     DriverTrip.Purpose = Activity.FacilitatePassenger;
     DriverTrip.OriginalZone = DriverTrip.DestinationZone = HomeZone;
     DriverTrip.Mode = mode;
     DriverTrip.ActivityStartTime = EndTime;
     DriverTrip.TripStartTime = StartTime;
     return DriverTrip;
 }
示例#33
0
 public bool RuntimeValidation(ref string error)
 {
     foreach(var mode in Root.AllModes)
     {
         if(mode.ModeName == ModeName)
         {
             Mode = mode;
             return true;
         }
     }
     error = "In '" + Name + "' we were unable to find a mode called '" + ModeName + "'";
     return false;
 }
示例#34
0
 public int GetIndexOfMode(ITashaMode mode)
 {
     if(AllModes == null) return -1;
     var length = AllModes.Count;
     for(int i = 0; i < length; i++)
     {
         if(AllModes[i] == mode)
         {
             return i;
         }
     }
     return -1;
 }
示例#35
0
文件: Trip.cs 项目: Cocotus/XTMF
 public Trip(int householdIterations)
 {
     ModesChosen = new ITashaMode[householdIterations];
 }
示例#36
0
 public bool Pass1(ITashaMode[] modes)
 {
     var trips = TripChain.Trips;
     var tripData = TripData;
     for(int i = 0; i < tripData.Length; i++)
     {
         bool anyModeFeasible = false;
         ModeChoiceTripData currentTrip = tripData[i];
         for(int j = 0; j < modes.Length; j++)
         {
             // go through each non shared mode and if it is feasible get the V for that mode
             if(currentTrip.Feasible[j] = modes[j].Feasible(trips[i]))
             {
                 var value = (float)modes[j].CalculateV(trips[i]);
                 if(!(float.IsNaN(value) | float.IsInfinity(value)))
                 {
                     currentTrip.V[j] = value;
                     anyModeFeasible = true;
                 }
                 else
                 {
                     currentTrip.V[j] = float.NegativeInfinity;
                     currentTrip.Feasible[j] = false;
                 }
             }
             else
             {
                 currentTrip.V[j] = float.NegativeInfinity;
             }
         }
         if(!anyModeFeasible)
         {
             return false;
         }
     }
     ComputePossibleAssignments(modes);
     return PossibleAssignments.Count > 0;
 }
示例#37
0
 private int GetTripModeIndex(ITashaMode mode)
 {
     for (int i = 0; i < Modes.Length; i++)
     {
         if (mode == Modes[i])
         {
             return i;
         }
     }
     return -1;
 }
示例#38
0
 /// <summary>
 /// check to see if the mode being used for this trip is one that we are interested in.
 /// </summary>
 /// <param name="trip"></param>
 /// <returns></returns>
 private bool UsesMode(ITashaMode mode)
 {
     for(int i = 0; i < Modes.Length; i++)
     {
         if(Modes[i].Mode == mode)
         {
             return true;
         }
     }
     return false;
 }
示例#39
0
 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 int GetIndexOfMode(ITashaMode mode)
 {
     throw new NotImplementedException();
 }
示例#41
0
文件: Scheduler.cs 项目: Cocotus/XTMF
        /// <summary>
        /// Load the data we only need to get once
        /// </summary>
        public void LoadOneTimeLocalData()
        {
            if ( this.AlternativeTravelModeName != null && this.AlternativeTravelModeName != String.Empty )
            {
                var allModes = this.TashaRuntime.AllModes;
                bool found = false;
                foreach ( var mode in allModes )
                {
                    if ( mode.ModeName == this.AlternativeTravelModeName )
                    {
                        this.AlternativeTravelMode = mode;
                        found = true;
                        break;
                    }
                }
                if ( !found )
                {
                    throw new XTMFRuntimeException( "Unable to find the Alternative Travel Mode called " + this.AlternativeTravelModeName );
                }
            }
            Scheduler.LocalScheduler = this;
            Scheduler.Tasha = this.TashaRuntime;
            Scheduler.MinimumWorkingAge = this.MinWorkingAgeLocal;
            Scheduler.EpisodeSchedulingAttempts = this.EpisodeSchedulingAttemptsLocal;
            Scheduler.ActivityLevels = this.GetFullPath( this.ActivityLevelsLocal );
            Scheduler.SchoolMorningStart = this.SchoolMorningStartDateTime;
            Scheduler.SchoolMorningEnd = this.SchoolMorningEndDateTime;
            Scheduler.SchoolAfternoonStart = this.SchoolAfternoonStartDateTime;
            Scheduler.SchoolAfternoonEnd = this.SchoolAfternoonEndDateTime;
            Scheduler.SecondaryWorkThreshold = this.SecondaryWorkThresholdDateTime;
            Scheduler.StartTimeQuanta = this.StartTimeQuantaLocal;
            Scheduler.StartTimeQuantaInterval = (short)( ( 24 * 60 ) / Scheduler.StartTimeQuanta );
            Time.OneQuantum = this.MinimumDurationDateTime;
            Time.StartOfDay = new Time() { Hours = 4 };
            Time.EndOfDay = new Time() { Hours = 28 };
            Scheduler.PercentOverlapAllowed = this.PercentOverlapAllowedLocal;
            Scheduler.SecondaryWorkMinStartTime = this.SecondaryWorkMinStartTimeDateTime;
            Scheduler.MinPrimaryWorkDurationForReturnHomeFromWork = this.MinPrimaryWorkDurationForReturnHomeFromWorkDateTime;
            Scheduler.MaxPrimeWorkStartTimeForReturnHomeFromWork = this.MaxPrimeWorkStartTimeForReturnHomeFromWorkDateTime;
            Scheduler.ReturnHomeFromWorkMaxEndTime = this.ReturnHomeFromWorkMaxEndTimeDateTime;
            Scheduler.FullTimeActivity = this.FullTimeActivityDateTime;
            Scheduler.LocationChoiceModel = this.LocationChoiceModelLocal;
            Scheduler.LocationChoiceModel.LoadLocationChoiceCache();
            //Distributions
            Scheduler.AdultDistributionsFile = this.GetFullPath( this.AdultDistributionsFileLocal );
            Scheduler.FrequencyDistributionsFile = this.GetFullPath( this.FrequencyDistributionsFileLocal );
            Scheduler.NumberOfDistributions = this.NumberOfDistributionsLocal;
            Scheduler.NumberOfAdultFrequencies = this.NumberOfAdultFrequenciesLocal;
            Scheduler.NumberOfAdultDistributions = this.NumberOfAdultDistributionsLocal;

            Scheduler.MaxFrequency = this.MaxFrequencyLocal;
            Distribution.TashaRuntime = this.TashaRuntime;
            Distribution.InitializeDistributions();

            HouseholdExtender.TashaRuntime = this.TashaRuntime;
            // references in scheduler
            SchedulerHousehold.TashaRuntime = this.TashaRuntime;
            Schedule.Scheduler = this;
        }
示例#42
0
 private string GetVariableName(ITashaMode selectedMode, string parameterName)
 {
     // Search for a field or property that has an attribute with this name
     var modeType = selectedMode.GetType();
     foreach(var f in modeType.GetProperties())
     {
         // search the attributes
         var attributes = f.GetCustomAttributes(true);
         foreach(var at in attributes)
         {
             // if we find an attribute from XTMF
             ParameterAttribute parameter;
             if((parameter = ((at as ParameterAttribute))) != null)
             {
                 // Check to see if this is our parameter
                 if(parameter.Name == parameterName)
                 {
                     return f.Name;
                 }
             }
         }
     }
     foreach(var f in modeType.GetFields())
     {
         // search the attributes
         var attributes = f.GetCustomAttributes(true);
         foreach(var at in attributes)
         {
             // if we find an attribute from XTMF
             ParameterAttribute parameter;
             if((parameter = ((at as ParameterAttribute))) != null)
             {
                 // Check to see if this is our parameter
                 if(parameter.Name == parameterName)
                 {
                     return f.Name;
                 }
             }
         }
     }
     // If we get here then we did not find it!
     throw new XTMFRuntimeException("We were unable to find a parameter with the name \"" + parameterName + "\" in the mode " + selectedMode.ModeName);
 }
示例#43
0
        private void AddToDictionary(Dictionary<ITashaMode, float> modeDictionary, ITashaMode mode, float toAdd)
        {
            float initialValue;

            if(!modeDictionary.TryGetValue(mode, out initialValue ))
            {
                initialValue = 0;
            }
            modeDictionary[mode] = toAdd + initialValue;
        }
示例#44
0
 private void LoadMode()
 {
     foreach(var mode in Root.AllModes)
     {
         if(mode.ModeName == OurModeName)
         {
             OurMode = mode;
             return;
         }
     }
     throw new XTMFRuntimeException("In '" + Name + "' we were unable to find a mode named '" + OurModeName + "'.");
 }
示例#45
0
 public bool RuntimeValidation(ref string error)
 {
     if (!BaseYearTrips.CheckResourceType<List<ITripChain>>())
     {
         error = "In '" + this.Name + "' the resource for Base Year Trips was not of type List<ITripChain>!";
         return false;
     }
     if (!BaseYearPopulation.CheckResourceType<SparseArray<float>>())
     {
         error = "In '" + this.Name + "' the resource for Base Year Population was not of type SparseArray<float>!";
         return false;
     }
     foreach (var mode in this.Root.AllModes)
     {
         if (ModeName == mode.ModeName)
         {
             Mode = mode;
         }
     }
     if (Mode == null)
     {
         error = "In '" + this.Name + "' we were unable to find a mode with the name '" + ModeName + "'!";
         return false;
     }
     return true;
 }
示例#46
0
 private void ComputePossibleAssignments(ITashaMode[] modes)
 {
     var possibleAssignments = PossibleAssignments;
     var topLevel = TripData.Length - 1;
     int level = 0;
     int mode = 0;
     var trips = TripChain.Trips;
     int chainLength = trips.Count;
     ITrip currentTrip = trips[0];
     int[] possibleSolution;
     ITourDependentMode[] tourDependentModes;
     if((possibleSolution = PossibleSolution) == null || possibleSolution.Length < chainLength)
     {
         PossibleSolution = possibleSolution = new int[chainLength];
     }
     if((tourDependentModes = TourDependentModes) == null)
     {
         tourDependentModes = TourDependentModes = new ITourDependentMode[modes.Length];
         for(int i = 0; i < tourDependentModes.Length; i++)
         {
             tourDependentModes[i] = modes[i] as ITourDependentMode;
         }
     }
     while(level != -1)
     {
         for(; mode < modes.Length; mode++)
         {
             // For each feasible mode
             var currentData = TripData[level];
             if(currentData.Feasible[mode])
             {
                 // find the total utility
                 // store the mode into our set and chain
                 currentTrip.Mode = modes[mode];
                 possibleSolution[level] = mode;
                 // if we are at the end, store the set
                 if(level >= topLevel)
                 {
                     bool feasible = true;
                     TourData tourData = null;
                     // make sure this chain is allowed
                     for(int j = 0; j < modes.Length; j++)
                     {
                         // if this doesn't work don't save it
                         if(!modes[j].Feasible(TripChain))
                         {
                             feasible = false;
                             break;
                         }
                     }
                     // if the modes think it is allowed calculate the tour level data
                     if(feasible)
                     {
                         for(int i = 0; i < chainLength; i++)
                         {
                             if(tourDependentModes[possibleSolution[i]] != null)
                             {
                                 float tourUtility;
                                 Action<ITripChain> onSelection;
                                 if(tourDependentModes[possibleSolution[i]].CalculateTourDependentUtility(TripChain, i, out tourUtility, out onSelection))
                                 {
                                     if(tourData == null)
                                     {
                                         tourData = new TourData(new float[chainLength], new Action<ITripChain>[chainLength]);
                                     }
                                     tourData.TourUtilityModifiers[i] = tourUtility;
                                     tourData.OnSolution[i] = onSelection;
                                 }
                                 else
                                 {
                                     feasible = false;
                                     break;
                                 }
                             }
                         }
                     }
                     // if the tour level data thinks it is allowed, then it works and we can add it
                     if(feasible)
                     {
                         possibleAssignments.Add(new PossibleTripChainSolution(TripData, possibleSolution, tourData));
                     }
                 }
                 else
                 {
                     // otherwise go to the next trip
                     level++;
                     currentTrip = trips[level];
                     mode = -1;
                     continue;
                 }
             }
         }
         level--;
         if(level >= 0)
         {
             mode = possibleSolution[level] + 1;
             currentTrip = trips[level];
         }
     }
 }
示例#47
0
 public int GetIndexOfMode(ITashaMode mode)
 {
     throw new NotImplementedException();
 }
示例#48
0
        private void CreateData(ITashaHousehold[] hhlds, ITashaMode mode, SparseTwinIndex<float> AM, SparseTwinIndex<float> PM, SparseTwinIndex<float> FF)
        {
            var length = (float)hhlds.Length;
            this.Progress = 0;
            int count = 0;
            foreach ( var household in hhlds )
            {
                foreach ( var person in household.Persons )
                {
                    foreach ( var TripChain in person.TripChains )
                    {
                        foreach ( var Trip in TripChain.Trips )
                        {
                            if ( Trip[ObservedModeAttachment] as IMode == mode )
                            {
                                var Origin = Trip.OriginalZone.ZoneNumber;
                                var Destination = Trip.DestinationZone.ZoneNumber;

                                if ( Trip.TripStartTime < AMRushEnd && Trip.TripStartTime > AMRushStart )
                                {
                                    AM[Origin, Destination] += household.ExpansionFactor;
                                }
                                else if ( Trip.TripStartTime < PMRushEnd && Trip.TripStartTime > PMRushStart )
                                {
                                    PM[Origin, Destination] += household.ExpansionFactor;
                                }
                                else
                                {
                                    FF[Origin, Destination] += household.ExpansionFactor;
                                }
                            }
                        }
                    }
                }
                this.Progress = count++ / length;
            }
        }